1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2008 Robert Osfield
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.
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.
14// Code by: Jeremy Moles (cubicool) 2007-2008
16#ifndef OSGWIDGET_UI_OBJECT_PARENT
17#define OSGWIDGET_UI_OBJECT_PARENT
20#include <osg/observer_ptr>
29 typedef T object_type;
30 typedef osg::observer_ptr<object_type> ptr_type;
31 typedef std::vector<ptr_type> Vector;
32 typedef typename Vector::iterator Iterator;
33 typedef typename Vector::const_iterator ConstIterator;
36 return _objects.begin();
39 ConstIterator begin() const {
40 return _objects.begin();
44 return _objects.end();
47 ConstIterator end() const {
48 return _objects.end();
51 typename Vector::size_type size() const {
52 return _objects.size();
55 object_type* getByName(const std::string& name) {
56 return _getByName(name);
59 const object_type* getByName(const std::string& name) const {
60 return _getByName(name);
63 object_type* getByIndex(unsigned int index) {
64 return _getByIndex(index);
67 const object_type* getByIndex(unsigned int index) const {
68 return _getByIndex(index);
71 unsigned int getNumObjects() const {
72 return _objects.size();
75 Vector& getObjects() {
79 const Vector& getObjects() const {
85 bool _remove(object_type* obj) {
86 Iterator i = std::find(begin(), end(), obj);
88 if(i == end()) return false;
95 bool _removeByName(const std::string& name) {
96 for(Iterator i = begin(); i != end(); i++) if(i->get()->getName() == name) {
109 // I had to add this to avoid ambiguity errors with MSVC. Garbage.
110 object_type* _getByName(const std::string& name) const {
111 for(ConstIterator i = begin(); i != end(); i++) {
112 if(i->valid() && i->get()->getName() == name) return i->get();
118 object_type* _getByIndex(unsigned int index) const {
119 for(ConstIterator i = begin(); i != end(); i++) {
120 if(i->valid() && i->get()->getIndex() == index) return i->get();