fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / FileIO / OpenFlight / OSGOFRecords.h
blob8f6c3bd5d30e5ae5e952ad77dcceb95ce83b6ea6
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2008 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 _OSGOFRECORDS_H_
40 #define _OSGOFRECORDS_H_
42 #include "boost/function.hpp"
44 #include "OSGFileIODef.h"
45 #include "OSGBaseTypes.h"
46 #include "OSGBaseFunctions.h"
47 #include "OSGSingletonHolder.h"
48 #include "OSGNode.h"
49 #include "OSGMaterialChunk.h"
50 #include "OSGMemoryObject.h"
52 #include "OSGTypedGeoIntegralProperty.h"
53 #include "OSGTypedGeoVectorProperty.h"
55 #include <map>
57 OSG_BEGIN_NAMESPACE
59 //---------------------------------------------------------------------------
60 // Class
61 //---------------------------------------------------------------------------
63 class OFRecord;
64 class OFDatabase;
66 class Geometry;
68 /*! \brief General VRML Node Desc
69 \ingroup GrpFileIOOpenFlight
70 \nohierarchy
71 */
73 struct OFRecordHeader
75 UInt16 sOpCode;
76 UInt16 sLength;
78 bool read(std::istream &is)
80 is.read(reinterpret_cast<char *>(&sOpCode), 2);
81 is.read(reinterpret_cast<char *>(&sLength), 2);
83 sOpCode = osgNetToHost(sOpCode);
84 sLength = osgNetToHost(sLength);
86 return is.good();
90 /*! \ingroup GrpFileIOOpenFlight
93 typedef TransitPtr<OFRecord> OFRecordTransitPtr;
95 //---------------------------------------------------------------------------
96 // Class
97 //---------------------------------------------------------------------------
99 /*! \ingroup GrpFileIOOpenFlight
100 \nohierarchy
103 class OSG_FILEIO_DLLMAPPING OFRecordFactoryBase
105 /*========================== PUBLIC =================================*/
107 public :
109 typedef boost::function<
110 OFRecordTransitPtr (const OFRecordHeader &,
111 OFDatabase & )> CreateRecord;
113 /*! \nohierarchy
115 class OSG_FILEIO_DLLMAPPING RegisterRecord
117 public:
119 RegisterRecord(CreateRecord fCreate,
120 UInt16 sRecordOpCode);
123 /*---------------------------------------------------------------------*/
124 /*! \name Class Get */
125 /*! \{ */
127 /*! \} */
128 /*---------------------------------------------------------------------*/
129 /*! \name Helper */
130 /*! \{ */
133 /*! \} */
134 /*---------------------------------------------------------------------*/
135 /*! \name Field */
136 /*! \{ */
138 void registerRecord(CreateRecord fRecord,
139 UInt16 sRecordOpCode);
141 /*! \} */
142 /*---------------------------------------------------------------------*/
143 /*! \name Prototypes */
144 /*! \{ */
146 OFRecordTransitPtr createRecord(const OFRecordHeader &oHeader,
147 OFDatabase &oDB );
149 /*! \} */
150 /*---------------------------------------------------------------------*/
151 /*! \name Node */
152 /*! \{ */
154 /*! \} */
155 /*---------------------------------------------------------------------*/
156 /*! \name FieldValue */
157 /*! \{ */
160 /*! \} */
161 /*---------------------------------------------------------------------*/
162 /*! \name Dump */
163 /*! \{ */
165 /*! \} */
166 /*========================= PROTECTED ===============================*/
168 protected:
170 template <class SingletonT>
171 friend class SingletonHolder;
173 typedef std::map<UInt16,
174 CreateRecord> NameRecordCreateMap;
176 /*---------------------------------------------------------------------*/
177 /*! \name Constructors */
178 /*! \{ */
180 OFRecordFactoryBase(void);
182 /*! \} */
183 /*---------------------------------------------------------------------*/
184 /*! \name Destructor */
185 /*! \{ */
187 virtual ~OFRecordFactoryBase(void);
189 /*! \} */
190 /*---------------------------------------------------------------------*/
191 /*! \name Member */
192 /*! \{ */
194 /*! \} */
195 /*---------------------------------------------------------------------*/
196 /*! \name Member */
197 /*! \{ */
199 NameRecordCreateMap _mRegisteredRecords;
201 /*! \} */
202 /*========================== PRIVATE ================================*/
204 private:
206 /*!\brief prohibit default function (move to 'public' if needed) */
207 OFRecordFactoryBase(const OFRecordFactoryBase &source);
208 /*!\brief prohibit default function (move to 'public' if needed) */
209 void operator =(const OFRecordFactoryBase &source);
212 #if defined(WIN32)
213 OSG_FILEIO_EXPIMP_TMPL
214 template class OSG_FILEIO_DLLMAPPING SingletonHolder<OFRecordFactoryBase>;
215 #endif
217 /*! \ingroup GrpFileIOOpenFlight
220 typedef SingletonHolder<OFRecordFactoryBase> OFRecordFactory;
222 //---------------------------------------------------------------------------
223 // Class
224 //---------------------------------------------------------------------------
226 /*! \ingroup GrpFileIOOpenFlight
227 \nohierarchy
230 class OSG_FILEIO_DLLMAPPING OFRecord : public MemoryObject
232 public:
233 /*---------------------------------------------------------------------*/
235 enum CategoryE
237 RC_Control = 0,
238 RC_Primary = 1,
239 RC_Ancillary = 2,
240 RC_Continuation = 3,
242 RC_Undefined = 4
245 /*---------------------------------------------------------------------*/
247 static const Char8 *getOpCodeString (UInt16 sOpCode);
248 static const Char8 *getCategoryString(CategoryE cat );
250 /*---------------------------------------------------------------------*/
252 virtual UInt16 getOpCode (void) const = 0;
253 const Char8 *getOpCodeString (void) const;
255 virtual CategoryE getCategory (void) const = 0;
256 const Char8 *getCategoryString(void) const;
258 /*---------------------------------------------------------------------*/
260 virtual bool read (std::istream &is );
261 virtual bool readContinue(std::istream &is,
262 UInt16 uiLength);
264 virtual NodeTransitPtr convertToNode(void);
266 virtual bool addChild (OFRecord *pChild) = 0;
268 /*---------------------------------------------------------------------*/
270 virtual void dump(UInt32 uiIndent) const;
272 protected:
274 typedef MemoryObject Inherited;
276 /*---------------------------------------------------------------------*/
278 OFDatabase &_oDB;
279 UInt16 _sLength;
281 /*---------------------------------------------------------------------*/
283 void readChar8 (std::istream &is, Char8 *cVal, UInt32 iSize);
285 /*---------------------------------------------------------------------*/
287 template<class ValueT>
288 UInt32 readVal(std::istream &is, ValueT &val);
290 /*---------------------------------------------------------------------*/
292 OFRecord(const OFRecordHeader &oHeader,
293 OFDatabase &oDB );
294 virtual ~OFRecord(void);
297 /*! \ingroup GrpFileIOOpenFlight
300 typedef RefCountPtr<OFRecord, MemObjRefCountPolicy> OFRecordRCPtr;
302 //---------------------------------------------------------------------------
303 // Forward declarations
304 //---------------------------------------------------------------------------
306 /*! \ingroup GrpFileIOOpenFlight
308 class OFPrimaryRecord;
309 /*! \ingroup GrpFileIOOpenFlight
311 typedef RefCountPtr<OFPrimaryRecord,
312 MemObjRefCountPolicy> OFPrimaryRecordRCPtr;
314 /*! \ingroup GrpFileIOOpenFlight
316 class OFAncillaryRecord;
317 /*! \ingroup GrpFileIOOpenFlight
319 typedef RefCountPtr<OFAncillaryRecord,
320 MemObjRefCountPolicy> OFAncillaryRecordRCPtr;
322 //---------------------------------------------------------------------------
323 // Class
324 //---------------------------------------------------------------------------
326 /*! \ingroup GrpFileIOOpenFlight
327 \nohierarchy
330 class OFPrimaryRecord : public OFRecord
332 public:
333 static const CategoryE Category = RC_Primary;
335 /*---------------------------------------------------------------------*/
337 static CategoryE getClassCategory(void);
338 virtual CategoryE getCategory (void) const;
340 /*---------------------------------------------------------------------*/
342 virtual bool addChild(OFRecord *pChild);
344 /*---------------------------------------------------------------------*/
346 virtual void dump(UInt32 uiIndent) const;
348 protected:
349 typedef OFRecord Inherited;
351 typedef std::vector<OFPrimaryRecordRCPtr > PrimaryStore;
352 typedef std::vector<OFAncillaryRecordRCPtr> AncillaryStore;
354 OFPrimaryRecord(const OFRecordHeader &oHeader,
355 OFDatabase &oDB );
356 virtual ~OFPrimaryRecord(void ) = 0;
358 PrimaryStore _primaryChildren;
359 AncillaryStore _ancillaryChildren;
362 //---------------------------------------------------------------------------
363 // Class
364 //---------------------------------------------------------------------------
366 /*! \ingroup GrpFileIOOpenFlight
367 \nohierarchy
370 class OFAncillaryRecord : public OFRecord
372 public:
373 static const CategoryE Category = RC_Ancillary;
375 /*---------------------------------------------------------------------*/
377 static CategoryE getClassCategory(void);
378 virtual CategoryE getCategory (void) const;
380 /*---------------------------------------------------------------------*/
382 virtual bool addChild (OFRecord *pChild);
383 virtual NodeTransitPtr convertToNode(void );
384 virtual NodeTransitPtr convert (Node *pNode );
386 protected:
387 typedef OFRecord Inherited;
389 OFAncillaryRecord(const OFRecordHeader &oHeader,
390 OFDatabase &oDB );
391 virtual ~OFAncillaryRecord(void ) = 0;
394 //---------------------------------------------------------------------------
395 // Class
396 //---------------------------------------------------------------------------
398 /*! \ingroup GrpFileIOOpenFlight
399 \nohierarchy
402 class OFControlRecord : public OFRecord
404 public:
405 static const CategoryE Category = RC_Control;
407 /*---------------------------------------------------------------------*/
409 static CategoryE getClassCategory(void);
410 virtual CategoryE getCategory (void) const;
412 /*---------------------------------------------------------------------*/
414 virtual bool addChild(OFRecord *pChild);
416 protected:
417 typedef OFRecord Inherited;
419 OFControlRecord(const OFRecordHeader &oHeader,
420 OFDatabase &oDB );
421 virtual ~OFControlRecord(void ) = 0;
424 /*! \ingroup GrpFileIOOpenFlight
426 typedef RefCountPtr<OFControlRecord,
427 MemObjRefCountPolicy> OFControlRecordRCPtr;
429 //---------------------------------------------------------------------------
430 // Class
431 //---------------------------------------------------------------------------
433 /*! \ingroup GrpFileIOOpenFlight
434 \nohierarchy
437 class OSG_FILEIO_DLLMAPPING OFUnknownRecord : public OFRecord
439 protected:
441 typedef OFRecord Inherited;
443 /*---------------------------------------------------------------------*/
445 UInt16 _sOpCode;
446 std::vector<OFRecordRCPtr> _vChildren;
448 /*---------------------------------------------------------------------*/
450 OFUnknownRecord(const OFRecordHeader &oHeader,
451 OFDatabase &oDB );
452 virtual ~OFUnknownRecord(void );
454 /*---------------------------------------------------------------------*/
456 friend class OFRecordFactoryBase;
458 public:
460 virtual bool read (std::istream &is );
461 virtual NodeTransitPtr convertToNode(void );
462 virtual bool addChild (OFRecord *pChild);
464 /*---------------------------------------------------------------------*/
466 virtual UInt16 getOpCode (void) const;
467 virtual CategoryE getCategory(void) const;
469 /*---------------------------------------------------------------------*/
471 virtual void dump(UInt32 uiIndent) const;
474 OSG_END_NAMESPACE
476 #include "OSGOFRecords.inl"
478 #endif /* _OSGOFRECORDS_H_ */