Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentation/src/libraries/util/OrxEnum.h @ 9215

Last change on this file since 9215 was 7401, checked in by landauf, 14 years ago

merged doc branch back to trunk

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