fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / FileIO / OSB / OSGOSBGenericElement.cpp
blob93a596d23c5190dcdd7b58331bbbb15ed0043d69
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 #include "OSGOSBGenericElement.h"
41 #include "OSGOSBRootElement.h"
43 OSG_USING_NAMESPACE
45 /*-------------------------------------------------------------------------*/
46 /* OSBGenericElement */
47 /*-------------------------------------------------------------------------*/
49 /*! \class OSG::OSBGenericElement
50 The default element that can be used to read all types that do not require
51 special handling and thus have their own elments.
53 \dev
54 The generic format is:
55 UInt8 ptrTypeId an id classifying the kind of container
56 UInt16 version OSB version used to write this container
58 for each non-internal field:
59 std::string fieldName name of the field
60 std::string fieldTypeName name of the type stored in the field
61 UInt32 fieldSize number of following bytes for this field
62 [Binary representation of the fields contents]
63 \enddev
66 /*-------------------------------------------------------------------------*/
67 /* Static members */
69 OSBDefaultElementRegistrationHelper<OSBGenericElement>
70 OSBGenericElement::_regHelper =
71 OSBDefaultElementRegistrationHelper<OSBGenericElement>();
73 /*-------------------------------------------------------------------------*/
74 /* Constructor */
76 OSBGenericElement::OSBGenericElement(OSBRootElement *root)
77 : Inherited(root, OSGOSBHeaderVersion200)
79 // nothing to do.
82 /*-------------------------------------------------------------------------*/
83 /* Destructor */
85 OSBGenericElement::~OSBGenericElement(void)
87 // nothing to do.
90 /*-------------------------------------------------------------------------*/
91 /* Reading */
93 void
94 OSBGenericElement::read(const std::string &typeName)
96 OSG_OSB_LOG(("OSBGenericElement::read [%s]\n", typeName.c_str()));
98 BinaryReadHandler *rh = editRoot()->getReadHandler();
100 UInt8 ptrTypeTag;
101 UInt16 version;
103 rh->getValue(ptrTypeTag);
104 rh->getValue(version );
106 OSG_OSB_LOG(("OSBGenericElement::read: version: [%u] ptrTypeTag [%u]\n",
107 version, ptrTypeTag));
109 setContainer(FieldContainerUnrecPtr(
110 FieldContainerFactory::the()->createContainer(typeName.c_str())));
112 if(getContainer() == NULL)
114 FWARNING(("OSBGenericElement::read: Skipping unknown "
115 "FieldContainer [%s].\n", typeName.c_str()));
117 skipFields();
119 setContainer(FieldContainerUnrecPtr(createReplacementFC(ptrTypeTag)));
120 return;
123 readFields("", "");
126 void
127 OSBGenericElement::postRead(void)
131 /*-------------------------------------------------------------------------*/
132 /* Writing */
134 void
135 OSBGenericElement::preWrite(FieldContainer * const fc)
137 OSG_OSB_LOG(("OSBGenericElement::preWrite\n"));
139 preWriteFieldContainer(fc, "");
142 void
143 OSBGenericElement::write(void)
145 OSG_OSB_LOG(("OSBGenericElement::write\n"));
147 if(getContainer() == NULL)
149 FWARNING(("OSBGenericElement::write: Attempt to write NULL.\n"));
150 return;
153 BinaryWriteHandler *wh = editRoot()->getWriteHandler();
155 wh->putValue(getFCPtrType(getContainer()));
156 wh->putValue(getVersion() );
158 writeFields("", true);