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 _OSGOSBROOTELEMENT_H_
40 #define _OSGOSBROOTELEMENT_H_
45 #include "OSGOSBCommonElement.h"
46 #include "OSGOSBElementFactoryHelper.h"
47 #include "OSGNFIOOptions.h"
48 #include "OSGBinaryDataHandler.h"
50 // TODO: Add infrastructure for file level and element level options
51 // Keep it simple: Option object serializes to a string and must be able
52 // to parse that string.
56 /*! \ingroup GrpFileIOOSB
60 class OSG_FILEIO_DLLMAPPING OSBRootElement
: public OSBCommonElement
62 /*========================== PUBLIC =================================*/
64 /*---------------------------------------------------------------------*/
68 typedef OSBCommonElement Inherited
;
69 typedef OSBRootElement Self
;
71 typedef Inherited::BinaryReadHandler BinaryReadHandler
;
72 typedef Inherited::BinaryWriteHandler BinaryWriteHandler
;
74 typedef Inherited::PtrFieldList PtrFieldList
;
75 typedef Inherited::PtrFieldListIt PtrFieldListIt
;
76 typedef Inherited::PtrFieldListConstIt PtrFieldListConstIt
;
78 typedef Inherited::FieldContainerIdMap FieldContainerIdMap
;
79 typedef Inherited::FieldContainerIdMapIt FieldContainerIdMapIt
;
80 typedef Inherited::FieldContainerIdMapConstIt FieldContainerIdMapConstIt
;
82 typedef Inherited::FieldContainerList FieldContainerList
;
83 typedef Inherited::FieldContainerListIt FieldContainerListIt
;
84 typedef Inherited::FieldContainerListConstIt FieldContainerListConstIt
;
86 typedef Inherited::FieldContainerIdSet FieldContainerIdSet
;
87 typedef Inherited::FieldContainerIdSetIt FieldContainerIdSetIt
;
88 typedef Inherited::FieldContainerIdSetConstIt FieldContainerIdSetConstIt
;
90 typedef std::list
<OSBElementBase
*> ElementList
;
91 typedef ElementList::iterator ElementListIt
;
92 typedef ElementList::const_iterator ElementListConstIt
;
94 typedef std::map
<UInt32
, OSBElementBase
*> IdElemMap
;
95 typedef IdElemMap::iterator IdElemMapIt
;
96 typedef IdElemMap::const_iterator IdElemMapConstIt
;
99 /*---------------------------------------------------------------------*/
100 /*! \name Constructor */
103 OSBRootElement(OSBRootElement
*root
);
106 /*---------------------------------------------------------------------*/
107 /*! \name Destructor */
110 virtual ~OSBRootElement(void);
113 /*---------------------------------------------------------------------*/
117 void initialiseRead( std::istream
&inStream
);
118 void terminateRead ( void );
120 virtual void read (const std::string
&typeName
);
121 virtual void postRead ( void );
122 virtual void postMap ( void );
125 /*---------------------------------------------------------------------*/
129 void initialiseWrite(std::ostream
&outStream
);
130 void terminateWrite (void );
132 virtual void preWrite (FieldContainer
* const fc
);
133 virtual void write (void );
136 /*---------------------------------------------------------------------*/
137 /*! \name State access */
140 inline BinaryReadHandler
*getReadHandler (void);
141 inline BinaryWriteHandler
*getWriteHandler (void);
143 inline const NFIOOptions
&getOptions (void) const;
144 inline NFIOOptions
&editOptions (void);
146 inline void setHeaderVersion (const UInt16 version
);
147 inline UInt16
getHeaderVersion (void) const;
149 inline const FieldContainerIdMap
&getIdMap (void) const;
150 inline FieldContainerIdMap
&editIdMap (void);
152 inline const PtrFieldList
&getPtrFieldList (void) const;
153 inline PtrFieldList
&editPtrFieldList (void);
155 inline const ElementList
&getElementList (void) const;
156 inline ElementList
&editElementList (void);
158 inline const IdElemMap
&getIdElemMap (void) const;
159 inline IdElemMap
&editIdElemMap (void);
161 inline const FieldContainerList
&getContainerList (void) const;
162 inline FieldContainerList
&editContainerList(void);
164 inline const FieldContainerIdSet
&getIdSet (void) const;
165 inline FieldContainerIdSet
&editIdSet (void);
168 /*========================= PROTECTED ===============================*/
171 /*---------------------------------------------------------------------*/
172 /*! \name Helper methods */
175 void mapPtrField(const PtrFieldInfo
&ptrField
);
177 void dumpIdMap(void) const;
180 /*---------------------------------------------------------------------*/
182 static OSBElementRegistrationHelper
<OSBRootElement
> _regHelper
;
184 BinaryReadHandler
*_readHandler
;
185 BinaryWriteHandler
*_writeHandler
;
187 NFIOOptions _options
;
188 ElementList _elements
;
189 IdElemMap _idElemMap
;
191 UInt16 _readHeaderVersion
;
192 FieldContainerIdMap _readIdMap
;
193 PtrFieldList _readPtrFields
;
195 FieldContainerList _writeFCList
;
196 FieldContainerIdSet _writeIdSet
;
200 OSBRootElement(const OSBRootElement
&other
);
201 void operator =(const OSBRootElement
&rhs
);
206 #include "OSGOSBRootElement.inl"
208 #endif /* _OSGOSBROOTELEMENT_H_ */