]> git.mxchange.org Git - simgear.git/blob - simgear/scene/model/ModelRegistry.hxx
Move SGReadFileCallback from model.cxx to public class ModelRegistry
[simgear.git] / simgear / scene / model / ModelRegistry.hxx
1 // ModelRegistry.hxx -- interface to the OSG model registry
2 //
3 // Copyright (C) 2007  Tim Moore <timoore@redhat.com>
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License as
7 // published by the Free Software Foundation; either version 2 of the
8 // License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful, but
11 // WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18 #ifndef _SG_MODELREGISTRY_HXX
19 #define _SG_MODELREGISTRY_HXX 1
20
21 #include <osg/ref_ptr>
22 #include <osgDB/ReaderWriter>
23 #include <osgDB/Registry>
24
25 #include <simgear/compiler.h>
26
27 #include STL_STRING
28 #include <map>
29
30 namespace simgear
31 {
32 class ModelRegistry : public osgDB::Registry::ReadFileCallback {
33 public:
34     virtual osgDB::ReaderWriter::ReadResult
35     readImage(const std::string& fileName,
36               const osgDB::ReaderWriter::Options* opt);
37     virtual osgDB::ReaderWriter::ReadResult
38     readNode(const std::string& fileName,
39              const osgDB::ReaderWriter::Options* opt);
40     void addImageCallbackForExtension(const std::string& extension,
41                                       osgDB::Registry::ReadFileCallback*
42                                       callback);
43     void addNodeCallbackForExtension(const std::string& extension,
44                                      osgDB::Registry::ReadFileCallback*
45                                      callback);
46     static ModelRegistry* getInstance();
47 protected:
48     static osg::ref_ptr<ModelRegistry> instance;
49     typedef std::map<std::string, osg::ref_ptr<osgDB::Registry::ReadFileCallback> >
50     CallbackMap;
51     CallbackMap imageCallbackMap;
52     CallbackMap nodeCallbackMap;
53 };
54
55 // Proxy for registering extension-based callbacks
56
57 template<typename T>
58 class ModelRegistryCallbackProxy
59 {
60 public:
61     ModelRegistryCallbackProxy(std::string extension)
62     {
63         ModelRegistry::getInstance()->addNodeCallbackForExtension(extension,
64                                                                   new T);
65     }
66 };
67
68 // Callback for file extensions that load files using the default OSG
69 // implementation.
70
71 class OSGFileCallback : public osgDB::Registry::ReadFileCallback {
72 public:
73     virtual osgDB::ReaderWriter::ReadResult
74     readImage(const std::string& fileName,
75               const osgDB::ReaderWriter::Options* opt);
76     virtual osgDB::ReaderWriter::ReadResult
77     readNode(const std::string& fileName,
78              const osgDB::ReaderWriter::Options* opt);
79 };
80
81 }
82 #endif // _SG_MODELREGISTRY_HXX