HTML Tidy  0.1
buffio.h
Go to the documentation of this file.
00001 #ifndef __TIDY_BUFFIO_H__
00002 #define __TIDY_BUFFIO_H__
00003 
00004 /** @file buffio.h - Treat buffer as an I/O stream.
00005 
00006   (c) 1998-2007 (W3C) MIT, ERCIM, Keio University
00007   See tidy.h for the copyright notice.
00008 
00009   Requires buffer to automatically grow as bytes are added.
00010   Must keep track of current read and write points.
00011 
00012 */
00013 
00014 #include "platform.h"
00015 #include "tidy.h"
00016 
00017 #ifdef __cplusplus
00018 extern "C" {
00019 #endif
00020 
00021 /** TidyBuffer - A chunk of memory */
00022 TIDY_STRUCT
00023 struct _TidyBuffer 
00024 {
00025     TidyAllocator* allocator;  /**< Memory allocator */
00026     byte* bp;           /**< Pointer to bytes */
00027     uint  size;         /**< # bytes currently in use */
00028     uint  allocated;    /**< # bytes allocated */ 
00029     uint  next;         /**< Offset of current input position */
00030 };
00031 
00032 /** Initialize data structure using the default allocator */
00033 TIDY_EXPORT void TIDY_CALL tidyBufInit( TidyBuffer* buf );
00034 
00035 /** Initialize data structure using the given custom allocator */
00036 TIDY_EXPORT void TIDY_CALL tidyBufInitWithAllocator( TidyBuffer* buf, TidyAllocator* allocator );
00037 
00038 /** Free current buffer, allocate given amount, reset input pointer,
00039     use the default allocator */
00040 TIDY_EXPORT void TIDY_CALL tidyBufAlloc( TidyBuffer* buf, uint allocSize );
00041 
00042 /** Free current buffer, allocate given amount, reset input pointer,
00043     use the given custom allocator */
00044 TIDY_EXPORT void TIDY_CALL tidyBufAllocWithAllocator( TidyBuffer* buf,
00045                                                       TidyAllocator* allocator,
00046                                                       uint allocSize );
00047 
00048 /** Expand buffer to given size. 
00049 **  Chunk size is minimum growth. Pass 0 for default of 256 bytes.
00050 */
00051 TIDY_EXPORT void TIDY_CALL tidyBufCheckAlloc( TidyBuffer* buf,
00052                                               uint allocSize, uint chunkSize );
00053 
00054 /** Free current contents and zero out */
00055 TIDY_EXPORT void TIDY_CALL tidyBufFree( TidyBuffer* buf );
00056 
00057 /** Set buffer bytes to 0 */
00058 TIDY_EXPORT void TIDY_CALL tidyBufClear( TidyBuffer* buf );
00059 
00060 /** Attach to existing buffer */
00061 TIDY_EXPORT void TIDY_CALL tidyBufAttach( TidyBuffer* buf, byte* bp, uint size );
00062 
00063 /** Detach from buffer.  Caller must free. */
00064 TIDY_EXPORT void TIDY_CALL tidyBufDetach( TidyBuffer* buf );
00065 
00066 
00067 /** Append bytes to buffer.  Expand if necessary. */
00068 TIDY_EXPORT void TIDY_CALL tidyBufAppend( TidyBuffer* buf, void* vp, uint size );
00069 
00070 /** Append one byte to buffer.  Expand if necessary. */
00071 TIDY_EXPORT void TIDY_CALL tidyBufPutByte( TidyBuffer* buf, byte bv );
00072 
00073 /** Get byte from end of buffer */
00074 TIDY_EXPORT int TIDY_CALL  tidyBufPopByte( TidyBuffer* buf );
00075 
00076 
00077 /** Get byte from front of buffer.  Increment input offset. */
00078 TIDY_EXPORT int TIDY_CALL  tidyBufGetByte( TidyBuffer* buf );
00079 
00080 /** At end of buffer? */
00081 TIDY_EXPORT Bool TIDY_CALL tidyBufEndOfInput( TidyBuffer* buf );
00082 
00083 /** Put a byte back into the buffer.  Decrement input offset. */
00084 TIDY_EXPORT void TIDY_CALL tidyBufUngetByte( TidyBuffer* buf, byte bv );
00085 
00086 
00087 /**************
00088    TIDY
00089 **************/
00090 
00091 /* Forward declarations
00092 */
00093 
00094 /** Initialize a buffer input source */
00095 TIDY_EXPORT void TIDY_CALL tidyInitInputBuffer( TidyInputSource* inp, TidyBuffer* buf );
00096 
00097 /** Initialize a buffer output sink */
00098 TIDY_EXPORT void TIDY_CALL tidyInitOutputBuffer( TidyOutputSink* outp, TidyBuffer* buf );
00099 
00100 #ifdef __cplusplus
00101 }
00102 #endif
00103 #endif /* __TIDY_BUFFIO_H__ */
00104 
00105 /*
00106  * local variables:
00107  * mode: c
00108  * indent-tabs-mode: nil
00109  * c-basic-offset: 4
00110  * eval: (c-set-offset 'substatement-open 0)
00111  * end:
00112  */