Orxonox  0.0.5 Codename: Arcturus
ClassTreeMask.h
Go to the documentation of this file.
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 
67 #ifndef _ClassTreeMask_H__
68 #define _ClassTreeMask_H__
69 
70 #include "CorePrereqs.h"
71 
72 #include <list>
73 #include <stack>
74 #include "BaseObject.h"
75 #include "object/Iterator.h"
76 #include "class/Identifier.h"
77 
78 namespace orxonox
79 {
80  // ###################################
81  // ### ClassTreeMaskNode ###
82  // ###################################
91  {
92  friend class ClassTreeMask;
93  friend class ClassTreeMaskIterator;
95 
96  public:
97  ClassTreeMaskNode(const Identifier* subclass, bool bIncluded = true);
99 
100  void include(bool overwrite = true);
101  void exclude(bool overwrite = true);
102  void setIncluded(bool bIncluded, bool overwrite = true);
103 
104  void addSubnode(ClassTreeMaskNode* subnode);
105 
107  inline bool isIncluded() const { return this->bIncluded_; }
109  inline bool isExcluded() const { return (!this->bIncluded_); }
110 
112  inline const Identifier* getClass() const { return this->subclass_; }
113 
115  inline bool hasSubnodes() const { return !this->subnodes_.empty(); }
116 
117  private:
118  void deleteAllSubnodes();
119 
121  bool bIncluded_;
122  std::list<ClassTreeMaskNode*> subnodes_;
123  };
124 
125 
126  // ###################################
127  // ### ClassTreeMaskIterator ###
128  // ###################################
146  {
147  public:
150 
151  const ClassTreeMaskIterator& operator++();
152  ClassTreeMaskNode* operator*() const;
153  ClassTreeMaskNode* operator->() const;
154  explicit operator bool() const;
155  bool operator==(ClassTreeMaskNode* compare) const;
156  bool operator!=(ClassTreeMaskNode* compare) const;
157 
158  private:
159  std::stack<std::pair<std::list<ClassTreeMaskNode*>::iterator, std::list<ClassTreeMaskNode*>::iterator>> nodes_;
160  std::list<ClassTreeMaskNode*> rootlist_;
161  };
162 
163 
164  // ###################################
165  // ### ClassTreeMask ###
166  // ###################################
188  {
190 
191  public:
192  ClassTreeMask();
193  ClassTreeMask(const ClassTreeMask& other);
194  ~ClassTreeMask();
195 
196  void include(const Identifier* subclass, bool overwrite = true, bool clean = true);
197  void exclude(const Identifier* subclass, bool overwrite = true, bool clean = true);
198  void add(const Identifier* subclass, bool bInclude, bool overwrite = true, bool clean = true);
199 
200  void includeSingle(const Identifier* subclass, bool clean = true);
201  void excludeSingle(const Identifier* subclass, bool clean = true);
202  void addSingle(const Identifier* subclass, bool bInclude, bool clean = true);
203 
204  void reset();
205  void clean();
206 
207  bool isIncluded(const Identifier* subclass) const;
208  bool isExcluded(const Identifier* subclass) const;
209 
211  inline const ClassTreeMask& begin() const { return (*this); }
213  inline BaseObject* end() const { return nullptr; }
214 
215  ClassTreeMask& operator=(const ClassTreeMask& other);
216 
217  bool operator==(const ClassTreeMask& other) const;
218  bool operator!=(const ClassTreeMask& other) const;
219 
220  const ClassTreeMask& operator+() const;
221  ClassTreeMask operator-() const;
222 
223  ClassTreeMask operator+(const ClassTreeMask& other) const;
224  ClassTreeMask operator*(const ClassTreeMask& other) const;
225  ClassTreeMask operator-(const ClassTreeMask& other) const;
226  ClassTreeMask operator!() const;
227 
228  const ClassTreeMask& operator+=(const ClassTreeMask& other);
229  const ClassTreeMask& operator*=(const ClassTreeMask& other);
230  const ClassTreeMask& operator-=(const ClassTreeMask& other);
231 
232  ClassTreeMask operator&(const ClassTreeMask& other) const;
233  ClassTreeMask operator|(const ClassTreeMask& other) const;
234  ClassTreeMask operator^(const ClassTreeMask& other) const;
235  ClassTreeMask operator~() const;
236 
237  const ClassTreeMask& operator&=(const ClassTreeMask& other);
238  const ClassTreeMask& operator|=(const ClassTreeMask& other);
239  const ClassTreeMask& operator^=(const ClassTreeMask& other);
240 
241  friend std::ostream& operator<<(std::ostream& out, const ClassTreeMask& mask);
242 
243  private:
244  void add(ClassTreeMaskNode* node, const Identifier* subclass, bool bInclude, bool overwrite = true);
245  bool isIncluded(ClassTreeMaskNode* node, const Identifier* subclass) const;
246  void clean(ClassTreeMaskNode* node);
247  bool nodeExists(const Identifier* subclass);
248 
250  };
251 
252 
253  // ###################################
254  // ### ClassTreeMaskObjectIterator ###
255  // ###################################
275  {
276  public:
278  inline ClassTreeMaskObjectIterator() = default;
280  inline ClassTreeMaskObjectIterator(const ClassTreeMask& mask) { (*this) = mask; }
281 
282  ClassTreeMaskObjectIterator& operator=(const ClassTreeMask& mask);
283 
284  const ClassTreeMaskObjectIterator& operator++();
285 
287  inline bool operator==(BaseObject* pointer) const { return (this->objectIterator_ && (*this->objectIterator_) == pointer) || (!this->objectIterator_ && pointer == nullptr); }
289  inline bool operator!=(BaseObject* pointer) const { return (this->objectIterator_ && (*this->objectIterator_) != pointer) || (!this->objectIterator_ && pointer != nullptr); }
291  inline explicit operator bool() const { return this->objectIterator_.operator bool(); }
293  inline BaseObject* operator*() const { return (*this->objectIterator_); }
295  inline BaseObject* operator->() const { return (*this->objectIterator_); }
296 
297  private:
298  void create(ClassTreeMaskNode* node);
299 
300  std::list<std::pair<const Identifier*, bool>> subclasses_;
301  std::list<std::pair<const Identifier*, bool>>::iterator subclassIterator_;
303  };
304 }
305 
306 #endif /* _ClassTreeMask_H__ */
constexpr bool operator!=(bool x, tribool y)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: tribool.h:128
The BaseObject is the parent of all classes representing an instance in the game. ...
Definition: BaseObject.h:63
std::list< ClassTreeMaskNode * > rootlist_
A list for internal use (it only stores the root-node)
Definition: ClassTreeMask.h:160
bool operator!=(BaseObject *pointer) const
Returns true if the ClassTreeMaskObjectIterator doesn&#39;t point at the given object.
Definition: ClassTreeMask.h:289
The ClassTreeMask is a set of rules, containing the information for each class whether it&#39;s included ...
Definition: ClassTreeMask.h:187
The Iterator allows to iterate through a given ObjectList.
Definition: CorePrereqs.h:192
InputManager::State operator|=(InputManager::State &lval, InputManager::State rval)
Defines the |= operator for easier use.
Definition: InputManager.cc:76
Shared library macros, enums, constants and forward declarations for the core library ...
bool operator==(BaseObject *pointer) const
Returns true if the ClassTreeMaskObjectIterator points at the given object.
Definition: ClassTreeMask.h:287
TiXmlString operator+(const TiXmlString &a, const TiXmlString &b)
Definition: tinystr.cpp:86
ClassTreeMaskNode * root_
The root-node of the internal rule-tree, usually BaseObject.
Definition: ClassTreeMask.h:249
bool isIncluded() const
Tells if the rule is "included" or not.
Definition: ClassTreeMask.h:107
Declaration of Identifier, definition of ClassIdentifier<T>; used to identify the class of an object...
Iterator< BaseObject > objectIterator_
The current object of the iterator.
Definition: ClassTreeMask.h:302
The DistanceTrigger is in exclude-mode.
BaseObject * operator*() const
Returns the object the ClassTreeMaskObjectIterator currently points at.
Definition: ClassTreeMask.h:293
std::stack< std::pair< std::list< ClassTreeMaskNode * >::iterator, std::list< ClassTreeMaskNode * >::iterator > > nodes_
A stack to store list-iterators.
Definition: ClassTreeMask.h:159
The ClassTreeMaskIterator moves through all ClassTreeMaskNodes of the internal tree of a ClassTreeMas...
Definition: ClassTreeMask.h:145
Die Wagnis Klasse hat die folgenden Aufgaben:
Definition: ApplicationPaths.cc:66
BaseObject * operator->() const
Returns the object the ClassTreeMaskObjectIterator currently points at.
Definition: ClassTreeMask.h:295
#define _CoreExport
Definition: CorePrereqs.h:61
std::ostream & operator<<(std::ostream &out, const std::set< const Identifier * > &list)
Lists the names of all Identifiers in a std::set<const Identifier*>.
Definition: Identifier.cc:466
The Identifier is used to identify the class of an object and to store information about the class...
Definition: Identifier.h:109
std::list< ClassTreeMaskNode * > subnodes_
A list containing all subnodes of this node.
Definition: ClassTreeMask.h:122
Declaration of BaseObject, the base class of all objects in Orxonox.
BaseObject * end() const
End of the ClassTreeMaskObjectIterator.
Definition: ClassTreeMask.h:213
bool bIncluded_
The rule: included or excluded.
Definition: ClassTreeMask.h:121
Definition of the Iterator class, used to iterate through object-lists.
const Identifier * getClass() const
Returns the Identifier of the class the rule refers to.
Definition: ClassTreeMask.h:112
bool isExcluded() const
Tells if the rule is "excluded" or not.
Definition: ClassTreeMask.h:109
std::list< std::pair< const Identifier *, bool > >::iterator subclassIterator_
The current class of the iterator.
Definition: ClassTreeMask.h:301
const ClassTreeMask & begin() const
Begin of the ClassTreeMaskObjectIterator.
Definition: ClassTreeMask.h:211
bool hasSubnodes() const
Returns true if the node has some subnodes.
Definition: ClassTreeMask.h:115
constexpr bool operator==(bool x, tribool y)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: tribool.h:117
The ClassTreeMaskObjectIterator iterates through all objects of the classes that were included by a C...
Definition: ClassTreeMask.h:274
const Identifier * subclass_
The Identifier of the subclass the rule refers to.
Definition: ClassTreeMask.h:120
The ClassTreeMaskNode is a node in the internal tree of the ClassTreeMask, containing the rules of th...
Definition: ClassTreeMask.h:90
ClassTreeMaskObjectIterator(const ClassTreeMask &mask)
Copy-Constructor: Initializes the iterator from another ClassTreeMask.
Definition: ClassTreeMask.h:280
std::list< std::pair< const Identifier *, bool > > subclasses_
A list of all Identifiers through which objects the iterator should iterate.
Definition: ClassTreeMask.h:300
InputManager::State operator&=(InputManager::State &lval, int rval)
Defines the &= operator for easier use.
Definition: InputManager.cc:82