root/OpenSceneGraph/trunk/include/osgDB/Options @ 10172

Revision 10172, 10.0 kB (checked in by robert, 5 years ago)

Moved Options copy constructor to .cpp

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_OPTIONS
15#define OSGDB_OPTIONS 1
16
17#include <osgDB/AuthenticationMap>
18#include <osgDB/ReaderWriter>
19
20#include <deque>
21#include <list>
22#include <iosfwd>
23
24namespace osgDB {
25
26/** list of directories to search through which searching for files. */
27typedef std::deque<std::string> FilePathList;
28
29enum CaseSensitivity
30{
31    CASE_SENSITIVE,
32    CASE_INSENSITIVE
33};
34
35// forward decare
36class Options;
37
38class OSGDB_EXPORT FindFileCallback : public virtual osg::Referenced
39{
40    public:
41
42        virtual std::string findDataFile(const std::string& filename, const Options* options, CaseSensitivity caseSensitivity);
43
44        virtual std::string findLibraryFile(const std::string& filename, const Options* options, CaseSensitivity caseSensitivity);
45
46    protected:
47        virtual ~FindFileCallback() {}
48};
49
50
51class OSGDB_EXPORT ReadFileCallback : public virtual osg::Referenced
52{
53    public:
54
55        virtual ReaderWriter::ReadResult openArchive(const std::string& filename,ReaderWriter::ArchiveStatus status, unsigned int indexBlockSizeHint, const Options* useObjectCache);
56
57        virtual ReaderWriter::ReadResult readObject(const std::string& filename, const Options* options);
58
59        virtual ReaderWriter::ReadResult readImage(const std::string& filename, const Options* options);
60
61        virtual ReaderWriter::ReadResult readHeightField(const std::string& filename, const Options* options);
62
63        virtual ReaderWriter::ReadResult readNode(const std::string& filename, const Options* options);
64
65        virtual ReaderWriter::ReadResult readShader(const std::string& filename, const Options* options);
66
67    protected:
68        virtual ~ReadFileCallback() {}
69};
70
71class OSGDB_EXPORT WriteFileCallback : public virtual osg::Referenced
72{
73    public:
74
75        virtual ReaderWriter::WriteResult writeObject(const osg::Object& obj, const std::string& fileName,const Options* options);
76
77        virtual ReaderWriter::WriteResult writeImage(const osg::Image& obj, const std::string& fileName,const Options* options);
78
79        virtual ReaderWriter::WriteResult writeHeightField(const osg::HeightField& obj, const std::string& fileName,const Options* options);
80
81        virtual ReaderWriter::WriteResult writeNode(const osg::Node& obj, const std::string& fileName,const Options* options);
82
83        virtual ReaderWriter::WriteResult writeShader(const osg::Shader& obj, const std::string& fileName,const Options* options);
84
85    protected:
86        virtual ~WriteFileCallback() {}
87};
88
89/** Options base class used for passing options into plugins to control their operation.*/
90class Options : public osg::Object
91{
92    public:
93
94        /// bit mask for setting up which object types get cached by readObject/Image/HeightField/Node(filename) calls
95        enum CacheHintOptions
96        {   /// do not cache objects of any type
97            CACHE_NONE          = 0,
98
99            /// cache nodes loaded via readNode(filename)
100            CACHE_NODES         = 1<<0,
101
102            /// cache images loaded via readImage(filename)
103            CACHE_IMAGES        = 1<<1,
104
105            /// cache heightfield loaded via readHeightField(filename)
106            CACHE_HEIGHTFIELDS  = 1<<2,
107
108            /// cache heightfield loaded via readHeightField(filename)
109            CACHE_ARCHIVES      = 1<<3,
110
111            /// cache objects loaded via readObject(filename)
112            CACHE_OBJECTS       = 1<<4,
113
114            /// cache shaders loaded via readShader(filename)
115            CACHE_SHADERS       = 1<<5,
116
117            /// cache on all read*(filename) calls
118            CACHE_ALL           = CACHE_NODES |
119                                    CACHE_IMAGES |
120                                    CACHE_HEIGHTFIELDS |
121                                    CACHE_ARCHIVES |
122                                    CACHE_OBJECTS |
123                                    CACHE_SHADERS
124        };
125
126        /// range of options of whether to build kdtrees automatically on loading
127        enum BuildKdTreesHint
128        {
129            NO_PREFERENCE,
130            DO_NOT_BUILD_KDTREES,
131            BUILD_KDTREES
132        };
133
134
135        Options():
136            osg::Object(true),
137            _objectCacheHint(CACHE_ARCHIVES),
138            _buildKdTreesHint(NO_PREFERENCE) {}
139
140        Options(const std::string& str):
141            osg::Object(true),
142            _str(str),
143            _objectCacheHint(CACHE_ARCHIVES),
144            _buildKdTreesHint(NO_PREFERENCE) {}
145
146        Options(const Options& options,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
147
148        META_Object(osgDB,Options);
149
150        /** Set the general Options string.*/
151        void setOptionString(const std::string& str) { _str = str; }
152
153        /** Get the general Options string.*/
154        const std::string& getOptionString() const { return _str; }
155
156        /** Set the database path to use a hint of where to look when loading models.*/
157        void setDatabasePath(const std::string& str) { _databasePaths.clear();  _databasePaths.push_back(str); }
158
159        /** Get the database path which is used a hint of where to look when loading models.*/
160        FilePathList& getDatabasePathList() { return _databasePaths; }
161
162        /** Get the const database path which is used a hint of where to look when loading models.*/
163        const FilePathList& getDatabasePathList() const { return _databasePaths; }
164
165
166        /** Set whether the Registry::ObjectCache should be used by default.*/
167        void setObjectCacheHint(CacheHintOptions useObjectCache) { _objectCacheHint = useObjectCache; }
168
169        /** Get whether the Registry::ObjectCache should be used by default.*/
170        CacheHintOptions getObjectCacheHint() const { return _objectCacheHint; }
171
172
173        /** Set whether the KdTrees should be built for geometry in the loader model. */
174        void setBuildKdTreesHint(BuildKdTreesHint hint) { _buildKdTreesHint = hint; }
175
176        /** Get whether the KdTrees should be built for geometry in the loader model. */
177        BuildKdTreesHint getBuildKdTreesHint() const { return _buildKdTreesHint; }
178
179
180        /** Set the password map to be used by plugins when access files from secure locations.*/
181        void setAuthenticationMap(AuthenticationMap* authenticationMap) { _authenticationMap = authenticationMap; }
182
183        /** Get the password map to be used by plugins when access files from secure locations.*/
184        const AuthenticationMap* getAuthenticationMap() const { return _authenticationMap.get(); }
185
186
187        /** Sets a plugindata value PluginData with a string */
188        void setPluginData(const std::string& s, void* v) const { _pluginData[s] = v; }
189
190        /** Get a value from the PluginData */
191        void* getPluginData(const std::string& s) { return _pluginData[s]; }
192
193        /** Get a value from the PluginData */
194        const void* getPluginData(const std::string& s) const
195        {
196            PluginDataMap::const_iterator itr = _pluginData.find(s);
197            return (itr == _pluginData.end()) ? 0 : itr->second;
198        }
199
200        /** Remove a value from the PluginData */
201        void removePluginData(const std::string& s) const { _pluginData.erase(s); }
202
203
204        /** Sets a plugindata value PluginData with a string */
205        void setPluginStringData(const std::string& s, const std::string& v) const { _pluginStringData[s] = v; }
206
207        /** Get a string from the PluginStrData */
208        std::string getPluginStringData(const std::string& s) { return _pluginStringData[s]; }
209
210        /** Get a value from the PluginData */
211        const std::string getPluginStringData(const std::string& s) const
212        {
213            PluginStringDataMap::const_iterator itr = _pluginStringData.find(s);
214            return (itr == _pluginStringData.end()) ? std::string("") : itr->second;
215        }
216
217        /** Remove a value from the PluginData */
218        void removePluginStringData(const std::string& s) const { _pluginStringData.erase(s); }
219
220
221
222        /** Set the find callback to use in place of the default findFile calls.*/
223        void setFindFileCallback( FindFileCallback* cb) { _findFileCallback = cb; }
224
225        /** Get the const findFile callback.*/
226        FindFileCallback* getFindFileCallback() const { return _findFileCallback.get(); }
227
228
229        /** Set the read callback to use in place of the default readFile calls.*/
230        void setReadFileCallback( ReadFileCallback* cb) { _readFileCallback = cb; }
231
232        /** Get the const readFile callback.*/
233        ReadFileCallback* getReadFileCallback() const { return _readFileCallback.get(); }
234
235
236        /** Set the Registry callback to use in place of the default writeFile calls.*/
237        void setWriteFileCallback( WriteFileCallback* cb) { _writeFileCallback = cb; }
238
239        /** Get the const writeFile callback.*/
240        WriteFileCallback* getWriteFileCallback() const { return _writeFileCallback.get(); }
241
242
243    protected:
244
245        virtual ~Options() {}
246
247        std::string                     _str;
248        FilePathList                    _databasePaths;
249        CacheHintOptions                _objectCacheHint;
250        BuildKdTreesHint                _buildKdTreesHint;
251        osg::ref_ptr<AuthenticationMap> _authenticationMap;
252
253        typedef std::map<std::string,void*> PluginDataMap;
254        mutable PluginDataMap _pluginData;
255        typedef std::map<std::string,std::string> PluginStringDataMap;
256        mutable PluginStringDataMap _pluginStringData;
257
258        osg::ref_ptr<FindFileCallback>      _findFileCallback;
259        osg::ref_ptr<ReadFileCallback>      _readFileCallback;
260        osg::ref_ptr<WriteFileCallback>     _writeFileCallback;
261};
262
263}
264
265#endif // OSGDB_OPTIONS
Note: See TracBrowser for help on using the browser.