]> git.mxchange.org Git - simgear.git/commitdiff
Provide SGReaderWriterOptions::copyOrCreate(const osgDB::Options*).
authorMathias Froehlich <Mathias.Froehlich@web.de>
Sun, 4 Mar 2012 06:16:59 +0000 (07:16 +0100)
committerMathias Froehlich <Mathias.Froehlich@web.de>
Sun, 4 Mar 2012 06:42:31 +0000 (07:42 +0100)
This functions tries to preserve the database options as much
as possible and guarantees to return a non zero options
pointer.

simgear/scene/util/SGReaderWriterOptions.hxx

index 082cfb8228fef18f4f0bad054ed1cfab39322fc2..ef7a586487e54c78eadf00c5f0f3baee8aa3e0f6 100644 (file)
@@ -21,6 +21,7 @@
 #define SGREADERWRITEROPTIONS_HXX 1
 
 #include <osgDB/Options>
+#include <osgDB/Registry>
 #include <simgear/scene/model/modellib.hxx>
 #include <simgear/props/props.hxx>
 
@@ -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<const SGReaderWriterOptions*>(options))
+            return new SGReaderWriterOptions(*options);
+        return new SGReaderWriterOptions(*static_cast<const SGReaderWriterOptions*>(options));
+    }
+
 protected:
     virtual ~SGReaderWriterOptions() {}