#pragma region CPL License /* Nuclex Native Framework Copyright (C) 2002-2013 Nuclex Development Labs This library is free software; you can redistribute it and/or modify it under the terms of the IBM Common Public License as published by the IBM Corporation; either version 1.0 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the IBM Common Public License for more details. You should have received a copy of the IBM Common Public License along with this library */ #pragma endregion // CPL License #ifndef NUCLEX_SCENE_GRAPH_CHILDENTITYSET_H #define NUCLEX_SCENE_GRAPH_CHILDENTITYSET_H #include "Nuclex/Scene/Config.h" #include #include #include namespace Nuclex { namespace Scene { namespace Graph { // ------------------------------------------------------------------------------------------- // class Entity; // ------------------------------------------------------------------------------------------- // /// Stores an entities children class ChildEntitySet { #pragma region class Iterator /// Iterates over the entities in the set public: class Iterator { /// Initializes a new entity iterator /// Child entity set that will be enumerated /// Index the iterator will be placed at public: NUCLEX_SCENE_API Iterator( const ChildEntitySet &childEntitySet, std::size_t index = 0 ) : childEntitySet(&childEntitySet), index(index) {} /// Initializes an iterator as copy of another iterator /// Other iterator that will be copied public: NUCLEX_SCENE_API Iterator(const Iterator &other) : childEntitySet(other.childEntitySet), index(other.index) {} /// Tests whether another iterator is at a different position /// Other iterator that will be compared /// True if the other iterator is at a different position public: NUCLEX_SCENE_API bool operator !=(const Iterator &other) { using namespace std; assert( (this->childEntitySet == other.childEntitySet) && "Compared iterators must belong to the same component set" ); return this->index != other.index; } /// Advances the iterator to the next position /// The iterator itself after incrementing public: NUCLEX_SCENE_API Iterator &operator ++() { ++this->index; return *this; } /// Accesses the element at the iterator's current position /// The entity at the enumerator's current position public: NUCLEX_SCENE_API const std::shared_ptr &operator *() { using namespace std; assert( (this->index < this->childEntitySet->entities.size()) && "Iterator must be on a valid position to be dereferenced" ); return this->childEntitySet->entities[this->index]; } /// Accesses the element at the iterator's current position /// The type of the component at the enumerator's current position public: NUCLEX_SCENE_API Iterator &operator =(const Iterator &other) { this->childEntitySet = other.childEntitySet; this->index = other.index; return *this; } /// Component set whose types the iterator is iterating over private: const ChildEntitySet *childEntitySet; /// Current position of the enumerator private: std::size_t index; }; #pragma endregion // class Iterator /// Initializes a new child entity set /// Parent that will be assigned to all children public: NUCLEX_SCENE_API ChildEntitySet(Entity &parent) : parent(parent) {} /// Adds the specified child to the set /// Child that will be added to the set public: NUCLEX_SCENE_API void Add(const std::shared_ptr &child); /// Removes the specified child from the set /// Child that will be removed from the set /// True if the child was found and has been removed, otherwise false public: NUCLEX_SCENE_API bool Remove(const std::shared_ptr &child); /// Returns the number of child entities in the set public: NUCLEX_SCENE_API std::size_t Count() const { return this->entities.size(); } /// An iterator pointing to the first entry in the entity list public: NUCLEX_SCENE_API Iterator begin() { return Iterator(*this); } /// An iterator pointing one past the end of the entity list public: NUCLEX_SCENE_API Iterator end() { return Iterator(*this, this->entities.size()); } private: ChildEntitySet(const ChildEntitySet &); private: ChildEntitySet &operator =(const ChildEntitySet &); /// List holding child entities private: typedef std::vector> EntityList; /// Parent the children will have assigned private: Entity &parent; /// Stores the child entities private: EntityList entities; }; // ------------------------------------------------------------------------------------------- // }}} // namespace Nuclex::Scene::Graph #endif // NUCLEX_SCENE_GRAPH_CHILDENTITYSET_H