]> git.mxchange.org Git - simgear.git/commitdiff
Get Canvas/PropertyBasedElement by name
authorThomas Geymayer <tomgey@gmail.com>
Sun, 18 Nov 2012 15:26:50 +0000 (16:26 +0100)
committerThomas Geymayer <tomgey@gmail.com>
Sun, 18 Nov 2012 15:27:05 +0000 (16:27 +0100)
simgear/canvas/CanvasMgr.cxx
simgear/canvas/CanvasMgr.hxx
simgear/nasal/cppbind/Ghost.hxx
simgear/props/PropertyBasedMgr.cxx
simgear/props/PropertyBasedMgr.hxx

index de1d5400474d290fb191ae1c3e95e42c00473a48..3c087774c09670c9d02d8491e7b9471b666416b7 100644 (file)
@@ -55,6 +55,12 @@ namespace canvas
     return boost::static_pointer_cast<Canvas>( getElement(index) );
   }
 
+  //----------------------------------------------------------------------------
+  CanvasPtr CanvasMgr::getCanvas(const std::string& name) const
+  {
+    return boost::static_pointer_cast<Canvas>( getElement(name) );
+  }
+
   //----------------------------------------------------------------------------
   void CanvasMgr::elementCreated(PropertyBasedElementPtr element)
   {
index cc67b4fd288a6be80f15d9639330d54cd93fa32f..238fcc76118380bbedf5c8289f1e8ff854c2f5d9 100644 (file)
@@ -55,6 +55,14 @@ namespace canvas
        */
       CanvasPtr getCanvas(size_t index) const;
 
+      /**
+       * Get ::Canvas by name
+       *
+       * @param name Value of child node "name" in
+       *             /canvas/by-index/texture[i]/name
+       */
+      CanvasPtr getCanvas(const std::string& name) const;
+
     protected:
 
       SystemAdapterPtr _system_adapter;
index 288c5113e5b3aff5b61dbd75b04693d9aaeb94fd..759b25ed9be4d2aa8ecc26f7995e463001639710 100644 (file)
@@ -655,6 +655,9 @@ namespace nasal
 
       static naRef makeGhost(naContext c, void *ptr)
       {
+        if( !Ghost::getRawPtr(ptr) )
+          return naNil();
+
         naGhostType* ghost_type = 0;
         if( Ghost::returns_dynamic_type::value )
           // For pointer policies already returning instances of an object with
index b3d3ed747581450cac288e7b6f96760c7858a16c..46f3c736d0bad49a08f81d623eb6f8710cedb8cf 100644 (file)
@@ -18,6 +18,8 @@
 
 #include "PropertyBasedMgr.hxx"
 
+#include <boost/foreach.hpp>
+
 #include <stdexcept>
 #include <string>
 
@@ -65,6 +67,20 @@ namespace simgear
     return _elements[index];
   }
 
+  //----------------------------------------------------------------------------
+  PropertyBasedElementPtr
+  PropertyBasedMgr::getElement(const std::string& name) const
+  {
+    if( name.empty() )
+      return PropertyBasedElementPtr();
+
+    BOOST_FOREACH(PropertyBasedElementPtr el, _elements)
+      if( el->getProps()->getStringValue("name") == name )
+        return el;
+
+    return PropertyBasedElementPtr();
+  }
+
   //----------------------------------------------------------------------------
   const SGPropertyNode* PropertyBasedMgr::getPropertyRoot() const
   {
index 0abe9b83f557e9569f565a82b8735dfbff2c13c1..e719ca3374d0196793e3d53617049a02497c462d 100644 (file)
@@ -53,6 +53,13 @@ namespace simgear
        */
       PropertyBasedElementPtr getElement(size_t index) const;
 
+      /**
+       * Get an existing PropertyBasedElement by its name
+       *
+       * @param name    Name (value of child node "name" will be matched)
+       */
+      PropertyBasedElementPtr getElement(const std::string& name) const;
+
       virtual const SGPropertyNode* getPropertyRoot() const;
 
     protected: