1 /* AbiSource Program Utilities 2 * Copyright (C) 1998 AbiSource, Inc. 3 * 4 * This program is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU General Public License 6 * as published by the Free Software Foundation; either version 2 7 * of the License, or (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 17 * 02110-1301 USA. 18 */ 19 20 21 22 #ifndef UT_BYTEBUF_H 23 #define UT_BYTEBUF_H 24 25 /***************************************************************** 26 ** A buffer class which can grow and shrink 27 *****************************************************************/ 28 29 #include <stdio.h> 30 #include <gsf/gsf-input.h> 31 32 /* pre-emptive dismissal; ut_types.h is needed by just about everything, 33 * so even if it's commented out in-file that's still a lot of work for 34 * the preprocessor to do... 35 */ 36 #ifndef UT_TYPES_H 37 #include "ut_types.h" 38 #endif 39 40 /* sigh... total hack here. Solaris does the following in unistd.h 41 * #define truncate truncate64 42 * I really hate/fear this kind of interaction of preprocessor and 43 * C++ method name. 44 * Anyway, I'm going to redefine truncate here; make sure to include 45 * this file *after* unistd.h, however... - fjf 46 */ 47 #ifndef abi_std_truncate 48 #define abi_std_truncate truncate 49 #endif 50 #ifdef truncate 51 #undef truncate 52 #endif 53 54 class ABI_EXPORT UT_ByteBuf 55 { 56 public: 57 UT_ByteBuf(UT_uint32 iChunk = 0); 58 ~UT_ByteBuf(); 59 60 bool append(const UT_Byte * pValue, UT_uint32 length); 61 bool ins(UT_uint32 position, const UT_Byte * pValue, UT_uint32 length); 62 bool ins(UT_uint32 position, UT_uint32 length); 63 bool del(UT_uint32 position, UT_uint32 amount); 64 bool overwrite(UT_uint32 position, const UT_Byte * pValue, UT_uint32 length); 65 void truncate(UT_uint32 position); 66 UT_uint32 getLength(void) const; 67 const UT_Byte * getPointer(UT_uint32 position) const; /* temporary use only */ 68 bool writeToFile(const char* pszFileName) const; 69 bool writeToURI(const char* pszURI) const; 70 bool insertFromFile(UT_uint32 iPosition, const char* pszFilename); 71 bool insertFromURI(UT_uint32 iPosition, const char* pszURI); 72 bool insertFromInput(UT_uint32 iPosition, GsfInput * fp); 73 bool insertFromFile(UT_uint32 iPosition, FILE * fp); 74 private: 75 bool _byteBuf(UT_uint32 spaceNeeded); 76 77 UT_Byte * m_pBuf; 78 UT_uint32 m_iSize; /* amount currently used */ 79 UT_uint32 m_iSpace; /* space currently allocated */ 80 UT_uint32 m_iChunk; /* unit for g_try_realloc */ 81 }; 82 83 #endif /* UT_BYTEBUF_H */ 84