Refactored the UserDataContainer so that the osg::UserDataContainer is now a pure virtual base class,
with a osg::DefaultUserDataContainer subclassed from this. The user object access methods have now all been moved from osg::Object into the UserDataContainer class, except for the set/getUserData() methods that are left in osg::Object for backwards compatibility, and the description list access methods have been moved back into osg::Node. main UserObject access methods are now all def
This commit is contained in:
@@ -318,6 +318,33 @@ class OSG_EXPORT Node : public Object
|
||||
/** Return the node's const StateSet. Returns NULL if a stateset is not attached.*/
|
||||
inline const osg::StateSet* getStateSet() const { return _stateset.get(); }
|
||||
|
||||
|
||||
/** A vector of std::string's which are used to describe the object.*/
|
||||
typedef std::vector<std::string> DescriptionList;
|
||||
|
||||
/** Set the list of string descriptions.*/
|
||||
void setDescriptions(const DescriptionList& descriptions);
|
||||
|
||||
/** Get the description list of the node.*/
|
||||
DescriptionList& getDescriptions();
|
||||
|
||||
/** Get the const description list of the const node.*/
|
||||
const DescriptionList& getDescriptions() const;
|
||||
|
||||
|
||||
/** Get a single const description of the const node.*/
|
||||
const std::string& getDescription(unsigned int i) const;
|
||||
|
||||
/** Get a single description of the node.*/
|
||||
std::string& getDescription(unsigned int i);
|
||||
|
||||
/** Get the number of descriptions of the node.*/
|
||||
unsigned int getNumDescriptions() const;
|
||||
|
||||
/** Add a description string to the node.*/
|
||||
void addDescription(const std::string& desc);
|
||||
|
||||
|
||||
/** Set the initial bounding volume to use when computing the overall bounding volume.*/
|
||||
void setInitialBound(const osg::BoundingSphere& bsphere) { _initialBound = bsphere; dirtyBound(); }
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ namespace osg {
|
||||
|
||||
// forward declare
|
||||
class State;
|
||||
class UserDataContainer;
|
||||
|
||||
#define _ADDQUOTES(def) #def
|
||||
#define ADDQUOTES(def) _ADDQUOTES(def)
|
||||
@@ -54,9 +55,9 @@ class OSG_EXPORT Object : public Referenced
|
||||
and therefore cannot be constructed on its own, only derived
|
||||
classes which override the clone and className methods are
|
||||
concrete classes and can be constructed.*/
|
||||
inline Object():Referenced(),_dataVariance(UNSPECIFIED) {}
|
||||
inline Object():Referenced(),_dataVariance(UNSPECIFIED), _userDataContainer(0) {}
|
||||
|
||||
inline explicit Object(bool threadSafeRefUnref):Referenced(threadSafeRefUnref),_dataVariance(UNSPECIFIED) {}
|
||||
inline explicit Object(bool threadSafeRefUnref):Referenced(threadSafeRefUnref),_dataVariance(UNSPECIFIED),_userDataContainer(0) {}
|
||||
|
||||
/** Copy constructor, optional CopyOp object can be used to control
|
||||
* shallow vs deep copying of dynamic data.*/
|
||||
@@ -121,17 +122,17 @@ class OSG_EXPORT Object : public Referenced
|
||||
|
||||
|
||||
/** set the UserDataContainer object.*/
|
||||
void setUserDataContainer(osg::Object* udc) { _userDataContainer = udc; }
|
||||
void setUserDataContainer(osg::UserDataContainer* udc);
|
||||
|
||||
/** get the UserDataContainer attached to this object.*/
|
||||
osg::Object* getUserDataContainer() { return _userDataContainer.get(); }
|
||||
osg::UserDataContainer* getUserDataContainer() { return _userDataContainer; }
|
||||
|
||||
/** get the const UserDataContainer attached to this object.*/
|
||||
const osg::Object* getUserDataContainer() const { return _userDataContainer.get(); }
|
||||
const osg::UserDataContainer* getUserDataContainer() const { return _userDataContainer; }
|
||||
|
||||
/** Convinience method that returns the UserDataContainer, and if one doesn't already exist creates and assigns
|
||||
* one to the Object and then return this new UserDataContainer.*/
|
||||
osg::Object* getOrCreateUserDataContainer();
|
||||
* a DefaultUserDataContainer to the Object and then return this new UserDataContainer.*/
|
||||
osg::UserDataContainer* getOrCreateUserDataContainer();
|
||||
|
||||
|
||||
/**
|
||||
@@ -148,37 +149,6 @@ class OSG_EXPORT Object : public Referenced
|
||||
/** Get const user data.*/
|
||||
virtual const Referenced* getUserData() const;
|
||||
|
||||
/** Add user data object. Returns the index position of object added. */
|
||||
virtual unsigned int addUserObject(Object* obj);
|
||||
|
||||
/** Add element to list of user data objects.*/
|
||||
virtual void setUserObject(unsigned int i, Object* obj);
|
||||
|
||||
/** Remove element from the list of user data objects.*/
|
||||
virtual void removeUserObject(unsigned int i);
|
||||
|
||||
|
||||
/** Get user data object as specified index position. */
|
||||
virtual Object* getUserObject(unsigned int i);
|
||||
|
||||
/** Get const user data object as specified index position. */
|
||||
virtual const Object* getUserObject(unsigned int i) const;
|
||||
|
||||
/** Get number of user objects assigned to this object.*/
|
||||
virtual unsigned int getNumUserObjects() const;
|
||||
|
||||
/** Get the index position of specified user data object.*/
|
||||
virtual unsigned int getUserObjectIndex(const osg::Object* obj, unsigned int startPos=0) const;
|
||||
|
||||
/** Get the index position of first user data object that matches specified name.*/
|
||||
virtual unsigned int getUserObjectIndex(const std::string& name, unsigned int startPos=0) const;
|
||||
|
||||
|
||||
/** Get first user data object with specified name. */
|
||||
Object* getUserObject(const std::string& name, unsigned int startPos=0);
|
||||
|
||||
/** Get first const user data object with specified name. */
|
||||
const Object* getUserObject(const std::string& name, unsigned int startPos=0) const;
|
||||
|
||||
|
||||
/** Convinience method that casts the named UserObject to osg::TemplateValueObject<T> and gets the value.
|
||||
@@ -192,33 +162,6 @@ class OSG_EXPORT Object : public Referenced
|
||||
template<typename T>
|
||||
void setUserValue(const std::string& name, const T& value);
|
||||
|
||||
|
||||
/** A vector of std::string's which are used to describe the object.*/
|
||||
typedef std::vector<std::string> DescriptionList;
|
||||
|
||||
/** Set the list of string descriptions.*/
|
||||
virtual void setDescriptions(const DescriptionList& descriptions);
|
||||
|
||||
/** Get the description list of the node.*/
|
||||
virtual DescriptionList& getDescriptions();
|
||||
|
||||
/** Get the const description list of the const node.*/
|
||||
virtual const DescriptionList& getDescriptions() const;
|
||||
|
||||
|
||||
/** Get a single const description of the const node.*/
|
||||
const std::string& getDescription(unsigned int i) const;
|
||||
|
||||
/** Get a single description of the node.*/
|
||||
std::string& getDescription(unsigned int i);
|
||||
|
||||
/** Get the number of descriptions of the node.*/
|
||||
unsigned int getNumDescriptions() const;
|
||||
|
||||
/** Add a description string to the node.*/
|
||||
void addDescription(const std::string& desc);
|
||||
|
||||
|
||||
|
||||
/** Resize any per context GLObject buffers to specified size. */
|
||||
virtual void resizeGLObjectBuffers(unsigned int /*maxSize*/) {}
|
||||
@@ -238,12 +181,12 @@ class OSG_EXPORT Object : public Referenced
|
||||
Nodes cannot be created on stack i.e Node node will not compile,
|
||||
forcing all nodes to be created on the heap i.e Node* node
|
||||
= new Node().*/
|
||||
virtual ~Object() {}
|
||||
virtual ~Object();
|
||||
|
||||
std::string _name;
|
||||
DataVariance _dataVariance;
|
||||
|
||||
ref_ptr<osg::Object> _userDataContainer;
|
||||
osg::UserDataContainer* _userDataContainer;
|
||||
|
||||
private:
|
||||
|
||||
|
||||
@@ -28,9 +28,95 @@ class OSG_EXPORT UserDataContainer : public osg::Object
|
||||
UserDataContainer();
|
||||
UserDataContainer(const UserDataContainer& udc, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
||||
|
||||
META_Object(osg, UserDataContainer)
|
||||
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const UserDataContainer*>(obj)!=0; }
|
||||
|
||||
/** return the name of the object's library. Must be defined
|
||||
by derived classes. The OpenSceneGraph convention is that the
|
||||
namespace of a library is the same as the library name.*/
|
||||
virtual const char* libraryName() const { return "osg"; }
|
||||
|
||||
/** return the name of the object's class type. Must be defined
|
||||
by derived classes.*/
|
||||
virtual const char* className() const { return "UserDataContainer"; }
|
||||
|
||||
/**
|
||||
* Set user data, data must be subclassed from Referenced to allow
|
||||
* automatic memory handling. If your own data isn't directly
|
||||
* subclassed from Referenced then create an adapter object
|
||||
* which points to your own object and handles the memory addressing.
|
||||
*/
|
||||
virtual void setUserData(Referenced* obj) = 0;
|
||||
|
||||
/** Get user data.*/
|
||||
virtual Referenced* getUserData() = 0;
|
||||
|
||||
/** Get const user data.*/
|
||||
virtual const Referenced* getUserData() const = 0;
|
||||
|
||||
/** Add user data object. Returns the index position of object added. */
|
||||
virtual unsigned int addUserObject(Object* obj) = 0;
|
||||
|
||||
/** Add element to list of user data objects.*/
|
||||
virtual void setUserObject(unsigned int i, Object* obj) = 0;
|
||||
|
||||
/** Remove element from the list of user data objects.*/
|
||||
virtual void removeUserObject(unsigned int i) = 0;
|
||||
|
||||
|
||||
/** Get user data object as specified index position. */
|
||||
virtual Object* getUserObject(unsigned int i) = 0;
|
||||
|
||||
/** Get const user data object as specified index position. */
|
||||
virtual const Object* getUserObject(unsigned int i) const = 0;
|
||||
|
||||
/** Get number of user objects assigned to this object.*/
|
||||
virtual unsigned int getNumUserObjects() const = 0;
|
||||
|
||||
/** Get the index position of specified user data object.*/
|
||||
virtual unsigned int getUserObjectIndex(const osg::Object* obj, unsigned int startPos=0) const = 0;
|
||||
|
||||
/** Get the index position of first user data object that matches specified name.*/
|
||||
virtual unsigned int getUserObjectIndex(const std::string& name, unsigned int startPos=0) const = 0;
|
||||
|
||||
|
||||
/** Get first user data object with specified name. */
|
||||
virtual Object* getUserObject(const std::string& name, unsigned int startPos=0);
|
||||
|
||||
/** Get first const user data object with specified name. */
|
||||
virtual const Object* getUserObject(const std::string& name, unsigned int startPos=0) const;
|
||||
|
||||
|
||||
typedef std::vector<std::string> DescriptionList;
|
||||
|
||||
/** Set the list of string descriptions.*/
|
||||
virtual void setDescriptions(const DescriptionList& descriptions) = 0;
|
||||
|
||||
/** Get the description list.*/
|
||||
virtual DescriptionList& getDescriptions() = 0;
|
||||
|
||||
/** Get the const description list.*/
|
||||
virtual const DescriptionList& getDescriptions() const = 0;
|
||||
|
||||
/** Get number of description strings.*/
|
||||
virtual unsigned int getNumDescriptions() const = 0;
|
||||
|
||||
/** Add a description string.*/
|
||||
virtual void addDescription(const std::string& desc) = 0;
|
||||
|
||||
protected:
|
||||
virtual ~UserDataContainer() {}
|
||||
};
|
||||
|
||||
/** Internal structure for storing all user data.*/
|
||||
class OSG_EXPORT DefaultUserDataContainer : public osg::UserDataContainer
|
||||
{
|
||||
public:
|
||||
DefaultUserDataContainer();
|
||||
DefaultUserDataContainer(const DefaultUserDataContainer& udc, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
||||
|
||||
META_Object(osg, DefaultUserDataContainer)
|
||||
|
||||
|
||||
virtual void setThreadSafeRefUnref(bool threadSafe);
|
||||
|
||||
/**
|
||||
@@ -73,18 +159,26 @@ class OSG_EXPORT UserDataContainer : public osg::Object
|
||||
virtual unsigned int getUserObjectIndex(const std::string& name, unsigned int startPos=0) const;
|
||||
|
||||
|
||||
|
||||
|
||||
/** Set the list of string descriptions.*/
|
||||
virtual void setDescriptions(const DescriptionList& descriptions);
|
||||
|
||||
/** Get the description list of the node.*/
|
||||
/** Get the description list.*/
|
||||
virtual DescriptionList& getDescriptions();
|
||||
|
||||
/** Get the const description list of the const node.*/
|
||||
/** Get the const description list.*/
|
||||
virtual const DescriptionList& getDescriptions() const;
|
||||
|
||||
/** Get number of description strings.*/
|
||||
virtual unsigned int getNumDescriptions() const;
|
||||
|
||||
protected:
|
||||
virtual ~UserDataContainer() {}
|
||||
/** Add a description string.*/
|
||||
virtual void addDescription(const std::string& desc);
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~DefaultUserDataContainer() {}
|
||||
|
||||
typedef std::vector< osg::ref_ptr<osg::Object> > ObjectList;
|
||||
|
||||
@@ -93,7 +187,6 @@ class OSG_EXPORT UserDataContainer : public osg::Object
|
||||
ObjectList _objectList;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#define OSG_VALUEOBJECT 1
|
||||
|
||||
#include <osg/Object>
|
||||
#include <osg/UserDataContainer>
|
||||
|
||||
namespace osg {
|
||||
|
||||
@@ -171,7 +172,7 @@ template<typename T>
|
||||
bool osg::Object::getUserValue(const std::string& name, T& value) const
|
||||
{
|
||||
typedef TemplateValueObject<T> UserValueObject;
|
||||
const UserValueObject* uvo = dynamic_cast<const UserValueObject*>(getUserObject(name));
|
||||
const UserValueObject* uvo = _userDataContainer ? dynamic_cast<const UserValueObject*>(_userDataContainer->getUserObject(name)) : 0;
|
||||
if (uvo)
|
||||
{
|
||||
value = uvo->getValue();
|
||||
@@ -189,9 +190,11 @@ void osg::Object::setUserValue(const std::string& name, const T& value)
|
||||
{
|
||||
typedef TemplateValueObject<T> UserValueObject;
|
||||
|
||||
unsigned int i = getUserObjectIndex(name);
|
||||
if (i<getNumUserObjects()) setUserObject(i, new UserValueObject(name,value));
|
||||
else addUserObject(new UserValueObject(name,value));
|
||||
getOrCreateUserDataContainer();
|
||||
|
||||
unsigned int i = _userDataContainer->getUserObjectIndex(name);
|
||||
if (i<_userDataContainer->getNumUserObjects()) _userDataContainer->setUserObject(i, new UserValueObject(name,value));
|
||||
else _userDataContainer->addUserObject(new UserValueObject(name,value));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user