| 96 | | /** Options base class used for passing options into plugins to control their operation.*/ |
| 97 | | class Options : public osg::Object |
| 98 | | { |
| 99 | | public: |
| 100 | | |
| 101 | | |
| 102 | | /// bit mask for setting up which object types get cached by readObject/Image/HeightField/Node(filename) calls |
| 103 | | enum CacheHintOptions |
| 104 | | { /// do not cache objects of any type |
| 105 | | CACHE_NONE = 0, |
| 106 | | |
| 107 | | /// cache nodes loaded via readNode(filename) |
| 108 | | CACHE_NODES = 1<<0, |
| 109 | | |
| 110 | | /// cache images loaded via readImage(filename) |
| 111 | | CACHE_IMAGES = 1<<1, |
| 112 | | |
| 113 | | /// cache heightfield loaded via readHeightField(filename) |
| 114 | | CACHE_HEIGHTFIELDS = 1<<2, |
| 115 | | |
| 116 | | /// cache heightfield loaded via readHeightField(filename) |
| 117 | | CACHE_ARCHIVES = 1<<3, |
| 118 | | |
| 119 | | /// cache objects loaded via readObject(filename) |
| 120 | | CACHE_OBJECTS = 1<<4, |
| 121 | | |
| 122 | | /// cache shaders loaded via readShader(filename) |
| 123 | | CACHE_SHADERS = 1<<5, |
| 124 | | |
| 125 | | /// cache on all read*(filename) calls |
| 126 | | CACHE_ALL = CACHE_NODES | |
| 127 | | CACHE_IMAGES | |
| 128 | | CACHE_HEIGHTFIELDS | |
| 129 | | CACHE_ARCHIVES | |
| 130 | | CACHE_OBJECTS | |
| 131 | | CACHE_SHADERS |
| 132 | | }; |
| 133 | | |
| 134 | | /// range of options of whether to build kdtrees automatically on loading |
| 135 | | enum BuildKdTreesHint |
| 136 | | { |
| 137 | | NO_PREFERENCE, |
| 138 | | DO_NOT_BUILD_KDTREES, |
| 139 | | BUILD_KDTREES |
| 140 | | }; |
| 141 | | |
| 142 | | |
| 143 | | Options(): |
| 144 | | osg::Object(true), |
| 145 | | _objectCacheHint(CACHE_ARCHIVES), |
| 146 | | _buildKdTreesHint(NO_PREFERENCE) {} |
| 147 | | |
| 148 | | Options(const std::string& str): |
| 149 | | osg::Object(true), |
| 150 | | _str(str), |
| 151 | | _objectCacheHint(CACHE_ARCHIVES), |
| 152 | | _buildKdTreesHint(NO_PREFERENCE) {} |
| 153 | | |
| 154 | | Options(const Options& options,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY): |
| 155 | | osg::Object(options,copyop), |
| 156 | | _str(options._str), |
| 157 | | _databasePaths(options._databasePaths), |
| 158 | | _objectCacheHint(options._objectCacheHint), |
| 159 | | _buildKdTreesHint(options._buildKdTreesHint), |
| 160 | | _pluginData(options._pluginData), |
| 161 | | _pluginStringData(options._pluginStringData){} |
| 162 | | |
| 163 | | META_Object(osgDB,Options); |
| 164 | | |
| 165 | | /** Set the general Options string.*/ |
| 166 | | void setOptionString(const std::string& str) { _str = str; } |
| 167 | | |
| 168 | | /** Get the general Options string.*/ |
| 169 | | const std::string& getOptionString() const { return _str; } |
| 170 | | |
| 171 | | /** Set the database path to use a hint of where to look when loading models.*/ |
| 172 | | void setDatabasePath(const std::string& str) { _databasePaths.clear(); _databasePaths.push_back(str); } |
| 173 | | |
| 174 | | /** Get the database path which is used a hint of where to look when loading models.*/ |
| 175 | | FilePathList& getDatabasePathList() { return _databasePaths; } |
| 176 | | |
| 177 | | /** Get the const database path which is used a hint of where to look when loading models.*/ |
| 178 | | const FilePathList& getDatabasePathList() const { return _databasePaths; } |
| 179 | | |
| 180 | | |
| 181 | | /** Set whether the Registry::ObjectCache should be used by default.*/ |
| 182 | | void setObjectCacheHint(CacheHintOptions useObjectCache) { _objectCacheHint = useObjectCache; } |
| 183 | | |
| 184 | | /** Get whether the Registry::ObjectCache should be used by default.*/ |
| 185 | | CacheHintOptions getObjectCacheHint() const { return _objectCacheHint; } |
| 186 | | |
| 187 | | |
| 188 | | /** Set whether the KdTrees should be built for geometry in the loader model. */ |
| 189 | | void setBuildKdTreesHint(BuildKdTreesHint hint) { _buildKdTreesHint = hint; } |
| 190 | | |
| 191 | | /** Get whether the KdTrees should be built for geometry in the loader model. */ |
| 192 | | BuildKdTreesHint getBuildKdTreesHint() const { return _buildKdTreesHint; } |
| 193 | | |
| 194 | | |
| 195 | | /** Set the password map to be used by plugins when access files from secure locations.*/ |
| 196 | | void setAuthenticationMap(AuthenticationMap* authenticationMap) { _authenticationMap = authenticationMap; } |
| 197 | | |
| 198 | | /** Get the password map to be used by plugins when access files from secure locations.*/ |
| 199 | | const AuthenticationMap* getAuthenticationMap() const { return _authenticationMap.get(); } |
| 200 | | |
| 201 | | |
| 202 | | /** Sets a plugindata value PluginData with a string */ |
| 203 | | void setPluginData(const std::string& s, void* v) const { _pluginData[s] = v; } |
| 204 | | |
| 205 | | /** Get a value from the PluginData */ |
| 206 | | void* getPluginData(const std::string& s) { return _pluginData[s]; } |
| 207 | | |
| 208 | | /** Get a value from the PluginData */ |
| 209 | | const void* getPluginData(const std::string& s) const |
| 210 | | { |
| 211 | | PluginDataMap::const_iterator itr = _pluginData.find(s); |
| 212 | | return (itr == _pluginData.end()) ? 0 : itr->second; |
| 213 | | } |
| 214 | | |
| 215 | | /** Remove a value from the PluginData */ |
| 216 | | void removePluginData(const std::string& s) const { _pluginData.erase(s); } |
| 217 | | |
| 218 | | |
| 219 | | /** Sets a plugindata value PluginData with a string */ |
| 220 | | void setPluginStringData(const std::string& s, const std::string& v) const { _pluginStringData[s] = v; } |
| 221 | | |
| 222 | | /** Get a string from the PluginStrData */ |
| 223 | | std::string getPluginStringData(const std::string& s) { return _pluginStringData[s]; } |
| 224 | | |
| 225 | | /** Get a value from the PluginData */ |
| 226 | | const std::string getPluginStringData(const std::string& s) const |
| 227 | | { |
| 228 | | PluginStringDataMap::const_iterator itr = _pluginStringData.find(s); |
| 229 | | return (itr == _pluginStringData.end()) ? std::string("") : itr->second; |
| 230 | | } |
| 231 | | |
| 232 | | /** Remove a value from the PluginData */ |
| 233 | | void removePluginStringData(const std::string& s) const { _pluginStringData.erase(s); } |
| 234 | | |
| 235 | | |
| 236 | | |
| 237 | | |
| 238 | | protected: |
| 239 | | |
| 240 | | virtual ~Options() {} |
| 241 | | |
| 242 | | std::string _str; |
| 243 | | FilePathList _databasePaths; |
| 244 | | CacheHintOptions _objectCacheHint; |
| 245 | | BuildKdTreesHint _buildKdTreesHint; |
| 246 | | osg::ref_ptr<AuthenticationMap> _authenticationMap; |
| 247 | | |
| 248 | | typedef std::map<std::string,void*> PluginDataMap; |
| 249 | | mutable PluginDataMap _pluginData; |
| 250 | | typedef std::map<std::string,std::string> PluginStringDataMap; |
| 251 | | mutable PluginStringDataMap _pluginStringData; |
| 252 | | |
| 253 | | }; |