Moved get/setUserData from osg::Node into its superclass osg::Object to

allow other subclasses to add their own custom data.
This commit is contained in:
Robert Osfield 2002-07-18 19:41:52 +00:00
parent ff8b4c001d
commit 34be82c1ee
5 changed files with 22 additions and 21 deletions

View File

@ -9,7 +9,6 @@
#include <osg/StateSet> #include <osg/StateSet>
#include <osg/BoundingSphere> #include <osg/BoundingSphere>
#include <osg/NodeCallback> #include <osg/NodeCallback>
#include <osg/ref_ptr>
#include <string> #include <string>
#include <vector> #include <vector>
@ -148,20 +147,6 @@ class SG_EXPORT Node : public Object
/** return true if this node is an OccluderNode or the subgraph below this node are OccluderNodes.*/ /** return true if this node is an OccluderNode or the subgraph below this node are OccluderNodes.*/
const bool containsOccluderNodes() const; const bool containsOccluderNodes() const;
/**
* Set user data, data must be subclased from Referenced to allow
* automatic memory handling. If you own data isn't directly
* subclassed from Referenced then create and adapter object
* which points to your own objects and handles the memory addressing.
*/
inline void setUserData(osg::Referenced* obj) { _userData = obj; }
/** Get user data.*/
inline Referenced* getUserData() { return _userData.get(); }
/** Get const user data.*/
inline const Referenced* getUserData() const { return _userData.get(); }
typedef unsigned int NodeMask; typedef unsigned int NodeMask;
/** Set the node mask. Note, node mask is will be replaced by TraversalMask.*/ /** Set the node mask. Note, node mask is will be replaced by TraversalMask.*/
@ -258,8 +243,6 @@ class SG_EXPORT Node : public Object
int _numChildrenWithOccluderNodes; int _numChildrenWithOccluderNodes;
void setNumChildrenWithOccluderNodes(const int num); void setNumChildrenWithOccluderNodes(const int num);
osg::ref_ptr<Referenced> _userData;
NodeMask _nodeMask; NodeMask _nodeMask;
DescriptionList _descriptions; DescriptionList _descriptions;

View File

@ -7,6 +7,7 @@
#include <osg/Referenced> #include <osg/Referenced>
#include <osg/CopyOp> #include <osg/CopyOp>
#include <osg/ref_ptr>
namespace osg { namespace osg {
@ -77,6 +78,21 @@ class SG_EXPORT Object : public Referenced
inline const DataVariance getDataVariance() const { return _dataVariance; } inline const DataVariance getDataVariance() const { return _dataVariance; }
/**
* Set user data, data must be subclased from Referenced to allow
* automatic memory handling. If you own data isn't directly
* subclassed from Referenced then create and adapter object
* which points to your own objects and handles the memory addressing.
*/
inline void setUserData(Referenced* obj) { _userData = obj; }
/** Get user data.*/
inline Referenced* getUserData() { return _userData.get(); }
/** Get const user data.*/
inline const Referenced* getUserData() const { return _userData.get(); }
protected: protected:
/** Object destructor. Note, is protected so that Objects cannot /** Object destructor. Note, is protected so that Objects cannot
@ -90,6 +106,8 @@ class SG_EXPORT Object : public Referenced
DataVariance _dataVariance; DataVariance _dataVariance;
ref_ptr<Referenced> _userData;
private: private:
/** disallow any copy operator.*/ /** disallow any copy operator.*/

View File

@ -33,7 +33,6 @@ Node::Node(const Node& node,const CopyOp& copyop):
_cullingActive(node._cullingActive), _cullingActive(node._cullingActive),
_numChildrenWithCullingDisabled(0), // assume no children yet. _numChildrenWithCullingDisabled(0), // assume no children yet.
_numChildrenWithOccluderNodes(0), _numChildrenWithOccluderNodes(0),
_userData(copyop(node._userData.get())),
_nodeMask(node._nodeMask), _nodeMask(node._nodeMask),
_descriptions(node._descriptions), _descriptions(node._descriptions),
_dstate(copyop(node._dstate.get())) _dstate(copyop(node._dstate.get()))

View File

@ -14,6 +14,7 @@ Referenced::~Referenced()
} }
Object::Object(const Object& obj,const CopyOp&): Object::Object(const Object& obj,const CopyOp& copyop):
Referenced(), Referenced(),
_dataVariance(obj._dataVariance) {} _dataVariance(obj._dataVariance),
_userData(copyop(obj._userData.get())) {}

View File

@ -53,7 +53,7 @@ bool Geode_writeLocalData(const osg::Object& obj, Output& fw)
fw.indent() << "num_drawables " << geode.getNumDrawables() << std::endl; fw.indent() << "num_drawables " << geode.getNumDrawables() << std::endl;
for(int i=0;i<geode.getNumDrawables();++i) for(unsigned int i=0;i<geode.getNumDrawables();++i)
{ {
fw.writeObject(*geode.getDrawable(i)); fw.writeObject(*geode.getDrawable(i));
} }