openscenegraph
ShapeAttribute
Go to the documentation of this file.
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2007 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14#ifndef OSGSIM_SHAPEATTRIBUTE
15#define OSGSIM_SHAPEATTRIBUTE 1
16
17#include <osg/Object>
18#include <osg/MixinVector>
19
20#include <osgSim/Export>
21
22namespace osgSim
23{
24
25class OSGSIM_EXPORT ShapeAttribute
26{
27 public:
28 /// ShapeAttribute data type.
29 enum Type
30 {
31 UNKNOWN,
32 INTEGER,
33 DOUBLE,
34 STRING
35 };
36
37 ShapeAttribute();
38 ShapeAttribute(const char * name);
39 ShapeAttribute(const char * name, int value);
40 ShapeAttribute(const char * name, double value);
41
42 /** Note, ShapeAttribute takes a copy of both name and value, the calling code should manage its own clean up of the original strings.*/
43 ShapeAttribute(const char * name, const char * value);
44
45 ShapeAttribute(const ShapeAttribute & sa);
46
47 ~ShapeAttribute();
48
49 ShapeAttribute& operator = (const ShapeAttribute& sa);
50
51 /** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
52 int compare(const osgSim::ShapeAttribute& sa) const;
53
54 inline bool operator == (const osgSim::ShapeAttribute& sa) const { return compare(sa)==0; }
55 inline bool operator != (const osgSim::ShapeAttribute& sa) const { return compare(sa)!=0; }
56 inline bool operator < (const osgSim::ShapeAttribute& sa) const { return compare(sa)<0; }
57
58 /// Get the attribute name.
59 const std::string & getName() const { return _name; }
60
61 /// Set the attribute name.
62 void setName(const std::string& name) { _name = name; }
63
64 /// Get the attribute data type.
65 Type getType() const { return _type; }
66
67 /// Get the attribute data as an int.
68 int getInt() const { return _integer; }
69
70 /// Get the attribute data as a double.
71 double getDouble() const { return _double; }
72
73 /// Get the attribute data as a string.
74 const char * getString() const { return _string; }
75
76 /// Set an integer attribute data.
77 void setValue(int value) { free(); _type = INTEGER; _integer = value; }
78
79 /// Set a double attribute data.
80 void setValue(double value) { free(); _type = DOUBLE; _double = value; }
81
82 /// Set a string attribute data.
83 void setValue(const char * value);
84
85
86 private:
87
88 void free();
89 void copy(const ShapeAttribute& sa);
90
91 std::string _name;
92 Type _type;
93
94 union
95 {
96 int _integer;
97 double _double;
98 char* _string;
99 };
100};
101
102class OSGSIM_EXPORT ShapeAttributeList : public osg::Object, public osg::MixinVector<ShapeAttribute>
103{
104 public:
105 META_Object(osgSim, ShapeAttributeList)
106
107 ShapeAttributeList():
108 Object()
109 {}
110
111 /** Copy constructor, optional CopyOp object can be used to control
112 * shallow vs deep copying of dynamic data.*/
113 ShapeAttributeList(const ShapeAttributeList& sal,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
114 osg::Object(sal, copyop),
115 osg::MixinVector<ShapeAttribute>(sal)
116 {
117 }
118
119 /** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
120 virtual int compare(const osgSim::ShapeAttributeList& sal) const;
121
122 protected:
123 virtual ~ShapeAttributeList() {}
124};
125
126}
127
128#endif // ** SHAPEATTRIBUTE_ ** //