From: Thomas Geymayer Date: Sun, 18 Nov 2012 15:26:50 +0000 (+0100) Subject: Get Canvas/PropertyBasedElement by name X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=904d714d6d53cb30d0bfb483210bfc9cf38652be;p=simgear.git Get Canvas/PropertyBasedElement by name --- diff --git a/simgear/canvas/CanvasMgr.cxx b/simgear/canvas/CanvasMgr.cxx index de1d5400..3c087774 100644 --- a/simgear/canvas/CanvasMgr.cxx +++ b/simgear/canvas/CanvasMgr.cxx @@ -55,6 +55,12 @@ namespace canvas return boost::static_pointer_cast( getElement(index) ); } + //---------------------------------------------------------------------------- + CanvasPtr CanvasMgr::getCanvas(const std::string& name) const + { + return boost::static_pointer_cast( getElement(name) ); + } + //---------------------------------------------------------------------------- void CanvasMgr::elementCreated(PropertyBasedElementPtr element) { diff --git a/simgear/canvas/CanvasMgr.hxx b/simgear/canvas/CanvasMgr.hxx index cc67b4fd..238fcc76 100644 --- a/simgear/canvas/CanvasMgr.hxx +++ b/simgear/canvas/CanvasMgr.hxx @@ -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; diff --git a/simgear/nasal/cppbind/Ghost.hxx b/simgear/nasal/cppbind/Ghost.hxx index 288c5113..759b25ed 100644 --- a/simgear/nasal/cppbind/Ghost.hxx +++ b/simgear/nasal/cppbind/Ghost.hxx @@ -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 diff --git a/simgear/props/PropertyBasedMgr.cxx b/simgear/props/PropertyBasedMgr.cxx index b3d3ed74..46f3c736 100644 --- a/simgear/props/PropertyBasedMgr.cxx +++ b/simgear/props/PropertyBasedMgr.cxx @@ -18,6 +18,8 @@ #include "PropertyBasedMgr.hxx" +#include + #include #include @@ -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 { diff --git a/simgear/props/PropertyBasedMgr.hxx b/simgear/props/PropertyBasedMgr.hxx index 0abe9b83..e719ca33 100644 --- a/simgear/props/PropertyBasedMgr.hxx +++ b/simgear/props/PropertyBasedMgr.hxx @@ -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: