fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / FileIO / OSB / OSGOSBElementBase.h
bloba61a92a4bd5723522f3fc005db42a80181904eee
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2007 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
10 * *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13 * License *
14 * *
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
18 * *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
23 * *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
27 * *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
30 * Changes *
31 * *
32 * *
33 * *
34 * *
35 * *
36 * *
37 \*---------------------------------------------------------------------------*/
39 #ifndef _OSGOSBELEMENTBASE_H_
40 #define _OSGOSBELEMENTBASE_H_
41 #ifdef __sgi
42 #pragma once
43 #endif
45 #include "OSGConfig.h"
46 #include "OSGFileIODef.h"
47 #include "OSGFieldContainer.h"
48 #include "OSGOSBLog.h"
50 #include <iostream>
51 #include <list>
52 #include <map>
53 #include <set>
54 #include <string>
55 #include <vector>
57 OSG_BEGIN_NAMESPACE
59 class OSBRootElement;
61 /*! \ingroup GrpFileIOOSB
62 \nohierarchy
65 class OSG_FILEIO_DLLMAPPING OSBElementBase
67 /*========================== PUBLIC =================================*/
68 public:
69 /*---------------------------------------------------------------------*/
70 /*! \name Public Types */
71 /*! \{ */
73 /*! \nohierarchy
75 class BinaryReadHandler : public BinaryDataHandler
77 public:
78 BinaryReadHandler(std::istream &inStream);
80 virtual ~BinaryReadHandler(void);
82 inline void skip(UInt32 size );
84 protected:
85 virtual void read(MemoryHandle mem, UInt32 size);
87 private:
88 std::vector<UInt8> _readMemory;
89 std::istream &_is;
91 BinaryReadHandler(const BinaryReadHandler &source);
92 void operator = (const BinaryReadHandler &source);
95 /*! \nohierarchy
97 class BinaryWriteHandler : public BinaryDataHandler
99 public:
100 BinaryWriteHandler(std::ostream &outStream);
102 virtual ~BinaryWriteHandler(void);
104 protected:
105 virtual void write(MemoryHandle mem, UInt32 size);
107 private:
108 std::vector<UInt8> _writeMemory;
109 std::ostream &_os;
111 BinaryWriteHandler(const BinaryWriteHandler &source);
112 void operator = (const BinaryWriteHandler &source);
115 /*! \} */
116 /*---------------------------------------------------------------------*/
117 /*! \name Constants */
118 /*! \{ */
120 static const UInt16 OSGOSBHeaderVersion100;
121 static const UInt16 OSGOSBHeaderVersion200;
122 // static const UInt16 OSGOSBHeaderVersion201;
124 static const std::string OSGOSB_HEADER_ID_1;
125 static const std::string OSGOSB_HEADER_ID_2;
126 // static const std::string OSGOSB_HEADER_ID_201;
128 /*! \} */
129 /*---------------------------------------------------------------------*/
130 /*! \name Constructor */
131 /*! \{ */
133 OSBElementBase(OSBRootElement *root, const UInt16 version);
135 /*! \} */
136 /*---------------------------------------------------------------------*/
137 /*! \name Destructor */
138 /*! \{ */
140 virtual ~OSBElementBase(void);
142 /*! \} */
143 /*---------------------------------------------------------------------*/
144 /*! \name State access */
145 /*! \{ */
147 inline FieldContainer *getContainer(void );
148 inline void setContainer(FieldContainer * const cont);
150 inline const OSBRootElement *getRoot (void) const;
151 inline OSBRootElement *editRoot(void);
153 inline UInt32 getFCIdFile(void ) const;
154 inline void setFCIdFile(UInt32 fcIdFile);
156 inline UInt16 getVersion(void) const;
158 /*! \} */
159 /*---------------------------------------------------------------------*/
160 /*! \name Reading */
161 /*! \{ */
163 virtual void read (const std::string &typeName) = 0;
164 virtual void postRead( void ) = 0;
165 virtual void postMap ( void ) = 0;
166 /*! \} */
167 /*---------------------------------------------------------------------*/
168 /*! \name Writing */
169 /*! \{ */
171 virtual void preWrite(FieldContainer * const fc) = 0;
172 virtual void write ( void ) = 0;
174 /*! \} */
175 /*========================= PROTECTED ===============================*/
176 protected:
177 /*---------------------------------------------------------------------*/
178 /*! \name Protected Types */
179 /*! \{ */
181 /*! \nohierarchy
183 class PtrFieldInfo
185 public:
186 typedef std::vector<UInt32> PtrIdStore;
187 typedef PtrIdStore::iterator PtrIdStoreIt;
188 typedef PtrIdStore::const_iterator PtrIdStoreConstIt;
190 typedef std::vector<UInt16> BindingStore;
191 typedef BindingStore::iterator BindingStoreIt;
192 typedef BindingStore::const_iterator BindingStoreConstIt;
194 PtrFieldInfo(FieldContainer * const fc, UInt32 fieldId);
195 PtrFieldInfo(const PtrFieldInfo &other);
196 ~PtrFieldInfo(void);
198 inline FieldContainer *getContainer(void) const;
199 inline UInt32 getFieldId (void) const;
201 inline const PtrIdStore &getIdStore (void) const;
202 inline PtrIdStore &editIdStore (void);
203 inline PtrIdStoreConstIt beginIdStore (void) const;
204 inline PtrIdStoreIt beginIdStore (void);
205 inline PtrIdStoreConstIt endIdStore (void) const;
206 inline PtrIdStoreIt endIdStore (void);
208 inline const BindingStore &getBindingStore (void) const;
209 inline BindingStore &editBindingStore (void);
210 inline BindingStoreConstIt beginBindingStore(void) const;
211 inline BindingStoreIt beginBindingStore(void);
212 inline BindingStoreConstIt endBindingStore (void) const;
213 inline BindingStoreIt endBindingStore (void);
215 void setHandledField(bool bVal);
216 bool getHandledField(void ) const;
218 private:
219 FieldContainer *_fc;
220 UInt32 _fieldId;
221 PtrIdStore _ptrIds;
222 BindingStore _bindings;
223 bool _bHandledField;
225 void operator =(const PtrFieldInfo &rhs);
228 typedef std::list<PtrFieldInfo> PtrFieldList;
229 typedef PtrFieldList::iterator PtrFieldListIt;
230 typedef PtrFieldList::const_iterator PtrFieldListConstIt;
232 typedef std::map<UInt32, UInt32> FieldContainerIdMap;
233 typedef FieldContainerIdMap::iterator FieldContainerIdMapIt;
234 typedef FieldContainerIdMap::const_iterator FieldContainerIdMapConstIt;
236 typedef std::list<FieldContainer *> FieldContainerList;
237 typedef FieldContainerList::iterator FieldContainerListIt;
238 typedef FieldContainerList::const_iterator FieldContainerListConstIt;
240 typedef std::set<UInt32> FieldContainerIdSet;
241 typedef FieldContainerIdSet::iterator FieldContainerIdSetIt;
242 typedef FieldContainerIdSet::const_iterator FieldContainerIdSetConstIt;
244 /*! \} */
245 /*========================== PRIVATE ================================*/
246 private:
248 FieldContainerUnrecPtr _container;
249 OSBRootElement *_rootElement;
250 UInt32 _fcIdFile;
251 UInt16 _version;
253 /*!\brief prohibit default function (move to 'public' if needed) */
254 OSBElementBase(const OSBElementBase &source);
255 /*!\brief prohibit default function (move to 'public' if needed) */
256 void operator =(const OSBElementBase &source);
259 OSG_END_NAMESPACE
261 #include "OSGOSBElementBase.inl"
263 #endif /* _OSGOSBELEMENTBASE_H_ */