[1505] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * > www.orxonox.net < |
---|
| 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
| 23 | * Fabian 'x3n' Landau |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | /** |
---|
[7401] | 30 | @defgroup ObjectList Object-lists and iterators |
---|
| 31 | @ingroup Object |
---|
| 32 | */ |
---|
| 33 | |
---|
| 34 | /** |
---|
[2171] | 35 | @file |
---|
[7401] | 36 | @ingroup Object ObjectList |
---|
| 37 | @brief Definition of the ObjectList class, a wrapper of ObjectListBase. |
---|
[1505] | 38 | |
---|
[7401] | 39 | @ref orxonox::ObjectList "ObjectList<T>" is a wrapper of an @ref orxonox::ObjectListBase |
---|
| 40 | "ObjectListBase" of class @a T. Use @ref orxonox::ObjectListIterator "ObjectListIterator<T>" |
---|
| 41 | to iterate through the list. |
---|
[1505] | 42 | */ |
---|
| 43 | |
---|
| 44 | #ifndef _ObjectList_H__ |
---|
| 45 | #define _ObjectList_H__ |
---|
| 46 | |
---|
[9557] | 47 | #include "core/CorePrereqs.h" |
---|
[1505] | 48 | |
---|
[10466] | 49 | #include <boost/static_assert.hpp> |
---|
| 50 | #include <boost/type_traits/is_base_of.hpp> |
---|
| 51 | |
---|
[7278] | 52 | #include "ObjectListBase.h" |
---|
[1747] | 53 | #include "ObjectListIterator.h" |
---|
[9667] | 54 | #include "Context.h" |
---|
[1505] | 55 | |
---|
| 56 | namespace orxonox |
---|
| 57 | { |
---|
| 58 | // ############################### |
---|
| 59 | // ### ObjectList ### |
---|
| 60 | // ############################### |
---|
| 61 | /** |
---|
[7401] | 62 | @brief The ObjectList contains all objects of the given class. |
---|
| 63 | |
---|
| 64 | Wraps the ObjectListBase which contains all objects of type @a T. Use @ref ObjectListIterator |
---|
| 65 | "ObjectListIterator<T>" or its typedef ObjectList<T>::iterator to iterate through all objects |
---|
| 66 | in the list. |
---|
[1505] | 67 | */ |
---|
| 68 | template <class T> |
---|
| 69 | class ObjectList |
---|
| 70 | { |
---|
[10467] | 71 | BOOST_STATIC_ASSERT((boost::is_base_of<Listable, T>::value)); |
---|
[10466] | 72 | |
---|
[1505] | 73 | public: |
---|
[1747] | 74 | typedef ObjectListIterator<T> iterator; |
---|
[1505] | 75 | |
---|
[10567] | 76 | /// Returns the size of the list (for the root context) |
---|
| 77 | inline static size_t size() |
---|
| 78 | { return size(Context::getRootContext()); } |
---|
[9667] | 79 | /// Returns the size of the list |
---|
[10567] | 80 | inline static size_t size(Context* context) |
---|
[9667] | 81 | { |
---|
[10567] | 82 | return context->getObjectList<T>()->size(); |
---|
[9667] | 83 | } |
---|
| 84 | |
---|
[10567] | 85 | /// Returns an Iterator to the first element in the list (for the root context). |
---|
| 86 | inline static ObjectListElement<T>* begin() |
---|
| 87 | { return begin(Context::getRootContext()); } |
---|
[7401] | 88 | /// Returns an Iterator to the first element in the list. |
---|
[10567] | 89 | inline static ObjectListElement<T>* begin(Context* context) |
---|
[7271] | 90 | { |
---|
[10567] | 91 | ObjectListBase* list = context->getObjectList<T>(); |
---|
[9667] | 92 | return static_cast<ObjectListElement<T>*>(list->begin()); |
---|
[7271] | 93 | } |
---|
[1505] | 94 | |
---|
[10567] | 95 | /// Returns an Iterator to the element after the last element in the list (for the root context). |
---|
| 96 | inline static ObjectListElement<T>* end() |
---|
| 97 | { return end(Context::getRootContext()); } |
---|
[7401] | 98 | /// Returns an Iterator to the element after the last element in the list. |
---|
[10567] | 99 | inline static ObjectListElement<T>* end(Context* context) |
---|
[7271] | 100 | { |
---|
[10567] | 101 | ObjectListBase* list = context->getObjectList<T>(); |
---|
[9667] | 102 | return static_cast<ObjectListElement<T>*>(list->end()); |
---|
[7271] | 103 | } |
---|
[1505] | 104 | |
---|
[10567] | 105 | /// Returns an Iterator to the last element in the list (for the root context). |
---|
| 106 | inline static ObjectListElement<T>* rbegin() |
---|
| 107 | { return rbegin(Context::getRootContext()); } |
---|
[7401] | 108 | /// Returns an Iterator to the last element in the list. |
---|
[10567] | 109 | inline static ObjectListElement<T>* rbegin(Context* context) |
---|
[7271] | 110 | { |
---|
[10567] | 111 | ObjectListBase* list = context->getObjectList<T>(); |
---|
[9667] | 112 | return static_cast<ObjectListElement<T>*>(list->rbegin()); |
---|
[7271] | 113 | } |
---|
[1505] | 114 | |
---|
[10567] | 115 | /// Returns an Iterator to the element before the first element in the list (for the root context). |
---|
| 116 | inline static ObjectListElement<T>* rend() |
---|
| 117 | { return rend(Context::getRootContext()); } |
---|
[7401] | 118 | /// Returns an Iterator to the element before the first element in the list. |
---|
[10567] | 119 | inline static ObjectListElement<T>* rend(Context* context) |
---|
[7271] | 120 | { |
---|
[10567] | 121 | ObjectListBase* list = context->getObjectList<T>(); |
---|
[9667] | 122 | return static_cast<ObjectListElement<T>*>(list->rend()); |
---|
[7271] | 123 | } |
---|
[1505] | 124 | }; |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | #endif /* _ObjectList_H__ */ |
---|