Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/ogre/Tools/3dsmaxExport/LEXIExporter/SharedUtilities/Sources/DataStream.h @ 11

Last change on this file since 11 was 6, checked in by anonymous, 18 years ago

=…

File size: 2.8 KB
Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of LEXIExporter
4
5Copyright 2006 NDS Limited
6
7Author(s):
8Lasse Tassing
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23-----------------------------------------------------------------------------
24*/
25
26#ifndef __DATA_STREAM__
27#define __DATA_STREAM__
28
29// Helper class. Binary packages can be build and serialized using this class
30class CDataStream : public CRefCount
31{
32public:
33        CDataStream(unsigned iInitSize=512, unsigned iGrow=512);
34        CDataStream(const CDataStream &other);
35        CDataStream(const void *pData, unsigned iSize, CRefCount *pDataOwner=NULL);
36        CDataStream(void *pData, unsigned iSize);       // NOTE! This takes ownership of data
37        ~CDataStream(void);
38
39        //
40        void    Reserve(unsigned int iNewAlloc);
41
42        // Insertion
43        void    InsertInt(int iData, int iPosition=0);
44        void    InsertString(const char *pszData, int iPosition=0);
45
46        // Add
47        void    AddByte(unsigned char bDate);
48        void    AddInt(int iData);
49        void    AddFloat(float fData);
50        void    AddString(const char *pszData);
51        void    AddBinary(const void *pData, unsigned iLen);
52        void    AddRAW(const void *pData, unsigned iLen);               // Adds raw data to the stream
53        void    AddBool(bool bData);
54
55        // Retrieve
56        unsigned char GetByte() const;
57        int             GetInt(void) const;
58        float   GetFloat(void) const;
59        const char *GetString(void) const;
60        const void *GetBinary(unsigned &iLen) const;
61        const void *GetRAW(unsigned iLen) const;                                // Get raw data from the stream (from current position)
62        bool    GetBool() const;
63
64        // Reset position
65        void    Reset(void)  { SetPosition(0); }
66        void    SetPosition(unsigned iPos) const;
67        int             GetPosition(void) const;
68
69        // Retrieve base data (mostly used when serializing the stream)
70        const void*     GetBaseData(void) const { return m_pData; }
71
72        unsigned        GetAllocSize(void) const { return m_iAllocSize; }
73       
74private:
75        void    Realloc(int iSpaceNeeded);
76
77        // Released, if valid
78        const CRefCount *m_pDataOwner;
79       
80        // Data
81        bool    m_bOwnData;
82        char    *m_pData;
83        mutable unsigned        m_iPosition;
84        unsigned        m_iAllocSize;
85        unsigned        m_iGrowSize;
86
87#ifdef _DEBUG
88    unsigned    m_iReallocCount;
89#endif
90};
91
92#endif
Note: See TracBrowser for help on using the repository browser.