1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2008 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 _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"
49 #include "OSGMaterialChunk.h"
50 #include "OSGMemoryObject.h"
52 #include "OSGTypedGeoIntegralProperty.h"
53 #include "OSGTypedGeoVectorProperty.h"
59 //---------------------------------------------------------------------------
61 //---------------------------------------------------------------------------
68 /*! \brief General VRML Node Desc
69 \ingroup GrpFileIOOpenFlight
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
);
90 /*! \ingroup GrpFileIOOpenFlight
93 typedef TransitPtr
<OFRecord
> OFRecordTransitPtr
;
95 //---------------------------------------------------------------------------
97 //---------------------------------------------------------------------------
99 /*! \ingroup GrpFileIOOpenFlight
103 class OSG_FILEIO_DLLMAPPING OFRecordFactoryBase
105 /*========================== PUBLIC =================================*/
109 typedef boost::function
<
110 OFRecordTransitPtr (const OFRecordHeader
&,
111 OFDatabase
& )> CreateRecord
;
115 class OSG_FILEIO_DLLMAPPING RegisterRecord
119 RegisterRecord(CreateRecord fCreate
,
120 UInt16 sRecordOpCode
);
123 /*---------------------------------------------------------------------*/
124 /*! \name Class Get */
128 /*---------------------------------------------------------------------*/
134 /*---------------------------------------------------------------------*/
138 void registerRecord(CreateRecord fRecord
,
139 UInt16 sRecordOpCode
);
142 /*---------------------------------------------------------------------*/
143 /*! \name Prototypes */
146 OFRecordTransitPtr
createRecord(const OFRecordHeader
&oHeader
,
150 /*---------------------------------------------------------------------*/
155 /*---------------------------------------------------------------------*/
156 /*! \name FieldValue */
161 /*---------------------------------------------------------------------*/
166 /*========================= PROTECTED ===============================*/
170 template <class SingletonT
>
171 friend class SingletonHolder
;
173 typedef std::map
<UInt16
,
174 CreateRecord
> NameRecordCreateMap
;
176 /*---------------------------------------------------------------------*/
177 /*! \name Constructors */
180 OFRecordFactoryBase(void);
183 /*---------------------------------------------------------------------*/
184 /*! \name Destructor */
187 virtual ~OFRecordFactoryBase(void);
190 /*---------------------------------------------------------------------*/
195 /*---------------------------------------------------------------------*/
199 NameRecordCreateMap _mRegisteredRecords
;
202 /*========================== 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
);
213 OSG_FILEIO_EXPIMP_TMPL
214 template class OSG_FILEIO_DLLMAPPING SingletonHolder
<OFRecordFactoryBase
>;
217 /*! \ingroup GrpFileIOOpenFlight
220 typedef SingletonHolder
<OFRecordFactoryBase
> OFRecordFactory
;
222 //---------------------------------------------------------------------------
224 //---------------------------------------------------------------------------
226 /*! \ingroup GrpFileIOOpenFlight
230 class OSG_FILEIO_DLLMAPPING OFRecord
: public MemoryObject
233 /*---------------------------------------------------------------------*/
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
,
264 virtual NodeTransitPtr
convertToNode(void);
266 virtual bool addChild (OFRecord
*pChild
) = 0;
268 /*---------------------------------------------------------------------*/
270 virtual void dump(UInt32 uiIndent
) const;
274 typedef MemoryObject Inherited
;
276 /*---------------------------------------------------------------------*/
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
,
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 //---------------------------------------------------------------------------
324 //---------------------------------------------------------------------------
326 /*! \ingroup GrpFileIOOpenFlight
330 class OFPrimaryRecord
: public OFRecord
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;
349 typedef OFRecord Inherited
;
351 typedef std::vector
<OFPrimaryRecordRCPtr
> PrimaryStore
;
352 typedef std::vector
<OFAncillaryRecordRCPtr
> AncillaryStore
;
354 OFPrimaryRecord(const OFRecordHeader
&oHeader
,
356 virtual ~OFPrimaryRecord(void ) = 0;
358 PrimaryStore _primaryChildren
;
359 AncillaryStore _ancillaryChildren
;
362 //---------------------------------------------------------------------------
364 //---------------------------------------------------------------------------
366 /*! \ingroup GrpFileIOOpenFlight
370 class OFAncillaryRecord
: public OFRecord
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
);
387 typedef OFRecord Inherited
;
389 OFAncillaryRecord(const OFRecordHeader
&oHeader
,
391 virtual ~OFAncillaryRecord(void ) = 0;
394 //---------------------------------------------------------------------------
396 //---------------------------------------------------------------------------
398 /*! \ingroup GrpFileIOOpenFlight
402 class OFControlRecord
: public OFRecord
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
);
417 typedef OFRecord Inherited
;
419 OFControlRecord(const OFRecordHeader
&oHeader
,
421 virtual ~OFControlRecord(void ) = 0;
424 /*! \ingroup GrpFileIOOpenFlight
426 typedef RefCountPtr
<OFControlRecord
,
427 MemObjRefCountPolicy
> OFControlRecordRCPtr
;
429 //---------------------------------------------------------------------------
431 //---------------------------------------------------------------------------
433 /*! \ingroup GrpFileIOOpenFlight
437 class OSG_FILEIO_DLLMAPPING OFUnknownRecord
: public OFRecord
441 typedef OFRecord Inherited
;
443 /*---------------------------------------------------------------------*/
446 std::vector
<OFRecordRCPtr
> _vChildren
;
448 /*---------------------------------------------------------------------*/
450 OFUnknownRecord(const OFRecordHeader
&oHeader
,
452 virtual ~OFUnknownRecord(void );
454 /*---------------------------------------------------------------------*/
456 friend class OFRecordFactoryBase
;
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;
476 #include "OSGOFRecords.inl"
478 #endif /* _OSGOFRECORDS_H_ */