From Wang Rui, "a new parsePluginStringData() method in the osgDB::Options class which will be automatically executed to parse option string to the string data map"

This commit is contained in:
Robert Osfield 2010-11-03 10:37:02 +00:00
parent 1beedce6fc
commit afa563df57
2 changed files with 36 additions and 2 deletions

View File

@ -104,7 +104,10 @@ class OSGDB_EXPORT Options : public osg::Object
_str(str),
_objectCacheHint(CACHE_ARCHIVES),
_precisionHint(FLOAT_PRECISION_ALL),
_buildKdTreesHint(NO_PREFERENCE) {}
_buildKdTreesHint(NO_PREFERENCE)
{
parsePluginStringData(str);
}
Options(const Options& options,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
@ -113,7 +116,7 @@ class OSGDB_EXPORT Options : public osg::Object
Options* cloneOptions() const { return new Options(*this); }
/** Set the general Options string.*/
void setOptionString(const std::string& str) { _str = str; }
void setOptionString(const std::string& str) { _str = str; parsePluginStringData(str); }
/** Get the general Options string.*/
const std::string& getOptionString() const { return _str; }
@ -169,6 +172,9 @@ class OSGDB_EXPORT Options : public osg::Object
/** Remove a value from the PluginData */
void removePluginData(const std::string& s) const { _pluginData.erase(s); }
/** Get number of PluginData values */
unsigned int getNumPluginData() const { return _pluginData.size(); }
/** Sets a plugindata value PluginData with a string */
@ -187,6 +193,11 @@ class OSGDB_EXPORT Options : public osg::Object
/** Remove a value from the PluginData */
void removePluginStringData(const std::string& s) const { _pluginStringData.erase(s); }
/** Get number of PluginStrData values */
unsigned int getNumPluginStringData() const { return _pluginStringData.size(); }
/** Parse string into plugin string data. This will be automatically done in Options(const std::string&) */
void parsePluginStringData(const std::string& str, char separator1=' ', char separator2='=');
/** Set the find callback to use in place of the default findFile calls.*/

View File

@ -30,3 +30,26 @@ Options::Options(const Options& options,const osg::CopyOp& copyop):
_writeFileCallback(options._writeFileCallback),
_fileLocationCallback(options._fileLocationCallback),
_fileCache(options._fileCache) {}
void Options::parsePluginStringData(const std::string& str, char separator1, char separator2)
{
StringList valueList;
split(str, valueList, separator1);
if (valueList.size() > 0)
{
StringList keyAndValue;
for (StringList::iterator itr=valueList.begin(); itr!=valueList.end(); ++itr)
{
split(*itr, keyAndValue, separator2);
if (keyAndValue.size() > 1)
{
setPluginStringData(keyAndValue.front(), keyAndValue.back());
}
else if (keyAndValue.size() > 0)
{
setPluginStringData(keyAndValue.front(), "true");
}
keyAndValue.clear();
}
}
}