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/01 17:52:20 $ 
00013     $Revision: 1.8 $ 
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 /** Zero out data structure */
00039 TIDY_EXPORT void TIDY_CALL tidyBufInit( TidyBuffer* buf );
00040 
00041 /** Zero out data structure, use 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 TIDY_EXPORT void TIDY_CALL tidyBufAlloc( TidyBuffer* buf, uint allocSize );
00046 
00047 /** Free current buffer, allocate given amount, reset input pointer,
00048     use given custom allocator */
00049 TIDY_EXPORT void TIDY_CALL tidyBufAllocWithAllocator( TidyBuffer* buf,
00050                                                       TidyAllocator* allocator,
00051                                                       uint allocSize );
00052 
00053 /** Expand buffer to given size. 
00054 **  Chunk size is minimum growth. Pass 0 for default of 256 bytes.
00055 */
00056 TIDY_EXPORT void TIDY_CALL tidyBufCheckAlloc( TidyBuffer* buf,
00057                                               uint allocSize, uint chunkSize );
00058 
00059 /** Free current contents and zero out */
00060 TIDY_EXPORT void TIDY_CALL tidyBufFree( TidyBuffer* buf );
00061 
00062 /** Set buffer bytes to 0 */
00063 TIDY_EXPORT void TIDY_CALL tidyBufClear( TidyBuffer* buf );
00064 
00065 /** Attach to existing buffer */
00066 TIDY_EXPORT void TIDY_CALL tidyBufAttach( TidyBuffer* buf, byte* bp, uint size );
00067 
00068 /** Detach from buffer.  Caller must free. */
00069 TIDY_EXPORT void TIDY_CALL tidyBufDetach( TidyBuffer* buf );
00070 
00071 
00072 /** Append bytes to buffer.  Expand if necessary. */
00073 TIDY_EXPORT void TIDY_CALL tidyBufAppend( TidyBuffer* buf, void* vp, uint size );
00074 
00075 /** Append one byte to buffer.  Expand if necessary. */
00076 TIDY_EXPORT void TIDY_CALL tidyBufPutByte( TidyBuffer* buf, byte bv );
00077 
00078 /** Get byte from end of buffer */
00079 TIDY_EXPORT int TIDY_CALL  tidyBufPopByte( TidyBuffer* buf );
00080 
00081 
00082 /** Get byte from front of buffer.  Increment input offset. */
00083 TIDY_EXPORT int TIDY_CALL  tidyBufGetByte( TidyBuffer* buf );
00084 
00085 /** At end of buffer? */
00086 TIDY_EXPORT Bool TIDY_CALL tidyBufEndOfInput( TidyBuffer* buf );
00087 
00088 /** Put a byte back into the buffer.  Decrement input offset. */
00089 TIDY_EXPORT void TIDY_CALL tidyBufUngetByte( TidyBuffer* buf, byte bv );
00090 
00091 
00092 /**************
00093    TIDY
00094 **************/
00095 
00096 /* Forward declarations
00097 */
00098 
00099 /** Initialize a buffer input source */
00100 TIDY_EXPORT void TIDY_CALL tidyInitInputBuffer( TidyInputSource* inp, TidyBuffer* buf );
00101 
00102 /** Initialize a buffer output sink */
00103 TIDY_EXPORT void TIDY_CALL tidyInitOutputBuffer( TidyOutputSink* outp, TidyBuffer* buf );
00104 
00105 #ifdef __cplusplus
00106 }
00107 #endif
00108 #endif /* __TIDY_BUFFIO_H__ */
00109 
00110 /*
00111  * local variables:
00112  * mode: c
00113  * indent-tabs-mode: nil
00114  * c-basic-offset: 4
00115  * eval: (c-set-offset 'substatement-open 0)
00116  * end:
00117  */

Generated on Tue Jan 23 10:43:44 2007 for HTML Tidy by  doxygen 1.5.1