root/OpenSceneGraph/trunk/include/osgDB/ReadFile @ 13172

Revision 13172, 13.3 kB (checked in by robert, 6 hours ago)

Reordered method implemenations to make it easier to compare similar methods

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version.  The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14#ifndef OSGDB_READFILE
15#define OSGDB_READFILE 1
16
17#include <string>
18
19#include <osg/Node>
20#include <osg/Image>
21#include <osg/ArgumentParser>
22
23#include <osgDB/Export>
24#include <osgDB/Registry>
25
26namespace osgDB {
27
28
29/** Read an osg::Object from file.
30  * Return valid osg::Object on success,
31  * return NULL on failure.
32  * Use the Options object to control cache operations and file search paths in osgDB::Registry.
33  * The osgDB::Registry is used to load the appropriate ReaderWriter plugin
34  * for the filename extension, and this plugin then handles the request
35  * to read the specified file.*/
36extern OSGDB_EXPORT osg::Object* readObjectFile(const std::string& filename,const Options* options);
37
38/** Read an osg::Object from file.
39  * Return valid osg::Object on success,
40  * return NULL on failure.
41  * The osgDB::Registry is used to load the appropriate ReaderWriter plugin
42  * for the filename extension, and this plugin then handles the request
43  * to read the specified file.*/
44inline osg::Object* readObjectFile(const std::string& filename)
45{
46    return readObjectFile(filename, Registry::instance()->getOptions());
47}
48
49template<typename T>
50inline T* readFile(const std::string& filename, const Options* options)
51{
52    osg::ref_ptr<osg::Object> object = readObjectFile(filename, options);
53    osg::ref_ptr<T> t = dynamic_cast<T*>(object.get());
54    object = 0;   
55    return t.release();
56}
57
58template<typename T>
59inline T* readFile(const std::string& filename)
60{
61    return readFile<T>(filename, Registry::instance()->getOptions());
62}
63
64
65/** Read an osg::Image from file.
66  * Return valid osg::Image on success,
67  * return NULL on failure.
68  * Use the Options object to control cache operations and file search paths in osgDB::Registry.
69  * The osgDB::Registry is used to load the appropriate ReaderWriter plugin
70  * for the filename extension, and this plugin then handles the request
71  * to read the specified file.*/
72extern OSGDB_EXPORT osg::Image*  readImageFile(const std::string& filename,const Options* options);
73
74/** Read an osg::Image from file.
75  * Return valid osg::Image on success,
76  * return NULL on failure.
77  * The osgDB::Registry is used to load the appropriate ReaderWriter plugin
78  * for the filename extension, and this plugin then handles the request
79  * to read the specified file.*/
80inline osg::Image*  readImageFile(const std::string& filename)
81{
82    return readImageFile(filename,Registry::instance()->getOptions());
83}
84
85/** Read an osg::HeightField from file.
86  * Return valid osg::HeightField on success,
87  * return NULL on failure.
88  * Use the Options object to control cache operations and file search paths in osgDB::Registry.
89  * The osgDB::Registry is used to load the appropriate ReaderWriter plugin
90  * for the filename extension, and this plugin then handles the request
91  * to read the specified file.*/
92extern OSGDB_EXPORT osg::HeightField*  readHeightFieldFile(const std::string& filename,const Options* options);
93
94/** Read an osg::HeightField from file.
95  * Return valid osg::HeightField on success,
96  * return NULL on failure.
97  * The osgDB::Registry is used to load the appropriate ReaderWriter plugin
98  * for the filename extension, and this plugin then handles the request
99  * to read the specified file.*/
100inline osg::HeightField*  readHeightFieldFile(const std::string& filename)
101{
102    return readHeightFieldFile(filename,Registry::instance()->getOptions());
103}
104
105/** Read an osg::Node from file.
106  * Return valid osg::Node on success,
107  * return NULL on failure.
108  * Use the Options object to control cache operations and file search paths in osgDB::Registry.
109  * The osgDB::Registry is used to load the appropriate ReaderWriter plugin
110  * for the filename extension, and this plugin then handles the request
111  * to read the specified file.*/
112extern OSGDB_EXPORT osg::Node*  readNodeFile(const std::string& filename,const Options* options);
113
114/** Read an osg::Node from file.
115  * Return valid osg::Node on success,
116  * return NULL on failure.
117  * The osgDB::Registry is used to load the appropriate ReaderWriter plugin
118  * for the filename extension, and this plugin then handles the request
119  * to read the specified file.*/
120inline osg::Node*  readNodeFile(const std::string& filename)
121{
122    return readNodeFile(filename,Registry::instance()->getOptions());
123}
124
125
126/** Read an osg::Node subgraph from files, creating a osg::Group to contain the nodes if more
127  * than one subgraph has been loaded.
128  * Use the Options object to control cache operations and file search paths in osgDB::Registry.
129  * Does NOT ignore strings beginning with a dash '-' character. */
130extern OSGDB_EXPORT osg::Node* readNodeFiles(std::vector<std::string>& fileList,const Options* options);
131
132/** Read an osg::Node subgraph from files, creating a osg::Group to contain the nodes if more
133  * than one subgraph has been loaded.*/
134inline osg::Node* readNodeFiles(std::vector<std::string>& fileList)
135{
136    return readNodeFiles(fileList,Registry::instance()->getOptions());
137}
138
139
140/** Read an osg::Node subgraph from files, creating a osg::Group to contain the nodes if more
141  * than one subgraph has been loaded.
142  * Use the Options object to control cache operations and file search paths in osgDB::Registry.*/
143extern OSGDB_EXPORT osg::Node* readNodeFiles(osg::ArgumentParser& parser,const Options* options);
144
145/** Read an osg::Node subgraph from files, creating a osg::Group to contain the nodes if more
146  * than one subgraph has been loaded.*/
147inline osg::Node* readNodeFiles(osg::ArgumentParser& parser)
148{
149    return readNodeFiles(parser,Registry::instance()->getOptions());
150}
151
152/** Read an osg::Shader from file.
153  * Return valid osg::Shader on success,
154  * return NULL on failure.
155  * Use the Options object to control cache operations and file search paths in osgDB::Registry.
156  * The osgDB::Registry is used to load the appropriate ReaderWriter plugin
157  * for the filename extension, and this plugin then handles the request
158  * to read the specified file.*/
159extern OSGDB_EXPORT osg::Shader*  readShaderFile(const std::string& filename,const Options* options);
160
161/** Read an osg::Shader from file.
162  * Return valid osg::Shader on success,
163  * return NULL on failure.
164  * The osgDB::Registry is used to load the appropriate ReaderWriter plugin
165  * for the filename extension, and this plugin then handles the request
166  * to read the specified file.*/
167inline osg::Shader*  readShaderFile(const std::string& filename)
168{
169    return readShaderFile(filename,Registry::instance()->getOptions());
170}
171
172/** Read an osg::Shader from file and set to specified shader type.
173  * Return valid osg::Shader on success,
174  * return NULL on failure.
175  * Use the Options object to control cache operations and file search paths in osgDB::Registry.
176  * The osgDB::Registry is used to load the appropriate ReaderWriter plugin
177  * for the filename extension, and this plugin then handles the request
178  * to read the specified file.*/
179inline osg::Shader* readShaderFile(osg::Shader::Type type, const std::string& filename,const Options* options)
180{
181    osg::Shader* shader = readShaderFile(filename, options);
182    if (shader && type != osg::Shader::UNDEFINED) shader->setType(type);
183    return shader;
184}
185
186/** Read an osg::Shader from file and set to specified shader type
187  * Return valid osg::Shader on success,
188  * return NULL on failure.
189  * The osgDB::Registry is used to load the appropriate ReaderWriter plugin
190  * for the filename extension, and this plugin then handles the request
191  * to read the specified file.*/
192inline osg::Shader* readShaderFile(osg::Shader::Type type, const std::string& filename)
193{
194    return readShaderFile(type, filename,Registry::instance()->getOptions());
195}
196
197/** Read an osg::Object from file.
198  * Return an assigned osg::ref_ptr on success,
199  * return an osg::ref_ptr with a NULL pointer assigned to it on failure.
200  * Use the Options object to control cache operations and file search paths in osgDB::Registry.
201  * The osgDB::Registry is used to load the appropriate ReaderWriter plugin
202  * for the filename extension, and this plugin then handles the request
203  * to read the specified file.*/
204extern OSGDB_EXPORT osg::ref_ptr<osg::Object> readRefObjectFile(const std::string& filename,const Options* options);
205
206/** Read an osg::Object from file.
207  * Return an assigned osg::ref_ptr on success,
208  * return an osg::ref_ptr with a NULL pointer assigned to it on failure.
209  * The osgDB::Registry is used to load the appropriate ReaderWriter plugin
210  * for the filename extension, and this plugin then handles the request
211  * to read the specified file.*/
212inline osg::ref_ptr<osg::Object> readRefObjectFile(const std::string& filename)
213{
214    return readRefObjectFile(filename,Registry::instance()->getOptions());
215}
216
217/** Read an osg::Image from file.
218  * Return an assigned osg::ref_ptr on success,
219  * return an osg::ref_ptr with a NULL pointer assigned to it on failure.
220  * Use the Options object to control cache operations and file search paths in osgDB::Registry.
221  * The osgDB::Registry is used to load the appropriate ReaderWriter plugin
222  * for the filename extension, and this plugin then handles the request
223  * to read the specified file.*/
224extern OSGDB_EXPORT osg::ref_ptr<osg::Image>  readRefImageFile(const std::string& filename,const Options* options);
225
226/** Read an osg::Image from file.
227  * Return an assigned osg::ref_ptr on success,
228  * return an osg::ref_ptr with a NULL pointer assigned to it on failure.
229  * The osgDB::Registry is used to load the appropriate ReaderWriter plugin
230  * for the filename extension, and this plugin then handles the request
231  * to read the specified file.*/
232inline osg::ref_ptr<osg::Image>  readRefImageFile(const std::string& filename)
233{
234    return readRefImageFile(filename,Registry::instance()->getOptions());
235}
236
237/** Read an osg::HeightField from file.
238  * Return an assigned osg::ref_ptr on success,
239  * return an osg::ref_ptr with a NULL pointer assigned to it on failure.
240  * Use the Options object to control cache operations and file search paths in osgDB::Registry.
241  * The osgDB::Registry is used to load the appropriate ReaderWriter plugin
242  * for the filename extension, and this plugin then handles the request
243  * to read the specified file.*/
244extern OSGDB_EXPORT osg::ref_ptr<osg::HeightField>  readRefHeightFieldFile(const std::string& filename,const Options* options);
245
246/** Read an osg::HeightField from file.
247  * Return an assigned osg::ref_ptr on success,
248  * return an osg::ref_ptr with a NULL pointer assigned to it on failure.
249  * The osgDB::Registry is used to load the appropriate ReaderWriter plugin
250  * for the filename extension, and this plugin then handles the request
251  * to read the specified file.*/
252inline osg::ref_ptr<osg::HeightField>  readRefHeightFieldFile(const std::string& filename)
253{
254    return readRefHeightFieldFile(filename,Registry::instance()->getOptions());
255}
256
257/** Read an osg::Node from file.
258  * Return an assigned osg::ref_ptr on success,
259  * return an osg::ref_ptr with a NULL pointer assigned to it on failure.
260  * Use the Options object to control cache operations and file search paths in osgDB::Registry.
261  * The osgDB::Registry is used to load the appropriate ReaderWriter plugin
262  * for the filename extension, and this plugin then handles the request
263  * to read the specified file.*/
264extern OSGDB_EXPORT osg::ref_ptr<osg::Node>  readRefNodeFile(const std::string& filename,const Options* options);
265
266/** Read an osg::Node from file.
267  * Return an assigned osg::ref_ptr on success,
268  * return an osg::ref_ptr with a NULL pointer assigned to it on failure.
269  * The osgDB::Registry is used to load the appropriate ReaderWriter plugin
270  * for the filename extension, and this plugin then handles the request
271  * to read the specified file.*/
272inline osg::ref_ptr<osg::Node>  readRefNodeFile(const std::string& filename)
273{
274    return readRefNodeFile(filename,Registry::instance()->getOptions());
275}
276
277/** Read an osg::Shader from file.
278  * Return an assigned osg::ref_ptr on success,
279  * return an osg::ref_ptr with a NULL pointer assigned to it on failure.
280  * Use the Options object to control cache operations and file search paths in osgDB::Registry.
281  * The osgDB::Registry is used to load the appropriate ReaderWriter plugin
282  * for the filename extension, and this plugin then handles the request
283  * to read the specified file.*/
284extern OSGDB_EXPORT osg::ref_ptr<osg::Shader>  readRefShaderFile(const std::string& filename,const Options* options);
285
286/** Read an osg::Shader from file.
287  * Return an assigned osg::ref_ptr on success,
288  * return an osg::ref_ptr with a NULL pointer assigned to it on failure.
289  * The osgDB::Registry is used to load the appropriate ReaderWriter plugin
290  * for the filename extension, and this plugin then handles the request
291  * to read the specified file.*/
292inline osg::ref_ptr<osg::Shader>  readRefShaderFile(const std::string& filename)
293{
294    return readRefShaderFile(filename,Registry::instance()->getOptions());
295}
296
297
298}
299
300#endif
Note: See TracBrowser for help on using the browser.