From: Mathias Froehlich Date: Sun, 4 Mar 2012 06:16:59 +0000 (+0100) Subject: Provide SGReaderWriterOptions::copyOrCreate(const osgDB::Options*). X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=1473eabc7c1db324bc95b50be676881643421d78;p=simgear.git Provide SGReaderWriterOptions::copyOrCreate(const osgDB::Options*). This functions tries to preserve the database options as much as possible and guarantees to return a non zero options pointer. --- diff --git a/simgear/scene/util/SGReaderWriterOptions.hxx b/simgear/scene/util/SGReaderWriterOptions.hxx index 082cfb82..ef7a5864 100644 --- a/simgear/scene/util/SGReaderWriterOptions.hxx +++ b/simgear/scene/util/SGReaderWriterOptions.hxx @@ -21,6 +21,7 @@ #define SGREADERWRITEROPTIONS_HXX 1 #include +#include #include #include @@ -92,6 +93,17 @@ public: void setInstantiateEffects(bool instantiateEffects) { _instantiateEffects = instantiateEffects; } + static SGReaderWriterOptions* copyOrCreate(const osgDB::Options* options) + { + if (!options) + options = osgDB::Registry::instance()->getOptions(); + if (!options) + return new SGReaderWriterOptions; + if (!dynamic_cast(options)) + return new SGReaderWriterOptions(*options); + return new SGReaderWriterOptions(*static_cast(options)); + } + protected: virtual ~SGReaderWriterOptions() {}