• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

ut_bytebuf.h

Go to the documentation of this file.
00001 /* AbiSource Program Utilities
00002  * Copyright (C) 1998 AbiSource, Inc.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017  * 02110-1301 USA.
00018  */
00019 
00020 
00021 
00022 #ifndef UT_BYTEBUF_H
00023 #define UT_BYTEBUF_H
00024 
00025 /*****************************************************************
00026 ** A buffer class which can grow and shrink
00027 *****************************************************************/
00028 
00029 #include <stdio.h>
00030 #include <gsf/gsf-input.h>
00031 
00032 /* pre-emptive dismissal; ut_types.h is needed by just about everything,
00033  * so even if it's commented out in-file that's still a lot of work for
00034  * the preprocessor to do...
00035  */
00036 #ifndef UT_TYPES_H
00037 #include "ut_types.h"
00038 #endif
00039 
00040 /* sigh... total hack here. Solaris does the following in unistd.h
00041  * #define truncate truncate64
00042  * I really hate/fear this kind of interaction of preprocessor and
00043  * C++ method name.
00044  * Anyway, I'm going to redefine truncate here; make sure to include
00045  * this file *after* unistd.h, however... - fjf
00046  */
00047 #ifndef abi_std_truncate
00048 #define abi_std_truncate truncate
00049 #endif
00050 #ifdef truncate
00051 #undef truncate
00052 #endif
00053 
00054 class ABI_EXPORT UT_ByteBuf
00055 {
00056 public:
00057     UT_ByteBuf(UT_uint32 iChunk = 0);
00058     ~UT_ByteBuf();
00059 
00060     bool                append(const UT_Byte * pValue, UT_uint32 length);
00061     bool                ins(UT_uint32 position, const UT_Byte * pValue, UT_uint32 length);
00062     bool                ins(UT_uint32 position, UT_uint32 length);
00063     bool                del(UT_uint32 position, UT_uint32 amount);
00064     bool                overwrite(UT_uint32 position, const UT_Byte * pValue, UT_uint32 length);
00065     void                truncate(UT_uint32 position);
00066     UT_uint32           getLength(void) const;
00067     const UT_Byte *     getPointer(UT_uint32 position) const;               /* temporary use only */
00068     bool                writeToFile(const char* pszFileName) const;
00069     bool                writeToURI(const char* pszURI) const;
00070     bool                insertFromFile(UT_uint32 iPosition, const char* pszFilename);
00071     bool                            insertFromURI(UT_uint32 iPosition, const char* pszURI);
00072     bool                            insertFromInput(UT_uint32 iPosition, GsfInput * fp);
00073     bool                insertFromFile(UT_uint32 iPosition, FILE * fp);
00074 private:
00075     bool                _byteBuf(UT_uint32 spaceNeeded);
00076 
00077     UT_Byte *           m_pBuf;
00078     UT_uint32           m_iSize;            /* amount currently used */
00079     UT_uint32           m_iSpace;           /* space currently allocated */
00080     UT_uint32           m_iChunk;           /* unit for g_try_realloc */
00081 };
00082 
00083 #endif /* UT_BYTEBUF_H */

Generated on Mon May 20 2013 for AbiWord by  doxygen 1.7.1