File: ShapeAttribute

package info (click to toggle)
openscenegraph 2.8.3-5
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 33,968 kB
  • ctags: 30,935
  • sloc: cpp: 287,169; ansic: 9,050; sh: 654; yacc: 548; objc: 374; makefile: 264; lex: 151; perl: 119
file content (114 lines) | stat: -rw-r--r-- 3,415 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2007 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 OSGSIM_SHAPEATTRIBUTE
#define OSGSIM_SHAPEATTRIBUTE 1

#include <string>
#include <vector>

#include <osg/Object>

#include <osgSim/Export>

namespace osgSim
{

class OSGSIM_EXPORT ShapeAttribute
{
    public:
        
        enum Type
        {
            UNKNOW,
            INTEGER,
            DOUBLE,
            STRING
        };
      
        ShapeAttribute();
        ShapeAttribute(const char * name);
        ShapeAttribute(const char * name, int value);
        ShapeAttribute(const char * name, double value);
        
        /** Note, ShapeAttribute takes a copy of both name and value, the calling code should manage its own clean up of the original strings.*/
        ShapeAttribute(const char * name, const char * value);
        
        ShapeAttribute(const ShapeAttribute & sa);
            
        ~ShapeAttribute();
        
        ShapeAttribute& operator = (const ShapeAttribute& sa);
        
        const std::string & getName() const { return _name; }
        void setName(const std::string& name) { _name = name; }

        const Type getType() const { return _type; }
        
        int getInt() const { return _integer; }
        double getDouble() const { return _double; }
        const char * getString() const { return _string; }
       
        void setValue(int value) { free(); _type = INTEGER; _integer = value; }
        void setValue(double value) { free(); _type = DOUBLE; _double = value; }
        void setValue(const char * value);

        /** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
        int compare(const osgSim::ShapeAttribute& sa) const;
        
        
    private:
    
        void free();
        void copy(const ShapeAttribute& sa);
        
        std::string _name;
        Type _type;
        
        union
        {
            int _integer;
            double _double;
            char* _string;
        };
        
        
};

class OSGSIM_EXPORT ShapeAttributeList : public osg::Object, public std::vector<ShapeAttribute>
{
    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):
            osg::Object(sal, copyop)
        {
            std::copy(sal.begin(),sal.end(), begin());
        }
    
        /** 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_ ** //