OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UserDataContainer.h
Go to the documentation of this file.
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 
22 namespace osg {
23 
26 {
27  public:
30 
31  virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const UserDataContainer*>(obj)!=0; }
32 
36  virtual const char* libraryName() const { return "osg"; }
37 
40  virtual const char* className() const { return "UserDataContainer"; }
41 
48  virtual void setUserData(Referenced* obj) = 0;
49 
51  virtual Referenced* getUserData() = 0;
52 
54  virtual const Referenced* getUserData() const = 0;
55 
57  virtual unsigned int addUserObject(Object* obj) = 0;
58 
60  virtual void setUserObject(unsigned int i, Object* obj) = 0;
61 
63  virtual void removeUserObject(unsigned int i) = 0;
64 
65 
67  virtual Object* getUserObject(unsigned int i) = 0;
68 
70  virtual const Object* getUserObject(unsigned int i) const = 0;
71 
73  virtual unsigned int getNumUserObjects() const = 0;
74 
76  virtual unsigned int getUserObjectIndex(const osg::Object* obj, unsigned int startPos=0) const = 0;
77 
79  virtual unsigned int getUserObjectIndex(const std::string& name, unsigned int startPos=0) const = 0;
80 
81 
83  virtual Object* getUserObject(const std::string& name, unsigned int startPos=0);
84 
86  virtual const Object* getUserObject(const std::string& name, unsigned int startPos=0) const;
87 
88 
89  typedef std::vector<std::string> DescriptionList;
90 
92  virtual void setDescriptions(const DescriptionList& descriptions) = 0;
93 
95  virtual DescriptionList& getDescriptions() = 0;
96 
98  virtual const DescriptionList& getDescriptions() const = 0;
99 
101  virtual unsigned int getNumDescriptions() const = 0;
102 
104  virtual void addDescription(const std::string& desc) = 0;
105 
106  protected:
107  virtual ~UserDataContainer() {}
108 };
109 
112 {
113  public:
116 
118 
119 
120  virtual void setThreadSafeRefUnref(bool threadSafe);
121 
128  virtual void setUserData(Referenced* obj);
129 
131  virtual Referenced* getUserData();
132 
134  virtual const Referenced* getUserData() const;
135 
137  virtual unsigned int addUserObject(Object* obj);
138 
140  virtual void setUserObject(unsigned int i, Object* obj);
141 
143  virtual void removeUserObject(unsigned int i);
144 
145 
147  virtual Object* getUserObject(unsigned int i);
148 
150  virtual const Object* getUserObject(unsigned int i) const;
151 
153  virtual unsigned int getNumUserObjects() const;
154 
156  virtual unsigned int getUserObjectIndex(const osg::Object* obj, unsigned int startPos=0) const;
157 
159  virtual unsigned int getUserObjectIndex(const std::string& name, unsigned int startPos=0) const;
160 
161 
162 
163 
165  virtual void setDescriptions(const DescriptionList& descriptions);
166 
168  virtual DescriptionList& getDescriptions();
169 
171  virtual const DescriptionList& getDescriptions() const;
172 
174  virtual unsigned int getNumDescriptions() const;
175 
177  virtual void addDescription(const std::string& desc);
178 
179 protected:
180 
182 
183  typedef std::vector< osg::ref_ptr<osg::Object> > ObjectList;
184 
186  DescriptionList _descriptionList;
187  ObjectList _objectList;
188 };
189 
190 
192 inline Object* getUserObject(osg::Object* object, const std::string& name)
193 {
195  return udc ? udc->getUserObject(name) : 0;
196 }
197 
199 inline const Object* getUserObject(const osg::Object* object, const std::string& name)
200 {
201  const osg::UserDataContainer* udc = object->getUserDataContainer();
202  return udc ? udc->getUserObject(name) : 0;
203 }
204 
205 
206 }
207 
208 #endif
#define OSG_EXPORT
Definition: Export.h:43
std::vector< osg::ref_ptr< osg::Object > > ObjectList
std::vector< std::string > DescriptionList
Object * getUserObject(osg::Object *object, const std::string &name)
ref_ptr< Referenced > _userData
virtual Object * getUserObject(unsigned int i)=0
#define META_Object(library, name)
Definition: Object.h:42
virtual bool isSameKindAs(const Object *obj) const
virtual const char * libraryName() const
virtual const char * className() const
osg::UserDataContainer * getUserDataContainer()
Definition: Object.h:172
Definition: AlphaFunc.h:19