1 #ifndef __TIDY_BUFFIO_H__
2 #define __TIDY_BUFFIO_H__
4 /** @file buffio.h - Treat buffer as an I/O stream.
6 (c) 1998-2007 (W3C) MIT, ERCIM, Keio University
7 See tidy.h for the copyright notice.
9 Requires buffer to automatically grow as bytes are added.
10 Must keep track of current read and write points.
21 /** TidyBuffer - A chunk of memory */
25 TidyAllocator* allocator; /**< Memory allocator */
26 byte* bp; /**< Pointer to bytes */
27 uint size; /**< # bytes currently in use */
28 uint allocated; /**< # bytes allocated */
29 uint next; /**< Offset of current input position */
32 /** Initialize data structure using the default allocator */
33 TIDY_EXPORT void TIDY_CALL tidyBufInit( TidyBuffer* buf );
35 /** Initialize data structure using the given custom allocator */
36 TIDY_EXPORT void TIDY_CALL tidyBufInitWithAllocator( TidyBuffer* buf, TidyAllocator* allocator );
38 /** Free current buffer, allocate given amount, reset input pointer,
39 use the default allocator */
40 TIDY_EXPORT void TIDY_CALL tidyBufAlloc( TidyBuffer* buf, uint allocSize );
42 /** Free current buffer, allocate given amount, reset input pointer,
43 use the given custom allocator */
44 TIDY_EXPORT void TIDY_CALL tidyBufAllocWithAllocator( TidyBuffer* buf,
45 TidyAllocator* allocator,
48 /** Expand buffer to given size.
49 ** Chunk size is minimum growth. Pass 0 for default of 256 bytes.
51 TIDY_EXPORT void TIDY_CALL tidyBufCheckAlloc( TidyBuffer* buf,
52 uint allocSize, uint chunkSize );
54 /** Free current contents and zero out */
55 TIDY_EXPORT void TIDY_CALL tidyBufFree( TidyBuffer* buf );
57 /** Set buffer bytes to 0 */
58 TIDY_EXPORT void TIDY_CALL tidyBufClear( TidyBuffer* buf );
60 /** Attach to existing buffer */
61 TIDY_EXPORT void TIDY_CALL tidyBufAttach( TidyBuffer* buf, byte* bp, uint size );
63 /** Detach from buffer. Caller must free. */
64 TIDY_EXPORT void TIDY_CALL tidyBufDetach( TidyBuffer* buf );
67 /** Append bytes to buffer. Expand if necessary. */
68 TIDY_EXPORT void TIDY_CALL tidyBufAppend( TidyBuffer* buf, void* vp, uint size );
70 /** Append one byte to buffer. Expand if necessary. */
71 TIDY_EXPORT void TIDY_CALL tidyBufPutByte( TidyBuffer* buf, byte bv );
73 /** Get byte from end of buffer */
74 TIDY_EXPORT int TIDY_CALL tidyBufPopByte( TidyBuffer* buf );
77 /** Get byte from front of buffer. Increment input offset. */
78 TIDY_EXPORT int TIDY_CALL tidyBufGetByte( TidyBuffer* buf );
80 /** At end of buffer? */
81 TIDY_EXPORT Bool TIDY_CALL tidyBufEndOfInput( TidyBuffer* buf );
83 /** Put a byte back into the buffer. Decrement input offset. */
84 TIDY_EXPORT void TIDY_CALL tidyBufUngetByte( TidyBuffer* buf, byte bv );
91 /* Forward declarations
94 /** Initialize a buffer input source */
95 TIDY_EXPORT void TIDY_CALL tidyInitInputBuffer( TidyInputSource* inp, TidyBuffer* buf );
97 /** Initialize a buffer output sink */
98 TIDY_EXPORT void TIDY_CALL tidyInitOutputBuffer( TidyOutputSink* outp, TidyBuffer* buf );
103 #endif /* __TIDY_BUFFIO_H__ */
108 * indent-tabs-mode: nil
110 * eval: (c-set-offset 'substatement-open 0)