fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / FileIO / WRL / OSGVRMLSceneFileType.cpp
blob63122aedd31147e27557d0ec41d753848bfb9f7a
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2002 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 <cstdlib>
40 #include <cstdio>
42 #include <fstream>
44 #include "OSGConfig.h"
46 #include "OSGVRMLSceneFileType.h"
47 #include "OSGVRMLWriteAction.h"
49 #include "OSGVRMLFile.h"
51 OSG_USING_NAMESPACE
53 /*! \class OSG::VRMLSceneFileType
54 \ingroup GrpSystemFileIO
57 const Char8 *VRMLSceneFileType::_suffixA[] = { "wrl", "wrz" };
59 VRMLSceneFileType VRMLSceneFileType::_the(_suffixA,
60 sizeof(_suffixA),
61 false,
62 10,
63 (OSG_READ_SUPPORTED |
64 OSG_WRITE_SUPPORTED));
66 /*-------------------------------------------------------------------------*/
67 /* The */
69 VRMLSceneFileType &VRMLSceneFileType::the(void)
71 return _the;
75 /*-------------------------------------------------------------------------*/
76 /* Destructor */
78 VRMLSceneFileType::~VRMLSceneFileType(void)
82 /*-------------------------------------------------------------------------*/
83 /* Get */
85 const Char8 *VRMLSceneFileType::getName(void) const
87 return "VRML Geometry";
90 /*-------------------------------------------------------------------------*/
91 /* Read */
93 NodeTransitPtr VRMLSceneFileType::read( std::istream &is,
94 const Char8 *,
95 Resolver ) const
97 NodeTransitPtr root(NULL);
99 VRMLFile *loader = new VRMLFile();
101 bool pushNames = false;
103 if(this->getOptionAs("pushNames", pushNames) == true)
105 if(pushNames == true)
106 loader->addOptions(VRMLFile::PushNames);
109 loader->createStandardPrototypes();
111 root = loader->scanStream(is);
113 delete loader;
115 commitChanges();
117 return root;
120 /*-------------------------------------------------------------------------*/
121 /* Write */
123 bool VRMLSceneFileType::write(Node * const node,
124 std::ostream &os,
125 Char8 const *fileNameOrExtension) const
127 // This is a hack but should be safer.
129 std::ofstream *osf = dynamic_cast<std::ofstream *>(&os);
131 if(osf != NULL)
132 osf->close();
134 VRMLWriteAction *pWriter = VRMLWriteAction::create();
136 // parse options
137 bool inlineTex = false;
138 if(getOptionAs<bool>("inlineTextures", inlineTex))
140 if(inlineTex)
141 pWriter->addOptions(VRMLWriteAction::OSGPixelTextures);
142 else
143 pWriter->subOptions(VRMLWriteAction::OSGPixelTextures);
146 pWriter->open(fileNameOrExtension);
148 pWriter->write(node);
150 pWriter->close();
152 delete pWriter;
154 return true;
157 /*-------------------------------------------------------------------------*/
158 /* Constructors */
160 VRMLSceneFileType::VRMLSceneFileType(const Char8 *suffixArray[],
161 UInt16 suffixByteCount,
162 bool override,
163 UInt32 overridePriority,
164 UInt32 flags) :
165 Inherited(suffixArray,
166 suffixByteCount,
167 override,
168 overridePriority,
169 flags)