UserDataContainer
Go to the documentation of this file.
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSG_USERDATACONTAINER
#define OSG_USERDATACONTAINER 1
#include <osg/Object>
#include <string>
#include <vector>
namespace osg {
class OSG_EXPORT UserDataContainer : public osg::Object
{
public:
UserDataContainer();
UserDataContainer(const UserDataContainer& udc, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const UserDataContainer*>(obj)!=0; }
virtual const char* libraryName() const { return "osg"; }
virtual const char* className() const { return "UserDataContainer"; }
virtual UserDataContainer* asUserDataContainer() { return this; }
virtual const UserDataContainer* asUserDataContainer() const { return this; }
virtual void setUserData(Referenced* obj) = 0;
using osg::Object::setUserData;
virtual Referenced* getUserData() = 0;
virtual const Referenced* getUserData() const = 0;
virtual unsigned int addUserObject(Object* obj) = 0;
template<class T> unsigned int addUserObject(const osg::ref_ptr<T>& obj) { return addUserObject(obj.get()); }
virtual void setUserObject(unsigned int i, Object* obj) = 0;
virtual void removeUserObject(unsigned int i) = 0;
virtual Object* getUserObject(unsigned int i) = 0;
virtual const Object* getUserObject(unsigned int i) const = 0;
virtual unsigned int getNumUserObjects() const = 0;
virtual unsigned int getUserObjectIndex(const osg::Object* obj, unsigned int startPos=0) const = 0;
virtual unsigned int getUserObjectIndex(const std::string& name, unsigned int startPos=0) const = 0;
virtual Object* getUserObject(const std::string& name, unsigned int startPos=0);
virtual const Object* getUserObject(const std::string& name, unsigned int startPos=0) const;
typedef std::vector<std::string> DescriptionList;
virtual void setDescriptions(const DescriptionList& descriptions) = 0;
virtual DescriptionList& getDescriptions() = 0;
virtual const DescriptionList& getDescriptions() const = 0;
virtual unsigned int getNumDescriptions() const = 0;
virtual void addDescription(const std::string& desc) = 0;
protected:
virtual ~UserDataContainer() {}
};
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);
virtual void setUserData(Referenced* obj);
using osg::Object::setUserData;
using osg::UserDataContainer::addUserObject;
virtual Referenced* getUserData();
virtual const Referenced* getUserData() const;
virtual unsigned int addUserObject(Object* obj);
virtual void setUserObject(unsigned int i, Object* obj);
virtual void removeUserObject(unsigned int i);
virtual Object* getUserObject(unsigned int i);
virtual const Object* getUserObject(unsigned int i) const;
virtual unsigned int getNumUserObjects() const;
virtual unsigned int getUserObjectIndex(const osg::Object* obj, unsigned int startPos=0) const;
virtual unsigned int getUserObjectIndex(const std::string& name, unsigned int startPos=0) const;
virtual void setDescriptions(const DescriptionList& descriptions);
virtual DescriptionList& getDescriptions();
virtual const DescriptionList& getDescriptions() const;
virtual unsigned int getNumDescriptions() const;
virtual void addDescription(const std::string& desc);
protected:
virtual ~DefaultUserDataContainer() {}
typedef std::vector< osg::ref_ptr<osg::Object> > ObjectList;
ref_ptr<Referenced> _userData;
DescriptionList _descriptionList;
ObjectList _objectList;
};
inline Object* getUserObject(osg::Object* object, const std::string& name)
{
osg::UserDataContainer* udc = object->getUserDataContainer();
return udc ? udc->getUserObject(name) : 0;
}
inline const Object* getUserObject(const osg::Object* object, const std::string& name)
{
const osg::UserDataContainer* udc = object->getUserDataContainer();
return udc ? udc->getUserObject(name) : 0;
}
}
#endif
Object
osg::CopyOp
Definition CopyOp:41
osg::CopyOp::SHALLOW_COPY
@ SHALLOW_COPY
Definition CopyOp:47
osg::DefaultUserDataContainer::getUserObject
virtual const Object * getUserObject(unsigned int i) const
osg::DefaultUserDataContainer::getUserObjectIndex
virtual unsigned int getUserObjectIndex(const std::string &name, unsigned int startPos=0) const
osg::DefaultUserDataContainer::_objectList
ObjectList _objectList
Definition UserDataContainer:202
osg::DefaultUserDataContainer::setUserObject
virtual void setUserObject(unsigned int i, Object *obj)
osg::DefaultUserDataContainer::_userData
ref_ptr< Referenced > _userData
Definition UserDataContainer:200
osg::DefaultUserDataContainer::removeUserObject
virtual void removeUserObject(unsigned int i)
osg::DefaultUserDataContainer::setDescriptions
virtual void setDescriptions(const DescriptionList &descriptions)
osg::DefaultUserDataContainer::getUserObjectIndex
virtual unsigned int getUserObjectIndex(const osg::Object *obj, unsigned int startPos=0) const
osg::DefaultUserDataContainer::getUserData
virtual const Referenced * getUserData() const
osg::DefaultUserDataContainer::getDescriptions
virtual const DescriptionList & getDescriptions() const
osg::DefaultUserDataContainer::addUserObject
virtual unsigned int addUserObject(Object *obj)
osg::DefaultUserDataContainer::getUserObject
virtual Object * getUserObject(unsigned int i)
osg::DefaultUserDataContainer::getNumUserObjects
virtual unsigned int getNumUserObjects() const
osg::DefaultUserDataContainer::setUserData
virtual void setUserData(Referenced *obj)
osg::DefaultUserDataContainer::addDescription
virtual void addDescription(const std::string &desc)
osg::DefaultUserDataContainer::getDescriptions
virtual DescriptionList & getDescriptions()
osg::DefaultUserDataContainer::META_Object
META_Object(osg, DefaultUserDataContainer) virtual void setThreadSafeRefUnref(bool threadSafe)
osg::DefaultUserDataContainer::getNumDescriptions
virtual unsigned int getNumDescriptions() const
osg::DefaultUserDataContainer::DefaultUserDataContainer
DefaultUserDataContainer(const DefaultUserDataContainer &udc, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
osg::DefaultUserDataContainer::DefaultUserDataContainer
DefaultUserDataContainer()
osg::DefaultUserDataContainer::ObjectList
std::vector< osg::ref_ptr< osg::Object > > ObjectList
Definition UserDataContainer:198
osg::DefaultUserDataContainer::_descriptionList
DescriptionList _descriptionList
Definition UserDataContainer:201
osg::DefaultUserDataContainer::~DefaultUserDataContainer
virtual ~DefaultUserDataContainer()
Definition UserDataContainer:196
osg::DefaultUserDataContainer::getUserData
virtual Referenced * getUserData()
osg::Object
Definition Object:61
osg::Object::Object
Object()
Definition Object:69
osg::Object::getUserDataContainer
osg::UserDataContainer * getUserDataContainer()
Definition Object:243
osg::Object::setThreadSafeRefUnref
virtual void setThreadSafeRefUnref(bool threadSafe)
osg::Object::setUserData
virtual void setUserData(Referenced *obj)
osg::Referenced
Definition Referenced:44
osg::UserDataContainer
Definition UserDataContainer:26
osg::UserDataContainer::asUserDataContainer
virtual UserDataContainer * asUserDataContainer()
Definition UserDataContainer:44
osg::UserDataContainer::isSameKindAs
virtual bool isSameKindAs(const Object *obj) const
Definition UserDataContainer:31
osg::UserDataContainer::addDescription
virtual void addDescription(const std::string &desc)=0
osg::UserDataContainer::getUserData
virtual const Referenced * getUserData() const =0
osg::UserDataContainer::addUserObject
virtual unsigned int addUserObject(Object *obj)=0
osg::UserDataContainer::libraryName
virtual const char * libraryName() const
Definition UserDataContainer:36
osg::UserDataContainer::getDescriptions
virtual DescriptionList & getDescriptions()=0
osg::UserDataContainer::className
virtual const char * className() const
Definition UserDataContainer:40
osg::UserDataContainer::getNumUserObjects
virtual unsigned int getNumUserObjects() const =0
osg::UserDataContainer::getNumDescriptions
virtual unsigned int getNumDescriptions() const =0
osg::UserDataContainer::UserDataContainer
UserDataContainer(const UserDataContainer &udc, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
osg::UserDataContainer::DescriptionList
std::vector< std::string > DescriptionList
Definition UserDataContainer:101
osg::UserDataContainer::getUserObjectIndex
virtual unsigned int getUserObjectIndex(const osg::Object *obj, unsigned int startPos=0) const =0
osg::UserDataContainer::getUserObject
virtual const Object * getUserObject(const std::string &name, unsigned int startPos=0) const
osg::UserDataContainer::getDescriptions
virtual const DescriptionList & getDescriptions() const =0
osg::UserDataContainer::getUserData
virtual Referenced * getUserData()=0
osg::UserDataContainer::UserDataContainer
UserDataContainer()
osg::UserDataContainer::addUserObject
unsigned int addUserObject(const osg::ref_ptr< T > &obj)
Definition UserDataContainer:69
osg::UserDataContainer::getUserObject
virtual const Object * getUserObject(unsigned int i) const =0
osg::UserDataContainer::setUserData
virtual void setUserData(Referenced *obj)=0
osg::UserDataContainer::~UserDataContainer
virtual ~UserDataContainer()
Definition UserDataContainer:119
osg::UserDataContainer::removeUserObject
virtual void removeUserObject(unsigned int i)=0
osg::UserDataContainer::getUserObject
virtual Object * getUserObject(const std::string &name, unsigned int startPos=0)
osg::UserDataContainer::getUserObjectIndex
virtual unsigned int getUserObjectIndex(const std::string &name, unsigned int startPos=0) const =0
osg::UserDataContainer::setDescriptions
virtual void setDescriptions(const DescriptionList &descriptions)=0
osg::UserDataContainer::setUserObject
virtual void setUserObject(unsigned int i, Object *obj)=0
osg::UserDataContainer::asUserDataContainer
virtual const UserDataContainer * asUserDataContainer() const
Definition UserDataContainer:48
osg::UserDataContainer::getUserObject
virtual Object * getUserObject(unsigned int i)=0
osg::ref_ptr
Definition ref_ptr:32
osg::ref_ptr::get
T * get() const
Definition ref_ptr:117
osg
Definition AlphaFunc:19
osg::getUserObject
Object * getUserObject(osg::Object *object, const std::string &name)
Definition UserDataContainer:207
OSG_EXPORT
#define OSG_EXPORT
Definition osg/Export:39