OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ShapeAttribute.h
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 
22 namespace osgSim
23 {
24 
26 {
27  public:
29  enum Type
30  {
34  STRING
35  };
36 
38  ShapeAttribute(const char * name);
39  ShapeAttribute(const char * name, int value);
40  ShapeAttribute(const char * name, double value);
41 
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 
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 
59  const std::string & getName() const { return _name; }
60 
62  void setName(const std::string& name) { _name = name; }
63 
65  Type getType() const { return _type; }
66 
68  int getInt() const { return _integer; }
69 
71  double getDouble() const { return _double; }
72 
74  const char * getString() const { return _string; }
75 
77  void setValue(int value) { free(); _type = INTEGER; _integer = value; }
78 
80  void setValue(double value) { free(); _type = DOUBLE; _double = value; }
81 
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 
102 class OSGSIM_EXPORT ShapeAttributeList : public osg::Object, public osg::MixinVector<ShapeAttribute>
103 {
104  public:
106 
108  Object()
109  {}
110 
114  osg::Object(sal, copyop),
115  osg::MixinVector<ShapeAttribute>(sal)
116  {
117  }
118 
120  virtual int compare(const osgSim::ShapeAttributeList& sal) const;
121 
122  protected:
123  virtual ~ShapeAttributeList() {}
124 };
125 
126 }
127 
128 #endif // ** SHAPEATTRIBUTE_ ** //
#define OSGSIM_EXPORT
Definition: Export.h:38
Type getType() const
Get the attribute data type.
void setValue(double value)
Set a double attribute data.
META_Object(osgSim, ShapeAttributeList) ShapeAttributeList()
ShapeAttributeList(const ShapeAttributeList &sal, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
void setValue(int value)
Set an integer attribute data.
Type
ShapeAttribute data type.
int getInt() const
Get the attribute data as an int.
double getDouble() const
Get the attribute data as a double.
const std::string & getName() const
Get the attribute name.
const char * getString() const
Get the attribute data as a string.
Definition: AlphaFunc.h:19
void setName(const std::string &name)
Set the attribute name.