• 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 <memory>
00031 #include <gsf/gsf-input.h>
00032 
00033 /* pre-emptive dismissal; ut_types.h is needed by just about everything,
00034  * so even if it's commented out in-file that's still a lot of work for
00035  * the preprocessor to do...
00036  */
00037 #ifndef UT_TYPES_H
00038 #include "ut_types.h"
00039 #endif
00040 
00041 /* sigh... total hack here. Solaris does the following in unistd.h
00042  * #define truncate truncate64
00043  * I really hate/fear this kind of interaction of preprocessor and
00044  * C++ method name.
00045  * Anyway, I'm going to redefine truncate here; make sure to include
00046  * this file *after* unistd.h, however... - fjf
00047  */
00048 #ifndef abi_std_truncate
00049 #define abi_std_truncate truncate
00050 #endif
00051 #ifdef truncate
00052 #undef truncate
00053 #endif
00054 
00055 class ABI_EXPORT UT_ByteBuf
00056 {
00057 public:
00058     UT_ByteBuf(UT_uint32 iChunk = 0);
00059     ~UT_ByteBuf();
00060 
00061     bool                append(const UT_Byte * pValue, UT_uint32 length);
00062     bool                ins(UT_uint32 position, const UT_Byte * pValue, UT_uint32 length);
00063     bool                ins(UT_uint32 position, UT_uint32 length);
00064     bool                del(UT_uint32 position, UT_uint32 amount);
00065     bool                overwrite(UT_uint32 position, const UT_Byte * pValue, UT_uint32 length);
00066     void                truncate(UT_uint32 position);
00067     UT_uint32           getLength(void) const;
00068     const UT_Byte *     getPointer(UT_uint32 position) const;               /* temporary use only */
00069     bool                writeToFile(const char* pszFileName) const;
00070     bool                writeToURI(const char* pszURI) const;
00071     bool                insertFromFile(UT_uint32 iPosition, const char* pszFilename);
00072     bool                            insertFromURI(UT_uint32 iPosition, const char* pszURI);
00073     bool                            insertFromInput(UT_uint32 iPosition, GsfInput * fp);
00074     bool                insertFromFile(UT_uint32 iPosition, FILE * fp);
00075 private:
00076     bool                _byteBuf(UT_uint32 spaceNeeded);
00077 
00078     UT_Byte *           m_pBuf;
00079     UT_uint32           m_iSize;            /* amount currently used */
00080     UT_uint32           m_iSpace;           /* space currently allocated */
00081     UT_uint32           m_iChunk;           /* unit for g_try_realloc */
00082 };
00083 
00084 typedef std::shared_ptr<UT_ByteBuf> UT_ByteBufPtr;
00085 typedef std::shared_ptr<const UT_ByteBuf> UT_ConstByteBufPtr;
00086 
00087 #endif /* UT_BYTEBUF_H */

Generated on Sun Feb 14 2021 for AbiWord by  doxygen 1.7.1