/* -*-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 #include #include #include #include namespace osg { // forward declare class State; #define _ADDQUOTES(def) #def #define ADDQUOTES(def) _ADDQUOTES(def) /** META_Object macro define the standard clone, isSameKindAs and className methods. * Use when subclassing from Object to make it more convenient to define * the standard pure virtual clone, isSameKindAs and className methods * which are required for all Object subclasses.*/ #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(obj)!=NULL; } \ virtual const char* libraryName() const { return #library; }\ virtual const char* className() const { return #name; } template T* clone(const T* t, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) { if (t) { osg::ref_ptr obj = t->clone(copyop); T* ptr = dynamic_cast(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."< 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."< T* cloneType(const T* t) { if (t) { osg::ref_ptr obj = t->cloneType(); T* ptr = dynamic_cast(obj.get()); if (ptr) { obj.release(); return ptr; } else { OSG_WARN<<"Warning: osg::cloneType(const T*) cloned object not of type T, returning NULL."< _userData; private: /** disallow any copy operator.*/ Object& operator = (const Object&) { return *this; } }; } #endif