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_GROWBUF_H 00023 #define UT_GROWBUF_H 00024 00025 /***************************************************************** 00026 ** A buffer class which can grow and shrink 00027 *****************************************************************/ 00028 00029 /* pre-emptive dismissal; ut_types.h is needed by just about everything, 00030 * so even if it's commented out in-file that's still a lot of work for 00031 * the preprocessor to do... 00032 */ 00033 #ifndef UT_TYPES_H 00034 #include "ut_types.h" 00035 #endif 00036 00037 /* sigh... total hack here. Solaris does the following in unistd.h 00038 * #define truncate truncate64 00039 * I really hate/fear this kind of interaction of preprocessor and 00040 * C++ method name. 00041 * Anyway, I'm going to redefine truncate here; make sure to include 00042 * this file *after* unistd.h, however... - fjf 00043 */ 00044 #ifndef abi_std_truncate 00045 #define abi_std_truncate truncate 00046 #endif 00047 #ifdef truncate 00048 #undef truncate 00049 #endif 00050 00051 class ABI_EXPORT UT_GrowBuf 00052 { 00053 public: 00054 UT_GrowBuf(UT_uint32 iChunk = 0); 00055 ~UT_GrowBuf(); 00056 00057 bool append(const UT_GrowBufElement * pValue, UT_uint32 length); 00058 bool ins(UT_uint32 position, const UT_GrowBufElement * pValue, UT_uint32 length); 00059 bool ins(UT_uint32 position, UT_uint32 length); 00060 bool del(UT_uint32 position, UT_uint32 amount); 00061 bool overwrite(UT_uint32 position, UT_GrowBufElement * pValue, UT_uint32 length); 00062 void truncate(UT_uint32 position); 00063 UT_uint32 getLength(void) const; 00064 00065 UT_GrowBufElement * getPointer(UT_uint32 position) const; /* temporary use only */ 00066 00067 private: 00068 bool _growBuf(UT_uint32 spaceNeeded); 00069 00070 UT_GrowBufElement * m_pBuf; 00071 UT_uint32 m_iSize; /* amount currently used */ 00072 UT_uint32 m_iSpace; /* space currently allocated */ 00073 UT_uint32 m_iChunk; /* unit for g_try_realloc */ 00074 }; 00075 00076 #endif /* UT_GROWBUF_H */