Get Canvas/PropertyBasedElement by name

This commit is contained in:
Thomas Geymayer 2012-11-18 16:26:50 +01:00
parent 2aed93a576
commit 904d714d6d
5 changed files with 40 additions and 0 deletions

View File

@ -55,6 +55,12 @@ namespace canvas
return boost::static_pointer_cast<Canvas>( getElement(index) ); 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) void CanvasMgr::elementCreated(PropertyBasedElementPtr element)
{ {

View File

@ -55,6 +55,14 @@ namespace canvas
*/ */
CanvasPtr getCanvas(size_t index) const; 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: protected:
SystemAdapterPtr _system_adapter; SystemAdapterPtr _system_adapter;

View File

@ -655,6 +655,9 @@ namespace nasal
static naRef makeGhost(naContext c, void *ptr) static naRef makeGhost(naContext c, void *ptr)
{ {
if( !Ghost::getRawPtr(ptr) )
return naNil();
naGhostType* ghost_type = 0; naGhostType* ghost_type = 0;
if( Ghost::returns_dynamic_type::value ) if( Ghost::returns_dynamic_type::value )
// For pointer policies already returning instances of an object with // For pointer policies already returning instances of an object with

View File

@ -18,6 +18,8 @@
#include "PropertyBasedMgr.hxx" #include "PropertyBasedMgr.hxx"
#include <boost/foreach.hpp>
#include <stdexcept> #include <stdexcept>
#include <string> #include <string>
@ -65,6 +67,20 @@ namespace simgear
return _elements[index]; 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 const SGPropertyNode* PropertyBasedMgr::getPropertyRoot() const
{ {

View File

@ -53,6 +53,13 @@ namespace simgear
*/ */
PropertyBasedElementPtr getElement(size_t index) const; 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; virtual const SGPropertyNode* getPropertyRoot() const;
protected: protected: