// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+// You should have received a copy of the GNU Library General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
#ifndef SG_PROPERTY_BASED_ELEMENT_HXX_
#define SG_PROPERTY_BASED_ELEMENT_HXX_
#include <simgear/props/props.hxx>
-
-#include <boost/shared_ptr.hpp>
-#include <boost/weak_ptr.hpp>
-
+#include <simgear/structure/SGWeakReferenced.hxx>
namespace simgear
{
- class PropertyBasedElement;
- typedef boost::shared_ptr<PropertyBasedElement> PropertyBasedElementPtr;
- typedef boost::weak_ptr<PropertyBasedElement> PropertyBasedElementWeakPtr;
-
/**
* Base class for a property controlled element
*/
class PropertyBasedElement:
- public SGPropertyChangeListener
+ public SGPropertyChangeListener,
+ public SGWeakReferenced
{
public:
PropertyBasedElement(SGPropertyNode* node);
virtual ~PropertyBasedElement();
+ /**
+ * Remove the property listener of the element.
+ *
+ * You will need to call the appropriate methods (#childAdded,
+ * #childRemoved, #valueChanged) yourself to ensure the element still
+ * receives the needed events.
+ */
+ void removeListener();
+
+ /**
+ * Destroys this element (removes node from property tree)
+ */
+ void destroy();
+
virtual void update(double delta_time_sec) = 0;
SGConstPropertyNode_ptr getProps() const;
SGPropertyNode_ptr getProps();
- protected:
+ template<class T>
+ void set( const std::string& name,
+ const T& val )
+ {
+ setValue(_node->getNode(name, true), val);
+ }
+
+ template<class T>
+ T get( const std::string& name,
+ const T& def = T() )
+ {
+ SGPropertyNode const* child = _node->getNode(name);
+ if( !child )
+ return def;
- friend class PropertyBasedMgr;
+ return getValue<T>(child);
+ }
+
+ // Unshadow what we have just hidden...
+ using SGWeakReferenced::get;
+
+ virtual void onDestroy() {};
+
+ protected:
SGPropertyNode_ptr _node;
- PropertyBasedElementWeakPtr _self;
+
};
+ typedef SGSharedPtr<PropertyBasedElement> PropertyBasedElementPtr;
+ typedef SGWeakPtr<PropertyBasedElement> PropertyBasedElementWeakPtr;
+
} // namespace simgear
#endif /* SG_PROPERTY_BASED_ELEMENT_HXX_ */