root/OpenSceneGraph/trunk/include/osgDB/Registry @ 10227

Revision 10227, 32.7 kB (checked in by robert, 6 years ago)

Minor tweaks to avoid warnings when generating wrappers/doxygen documentation

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
RevLine 
[5328]1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
[1529]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*/
[51]13
[8]14#ifndef OSGDB_REGISTRY
15#define OSGDB_REGISTRY 1
16
[8929]17#include <OpenThreads/ReentrantMutex>
18
[8]19#include <osg/ref_ptr>
[1610]20#include <osg/ArgumentParser>
[8535]21#include <osg/KdTree>
[8]22
23#include <osgDB/DynamicLibrary>
24#include <osgDB/ReaderWriter>
[10171]25#include <osgDB/Options>
[8]26#include <osgDB/DotOsgWrapper>
[2614]27#include <osgDB/DatabasePager>
[9038]28#include <osgDB/FileCache>
[8]29
[773]30#include <vector>
31#include <map>
32#include <string>
33
[6769]34extern "C"
35{
36    typedef void (* CPluginFunction) (void);
37}
[773]38
[8]39namespace osgDB {
40
[2057]41/** basic structure for custom runtime inheritance checking */
42struct basic_type_wrapper {
[4461]43    virtual ~basic_type_wrapper() {}
[2877]44    virtual bool matches(const osg::Object *proto) const = 0;
[2057]45};
[225]46
[2057]47/** a class template that checks inheritance between a given
48    Object's class and a class defined at compile time through
[2877]49        the template parameter T.
50        This is used in conjunction with readObjectOfType() to
51        specify an abstract class as reference type.
[2057]52**/
53template<class T>
54struct type_wrapper: basic_type_wrapper {
[2877]55    bool matches(const osg::Object *proto) const
56    {
57        return dynamic_cast<const T*>(proto) != 0;
58    }
[2057]59};
60
[773]61
[8]62/**
63    Registry is a singleton factory which stores
[31]64    the reader/writers which are linked in
[8]65    at runtime for reading non-native file formats.
66
[31]67    The RegisterDotOsgWrapperProxy can be used to automatically register
68    DotOsgWrappers, at runtime with the Registry. A DotOsgWrapper encapsulates
69    the functions that can read and write to the .osg for each osg::Object.
[8]70
71    The RegisterReaderWriterProxy can be used to automatically
72    register at runtime a reader/writer with the Registry.
73*/
[1463]74class OSGDB_EXPORT Registry : public osg::Referenced
[8]75{
76    public:
77
[3580]78
[2877]79
80       
[2534]81        static Registry* instance(bool erase = false);
[434]82
[1610]83        /** read the command line arguments.*/
84        void readCommandLine(osg::ArgumentParser& commandLine);
85
[8]86        /** register an .fileextension alias to mapExt toExt, the later
[4461]87          * should the the extension name of the readerwriter plugin library.
88          * For example to map .tif files to the tiff loader, use
89          * addExtAlias("tif","tiff") which will enable .tif to be read
90          * by the libdb_tiff readerwriter plugin.*/
91        void addFileExtensionAlias(const std::string mapExt, const std::string toExt);
[8]92
[6089]93        /** Reads a file that configures extension mappings. File is ASCII text
[7648]94          * and each line contains the parameters to the addFileExtensionAlias
[6089]95          * method. Lines can be commented out with an initial '#' character.*/
96        bool readPluginAliasConfigurationFile( const std::string& file );
97
[10000]98        /** Registers a mapping of a mime-type to an extension. A process fetching data
99          * over HTTP can use this facility to determine the proper ReaderWriter to use
100          * when there is no filename extension to rely upon.
101          */
102        void addMimeTypeExtensionMapping(const std::string fromMimeType, const std::string toExt);
103
[8]104        void addDotOsgWrapper(DotOsgWrapper* wrapper);
105        void removeDotOsgWrapper(DotOsgWrapper* wrapper);
106
107        void addReaderWriter(ReaderWriter* rw);
108        void removeReaderWriter(ReaderWriter* rw);
109
110        /** create the platform specific library name associated with file.*/
111        std::string createLibraryNameForFile(const std::string& fileName);
112
113        /** create the platform specific library name associated with file extension.*/
[2016]114        std::string createLibraryNameForExtension(const std::string& ext);
[8]115
[742]116        /** create the platform specific library name associated with nodekit library name.*/
117        std::string createLibraryNameForNodeKit(const std::string& name);
118
[8947]119
120        enum LoadStatus {
121            NOT_LOADED = 0,
122            PREVIOUSLY_LOADED,
123            LOADED
124        };
125
[5697]126        /** find the library in the OSG_LIBRARY_PATH and load it.*/
[8947]127        LoadStatus loadLibrary(const std::string& fileName);
[5697]128       
[8]129        /** close the attached library with specified name.*/
130        bool closeLibrary(const std::string& fileName);
[5697]131       
[2534]132        /** close all libraries.*/
133        void closeAllLibraries();
[8]134
[8582]135        typedef std::vector< osg::ref_ptr<ReaderWriter> > ReaderWriterList;
136
[2016]137        /** get a reader writer which handles specified extension.*/
138        ReaderWriter* getReaderWriterForExtension(const std::string& ext);
[10000]139
140        /** gets a reader/writer that handles the extension mapped to by one of
141          * the registered mime-types. */
142        ReaderWriter* getReaderWriterForMimeType(const std::string& mimeType);
[8582]143       
144        /** get list of all registered ReaderWriters.*/
145        ReaderWriterList& getReaderWriterList() { return _rwList; }
146
147        /** get const list of all registered ReaderWriters.*/
148        const ReaderWriterList& getReaderWriterList() const { return _rwList; }
[2016]149 
[2057]150        osg::Object*         readObjectOfType(const osg::Object& compObj,Input& fr);       
151        osg::Object*         readObjectOfType(const basic_type_wrapper &btw, Input& fr);
[8]152
153        osg::Object*         readObject(Input& fr);
154        osg::Image*          readImage(Input& fr);
155        osg::Drawable*       readDrawable(Input& fr);
[4061]156        osg::Uniform*        readUniform(Input& fr);
[8]157        osg::StateAttribute* readStateAttribute(Input& fr);
158        osg::Node*           readNode(Input& fr);
[7908]159        osg::Shader*         readShader(Input& fr);
[8]160       
161        bool                 writeObject(const osg::Object& obj,Output& fw);
162
[10171]163
164        typedef class osgDB::FindFileCallback FindFileCallback;
165        typedef class osgDB::ReadFileCallback ReadFileCallback;
166        typedef class osgDB::WriteFileCallback WriteFileCallback;
[10174]167        typedef class osgDB::FileLocationCallback FileLocationCallback;
[10171]168
169        /** Set the Registry callback to use in place of the default findFile calls.*/
170        void setFindFileCallback( FindFileCallback* cb) { _findFileCallback = cb; }
171
172        /** Get the findFile callback.*/
173        FindFileCallback* getFindFileCallback() { return _findFileCallback.get(); }
174
175        /** Get the const findFile callback.*/
176        const FindFileCallback* getFindFileCallback() const { return _findFileCallback.get(); }
177
178
179        std::string findDataFile(const std::string& fileName, const Options* options, CaseSensitivity caseSensitivity)
[2877]180        {
[10171]181            if (options && options->getFindFileCallback()) return options->getFindFileCallback()->findDataFile(fileName, options, caseSensitivity);
182            else if (_findFileCallback.valid()) return _findFileCallback->findDataFile(fileName, options, caseSensitivity);
183            else return findDataFileImplementation(fileName, options, caseSensitivity);
184        }
185        std::string findDataFileImplementation(const std::string& fileName, const Options* options, CaseSensitivity caseSensitivity);
[8]186
[10171]187        std::string findLibraryFile(const std::string& fileName, const Options* options, CaseSensitivity caseSensitivity)
188        {
189            if (options && options->getFindFileCallback()) return options->getFindFileCallback()->findLibraryFile(fileName, options, caseSensitivity);
190            else if (_findFileCallback.valid()) return _findFileCallback->findLibraryFile(fileName, options, caseSensitivity);
191            else return findLibraryFileImplementation(fileName, options, caseSensitivity);
192        }
193        std::string findLibraryFileImplementation(const std::string& fileName, const Options* options, CaseSensitivity caseSensitivity);
[7908]194
[8]195
[10171]196
[2877]197        /** Set the Registry callback to use in place of the default readFile calls.*/
198        void setReadFileCallback( ReadFileCallback* cb) { _readFileCallback = cb; }
[2398]199
[2877]200        /** Get the readFile callback.*/
201        ReadFileCallback* getReadFileCallback() { return _readFileCallback.get(); }
[8]202       
[2877]203        /** Get the const readFile callback.*/
204        const ReadFileCallback* getReadFileCallback() const { return _readFileCallback.get(); }
205
206
[10171]207        ReaderWriter::ReadResult openArchive(const std::string& fileName,ReaderWriter::ArchiveStatus status, unsigned int indexBlockSizeHint, const Options* options)
[3580]208        {
[10171]209            if (options && options->getReadFileCallback()) return options->getReadFileCallback()->openArchive(fileName, status, indexBlockSizeHint, options);
210            else if (_readFileCallback.valid()) return _readFileCallback->openArchive(fileName, status, indexBlockSizeHint, options);
[3689]211            else return openArchiveImplementation(fileName, status, indexBlockSizeHint, options);
[3580]212        }
[10171]213        ReaderWriter::ReadResult openArchiveImplementation(const std::string& fileName, ReaderWriter::ArchiveStatus status, unsigned int indexBlockSizeHint, const Options* options);
[3580]214
[10171]215        ReaderWriter::ReadResult readObject(const std::string& fileName,const Options* options, bool buildKdTreeIfRequired=true)
[2877]216        {
[10171]217            ReaderWriter::ReadResult result;
218            if (options && options->getReadFileCallback()) result = options->getReadFileCallback()->readObject(fileName,options);
219            else if (_readFileCallback.valid()) result = _readFileCallback->readObject(fileName,options);
220            else result = readObjectImplementation(fileName,options);
221
[9038]222            if (buildKdTreeIfRequired) _buildKdTreeIfRequired(result, options);
[10171]223
[8535]224            return result;
[2877]225        }
[10171]226        ReaderWriter::ReadResult readObjectImplementation(const std::string& fileName,const Options* options);
227
228        ReaderWriter::ReadResult readImage(const std::string& fileName,const Options* options)
[2877]229        {
[10171]230            if (options && options->getReadFileCallback()) return options->getReadFileCallback()->readImage(fileName,options);
231            else if (_readFileCallback.valid()) return _readFileCallback->readImage(fileName,options);
[3689]232            else return readImageImplementation(fileName,options);
[2877]233        }
[10171]234        ReaderWriter::ReadResult readImageImplementation(const std::string& fileName,const Options* options);
[2877]235
[10171]236        ReaderWriter::ReadResult readHeightField(const std::string& fileName,const Options* options)
[2877]237        {
[10171]238            if (options && options->getReadFileCallback()) return options->getReadFileCallback()->readHeightField(fileName,options);
239            else if (_readFileCallback.valid()) return _readFileCallback->readHeightField(fileName,options);
[3689]240            else return readHeightFieldImplementation(fileName,options);
[2877]241        }
[10171]242        ReaderWriter::ReadResult readHeightFieldImplementation(const std::string& fileName,const Options* options);
[2877]243
[10171]244        ReaderWriter::ReadResult readNode(const std::string& fileName,const Options* options, bool buildKdTreeIfRequired=true)
[2877]245        {
[10171]246            ReaderWriter::ReadResult result;
247            if (options && options->getReadFileCallback()) result = options->getReadFileCallback()->readNode(fileName,options);
248            else if (_readFileCallback.valid()) result = _readFileCallback->readNode(fileName,options);
249            else result = readNodeImplementation(fileName,options);
250
[9038]251            if (buildKdTreeIfRequired) _buildKdTreeIfRequired(result, options);
[10171]252
[8535]253            return result;
[2877]254        }
[10171]255        ReaderWriter::ReadResult readNodeImplementation(const std::string& fileName,const Options* options);
[2877]256
[10171]257        ReaderWriter::ReadResult readShader(const std::string& fileName,const Options* options)
[7908]258        {
[10171]259            if (options && options->getReadFileCallback()) return options->getReadFileCallback()->readShader(fileName,options);
[7908]260            if (_readFileCallback.valid()) return _readFileCallback->readShader(fileName,options);
261            else return readShaderImplementation(fileName,options);
262        }
[10171]263        ReaderWriter::ReadResult readShaderImplementation(const std::string& fileName,const Options* options);
[2877]264
[3580]265
[2877]266        /** Set the Registry callback to use in place of the default writeFile calls.*/
267        void setWriteFileCallback( WriteFileCallback* cb) { _writeFileCallback = cb; }
268
269        /** Get the writeFile callback.*/
270        WriteFileCallback* getWriteFileCallback() { return _writeFileCallback.get(); }
271       
272        /** Get the const writeFile callback.*/
273        const WriteFileCallback* getWriteFileCallback() const { return _writeFileCallback.get(); }
274
275
[10171]276        ReaderWriter::WriteResult writeObject(const osg::Object& obj, const std::string& fileName,const Options* options)
[2877]277        {
[10171]278            if (options && options->getWriteFileCallback()) return options->getWriteFileCallback()->writeObject(obj,fileName,options);
279            else if (_writeFileCallback.valid()) return _writeFileCallback->writeObject(obj,fileName,options);
[7518]280            else return writeObjectImplementation(obj,fileName,options);
[2877]281        }
[10171]282        ReaderWriter::WriteResult writeObjectImplementation(const osg::Object& obj, const std::string& fileName,const Options* options);
[2877]283
[10171]284        ReaderWriter::WriteResult writeImage(const osg::Image& obj, const std::string& fileName,const Options* options)
[2877]285        {
[10171]286            if (options && options->getWriteFileCallback()) return options->getWriteFileCallback()->writeImage(obj,fileName,options);
287            else if (_writeFileCallback.valid()) return _writeFileCallback->writeImage(obj,fileName,options);
[7518]288            else return writeImageImplementation(obj,fileName,options);
[2877]289        }
[10171]290        ReaderWriter::WriteResult writeImageImplementation(const osg::Image& obj, const std::string& fileName,const Options* options);
[2877]291
[10171]292        ReaderWriter::WriteResult writeHeightField(const osg::HeightField& obj, const std::string& fileName,const Options* options)
[2877]293        {
[10171]294            if (options && options->getWriteFileCallback()) return options->getWriteFileCallback()->writeHeightField(obj,fileName,options);
295            else if (_writeFileCallback.valid()) return _writeFileCallback->writeHeightField(obj,fileName,options);
[7518]296            else return writeHeightFieldImplementation(obj,fileName,options);
[2877]297        }
[10171]298        ReaderWriter::WriteResult writeHeightFieldImplementation(const osg::HeightField& obj, const std::string& fileName,const Options* options);
[2877]299
[10171]300        ReaderWriter::WriteResult writeNode(const osg::Node& node, const std::string& fileName,const Options* options)
[2877]301        {
[10171]302            if (options && options->getWriteFileCallback()) return options->getWriteFileCallback()->writeNode(node,fileName,options);
303            else if (_writeFileCallback.valid()) return _writeFileCallback->writeNode(node,fileName,options);
[7518]304            else return writeNodeImplementation(node,fileName,options);
[2877]305        }
[10171]306        ReaderWriter::WriteResult writeNodeImplementation(const osg::Node& node, const std::string& fileName,const Options* options);
[2877]307       
[10171]308        ReaderWriter::WriteResult writeShader(const osg::Shader& obj, const std::string& fileName,const Options* options)
[7908]309        {
[10171]310            if (options && options->getWriteFileCallback()) return options->getWriteFileCallback()->writeShader(obj,fileName,options);
311            else if (_writeFileCallback.valid()) return _writeFileCallback->writeShader(obj,fileName,options);
[7908]312            else return writeShaderImplementation(obj,fileName,options);
313        }
[10171]314        ReaderWriter::WriteResult writeShaderImplementation(const osg::Shader& obj, const std::string& fileName,const Options* options);
[2877]315       
[3580]316
[10171]317        inline void _buildKdTreeIfRequired(ReaderWriter::ReadResult& result, const Options* options)
[8535]318        {
[10171]319            bool doKdTreeBuilder = (options && options->getBuildKdTreesHint()!=Options::NO_PREFERENCE) ?
320                options->getBuildKdTreesHint() == Options::BUILD_KDTREES :
321                _buildKdTreesHint == Options::BUILD_KDTREES;
[8535]322
323            if (doKdTreeBuilder && _kdTreeBuilder.valid() && result.validNode())
324            {
[8541]325                osg::ref_ptr<osg::KdTreeBuilder> builder = _kdTreeBuilder->clone();
326                result.getNode()->accept(*builder);
[8535]327            }
328        }
329
[10227]330        /** Set the callback to use inform the DatabasePager whether a file is located on local or remote file system.*/
[10174]331        void setFileLocationCallback( FileLocationCallback* cb) { _fileLocationCallback = cb; }
[8535]332
[10227]333        /** Get the callback to use inform the DatabasePager whether a file is located on local or remote file system.*/
[10174]334        FileLocationCallback* getFileLocationCallback() const { return _fileLocationCallback.get(); }
335
336
337
[8619]338        /** Set whether the KdTrees should be built for geometry in the loader model. */
[10171]339        void setBuildKdTreesHint(Options::BuildKdTreesHint hint) { _buildKdTreesHint = hint; }
[8619]340
341        /** Get whether the KdTrees should be built for geometry in the loader model. */
[10171]342        Options::BuildKdTreesHint getBuildKdTreesHint() const { return _buildKdTreesHint; }
[8535]343
[8619]344        /** Set the KdTreeBuilder visitor that is used to build KdTree on loaded models.*/
[8535]345        void setKdTreeBuilder(osg::KdTreeBuilder* builder) { _kdTreeBuilder = builder; }
[8619]346
347        /** Get the KdTreeBuilder visitor that is used to build KdTree on loaded models.*/
[8535]348        osg::KdTreeBuilder* getKdTreeBuilder() { return _kdTreeBuilder.get(); }
349
[10174]350
[9038]351        /** Set the FileCache that is used to manage local storage of files downloaded from the internet.*/
352        void setFileCache(FileCache* fileCache) { _fileCache = fileCache; }
[8535]353
[9038]354        /** Get the FileCache that is used to manage local storage of files downloaded from the internet.*/
355        FileCache* getFileCache() { return _fileCache.get(); }
356
357        /** Get the const FileCache that is used to manage local storage of files downloaded from the internet.*/
358        const FileCache* getFileCache() const { return _fileCache.get(); }
359
360
[8619]361        /** Set the password map to be used by plugins when access files from secure locations.*/
362        void setAuthenticationMap(AuthenticationMap* authenticationMap) { _authenticationMap = authenticationMap; }
363
364        /** Get the password map to be used by plugins when access files from secure locations.*/
[8641]365        AuthenticationMap* getAuthenticationMap() { return _authenticationMap.get(); }
366
367        /** Get the password map to be used by plugins when access files from secure locations.*/
[8619]368        const AuthenticationMap* getAuthenticationMap() const { return _authenticationMap.get(); }
369
370
[8]371        void setCreateNodeFromImage(bool flag) { _createNodeFromImage = flag; }
372        bool getCreateNodeFromImage() const { return _createNodeFromImage; }
[8619]373       
[8]374
[10171]375        void setOptions(Options* opt) { _options = opt; }
376        Options* getOptions() { return _options.get(); }
377        const Options*  getOptions() const { return _options.get(); }
[93]378
379
[7648]380        /** initialize both the Data and Library FilePaths, by default called by the
[773]381          * constructor, so it should only be required if you want to force
382          * the re-reading of environmental variables.*/
383        void initFilePathLists() { initDataFilePathList(); initLibraryFilePathList(); }
384       
[7648]385        /** initialize the Data FilePath by reading the OSG_FILE_PATH environmental variable.*/
[773]386        void initDataFilePathList();
387
388        /** Set the data file path using a list of paths stored in a FilePath, which is used when search for data files.*/
389        void setDataFilePathList(const FilePathList& filepath) { _dataFilePath = filepath; }
390
[7648]391        /** Set the data file path using a single string delimited either with ';' (Windows) or ':' (All other platforms), which is used when search for data files.*/
[3330]392        void setDataFilePathList(const std::string& paths);
[773]393
394        /** get the data file path which is used when search for data files.*/
395        FilePathList& getDataFilePathList() { return _dataFilePath; }
396
397        /** get the const data file path which is used when search for data files.*/
398        const FilePathList& getDataFilePathList() const { return _dataFilePath; }
399
[7648]400        /** initialize the Library FilePath by reading the OSG_LIBRARY_PATH
[773]401          * and the appropriate system environmental variables*/
402        void initLibraryFilePathList();
403
404        /** Set the library file path using a list of paths stored in a FilePath, which is used when search for data files.*/
405        void setLibraryFilePathList(const FilePathList& filepath) { _libraryFilePath = filepath; }
406
[7648]407        /** Set the library file path using a single string delimited either with ';' (Windows) or ':' (All other platforms), which is used when search for data files.*/
[3330]408        void setLibraryFilePathList(const std::string& paths);
[773]409
410        /** get the library file path which is used when search for library (dso/dll's) files.*/
411        FilePathList& getLibraryFilePathList() { return _libraryFilePath; }
412       
413        /** get the const library file path which is used when search for library (dso/dll's) files.*/
414        const FilePathList& getLibraryFilePathList() const { return _libraryFilePath; }
415
[1708]416        /** For each object in the cache which has an reference count greater than 1
417          * (and therefore referenced by elsewhere in the application) set the time stamp
418          * for that object in the cache to specified time.
419          * This would typically be called once per frame by applications which are doing database paging,
420          * and need to prune objects that are no longer required.
[7648]421          * Time value is time in seconds.*/
[7038]422        void updateTimeStampOfObjectsInCacheWithExternalReferences(double currentTime);
[1708]423
424        /** Removed object in the cache which have a time stamp at or before the specified expiry time.
425          * This would typically be called once per frame by applications which are doing database paging,
426          * and need to prune objects that are no longer required, and called after the a called
[7038]427          * after the call to updateTimeStampOfObjectsInCacheWithExternalReferences(currentTime).
[1708]428          * Note, the currentTime is not the expiryTime, one would typically set the expiry time
429          * to a fixed amount of time before currentTime, such as expiryTime = currentTime-10.0.
[7648]430          * Time value is time in seconds.*/
[1708]431        void removeExpiredObjectsInCache(double expiryTime);
432       
433        /** Remove all objects in the cache regardless of having external references or expiry times.*/
434        void clearObjectCache();
435
[7648]436        /** Add a filename,object,timestamp triple to the Registry::ObjectCache.*/
[2335]437        void addEntryToObjectCache(const std::string& filename, osg::Object* object, double timestamp = 0.0);
[3876]438
[4461]439        /** Get an object from the object cache*/
440        osg::Object* getFromObjectCache(const std::string& fileName);
[2340]441       
[3598]442        /** Add archive to archive cache so that future calls reference this archive.*/
443        void addToArchiveCache(const std::string& fileName, osgDB::Archive* archive);
444
445        /** Remove archive from cache.*/
446        void removeFromArchiveCache(const std::string& fileName);
447       
448        /** Get an archive from the archive cache*/
449        osgDB::Archive* getFromArchiveCache(const std::string& fileName);
450       
451        /** Remove all archives from the archive cache.*/
452        void clearArchiveCache();
[4170]453       
454         /** If State is non-zero, this function releases OpenGL objects for
455           * the specified graphics context. Otherwise, releases OpenGL objexts
456           * for all graphics contexts. */
457        void releaseGLObjects(osg::State* state=0);
[3598]458
[2166]459        /** get the attached library with specified name.*/
460        DynamicLibrary*              getLibrary(const std::string& fileName);
[8]461
[2631]462        /** Set the SharedStateManager.*/
463        void setSharedStateManager(SharedStateManager* SharedStateManager) { _sharedStateManager = SharedStateManager; }
464
465        /** Get the SharedStateManager, creating one if one is not already created.*/
466        SharedStateManager* getOrCreateSharedStateManager();
467       
468        /** Get the SharedStateManager. Return 0 if no SharedStateManager has been assigned.*/
469        SharedStateManager* getSharedStateManager() { return _sharedStateManager.get(); }
470
[6628]471        /** Add an Archive extension.*/
472        void addArchiveExtension(const std::string ext);
[9884]473       
474        /** registers a protocol */
475        void registerProtocol(const std::string& protocol);
476       
477        /** returns true, if named protocol is registered */
478        bool isProtocolRegistered(const std::string& protocol);
479       
[2534]480    protected:
[2522]481
[1463]482        virtual ~Registry();
483
[1708]484        typedef std::map< std::string, osg::ref_ptr<DotOsgWrapper> >    DotOsgWrapperMap;
485        typedef std::vector< osg::ref_ptr<DynamicLibrary> >             DynamicLibraryList;
486        typedef std::map< std::string, std::string>                     ExtensionAliasMap;
[10000]487        typedef std::map< std::string, std::string>                     MimeTypeExtensionMap;
[6628]488        typedef std::vector< std::string>                               ArchiveExtensionList;
[1708]489       
490        typedef std::pair<osg::ref_ptr<osg::Object>, double >           ObjectTimeStampPair;
491        typedef std::map<std::string, ObjectTimeStampPair >             ObjectCache;
[3598]492        typedef std::map<std::string, osg::ref_ptr<osgDB::Archive> >    ArchiveCache;
[9884]493       
494        typedef std::set<std::string>                                   RegisteredProtocolsSet;
[8]495
496        /** constructor is private, as its a singleton, preventing
497            construction other than via the instance() method and
498            therefore ensuring only one copy is ever constructed*/
499        Registry();
[10174]500
[8]501        /** get the attached library with specified name.*/
502        DynamicLibraryList::iterator getLibraryItr(const std::string& fileName);
503
[10171]504        Options::BuildKdTreesHint     _buildKdTreesHint;
[8535]505        osg::ref_ptr<osg::KdTreeBuilder>            _kdTreeBuilder;
506       
[9038]507        osg::ref_ptr<FileCache>                     _fileCache;
508       
[8619]509        osg::ref_ptr<AuthenticationMap>             _authenticationMap;
510       
[8535]511        bool                                        _createNodeFromImage;
[9884]512       
513        RegisteredProtocolsSet                      _registeredProtocols;
[8]514
515        osg::Object*       readObject(DotOsgWrapperMap& dowMap,Input& fr);
516
[742]517        void eraseWrapper(DotOsgWrapperMap& wrappermap,DotOsgWrapper* wrapper);
518
[3722]519    public:
[3596]520        /** Functor used in internal implementations.*/
521        struct ReadFunctor
522        {
[10171]523            ReadFunctor(const std::string& filename, const Options* options):
[3596]524                _filename(filename),
525                _options(options) {}
526
527            virtual ~ReadFunctor() {}
528            virtual ReaderWriter::ReadResult doRead(ReaderWriter& rw) const = 0;
529            virtual bool isValid(ReaderWriter::ReadResult& readResult) const = 0;
530            virtual bool isValid(osg::Object* object) const = 0;
531
532            std::string _filename;
[10171]533            const Options* _options;
[3596]534        };
535
[3722]536   protected:
[6881]537   
538        void destruct();
539   
[3598]540        // forward declare helper classes
[3596]541        struct ReadObjectFunctor;
542        struct ReadImageFunctor;
543        struct ReadHeightFieldFunctor;
544        struct ReadNodeFunctor;
545        struct ReadArchiveFunctor;
[7908]546        struct ReadShaderFunctor;
[3642]547       
548        // make helper classes friends to get round VS6.0 "issues"
[3646]549        friend struct ReadFunctor;
[3647]550        friend struct ReadObjectFunctor;
[3642]551        friend struct ReadImageFunctor;
552        friend struct ReadHeightFieldFunctor;
553        friend struct ReadNodeFunctor;
554        friend struct ReadArchiveFunctor;
[7908]555        friend struct ReadShaderFunctor;
[3596]556
[3581]557        ReaderWriter::ReadResult read(const ReadFunctor& readFunctor);
[10171]558        ReaderWriter::ReadResult readImplementation(const ReadFunctor& readFunctor,Options::CacheHintOptions cacheHint);
[742]559
[3598]560
[7648]561        // forward declare helper class
[3598]562        class AvailableReaderWriterIterator;
[3642]563        friend class AvailableReaderWriterIterator;
[3598]564
565
[10171]566        osg::ref_ptr<FindFileCallback>      _findFileCallback;
[2877]567        osg::ref_ptr<ReadFileCallback>      _readFileCallback;
568        osg::ref_ptr<WriteFileCallback>     _writeFileCallback;
[10174]569        osg::ref_ptr<FileLocationCallback>  _fileLocationCallback;
[2877]570
[8]571        DotOsgWrapperMap   _objectWrapperMap;
572        DotOsgWrapperMap   _imageWrapperMap;
573        DotOsgWrapperMap   _drawableWrapperMap;
574        DotOsgWrapperMap   _stateAttrWrapperMap;
[4061]575        DotOsgWrapperMap   _uniformWrapperMap;
[8]576        DotOsgWrapperMap   _nodeWrapperMap;
[7908]577        DotOsgWrapperMap   _shaderWrapperMap;
[8]578       
579        DotOsgWrapperMap   _classNameWrapperMap;
580
[8929]581        OpenThreads::ReentrantMutex _pluginMutex;
582        ReaderWriterList            _rwList;
583        DynamicLibraryList          _dlList;
[8]584
585        bool _openingLibrary;
[2877]586   
587        // map to alias to extensions to plugins.
588        ExtensionAliasMap  _extAliasMap;
[6089]589
[10000]590        // maps mime-types to extensions.
591        MimeTypeExtensionMap _mimeTypeExtMap;
592
[6089]593        // Utility: Removes whitespace from both ends of a string.
594        static std::string trim( const std::string& str );
[93]595       
596        // options to pass to reader writers.
[10171]597        osg::ref_ptr<Options>     _options;
[773]598       
[3689]599        FilePathList                            _dataFilePath;
600        FilePathList                            _libraryFilePath;
[2340]601
[3689]602        ObjectCache                             _objectCache;
603        OpenThreads::Mutex                      _objectCacheMutex;
[2614]604       
[3689]605        ArchiveCache                            _archiveCache;
606        OpenThreads::Mutex                      _archiveCacheMutex;
[6628]607
608        ArchiveExtensionList                    _archiveExtList;
[3598]609       
[3689]610        osg::ref_ptr<SharedStateManager>        _sharedStateManager;
[8]611
612};
613
[1610]614/** read the command line arguments.*/
615inline void readCommandLine(osg::ArgumentParser& parser)
616{
617    Registry::instance()->readCommandLine(parser);
618}
619
[8]620/**  Proxy class for automatic registration of DotOsgWrappers with the Registry.*/
621class RegisterDotOsgWrapperProxy
622{
623    public:
624   
625        RegisterDotOsgWrapperProxy(osg::Object* proto,
626                                   const std::string& name,
627                                   const std::string& associates,
628                                   DotOsgWrapper::ReadFunc readFunc,
629                                   DotOsgWrapper::WriteFunc writeFunc,
630                                   DotOsgWrapper::ReadWriteMode readWriteMode=DotOsgWrapper::READ_AND_WRITE)
631        {
632            if (Registry::instance())
633            {
[1418]634                _wrapper = new DotOsgWrapper(proto,name,associates,readFunc,writeFunc,readWriteMode);
[8]635                Registry::instance()->addDotOsgWrapper(_wrapper.get());
636            }
637        }
638       
639        ~RegisterDotOsgWrapperProxy()
640        {
641            if (Registry::instance())
642            {
643                Registry::instance()->removeDotOsgWrapper(_wrapper.get());
644            }
645        }
646       
647    protected:
648        osg::ref_ptr<DotOsgWrapper> _wrapper;
649};
650
[7422]651template<class T>
652class TemplateRegisterDotOsgWrapperProxy : public RegisterDotOsgWrapperProxy, public T
653{
654    public:
655   
656        TemplateRegisterDotOsgWrapperProxy(osg::Object* proto,
657                                   const std::string& name,
658                                   const std::string& associates,
659                                   DotOsgWrapper::ReadFunc readFunc,
660                                   DotOsgWrapper::WriteFunc writeFunc,
661                                   DotOsgWrapper::ReadWriteMode readWriteMode=DotOsgWrapper::READ_AND_WRITE):
662            RegisterDotOsgWrapperProxy(proto, name, associates, readFunc, writeFunc, readWriteMode) {}
663       
664};
665
[8]666/** Proxy class for automatic registration of reader/writers with the Registry.*/
667template<class T>
668class RegisterReaderWriterProxy
669{
670    public:
671        RegisterReaderWriterProxy()
672        {
673            if (Registry::instance())
674            {
[1418]675                _rw = new T;
[8]676                Registry::instance()->addReaderWriter(_rw.get());
677            }
678        }
679
680        ~RegisterReaderWriterProxy()
681        {
682            if (Registry::instance())
683            {
684                Registry::instance()->removeReaderWriter(_rw.get());
685            }
686        }
687       
[2512]688        T* get() { return _rw.get(); }
689       
[8]690    protected:
691        osg::ref_ptr<T> _rw;
692};
693
694
[6927]695struct PluginFunctionProxy
[6753]696{
[6927]697    PluginFunctionProxy(CPluginFunction function) { (function)(); }
[6753]698};
699
700#define USE_OSGPLUGIN(ext) \
701    extern "C" void osgdb_##ext(void); \
702    static osgDB::PluginFunctionProxy proxy_##ext(osgdb_##ext);
703
704#define REGISTER_OSGPLUGIN(ext, classname) \
705    extern "C" void osgdb_##ext(void) {} \
[6927]706    static osgDB::RegisterReaderWriterProxy<classname> g_proxy_##classname;
[6753]707
[9334]708
709#define USE_DOTOSGWRAPPER(classname) \
710    extern "C" void dotosgwrapper_##classname(void); \
711    static osgDB::PluginFunctionProxy proxy_dotosgwrapper_##classname(dotosgwrapper_##classname);
712
713#define REGISTER_DOTOSGWRAPPER(classname) \
714    extern "C" void dotosgwrapper_##classname(void) {} \
715    static osgDB::RegisterDotOsgWrapperProxy dotosgwrapper_proxy_##classname
716
[6753]717}
718
[8]719#endif
Note: See TracBrowser for help on using the browser.