Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/doc/src/libraries/util/OrxEnum.h @ 7367

Last change on this file since 7367 was 7367, checked in by rgrieder, 14 years ago

Added Doxygen documentation for ExprParser, MathConvert, OrxEnum, OrxAssert and TriBool.
Adjusted Doxygen documentation for Clock and Exception.

  • Property svn:eol-style set to native
File size: 2.6 KB
Line 
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 *      Reto Grieder
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#ifndef _OrxEnum_H__
30#define _OrxEnum_H__
31
32#include "UtilPrereqs.h"
33
34namespace orxonox
35{
36    /** Lightweight enumeration class that can be extended at run time.
37    @details
38        The class accepts type int and also defines operator int(). Therefore
39        int and OrxEnum can be used interchangeably so you can extend the content
40        of the enumeration at run time by adding ints.
41    @par Declaring an OrxEnum
42        Write a struct that inherits OrxEnum and use some macros:
43        @code
44        struct MyEnum : OrxEnum<MyEnum>
45        {
46            OrxEnumConstructors(MyEnum);
47
48            static const int Value1 = -1;
49            static const int Value2 = 0;
50            static const int Value3 = Value2 + 10;
51        };
52        @endcode
53    */
54    template <class T>
55    struct OrxEnum
56    {
57        public:
58            OrxEnum() { }
59            OrxEnum(int type)            { type_ = type; }
60            OrxEnum(const T& instance)   { type_ = instance.type_; }
61
62            operator int()               { return type_; }
63            T& operator =(int type)      { type_ = type; return *this; }
64            bool operator <(const T& right) const { return (type_ < right.type_); }
65            bool operator >(const T& right) const { return (type_ > right.type_); }
66
67        private:
68            OrxEnum(const OrxEnum& instance);
69            int type_;
70    };
71}
72
73/// See orxonox::OrxEnum for more info
74#define OrxEnumConstructors(enumName)                        \
75enumName() { }                                               \
76enumName(int type) : OrxEnum<enumName>(type)             { } \
77enumName(const enumName& inst) : OrxEnum<enumName>(inst) { } \
78void dummyFunction()
79
80#endif /* _OrxEnum_H__ */
Note: See TracBrowser for help on using the repository browser.