From 18d08e706faab7ae6b7086cc4454d90295f67bab Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 10 Jun 2011 11:42:02 +0000 Subject: [PATCH] Added handling of s/gUserValue() directly on a UserDataContainer. --- include/osg/ValueObject | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/include/osg/ValueObject b/include/osg/ValueObject index 0b2221623..3edbefa8f 100644 --- a/include/osg/ValueObject +++ b/include/osg/ValueObject @@ -167,12 +167,16 @@ META_ValueObject(Plane, PlaneValueObject) META_ValueObject(Matrixf, MatrixfValueObject) META_ValueObject(Matrixd, MatrixdValueObject) -/** provide implementation og osg::Object::getUserValue(..) template*/ +/** provide implementation of osg::Object::getUserValue(..) template*/ template bool osg::Object::getUserValue(const std::string& name, T& value) const { typedef TemplateValueObject UserValueObject; - const UserValueObject* uvo = _userDataContainer ? dynamic_cast(_userDataContainer->getUserObject(name)) : 0; + + const osg::UserDataContainer* udc = dynamic_cast(this); + if (!udc) udc = _userDataContainer; + + const UserValueObject* uvo = udc ? dynamic_cast(udc->getUserObject(name)) : 0; if (uvo) { value = uvo->getValue(); @@ -184,17 +188,22 @@ bool osg::Object::getUserValue(const std::string& name, T& value) const } } -/** provide implementation og osg::Object::setUserValue(..) template.*/ +/** provide implementation of osg::Object::setUserValue(..) template.*/ template void osg::Object::setUserValue(const std::string& name, const T& value) { typedef TemplateValueObject UserValueObject; - getOrCreateUserDataContainer(); + osg::UserDataContainer* udc = dynamic_cast(this); + if (!udc) + { + getOrCreateUserDataContainer(); + udc = _userDataContainer; + } - unsigned int i = _userDataContainer->getUserObjectIndex(name); - if (i<_userDataContainer->getNumUserObjects()) _userDataContainer->setUserObject(i, new UserValueObject(name,value)); - else _userDataContainer->addUserObject(new UserValueObject(name,value)); + unsigned int i = udc->getUserObjectIndex(name); + if (igetNumUserObjects()) udc->setUserObject(i, new UserValueObject(name,value)); + else udc->addUserObject(new UserValueObject(name,value)); } }