[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 | |
---|
[7278] | 49 | #include "ObjectListBase.h" |
---|
[1747] | 50 | #include "ObjectListIterator.h" |
---|
[9667] | 51 | #include "Context.h" |
---|
[1505] | 52 | |
---|
| 53 | namespace orxonox |
---|
| 54 | { |
---|
| 55 | // ############################### |
---|
| 56 | // ### ObjectList ### |
---|
| 57 | // ############################### |
---|
| 58 | /** |
---|
[7401] | 59 | @brief The ObjectList contains all objects of the given class. |
---|
| 60 | |
---|
| 61 | Wraps the ObjectListBase which contains all objects of type @a T. Use @ref ObjectListIterator |
---|
| 62 | "ObjectListIterator<T>" or its typedef ObjectList<T>::iterator to iterate through all objects |
---|
| 63 | in the list. |
---|
[1505] | 64 | */ |
---|
| 65 | template <class T> |
---|
| 66 | class ObjectList |
---|
| 67 | { |
---|
[11071] | 68 | static_assert(std::is_base_of<Listable, T>::value, "ObjectList can only be used with Listables"); |
---|
[10624] | 69 | |
---|
[1505] | 70 | public: |
---|
[1747] | 71 | typedef ObjectListIterator<T> iterator; |
---|
[1505] | 72 | |
---|
[11071] | 73 | ObjectList() : ObjectList(Context::getRootContext()) {} |
---|
| 74 | ObjectList(Context* context) : ObjectList(context->getObjectList<T>()) {} |
---|
| 75 | ObjectList(ObjectListBase* list) : list_(list) {} |
---|
| 76 | |
---|
[9667] | 77 | /// Returns the size of the list |
---|
[11071] | 78 | inline size_t size() |
---|
| 79 | { return this->list_->size(); } |
---|
[9667] | 80 | |
---|
[7401] | 81 | /// Returns an Iterator to the first element in the list. |
---|
[11071] | 82 | inline ObjectListIterator<T> begin() |
---|
| 83 | { return static_cast<ObjectListElement<T>*>(this->list_->begin()); } |
---|
[7401] | 84 | /// Returns an Iterator to the element after the last element in the list. |
---|
[11071] | 85 | inline ObjectListIterator<T> end() |
---|
| 86 | { return static_cast<ObjectListElement<T>*>(this->list_->end()); } |
---|
[1505] | 87 | |
---|
[7401] | 88 | /// Returns an Iterator to the last element in the list. |
---|
[11071] | 89 | inline ObjectListIterator<T> rbegin() |
---|
| 90 | { return static_cast<ObjectListElement<T>*>(this->list_->rbegin()); } |
---|
| 91 | /// Returns an Iterator to the element before the first element in the list. |
---|
| 92 | inline ObjectListIterator<T> rend() |
---|
| 93 | { return static_cast<ObjectListElement<T>*>(this->list_->rend()); } |
---|
[1505] | 94 | |
---|
[11071] | 95 | private: |
---|
| 96 | ObjectListBase* list_; |
---|
[1505] | 97 | }; |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | #endif /* _ObjectList_H__ */ |
---|