fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / FileIO / OSB / OSGOSBVoidPAttachmentElement.cpp
blob6a8be3d1c5b087eeae000a82d471fdbf1d258aac
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2011 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 \*---------------------------------------------------------------------------*/
30 #include "OSGOSBVoidPAttachmentElement.h"
32 #include "OSGOSBRootElement.h"
33 #include "OSGVoidPAttachment.h"
35 OSG_BEGIN_NAMESPACE
37 /*-------------------------------------------------------------------------*/
38 /* OSBVoidPAttachmentElement */
39 /*-------------------------------------------------------------------------*/
41 /*-------------------------------------------------------------------------*/
42 /* Static members */
44 OSBElementRegistrationHelper<OSBVoidPAttachmentElement>
45 OSBVoidPAttachmentElement::_regHelper =
46 OSBElementRegistrationHelper<OSBVoidPAttachmentElement>("VoidPAttachment");
48 /*-------------------------------------------------------------------------*/
49 /* Constructor */
51 OSBVoidPAttachmentElement::OSBVoidPAttachmentElement(OSBRootElement *root)
52 : Inherited(root, OSGOSBHeaderVersion200)
56 /*-------------------------------------------------------------------------*/
57 /* Destructor */
59 OSBVoidPAttachmentElement::~OSBVoidPAttachmentElement(void)
63 /*-------------------------------------------------------------------------*/
64 /* Reading */
66 void
67 OSBVoidPAttachmentElement::read(const std::string &typeName)
69 OSG_OSB_LOG(("OSBVoidPAttachmentElement::read [%s]\n", typeName.c_str()));
71 OSBRootElement *root = editRoot();
72 BinaryReadHandler *rh = editRoot()->getReadHandler();
73 UInt8 fcPtrType;
74 UInt16 version;
76 rh->getValue(fcPtrType);
77 rh->getValue(version );
79 setContainer(VoidPAttachmentUnrecPtr(VoidPAttachment::create()));
81 // keep these ordered from highest to lowest version
82 if(root->getHeaderVersion() >= OSGOSBHeaderVersion200)
84 if(root->getHeaderVersion() > OSGOSBHeaderVersion200)
86 FINFO(("OSBVoidPAttachmentElement::read: "
87 "Unknown header version, trying to read as latest.\n"));
90 readFields("", "");
92 else if(root->getHeaderVersion() >= OSGOSBHeaderVersion100)
94 // 1.x stores the address in 32 (!) chars and writes a string,
95 // skip it
97 readFields("'data'", "");
101 void
102 OSBVoidPAttachmentElement::postRead(void)
106 /*-------------------------------------------------------------------------*/
107 /* Writing */
109 void
110 OSBVoidPAttachmentElement::preWrite(FieldContainer * const fc)
112 OSG_OSB_LOG(("OSBVoidPAttachmentElement::preWrite\n"));
114 preWriteFieldContainer(fc, "");
117 void
118 OSBVoidPAttachmentElement::write(void)
120 OSG_OSB_LOG(("OSBVoidPAttachmentElement::write\n"));
122 if(getContainer() == NULL)
124 FWARNING(("OSBVoidPAttachmentElement::write: Attempt to write NULL.\n"));
125 return;
128 BinaryWriteHandler *wh = editRoot()->getWriteHandler();
130 wh->putValue(getFCPtrType(getContainer()));
131 wh->putValue(getVersion() );
133 writeFields("", true);
136 OSG_END_NAMESPACE