Object
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_OBJECT
#define OSG_OBJECT 1
#include <osg/Referenced>
#include <osg/CopyOp>
#include <osg/ref_ptr>
#include <osg/Notify>
#include <string>
#include <vector>
namespace osg {
// forward declare
class UserDataContainer;
class Node;
class NodeVisitor;
class StateAttribute;
class Uniform;
class Drawable;
class Camera;
class Callback;
class CallbackObject;
class ValueObject;
#define _ADDQUOTES(def) #def
#define ADDQUOTES(def) _ADDQUOTES(def)
#define META_Object(library,name) \
virtual osg::Object* cloneType() const { return new name (); } \
virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new name (*this,copyop); } \
virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const name *>(obj)!=NULL; } \
virtual const char* libraryName() const { return #library; }\
virtual const char* className() const { return #name; }
#define OSG_INIT_SINGLETON_PROXY(ProxyName, Func) static struct ProxyName{ ProxyName() { Func; } } s_##ProxyName;
class OSG_EXPORT Object : public Referenced
{
public:
inline Object():Referenced(),_dataVariance(UNSPECIFIED), _userDataContainer(0) {}
inline explicit Object(bool threadSafeRefUnref):Referenced(threadSafeRefUnref),_dataVariance(UNSPECIFIED),_userDataContainer(0) {}
Object(const Object&,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
virtual Object* cloneType() const = 0;
virtual Object* clone(const CopyOp&) const = 0;
virtual bool isSameKindAs(const Object*) const { return true; }
virtual const char* libraryName() const = 0;
virtual const char* className() const = 0;
std::string getCompoundClassName() const { return std::string(libraryName()) + std::string("::") + std::string(className()); }
virtual Node* asNode() { return 0; }
virtual const Node* asNode() const { return 0; }
virtual NodeVisitor* asNodeVisitor() { return 0; }
virtual const NodeVisitor* asNodeVisitor() const { return 0; }
virtual StateSet* asStateSet() { return 0; }
virtual const StateSet* asStateSet() const { return 0; }
virtual StateAttribute* asStateAttribute() { return 0; }
virtual const StateAttribute* asStateAttribute() const { return 0; }
virtual Uniform* asUniform() { return 0; }
virtual const Uniform* asUniform() const { return 0; }
virtual Camera* asCamera() { return 0; }
virtual const Camera* asCamera() const { return 0; }
virtual Drawable* asDrawable() { return 0; }
virtual const Drawable* asDrawable() const { return 0; }
virtual Callback* asCallback() { return 0; }
virtual const Callback* asCallback() const { return 0; }
virtual CallbackObject* asCallbackObject() { return 0; }
virtual const CallbackObject* asCallbackObject() const { return 0; }
virtual UserDataContainer* asUserDataContainer() { return 0; }
virtual const UserDataContainer* asUserDataContainer() const { return 0; }
virtual ValueObject* asValueObject() { return 0; }
virtual const ValueObject* asValueObject() const { return 0; }
virtual Image* asImage() { return 0; }
virtual const Image* asImage() const { return 0; }
virtual void setThreadSafeRefUnref(bool threadSafe);
virtual void setName( const std::string& name ) { _name = name; }
inline void setName( const char* name )
{
if (name) setName(std::string(name));
else setName(std::string());
}
inline const std::string& getName() const { return _name; }
enum DataVariance
{
DYNAMIC,
STATIC,
UNSPECIFIED
};
inline void setDataVariance(DataVariance dv) { _dataVariance = dv; }
inline DataVariance getDataVariance() const { return _dataVariance; }
virtual void computeDataVariance() {}
void setUserDataContainer(osg::UserDataContainer* udc);
template<class T> void setUserDataContainer(const ref_ptr<T>& udc) { setUserDataContainer(udc.get()); }
osg::UserDataContainer* getUserDataContainer() { return _userDataContainer; }
const osg::UserDataContainer* getUserDataContainer() const { return _userDataContainer; }
osg::UserDataContainer* getOrCreateUserDataContainer();
virtual void setUserData(Referenced* obj);
template<class T> void setUserData(const ref_ptr<T>& ud) { setUserData(ud.get()); }
virtual Referenced* getUserData();
virtual const Referenced* getUserData() const;
template<typename T>
bool getUserValue(const std::string& name, T& value) const;
template<typename T>
void setUserValue(const std::string& name, const T& value);
virtual void resizeGLObjectBuffers(unsigned int /*maxSize*/) {}
virtual void releaseGLObjects(osg::State* = 0) const {}
protected:
virtual ~Object();
std::string _name;
DataVariance _dataVariance;
osg::UserDataContainer* _userDataContainer;
private:
Object& operator = (const Object&) { return *this; }
};
template<typename T>
T* clone(const T* t, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY)
{
if (t)
{
osg::ref_ptr<osg::Object> obj = t->clone(copyop);
T* ptr = dynamic_cast<T*>(obj.get());
if (ptr)
{
obj.release();
return ptr;
}
else
{
OSG_WARN<<"Warning: osg::clone(const T*, osg::CopyOp&) cloned object not of type T, returning NULL."<<std::endl;
return 0;
}
}
else
{
OSG_WARN<<"Warning: osg::clone(const T*, osg::CopyOp&) passed null object to clone, returning NULL."<<std::endl;
return 0;
}
}
template<typename T>
T* clone(const T* t, const std::string& name, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY)
{
T* newObject = osg::clone(t, copyop);
if (newObject)
{
newObject->setName(name);
return newObject;
}
else
{
OSG_WARN<<"Warning: osg::clone(const T*, const std::string&, const osg::CopyOp) passed null object to clone, returning NULL."<<std::endl;
return 0;
}
}
template<typename T>
T* cloneType(const T* t)
{
if (t)
{
osg::ref_ptr<osg::Object> obj = t->cloneType();
T* ptr = dynamic_cast<T*>(obj.get());
if (ptr)
{
obj.release();
return ptr;
}
else
{
OSG_WARN<<"Warning: osg::cloneType(const T*) cloned object not of type T, returning NULL."<<std::endl;
return 0;
}
}
else
{
OSG_WARN<<"Warning: osg::cloneType(const T*) passed null object to clone, returning NULL."<<std::endl;
return 0;
}
}
class DummyObject : public osg::Object
{
public:
DummyObject() {}
DummyObject(const DummyObject& org, const CopyOp& copyop) :
Object(org, copyop) {}
META_Object(osg, DummyObject)
protected:
virtual ~DummyObject() {}
};
inline void resizeGLObjectBuffers(osg::Object* object, unsigned int maxSize) { if (object) object->resizeGLObjectBuffers(maxSize); }
template<class T> void resizeGLObjectBuffers(const osg::ref_ptr<T>& object, unsigned int maxSize) { if (object.valid()) object->resizeGLObjectBuffers(maxSize); }
inline void releaseGLObjects(osg::Object* object, osg::State* state = 0) { if (object) object->releaseGLObjects(state); }
template<class T> void releaseGLObjects(const osg::ref_ptr<T>& object, osg::State* state = 0) { if (object.valid()) object->releaseGLObjects(state); }
}
#endif
CopyOp
Notify
OSG_WARN
#define OSG_WARN
Definition Notify:85
Referenced
osg::CallbackObject
Definition Callback:134
osg::Callback
Definition Callback:34
osg::Camera
Definition Camera:45
osg::CopyOp
Definition CopyOp:41
osg::CopyOp::SHALLOW_COPY
@ SHALLOW_COPY
Definition CopyOp:47
osg::Drawable
Definition Drawable:89
osg::DummyObject::DummyObject
DummyObject()
Definition Object:386
osg::DummyObject::META_Object
META_Object(osg, DummyObject) protected
Definition Object:390
osg::DummyObject::DummyObject
DummyObject(const DummyObject &org, const CopyOp &copyop)
Definition Object:387
osg::Image
Definition Image:179
osg::NodeVisitor
Definition NodeVisitor:82
osg::Node
Definition Node:72
osg::Object
Definition Object:61
osg::Object::setUserData
void setUserData(const ref_ptr< T > &ud)
Definition Object:261
osg::Object::libraryName
virtual const char * libraryName() const =0
osg::Object::setUserDataContainer
void setUserDataContainer(osg::UserDataContainer *udc)
osg::Object::setDataVariance
void setDataVariance(DataVariance dv)
Definition Object:228
osg::Object::setName
void setName(const char *name)
Definition Object:206
osg::Object::setUserValue
void setUserValue(const std::string &name, const T &value)
Definition ValueObject:377
osg::Object::asUserDataContainer
virtual const UserDataContainer * asUserDataContainer() const
Definition Object:179
osg::Object::asNodeVisitor
virtual NodeVisitor * asNodeVisitor()
Definition Object:111
osg::Object::setName
virtual void setName(const std::string &name)
Definition Object:203
osg::Object::asDrawable
virtual Drawable * asDrawable()
Definition Object:151
osg::Object::asStateAttribute
virtual const StateAttribute * asStateAttribute() const
Definition Object:131
osg::Object::asUserDataContainer
virtual UserDataContainer * asUserDataContainer()
Definition Object:175
osg::Object::asValueObject
virtual ValueObject * asValueObject()
Definition Object:183
osg::Object::asValueObject
virtual const ValueObject * asValueObject() const
Definition Object:187
osg::Object::asImage
virtual const Image * asImage() const
Definition Object:195
osg::Object::~Object
virtual ~Object()
osg::Object::clone
virtual Object * clone(const CopyOp &) const =0
osg::Object::isSameKindAs
virtual bool isSameKindAs(const Object *) const
Definition Object:85
osg::Object::Object
Object()
Definition Object:69
osg::Object::cloneType
virtual Object * cloneType() const =0
osg::Object::Object
Object(bool threadSafeRefUnref)
Definition Object:71
osg::Object::asUniform
virtual const Uniform * asUniform() const
Definition Object:139
osg::Object::asCallbackObject
virtual CallbackObject * asCallbackObject()
Definition Object:167
osg::Object::asCamera
virtual const Camera * asCamera() const
Definition Object:147
osg::Object::asStateSet
virtual StateSet * asStateSet()
Definition Object:119
osg::Object::DataVariance
DataVariance
Definition Object:217
osg::Object::DYNAMIC
@ DYNAMIC
Definition Object:218
osg::Object::STATIC
@ STATIC
Definition Object:219
osg::Object::UNSPECIFIED
@ UNSPECIFIED
Definition Object:220
osg::Object::className
virtual const char * className() const =0
osg::Object::getUserData
virtual Referenced * getUserData()
osg::Object::asNode
virtual Node * asNode()
Definition Object:103
osg::Object::getUserDataContainer
osg::UserDataContainer * getUserDataContainer()
Definition Object:243
osg::Object::asStateAttribute
virtual StateAttribute * asStateAttribute()
Definition Object:127
osg::Object::setUserDataContainer
void setUserDataContainer(const ref_ptr< T > &udc)
Definition Object:240
osg::Object::getUserDataContainer
const osg::UserDataContainer * getUserDataContainer() const
Definition Object:246
osg::Object::computeDataVariance
virtual void computeDataVariance()
Definition Object:234
osg::Object::asCallback
virtual Callback * asCallback()
Definition Object:159
osg::Object::asDrawable
virtual const Drawable * asDrawable() const
Definition Object:155
osg::Object::_dataVariance
DataVariance _dataVariance
Definition Object:304
osg::Object::asNodeVisitor
virtual const NodeVisitor * asNodeVisitor() const
Definition Object:115
osg::Object::asCallback
virtual const Callback * asCallback() const
Definition Object:163
osg::Object::resizeGLObjectBuffers
virtual void resizeGLObjectBuffers(unsigned int)
Definition Object:284
osg::Object::getUserData
virtual const Referenced * getUserData() const
osg::Object::_userDataContainer
osg::UserDataContainer * _userDataContainer
Definition Object:306
osg::Object::asImage
virtual Image * asImage()
Definition Object:191
osg::Object::asNode
virtual const Node * asNode() const
Definition Object:107
osg::Object::asUniform
virtual Uniform * asUniform()
Definition Object:135
osg::Object::getCompoundClassName
std::string getCompoundClassName() const
Definition Object:98
osg::Object::asCamera
virtual Camera * asCamera()
Definition Object:143
osg::Object::asCallbackObject
virtual const CallbackObject * asCallbackObject() const
Definition Object:171
osg::Object::getName
const std::string & getName() const
Definition Object:213
osg::Object::setThreadSafeRefUnref
virtual void setThreadSafeRefUnref(bool threadSafe)
osg::Object::Object
Object(const Object &, const CopyOp &copyop=CopyOp::SHALLOW_COPY)
osg::Object::asStateSet
virtual const StateSet * asStateSet() const
Definition Object:123
osg::Object::releaseGLObjects
virtual void releaseGLObjects(osg::State *=0) const
Definition Object:289
osg::Object::getUserValue
bool getUserValue(const std::string &name, T &value) const
osg::Object::getOrCreateUserDataContainer
osg::UserDataContainer * getOrCreateUserDataContainer()
osg::Object::_name
std::string _name
Definition Object:303
osg::Object::setUserData
virtual void setUserData(Referenced *obj)
osg::Object::getDataVariance
DataVariance getDataVariance() const
Definition Object:231
osg::Referenced::Referenced
Referenced()
osg::StateAttribute
Definition StateAttribute:77
osg::StateSet
Definition StateSet:46
osg::State
Definition State:80
osg::Uniform
Definition Uniform:414
osg::UserDataContainer
Definition UserDataContainer:26
osg::ValueObject
Definition ValueObject:67
osg::ref_ptr
Definition ref_ptr:32
osg::ref_ptr::get
T * get() const
Definition ref_ptr:117
osg::ref_ptr::release
T * release()
Definition ref_ptr:126
osg
Definition AlphaFunc:19
osg::resizeGLObjectBuffers
void resizeGLObjectBuffers(osg::Object *object, unsigned int maxSize)
Definition Object:396
osg::releaseGLObjects
void releaseGLObjects(osg::Object *object, osg::State *state=0)
Definition Object:400
osg::clone
T * clone(const T *t, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
Definition Object:315
osg::cloneType
T * cloneType(const T *t)
Definition Object:357
OSG_EXPORT
#define OSG_EXPORT
Definition osg/Export:39
ref_ptr