fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / FileIO / OSB / OSGOSBDriver.cpp
blob14662316a4c1754e65a32ec11abbffaff0f76e1c
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 "OSGOSBDriver.h"
41 #include "OSGOSBElementFactory.h"
42 #include "OSGOSBRootElement.h"
44 OSG_BEGIN_NAMESPACE
46 /*-------------------------------------------------------------------------*/
47 /* OSBDriver */
48 /*-------------------------------------------------------------------------*/
50 /*! \class OSG::OSBDriver
51 This is the interface used by OSG::NFIOSceneFileType to access the
52 functionality of the OSB IO (OpenSG Binary IO) subsystem.
55 /*! Reads from \a inStream which must provide access to an ".osb" file.
57 \param[in] inStream Stream to read data from.
58 \param[in] options String that holds the options for the read operation.
60 \return On success a Node * to the root of the read scene,
61 NULL otherwise.
63 NodeTransitPtr OSBDriver::read( std::istream &inStream,
64 const IOFileTypeBase::OptionSet &options )
66 return dynamic_pointer_cast<Node>(readFC(inStream, options));
69 /*! Writes the scene with root \a node to \a outStream in OSB format.
71 \param[in] node Root of scene to write.
72 \param[in] outStream Stream to write data to.
73 \param[in] options String that holds the options for the write operation.
75 \return true.
76 \todo Should only return true if write was successful.
78 bool OSBDriver::write( Node * const node,
79 std::ostream &outStream,
80 const IOFileTypeBase::OptionSet &options )
82 return writeFC(node, outStream, options);
85 /*! Reads from \a inStream which must provide access to an ".osb" file.
87 \param[in] inStream Stream to read data from.
88 \param[in] options String that holds the options for the read operation.
90 \return On success a pointer to the container read from the file.
91 NULL otherwise.
93 FieldContainerTransitPtr
94 OSBDriver::readFC( std::istream &inStream,
95 const IOFileTypeBase::OptionSet &options )
97 FieldContainerTransitPtr retVal;
98 OSBRootElement *root = dynamic_cast<OSBRootElement *>(
99 OSBElementFactory::the()->acquire("RootElement", 0));
101 root->initialiseRead(inStream);
102 root->editOptions ( ).init(options);
104 root->read ("");
105 root->postRead( );
107 retVal = root->getContainer();
109 root->terminateRead();
111 OSBElementFactory::the()->release(root);
113 commitChanges();
115 return retVal;
118 bool
119 OSBDriver::writeFC( FieldContainer * const fc,
120 std::ostream &outStream,
121 const IOFileTypeBase::OptionSet &options )
123 OSBRootElement *root = dynamic_cast<OSBRootElement *>(
124 OSBElementFactory::the()->acquire("RootElement", 0));
126 root->initialiseWrite(outStream);
127 root->editOptions ( ).init(options);
129 root->preWrite(fc);
130 root->write ( );
132 root->terminateWrite();
134 OSBElementFactory::the()->release(root);
136 return true;
139 OSG_END_NAMESPACE