]> git.mxchange.org Git - simgear.git/commitdiff
More helper methods for Canvas and PropertyBasedElement.
authorThomas Geymayer <tomgey@gmail.com>
Sun, 2 Jun 2013 19:19:37 +0000 (21:19 +0200)
committerThomas Geymayer <tomgey@gmail.com>
Sun, 2 Jun 2013 19:19:37 +0000 (21:19 +0200)
simgear/canvas/Canvas.cxx
simgear/canvas/Canvas.hxx
simgear/canvas/elements/CanvasGroup.cxx
simgear/canvas/elements/CanvasGroup.hxx
simgear/props/PropertyBasedElement.hxx
simgear/props/props.hxx

index 74ccb60bd92136d1a690238156ee226041373aec..585281007df98d1ed3201dd453ecb01d1cb9d050 100644 (file)
@@ -177,6 +177,15 @@ namespace canvas
     );
   }
 
+  //----------------------------------------------------------------------------
+  GroupPtr Canvas::getGroup(const std::string& name)
+  {
+    return boost::dynamic_pointer_cast<Group>
+    (
+      _root_group->getChild(name)
+    );
+  }
+
   //----------------------------------------------------------------------------
   GroupPtr Canvas::getRootGroup()
   {
index 8e73552865a71388241db96f7404118fe285592b..1d508a8912543c12c07901949cfbaeae6addd8bf 100644 (file)
@@ -103,6 +103,7 @@ namespace canvas
       void removeChildCanvas(const CanvasWeakPtr& canvas);
 
       GroupPtr createGroup(const std::string& name = "");
+      GroupPtr getGroup(const std::string& name);
       GroupPtr getRootGroup();
 
       /**
index 9bfb8c2f26d3df44be309cc8815c591423dde953..05e752a321cf921f6096cae9e4beb5580117b6db 100644 (file)
@@ -93,6 +93,20 @@ namespace canvas
     return child->second;
   }
 
+  //----------------------------------------------------------------------------
+  ElementPtr Group::getChild(const std::string& id)
+  {
+    for( ChildList::iterator child = _children.begin();
+                             child != _children.end();
+                           ++child )
+    {
+      if( child->second->get<std::string>("id") == id )
+        return child->second;
+    }
+
+    return ElementPtr();
+  }
+
   //----------------------------------------------------------------------------
   ElementPtr Group::getElementById(const std::string& id)
   {
index 524b5dfbbdcd4d8651c6f5a18d2c17c94a901268..d1b86b7b92527ca220978095ae9c69b272c564a7 100644 (file)
@@ -48,6 +48,7 @@ namespace canvas
       ElementPtr createChild( const std::string& type,
                               const std::string& id = "" );
       ElementPtr getChild(const SGPropertyNode* node);
+      ElementPtr getChild(const std::string& id);
 
       /**
        * Get first child with given id (breadth-first search)
index f402b959c7e40a47ba9a34454762d6fca4ecca13..bdae05370fa01c2105a9f74995fb1115c761d9fc 100644 (file)
@@ -55,6 +55,17 @@ namespace simgear
         setValue(_node->getNode(name, true), val);
       }
 
+      template<class T>
+      T get( const std::string& name,
+             typename boost::call_traits<T>::param_type def = T() )
+      {
+        SGPropertyNode const* child = _node->getNode(name);
+        if( !child )
+          return def;
+
+        return getValue<T>(child);
+      }
+
       virtual void setSelf(const PropertyBasedElementPtr& self);
 
     protected:
index d06f4855e317f5074fc83dfef8cb84f895ff78ca..5103e8c0f9130a30b0805eb0e21e2f7f23e8b467 100644 (file)
@@ -1796,6 +1796,12 @@ inline const char * getValue<const char*>(const SGPropertyNode* node)
     return node->getStringValue ();
 }
 
+template<>
+inline std::string getValue<std::string>(const SGPropertyNode* node)
+{
+    return node->getStringValue();
+}
+
 inline bool setValue(SGPropertyNode* node, bool value)
 {
     return node->setBoolValue(value);