root/OpenSceneGraph/trunk/include/osg/UserDataContainer @ 13041

Revision 13041, 7.1 kB (checked in by robert, 3 years ago)

Ran script to remove trailing spaces and tabs

Line 
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 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 OSG_USERDATACONTAINER
15#define OSG_USERDATACONTAINER 1
16
17#include <osg/Object>
18
19#include <string>
20#include <vector>
21
22namespace osg {
23
24/** Internal structure for storing all user data.*/
25class OSG_EXPORT UserDataContainer : public osg::Object
26{
27    public:
28        UserDataContainer();
29        UserDataContainer(const UserDataContainer& udc, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
30
31        virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const UserDataContainer*>(obj)!=0; }
32
33        /** return the name of the object's library. Must be defined
34            by derived classes. The OpenSceneGraph convention is that the
35            namespace of a library is the same as the library name.*/
36        virtual const char* libraryName() const { return "osg"; }
37
38        /** return the name of the object's class type. Must be defined
39            by derived classes.*/
40        virtual const char* className() const  { return "UserDataContainer"; }
41
42        /**
43         * Set user data, data must be subclassed from Referenced to allow
44         * automatic memory handling.  If your own data isn't directly
45         * subclassed from Referenced then create an adapter object
46         * which points to your own object and handles the memory addressing.
47         */
48        virtual void setUserData(Referenced* obj) = 0;
49
50        /** Get user data.*/
51        virtual Referenced* getUserData() = 0;
52
53        /** Get const user data.*/
54        virtual const Referenced* getUserData() const  = 0;
55
56        /** Add user data object. Returns the index position of object added. */
57        virtual unsigned int addUserObject(Object* obj)  = 0;
58
59         /** Add element to list of user data objects.*/
60        virtual void setUserObject(unsigned int i, Object* obj)  = 0;
61
62        /** Remove element from the list of user data objects.*/
63        virtual void removeUserObject(unsigned int i)  = 0;
64
65
66        /** Get user data object as specified index position. */
67        virtual Object* getUserObject(unsigned int i)  = 0;
68
69        /** Get const user data object as specified index position. */
70        virtual const Object* getUserObject(unsigned int i) const  = 0;
71
72        /** Get number of user objects assigned to this object.*/
73        virtual unsigned int getNumUserObjects() const  = 0;
74
75        /** Get the index position of specified user data object.*/
76        virtual unsigned int getUserObjectIndex(const osg::Object* obj, unsigned int startPos=0) const = 0;
77
78        /** Get the index position of first user data object that matches specified name.*/
79        virtual unsigned int getUserObjectIndex(const std::string& name, unsigned int startPos=0) const = 0;
80
81
82        /** Get first user data object with specified name. */
83        virtual Object* getUserObject(const std::string& name, unsigned int startPos=0);
84
85        /** Get first const user data object with specified name. */
86        virtual const Object* getUserObject(const std::string& name, unsigned int startPos=0) const;
87
88
89        typedef std::vector<std::string> DescriptionList;
90
91        /** Set the list of string descriptions.*/
92        virtual void setDescriptions(const DescriptionList& descriptions) = 0;
93
94        /** Get the description list.*/
95        virtual DescriptionList& getDescriptions() = 0;
96
97        /** Get the const description list.*/
98        virtual const DescriptionList& getDescriptions() const = 0;
99
100        /** Get number of description strings.*/
101        virtual unsigned int getNumDescriptions() const = 0;
102
103        /** Add a description string.*/
104        virtual void addDescription(const std::string& desc) = 0;
105
106    protected:
107        virtual ~UserDataContainer() {}
108};
109
110/** Internal structure for storing all user data.*/
111class OSG_EXPORT DefaultUserDataContainer : public osg::UserDataContainer
112{
113    public:
114        DefaultUserDataContainer();
115        DefaultUserDataContainer(const DefaultUserDataContainer& udc, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
116
117        META_Object(osg, DefaultUserDataContainer)
118
119
120        virtual void setThreadSafeRefUnref(bool threadSafe);
121
122        /**
123         * Set user data, data must be subclassed from Referenced to allow
124         * automatic memory handling.  If your own data isn't directly
125         * subclassed from Referenced then create an adapter object
126         * which points to your own object and handles the memory addressing.
127         */
128        virtual void setUserData(Referenced* obj);
129
130        /** Get user data.*/
131        virtual Referenced* getUserData();
132
133        /** Get const user data.*/
134        virtual const Referenced* getUserData() const;
135
136        /** Add user data object. Returns the index position of object added. */
137        virtual unsigned int addUserObject(Object* obj);
138
139         /** Add element to list of user data objects.*/
140        virtual void setUserObject(unsigned int i, Object* obj);
141
142        /** Remove element from the list of user data objects.*/
143        virtual void removeUserObject(unsigned int i);
144
145
146        /** Get user data object as specified index position. */
147        virtual Object* getUserObject(unsigned int i);
148
149        /** Get const user data object as specified index position. */
150        virtual const Object* getUserObject(unsigned int i) const;
151
152        /** Get number of user objects assigned to this object.*/
153        virtual unsigned int getNumUserObjects() const;
154
155        /** Get the index position of specified user data object.*/
156        virtual unsigned int getUserObjectIndex(const osg::Object* obj, unsigned int startPos=0) const;
157
158        /** Get the index position of first user data object that matches specified name.*/
159        virtual unsigned int getUserObjectIndex(const std::string& name, unsigned int startPos=0) const;
160
161
162
163
164        /** Set the list of string descriptions.*/
165        virtual void setDescriptions(const DescriptionList& descriptions);
166
167        /** Get the description list.*/
168        virtual DescriptionList& getDescriptions();
169
170        /** Get the const description list.*/
171        virtual const DescriptionList& getDescriptions() const;
172
173        /** Get number of description strings.*/
174        virtual unsigned int getNumDescriptions() const;
175
176        /** Add a description string.*/
177        virtual void addDescription(const std::string& desc);
178
179protected:
180
181        virtual ~DefaultUserDataContainer() {}
182
183        typedef std::vector< osg::ref_ptr<osg::Object> > ObjectList;
184
185        ref_ptr<Referenced>     _userData;
186        DescriptionList         _descriptionList;
187        ObjectList              _objectList;
188};
189
190}
191
192#endif
Note: See TracBrowser for help on using the browser.