Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core/src/orxonox/core/ClassTreeMask.h @ 807

Last change on this file since 807 was 807, checked in by landauf, 16 years ago
  • fixed a small bug in ClassTreeMask
  • added more operators to ClassTreeMask
  • added testing code for ClassTreeMask
File size: 4.4 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *
4 *
5 *   License notice:
6 *
7 *   This program is free software; you can redistribute it and/or
8 *   modify it under the terms of the GNU General Public License
9 *   as published by the Free Software Foundation; either version 2
10 *   of the License, or (at your option) any later version.
11 *
12 *   This program is distributed in the hope that it will be useful,
13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 *   GNU General Public License for more details.
16 *
17 *   You should have received a copy of the GNU General Public License
18 *   along with this program; if not, write to the Free Software
19 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 *
21 *   Author:
22 *      Fabian 'x3n' Landau
23 *   Co-authors:
24 *      ...
25 *
26 */
27
28#ifndef _ClassTreeMask_H__
29#define _ClassTreeMask_H__
30
31#include <list>
32#include <stack>
33
34#include "CorePrereqs.h"
35
36namespace orxonox
37{
38    class ClassTreeMaskNode
39    {
40        friend class ClassTreeMask;
41        friend class ClassTreeMaskIterator;
42
43        public:
44            ClassTreeMaskNode(const Identifier* subclass, bool bIncluded = true);
45            ~ClassTreeMaskNode();
46
47            void include();
48            void exclude();
49            void setIncluded(bool bIncluded);
50
51            void addSubnode(ClassTreeMaskNode* subnode);
52
53            bool isIncluded() const;
54            bool isExcluded() const;
55
56            const Identifier* getClass() const;
57
58        private:
59            const Identifier* subclass_;
60            bool bIncluded_;
61            std::list<ClassTreeMaskNode*> subnodes_;
62    };
63
64    class ClassTreeMaskIterator
65    {
66        public:
67            ClassTreeMaskIterator(ClassTreeMaskNode* node);
68            ~ClassTreeMaskIterator();
69
70            ClassTreeMaskIterator& operator++();
71            ClassTreeMaskNode* operator*() const;
72            ClassTreeMaskNode* operator->() const;
73            operator bool();
74            bool operator==(ClassTreeMaskNode* compare);
75            bool operator!=(ClassTreeMaskNode* compare);
76
77        private:
78            std::stack<std::pair<std::list<ClassTreeMaskNode*>::iterator, std::list<ClassTreeMaskNode*>::iterator> > nodes_;
79            std::list<ClassTreeMaskNode*> rootlist_;
80    };
81
82    class ClassTreeMask
83    {
84        public:
85            ClassTreeMask();
86            ClassTreeMask(const ClassTreeMask& other);
87            ~ClassTreeMask();
88
89            void include(const Identifier* subclass);
90            void exclude(const Identifier* subclass);
91            void add(const Identifier* subclass, bool bInclude);
92            void reset();
93            void clean();
94
95            bool isIncluded(const Identifier* subclass) const;
96            bool isExcluded(const Identifier* subclass) const;
97
98            ClassTreeMask& operator=(const ClassTreeMask& other);
99
100            ClassTreeMask& operator+();
101            ClassTreeMask operator-() const;
102
103            ClassTreeMask operator+(const ClassTreeMask& other) const;
104            ClassTreeMask operator*(const ClassTreeMask& other) const;
105            ClassTreeMask operator-(const ClassTreeMask& other) const;
106            ClassTreeMask operator!() const;
107
108            ClassTreeMask& operator+=(const ClassTreeMask& other);
109            ClassTreeMask& operator*=(const ClassTreeMask& other);
110            ClassTreeMask& operator-=(const ClassTreeMask& other);
111
112            ClassTreeMask operator&(const ClassTreeMask& other) const;
113            ClassTreeMask operator|(const ClassTreeMask& other) const;
114            ClassTreeMask operator^(const ClassTreeMask& other) const;
115            ClassTreeMask operator~() const;
116
117            ClassTreeMask& operator&=(const ClassTreeMask& other);
118            ClassTreeMask& operator|=(const ClassTreeMask& other);
119            ClassTreeMask& operator^=(const ClassTreeMask& other);
120
121            friend std::ostream& operator<<(std::ostream& out, const ClassTreeMask& mask);
122
123        private:
124            void add(ClassTreeMaskNode* node, const Identifier* subclass, bool bInclude);
125            bool isIncluded(ClassTreeMaskNode* node, const Identifier* subclass) const;
126            void clean(ClassTreeMaskNode* node);
127
128            ClassTreeMaskNode* root_;
129    };
130}
131
132#endif /* _ClassTreeMask_H__ */
Note: See TracBrowser for help on using the repository browser.