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 "OSGOSBDriver.h"
41 #include "OSGOSBElementFactory.h"
42 #include "OSGOSBRootElement.h"
46 /*-------------------------------------------------------------------------*/
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,
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.
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.
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
);
107 retVal
= root
->getContainer();
109 root
->terminateRead();
111 OSBElementFactory::the()->release(root
);
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
);
132 root
->terminateWrite();
134 OSBElementFactory::the()->release(root
);