More helper methods for Canvas and PropertyBasedElement.
This commit is contained in:
@@ -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()
|
||||
{
|
||||
|
||||
@@ -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();
|
||||
|
||||
/**
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user