|
NCBI Home IEB Home C Toolkit docs C++ Toolkit source browser C Toolkit source browser (2) |
NCBI C Toolkit Cross ReferenceC/connect/ncbi_buffer.h |
source navigation diff markup identifier search freetext search file search |
1 #ifndef CONNECT___NCBI_BUFFER__H
2 #define CONNECT___NCBI_BUFFER__H
3
4 /* $Id: ncbi_buffer.h,v 6.12 2007/05/22 11:25:57 kazimird Exp $
5 * ===========================================================================
6 *
7 * PUBLIC DOMAIN NOTICE
8 * National Center for Biotechnology Information
9 *
10 * This software/database is a "United States Government Work" under the
11 * terms of the United States Copyright Act. It was written as part of
12 * the author's official duties as a United States Government employee and
13 * thus cannot be copyrighted. This software/database is freely available
14 * to the public for use. The National Library of Medicine and the U.S.
15 * Government have not placed any restriction on its use or reproduction.
16 *
17 * Although all reasonable efforts have been taken to ensure the accuracy
18 * and reliability of the software and data, the NLM and the U.S.
19 * Government do not and cannot warrant the performance or results that
20 * may be obtained by using this software or data. The NLM and the U.S.
21 * Government disclaim all warranties, express or implied, including
22 * warranties of performance, merchantability or fitness for any particular
23 * purpose.
24 *
25 * Please cite the author in any work or product based on this material.
26 *
27 * ===========================================================================
28 *
29 * Author: Denis Vakatov
30 *
31 * File Description:
32 * Memory-resident FIFO storage area (to be used e.g. in I/O buffering)
33 *
34 * Handle: BUF
35 *
36 * Functions:
37 * BUF_SetChunkSize
38 * BUF_Size
39 * BUF_Prepend
40 * BUF_Append
41 * BUF_Write
42 * BUF_PushBack
43 * BUF_Peek
44 * BUF_PeekAt
45 * BUF_PeekAtCB
46 * BUF_Read
47 * BUF_Erase
48 * BUF_Destroy
49 *
50 */
51
52 #if defined(NCBIBUF__H)
53 # error "<ncbibuf.h> and <ncbi_buffer.h> must never be #include'd together"
54 #endif
55
56 #include <connect/connect_export.h>
57 #include <stddef.h> /* ...to define "size_t"... */
58
59
60 /** @addtogroup BuffServices
61 *
62 * @{
63 */
64
65
66 #ifdef __cplusplus
67 extern "C" {
68 #endif
69
70
71 struct BUF_tag;
72 typedef struct BUF_tag* BUF; /* handle of a buffer */
73
74
75 /*!
76 * Set minimal size of a buffer memory chunk.
77 * Return the actually set chunk size on success; zero on error
78 * NOTE: if "*pBuf" == NULL then create it
79 * if "chunk_size" is passed 0 then set it to BUF_DEF_CHUNK_SIZE
80 */
81 #define BUF_DEF_CHUNK_SIZE 1024
82 extern NCBI_XCONNECT_EXPORT size_t BUF_SetChunkSize
83 (BUF* pBuf,
84 size_t chunk_size
85 );
86
87
88 /*!
89 * Return the number of bytes stored in "buf".
90 * NOTE: return 0 if "buf" == NULL
91 */
92 extern NCBI_XCONNECT_EXPORT size_t BUF_Size(BUF buf);
93
94
95 /*!
96 * Prepend a block of data (of the specified size) to the
97 * beginning of the buffer (to be read first). Note that unlike
98 * BUF_Pushback(), in this call the data is not copied into the buffer
99 * but instead is just linked in from the original location.
100 * Return non-zero (true) if succeeded, zero (false) if failed.
101 */
102 extern NCBI_XCONNECT_EXPORT int/*bool*/ BUF_Prepend
103 (BUF* pBuf,
104 const void* data,
105 size_t size
106 );
107
108
109 /*!
110 * Append a block of data (of the specified size) past the end
111 * of the buffer (to be read last). Note that unlike
112 * BUF_Write(), in this call the data is not copied to the buffer
113 * but instead is just linked in from the original location.
114 * Return non-zero (true) if succeeded, zero (false) if failed.
115 */
116 extern NCBI_XCONNECT_EXPORT int/*bool*/ BUF_Append
117 (BUF* pBuf,
118 const void* data,
119 size_t size
120 );
121
122
123 /*!
124 * Add new data to the end of "*pBuf" (to be read last).
125 * On error (failed memory allocation), return zero value.
126 * NOTE: if "*pBuf" == NULL then create it.
127 */
128 extern NCBI_XCONNECT_EXPORT /*bool*/int BUF_Write
129 (BUF* pBuf,
130 const void* data,
131 size_t size
132 );
133
134
135 /*!
136 * Write the data to the very beginning of "*pBuf" (to be read first).
137 * On error (failed memory allocation), return zero value.
138 * NOTE: if "*pBuf" == NULL then create it.
139 */
140 extern NCBI_XCONNECT_EXPORT /*bool*/int BUF_PushBack
141 (BUF* pBuf,
142 const void* data,
143 size_t size
144 );
145
146
147 /*!
148 * Equivalent to "BUF_PeekAt(buf, 0, data, size)", see description below.
149 */
150 extern NCBI_XCONNECT_EXPORT size_t BUF_Peek
151 (BUF buf,
152 void* data,
153 size_t size
154 );
155
156
157 /*!
158 * Copy up to "size" bytes stored in "buf" (starting at position "pos")
159 * to "data".
160 * Return the # of copied bytes (can be less than "size").
161 * Return zero and do nothing if "buf" is NULL or "pos" >= BUF_Size(buf).
162 * Do nothing and return min(BUF_Size(buf)-pos, size) if "data" is NULL.
163 */
164 extern NCBI_XCONNECT_EXPORT size_t BUF_PeekAt
165 (BUF buf,
166 size_t pos,
167 void* data,
168 size_t size
169 );
170
171
172 /*!
173 * Call "callback" on up to "size" bytes stored in "buf" (starting at position
174 * "pos"), each chunk separately. Pass data as opaque parameter to callback.
175 * Return the # of processed bytes (can be less than "size").
176 * Return zero and do nothing if "buf" is NULL or "pos" >= BUF_Size(buf).
177 * Do nothing and return min(BUF_Size(buf)-pos, size) if "callback" is NULL.
178 */
179 extern NCBI_XCONNECT_EXPORT size_t BUF_PeekAtCB
180 (BUF buf,
181 size_t pos,
182 void (*callback)(void*, void*, size_t),
183 void* data,
184 size_t size
185 );
186
187
188 /*!
189 * Copy up to "size" bytes stored in "buf" to "data" and remove
190 * copied data from the "buf".
191 * Return the # of copied-and/or-removed bytes(can be less than "size")
192 * NOTE: if "buf" == NULL then do nothing and return 0
193 * if "data" == NULL then do not copy data anywhere(still, remove it)
194 */
195 extern NCBI_XCONNECT_EXPORT size_t BUF_Read
196 (BUF buf,
197 void* data,
198 size_t size
199 );
200
201
202 /*!
203 * Make the buffer empty.
204 */
205 extern NCBI_XCONNECT_EXPORT void BUF_Erase(BUF buf);
206
207
208 /*!
209 * Destroy all internal data.
210 * NOTE: do nothing if "buf" == NULL
211 */
212 extern NCBI_XCONNECT_EXPORT void BUF_Destroy(BUF buf);
213
214
215 #ifdef __cplusplus
216 }
217 #endif
218
219
220 /* @} */
221
222 #endif /* CONNECT___NCBI_BUFFER__H */
223 |
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more information. |