root/OpenSceneGraph/trunk/src/osg/UserDataContainer.cpp @ 13041

Revision 13041, 4.8 kB (checked in by robert, 2 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#include <osg/UserDataContainer>
14
15namespace osg
16{
17
18///////////////////////////////////////////////////////////////////////////////////////////////////
19//
20// UserDataContainer
21//
22UserDataContainer::UserDataContainer():
23    Object(true)
24{
25}
26
27UserDataContainer::UserDataContainer(const UserDataContainer& udc, const osg::CopyOp& copyop):
28    Object(udc, copyop)
29{
30}
31
32Object* UserDataContainer::getUserObject(const std::string& name, unsigned int startPos)
33{
34     return getUserObject(getUserObjectIndex(name, startPos));
35}
36
37const Object* UserDataContainer::getUserObject(const std::string& name, unsigned int startPos) const
38{
39     return getUserObject(getUserObjectIndex(name, startPos));
40}
41
42//////////////////////////////////////////////////////////////////////////////////////////////////
43//
44// DefaultUserDataContainer
45//
46DefaultUserDataContainer::DefaultUserDataContainer()
47{
48}
49
50DefaultUserDataContainer::DefaultUserDataContainer(const DefaultUserDataContainer& udc, const osg::CopyOp& copyop):
51    UserDataContainer(udc, copyop)
52{
53    _userData = udc._userData;
54    _descriptionList = udc._descriptionList;
55    for(ObjectList::const_iterator itr = udc._objectList.begin();
56        itr != udc._objectList.end();
57        ++itr)
58    {
59        _objectList.push_back(copyop(itr->get()));
60    }
61}
62
63void DefaultUserDataContainer::setThreadSafeRefUnref(bool threadSafe)
64{
65    Object::setThreadSafeRefUnref(threadSafe);
66
67    if (_userData.valid()) _userData->setThreadSafeRefUnref(threadSafe);
68
69    for(ObjectList::iterator itr = _objectList.begin();
70        itr != _objectList.end();
71        ++itr)
72    {
73        (*itr)->setThreadSafeRefUnref(threadSafe);
74    }
75}
76
77void DefaultUserDataContainer::setUserData(Referenced* obj)
78{
79    _userData = obj;
80}
81
82Referenced* DefaultUserDataContainer::getUserData()
83{
84    return _userData.get();
85}
86
87const Referenced* DefaultUserDataContainer::getUserData() const
88{
89    return _userData.get();
90}
91
92unsigned int DefaultUserDataContainer::addUserObject(Object* obj)
93{
94    // make sure that the object isn't already in the container
95    unsigned int i = getUserObjectIndex(obj);
96    if (i<_objectList.size())
97    {
98        // object already in container so just return.
99        return i;
100    }
101
102    unsigned int pos = _objectList.size();
103
104    // object not already on user data container so add it in.
105    _objectList.push_back(obj);
106
107    return pos;
108}
109
110void DefaultUserDataContainer::removeUserObject(unsigned int i)
111{
112    if (i<_objectList.size())
113    {
114        _objectList.erase(_objectList.begin()+i);
115    }
116}
117
118void DefaultUserDataContainer::setUserObject(unsigned int i, Object* obj)
119{
120    if (i<_objectList.size())
121    {
122        _objectList[i] = obj;
123    }
124}
125
126Object* DefaultUserDataContainer::getUserObject(unsigned int i)
127{
128    if (i<_objectList.size())
129    {
130        return _objectList[i].get();
131    }
132    return 0;
133}
134
135const Object* DefaultUserDataContainer::getUserObject(unsigned int i) const
136{
137    if (i<_objectList.size())
138    {
139        return _objectList[i].get();
140    }
141    return 0;
142}
143
144unsigned int DefaultUserDataContainer::getNumUserObjects() const
145{
146    return _objectList.size();
147}
148
149unsigned int DefaultUserDataContainer::getUserObjectIndex(const osg::Object* obj, unsigned int startPos) const
150{
151    for(unsigned int i = startPos; i < _objectList.size(); ++i)
152    {
153        if (_objectList[i]==obj) return i;
154    }
155    return _objectList.size();
156}
157
158unsigned int DefaultUserDataContainer::getUserObjectIndex(const std::string& name, unsigned int startPos) const
159{
160    for(unsigned int i = startPos; i < _objectList.size(); ++i)
161    {
162        Object* obj = _objectList[i].get();
163        if (obj && obj->getName()==name) return i;
164    }
165    return _objectList.size();
166}
167
168void DefaultUserDataContainer::setDescriptions(const DescriptionList& descriptions)
169{
170    _descriptionList = descriptions;
171}
172
173UserDataContainer::DescriptionList& DefaultUserDataContainer::getDescriptions()
174{
175    return _descriptionList;
176}
177
178const UserDataContainer::DescriptionList& DefaultUserDataContainer::getDescriptions() const
179{
180    return _descriptionList;
181}
182
183unsigned int DefaultUserDataContainer::getNumDescriptions() const
184{
185    return _descriptionList.size();
186}
187
188void DefaultUserDataContainer::addDescription(const std::string& desc)
189{
190    _descriptionList.push_back(desc);
191}
192
193} // end of namespace osg
Note: See TracBrowser for help on using the browser.