1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2007 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
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. *
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. *
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. *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
37 \*---------------------------------------------------------------------------*/
39 #ifndef _OSGOSBELEMENTBASE_H_
40 #define _OSGOSBELEMENTBASE_H_
45 #include "OSGConfig.h"
46 #include "OSGFileIODef.h"
47 #include "OSGFieldContainer.h"
48 #include "OSGOSBLog.h"
61 /*! \ingroup GrpFileIOOSB
65 class OSG_FILEIO_DLLMAPPING OSBElementBase
67 /*========================== PUBLIC =================================*/
69 /*---------------------------------------------------------------------*/
70 /*! \name Public Types */
75 class BinaryReadHandler
: public BinaryDataHandler
78 BinaryReadHandler(std::istream
&inStream
);
80 virtual ~BinaryReadHandler(void);
82 inline void skip(UInt32 size
);
85 virtual void read(MemoryHandle mem
, UInt32 size
);
88 std::vector
<UInt8
> _readMemory
;
91 BinaryReadHandler(const BinaryReadHandler
&source
);
92 void operator = (const BinaryReadHandler
&source
);
97 class BinaryWriteHandler
: public BinaryDataHandler
100 BinaryWriteHandler(std::ostream
&outStream
);
102 virtual ~BinaryWriteHandler(void);
105 virtual void write(MemoryHandle mem
, UInt32 size
);
108 std::vector
<UInt8
> _writeMemory
;
111 BinaryWriteHandler(const BinaryWriteHandler
&source
);
112 void operator = (const BinaryWriteHandler
&source
);
116 /*---------------------------------------------------------------------*/
117 /*! \name Constants */
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;
129 /*---------------------------------------------------------------------*/
130 /*! \name Constructor */
133 OSBElementBase(OSBRootElement
*root
, const UInt16 version
);
136 /*---------------------------------------------------------------------*/
137 /*! \name Destructor */
140 virtual ~OSBElementBase(void);
143 /*---------------------------------------------------------------------*/
144 /*! \name State access */
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;
159 /*---------------------------------------------------------------------*/
163 virtual void read (const std::string
&typeName
) = 0;
164 virtual void postRead( void ) = 0;
165 virtual void postMap ( void ) = 0;
167 /*---------------------------------------------------------------------*/
171 virtual void preWrite(FieldContainer
* const fc
) = 0;
172 virtual void write ( void ) = 0;
175 /*========================= PROTECTED ===============================*/
177 /*---------------------------------------------------------------------*/
178 /*! \name Protected Types */
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
);
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;
222 BindingStore _bindings
;
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
;
245 /*========================== PRIVATE ================================*/
248 FieldContainerUnrecPtr _container
;
249 OSBRootElement
*_rootElement
;
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
);
261 #include "OSGOSBElementBase.inl"
263 #endif /* _OSGOSBELEMENTBASE_H_ */