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