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 #include "OSGOSBGenericElement.h"
41 #include "OSGOSBRootElement.h"
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.
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]
66 /*-------------------------------------------------------------------------*/
69 OSBDefaultElementRegistrationHelper
<OSBGenericElement
>
70 OSBGenericElement::_regHelper
=
71 OSBDefaultElementRegistrationHelper
<OSBGenericElement
>();
73 /*-------------------------------------------------------------------------*/
76 OSBGenericElement::OSBGenericElement(OSBRootElement
*root
)
77 : Inherited(root
, OSGOSBHeaderVersion200
)
82 /*-------------------------------------------------------------------------*/
85 OSBGenericElement::~OSBGenericElement(void)
90 /*-------------------------------------------------------------------------*/
94 OSBGenericElement::read(const std::string
&typeName
)
96 OSG_OSB_LOG(("OSBGenericElement::read [%s]\n", typeName
.c_str()));
98 BinaryReadHandler
*rh
= editRoot()->getReadHandler();
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()));
119 setContainer(FieldContainerUnrecPtr(createReplacementFC(ptrTypeTag
)));
127 OSBGenericElement::postRead(void)
131 /*-------------------------------------------------------------------------*/
135 OSBGenericElement::preWrite(FieldContainer
* const fc
)
137 OSG_OSB_LOG(("OSBGenericElement::preWrite\n"));
139 preWriteFieldContainer(fc
, "");
143 OSBGenericElement::write(void)
145 OSG_OSB_LOG(("OSBGenericElement::write\n"));
147 if(getContainer() == NULL
)
149 FWARNING(("OSBGenericElement::write: Attempt to write NULL.\n"));
153 BinaryWriteHandler
*wh
= editRoot()->getWriteHandler();
155 wh
->putValue(getFCPtrType(getContainer()));
156 wh
->putValue(getVersion() );
158 writeFields("", true);