2007-12-13 00:56:28 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2007 Robert Osfield
|
2007-12-09 23:43:49 +08:00
|
|
|
*
|
|
|
|
* 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 OSGSIM_SHAPEATTRIBUTE
|
|
|
|
#define OSGSIM_SHAPEATTRIBUTE 1
|
|
|
|
|
|
|
|
#include <osg/Object>
|
2011-06-23 19:09:49 +08:00
|
|
|
#include <osg/MixinVector>
|
2007-12-09 23:43:49 +08:00
|
|
|
|
2007-12-10 19:20:22 +08:00
|
|
|
#include <osgSim/Export>
|
2007-12-09 23:43:49 +08:00
|
|
|
|
|
|
|
namespace osgSim
|
|
|
|
{
|
|
|
|
|
2007-12-10 19:20:22 +08:00
|
|
|
class OSGSIM_EXPORT ShapeAttribute
|
2007-12-09 23:43:49 +08:00
|
|
|
{
|
|
|
|
public:
|
2011-06-24 16:32:25 +08:00
|
|
|
/// ShapeAttribute data type.
|
2007-12-09 23:43:49 +08:00
|
|
|
enum Type
|
|
|
|
{
|
2011-06-24 16:32:25 +08:00
|
|
|
UNKNOWN,
|
2007-12-09 23:43:49 +08:00
|
|
|
INTEGER,
|
|
|
|
DOUBLE,
|
|
|
|
STRING
|
|
|
|
};
|
|
|
|
|
|
|
|
ShapeAttribute();
|
|
|
|
ShapeAttribute(const char * name);
|
|
|
|
ShapeAttribute(const char * name, int value);
|
|
|
|
ShapeAttribute(const char * name, double value);
|
2007-12-13 20:30:31 +08:00
|
|
|
|
|
|
|
/** Note, ShapeAttribute takes a copy of both name and value, the calling code should manage its own clean up of the original strings.*/
|
2007-12-09 23:43:49 +08:00
|
|
|
ShapeAttribute(const char * name, const char * value);
|
2007-12-13 20:30:31 +08:00
|
|
|
|
2007-12-09 23:43:49 +08:00
|
|
|
ShapeAttribute(const ShapeAttribute & sa);
|
|
|
|
|
|
|
|
~ShapeAttribute();
|
|
|
|
|
2007-12-13 20:30:31 +08:00
|
|
|
ShapeAttribute& operator = (const ShapeAttribute& sa);
|
2007-12-09 23:43:49 +08:00
|
|
|
|
2011-06-24 16:05:54 +08:00
|
|
|
/** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
|
|
|
|
int compare(const osgSim::ShapeAttribute& sa) const;
|
|
|
|
|
|
|
|
inline bool operator == (const osgSim::ShapeAttribute& sa) const { return compare(sa)==0; }
|
|
|
|
inline bool operator != (const osgSim::ShapeAttribute& sa) const { return compare(sa)!=0; }
|
|
|
|
inline bool operator < (const osgSim::ShapeAttribute& sa) const { return compare(sa)<0; }
|
|
|
|
|
2011-06-24 16:32:25 +08:00
|
|
|
/// Get the attribute name.
|
2007-12-09 23:43:49 +08:00
|
|
|
const std::string & getName() const { return _name; }
|
2011-06-24 16:32:25 +08:00
|
|
|
|
|
|
|
/// Set the attribute name.
|
2008-09-01 18:06:19 +08:00
|
|
|
void setName(const std::string& name) { _name = name; }
|
|
|
|
|
2011-06-24 16:32:25 +08:00
|
|
|
/// Get the attribute data type.
|
2007-12-09 23:43:49 +08:00
|
|
|
const Type getType() const { return _type; }
|
|
|
|
|
2011-06-24 16:32:25 +08:00
|
|
|
/// Get the attribute data as an int.
|
2007-12-09 23:43:49 +08:00
|
|
|
int getInt() const { return _integer; }
|
2011-06-24 16:32:25 +08:00
|
|
|
|
|
|
|
/// Get the attribute data as a double.
|
2007-12-09 23:43:49 +08:00
|
|
|
double getDouble() const { return _double; }
|
2011-06-24 16:32:25 +08:00
|
|
|
|
|
|
|
/// Get the attribute data as a string.
|
2007-12-09 23:43:49 +08:00
|
|
|
const char * getString() const { return _string; }
|
2008-09-01 18:06:19 +08:00
|
|
|
|
2011-06-24 16:32:25 +08:00
|
|
|
/// Set an integer attribute data.
|
2008-09-01 18:48:28 +08:00
|
|
|
void setValue(int value) { free(); _type = INTEGER; _integer = value; }
|
2011-06-24 16:32:25 +08:00
|
|
|
|
|
|
|
/// Set a double attribute data.
|
2008-09-01 18:48:28 +08:00
|
|
|
void setValue(double value) { free(); _type = DOUBLE; _double = value; }
|
2011-06-24 16:32:25 +08:00
|
|
|
|
|
|
|
/// Set a string attribute data.
|
2008-12-13 02:47:30 +08:00
|
|
|
void setValue(const char * value);
|
2008-09-01 18:06:19 +08:00
|
|
|
|
2007-12-09 23:43:49 +08:00
|
|
|
|
|
|
|
private:
|
2007-12-13 20:30:31 +08:00
|
|
|
|
|
|
|
void free();
|
|
|
|
void copy(const ShapeAttribute& sa);
|
2007-12-09 23:43:49 +08:00
|
|
|
|
|
|
|
std::string _name;
|
|
|
|
Type _type;
|
|
|
|
|
|
|
|
union
|
|
|
|
{
|
|
|
|
int _integer;
|
|
|
|
double _double;
|
2007-12-13 20:30:31 +08:00
|
|
|
char* _string;
|
2007-12-09 23:43:49 +08:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2011-06-23 19:09:49 +08:00
|
|
|
class OSGSIM_EXPORT ShapeAttributeList : public osg::Object, public osg::MixinVector<ShapeAttribute>
|
2007-12-09 23:43:49 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
META_Object(osgSim, ShapeAttributeList)
|
|
|
|
|
|
|
|
ShapeAttributeList():
|
|
|
|
Object()
|
|
|
|
{}
|
|
|
|
|
|
|
|
/** Copy constructor, optional CopyOp object can be used to control
|
|
|
|
* shallow vs deep copying of dynamic data.*/
|
|
|
|
ShapeAttributeList(const ShapeAttributeList& sal,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
|
2011-06-23 19:09:49 +08:00
|
|
|
osg::Object(sal, copyop),
|
2011-06-23 23:42:45 +08:00
|
|
|
osg::MixinVector<ShapeAttribute>(sal)
|
2007-12-09 23:43:49 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
|
|
|
|
virtual int compare(const osgSim::ShapeAttributeList& sal) const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~ShapeAttributeList() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // ** SHAPEATTRIBUTE_ ** //
|