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

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

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
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/Object>
14#include <osg/UserDataContainer>
15
16namespace osg
17{
18
19///////////////////////////////////////////////////////////////////////////////////////////////////
20//
21// Object
22//
23Object::Object(const Object& obj,const CopyOp& copyop):
24    Referenced(),
25    _name(obj._name),
26    _dataVariance(obj._dataVariance),
27    _userDataContainer(0)
28{
29    if (obj._userDataContainer)
30    {
31        if (copyop.getCopyFlags()&osg::CopyOp::DEEP_COPY_USERDATA)
32        {
33            setUserDataContainer(osg::clone(obj._userDataContainer,copyop));
34        }
35        else
36        {
37            setUserDataContainer(obj._userDataContainer);
38        }
39    }
40}
41
42Object::~Object()
43{
44    if (_userDataContainer) _userDataContainer->unref();
45}
46
47
48void Object::setThreadSafeRefUnref(bool threadSafe)
49{
50    Referenced::setThreadSafeRefUnref(threadSafe);
51    if (_userDataContainer) _userDataContainer->setThreadSafeRefUnref(threadSafe);
52}
53
54void Object::setUserDataContainer(osg::UserDataContainer* udc)
55{
56    if (_userDataContainer == udc) return;
57
58    if (_userDataContainer) _userDataContainer->unref();
59
60    _userDataContainer = udc;
61
62    if (_userDataContainer) _userDataContainer->ref();
63}
64
65osg::UserDataContainer* Object::getOrCreateUserDataContainer()
66{
67    if (!_userDataContainer) setUserDataContainer(new DefaultUserDataContainer());
68    return _userDataContainer;
69}
70
71void Object::setUserData(Referenced* obj)
72{
73    if (getUserData()==obj) return;
74
75    getOrCreateUserDataContainer()->setUserData(obj);
76}
77
78Referenced* Object::getUserData()
79{
80    return _userDataContainer ? _userDataContainer->getUserData() : 0;
81}
82
83const Referenced* Object::getUserData() const
84{
85    return _userDataContainer ? _userDataContainer->getUserData() : 0;
86}
87
88} // end of namespace osg
Note: See TracBrowser for help on using the browser.