root/OpenSceneGraph/trunk/src/osgPlugins/OpenFlight/Registry.h @ 10283

Revision 10283, 4.3 kB (checked in by robert, 6 years ago)

From Gregory Jaegy and Robert Osfield, added support for static linking of OpenFlight? plugin

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
RevLine 
[7748]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
[5038]14//
15// OpenFlight® loader for OpenSceneGraph
16//
[7748]17//  Copyright (C) 2005-2007  Brede Johansen
[5038]18//
19
20#ifndef FLT_REGISTRY_H
21#define FLT_REGISTRY_H 1
22
23#include <queue>
[5136]24#include <map>
[5038]25#include <osg/ref_ptr>
[8003]26#include "Opcodes.h"
[5038]27#include "Record.h"
28
29namespace flt {
30
31class Registry : public osg::Referenced
32{
33    public:
34       
35        ~Registry();
36        static Registry* instance();
37
[5136]38        // Record prototypes
[5038]39        void addPrototype(int opcode, Record* prototype);
40        Record* getPrototype(int opcode);
41
[5136]42        // External read queue
43        typedef std::pair<std::string, osg::Group*> FilenameParentPair; // ExtNameNodePair;
44        typedef std::queue<FilenameParentPair> ExternalQueue;
[5038]45
[5136]46        inline ExternalQueue& getExternalReadQueue() { return _externalReadQueue; }
47        void addToExternalReadQueue(const std::string& filename, osg::Group* parent);
[5038]48
[5136]49        // Local cache
[5986]50        void addExternalToLocalCache(const std::string& filename, osg::Node* node);
51        osg::Node* getExternalFromLocalCache(const std::string& filename);
52        void addTextureToLocalCache(const std::string& filename, osg::StateSet* stateset);
53        osg::StateSet* getTextureFromLocalCache(const std::string& filename);
[5136]54        void clearLocalCache();
[5038]55
56    protected:
57
58        Registry();
59
60        typedef std::map<int, osg::ref_ptr<Record> > RecordProtoMap;
[5136]61        RecordProtoMap     _recordProtoMap;
[5038]62
[5136]63        ExternalQueue      _externalReadQueue;
64
[5986]65        // External cache
[5136]66        typedef std::map<std::string, osg::ref_ptr<osg::Node> > ExternalCacheMap;
[5986]67        ExternalCacheMap _externalCacheMap;
68
69        // Texture cache
70        typedef std::map<std::string, osg::ref_ptr<osg::StateSet> > TextureCacheMap;
71        TextureCacheMap    _textureCacheMap;
[5038]72};
73
[5136]74inline void Registry::addToExternalReadQueue(const std::string& filename, osg::Group* parent)
75{
76    _externalReadQueue.push( FilenameParentPair(filename,parent) );
77}
[5038]78
[5986]79inline void Registry::addExternalToLocalCache(const std::string& filename, osg::Node* node)
[5136]80{
81    _externalCacheMap[filename] = node;
82}
83
[5986]84inline osg::Node* Registry::getExternalFromLocalCache(const std::string& filename)
[5136]85{
86    ExternalCacheMap::iterator itr = _externalCacheMap.find(filename);
87    if (itr != _externalCacheMap.end())
88        return (*itr).second.get();
89    return NULL;
90}
91
[5986]92inline void Registry::addTextureToLocalCache(const std::string& filename, osg::StateSet* stateset)
93{
94    _textureCacheMap[filename] = stateset;
95}
96
97inline osg::StateSet* Registry::getTextureFromLocalCache(const std::string& filename)
98{
99    TextureCacheMap::iterator itr = _textureCacheMap.find(filename);
100    if (itr != _textureCacheMap.end())
101        return (*itr).second.get();
102    return NULL;
103}
104
[5136]105inline void Registry::clearLocalCache()
106{
107    _externalCacheMap.clear();
[5986]108    _textureCacheMap.clear();
[5136]109}
110
[5038]111/** Proxy class for automatic registration of reader/writers with the Registry.*/
112template<class T>
113class RegisterRecordProxy
114{
115    public:
116
117        explicit RegisterRecordProxy(int opcode)
118        {
119            Registry::instance()->addPrototype(opcode,new T);
120        }
121
122        ~RegisterRecordProxy() {}
123};
124
[10283]125//////////////////////////////////////////////////////////////////////////
126
127extern "C"
128{
129    typedef void (* CRecordFunction) (void);
130}
131
132struct RecordFunctionProxy
133{
134    RecordFunctionProxy(CRecordFunction function) { (function)(); }
135};
136
137#define USE_FLTRECORD(recname, opcode) \
138    extern "C" void osgfltrec_##recname_##opcode(void); \
139    static flt::RecordFunctionProxy proxy_fltrecord_##recname_##opcode(osgfltrec_##recname_##opcode);
140
141#define REGISTER_FLTRECORD(recname, opcode) \
142    extern "C" void osgfltrec_##recname_##opcode(void) {} \
143    static flt::RegisterRecordProxy<recname> g_proxy_fltrecord_##recname_##opcode(opcode);
144
145
[5038]146} // end namespace
147
148#endif
Note: See TracBrowser for help on using the browser.