~ubuntu-branches/debian/squeeze/openttd/squeeze

« back to all changes in this revision

Viewing changes to src/core/enum_type.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Jordi Mallach, Matthijs Kooijman, Jordi Mallach
  • Date: 2009-04-15 18:22:10 UTC
  • mfrom: (1.1.6 upstream) (2.1.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090415182210-22ktb8kdbp2tf3bm
[ Matthijs Kooijman ]
* New upstream release.
* Remove Debian specific desktop file, upstream provides one now. 
* Add debian/watch file.

[ Jordi Mallach ]
* Bump Standards-Version to 3.8.1, with no changes required.
* Move to debhelper compat 7. Bump Build-Depends accordingly.
* Use dh_prep.
* Add "set -e" to config script.
* Remove a few extra doc files that get installed by upstream Makefile.
* Add more complete copyright information.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: enum_type.hpp 11661 2007-12-18 19:52:14Z rubidium $ */
 
1
/* $Id: enum_type.hpp 15711 2009-03-14 18:16:29Z rubidium $ */
2
2
 
3
3
/** @file enum_type.hpp Type (helpers) for enums */
4
4
 
64
64
 
65
65
 
66
66
/** In some cases we use byte or uint16 to store values that are defined as enum. It is
67
 
        *  necessary in order to control the sizeof() such values. Some compilers make enum
68
 
        *  the same size as int (4 or 8 bytes instead of 1 or 2). As a consequence the strict
69
 
        *  compiler type-checking causes errors like:
70
 
        *     'HasPowerOnRail' : cannot convert parameter 1 from 'byte' to 'RailType' when
71
 
        *  u->u.rail.railtype is passed as argument or type RailType. In such cases it is better
72
 
        *  to teach the compiler that u->u.rail.railtype is to be treated as RailType. */
 
67
 *  necessary in order to control the sizeof() such values. Some compilers make enum
 
68
 *  the same size as int (4 or 8 bytes instead of 1 or 2). As a consequence the strict
 
69
 *  compiler type - checking causes errors like:
 
70
 *     'HasPowerOnRail' : cannot convert parameter 1 from 'byte' to 'RailType' when
 
71
 *  u->u.rail.railtype is passed as argument or type RailType. In such cases it is better
 
72
 *  to teach the compiler that u->u.rail.railtype is to be treated as RailType. */
73
73
template <typename Tenum_t> struct TinyEnumT;
74
74
 
75
75
/** The general declaration of TinyEnumT<> (above) */
76
 
template <typename Tenum_t> struct TinyEnumT
77
 
{
 
76
template <typename Tenum_t>
 
77
struct TinyEnumT {
78
78
        typedef Tenum_t enum_type;                      ///< expose our enumeration type (i.e. Trackdir) to outside
79
79
        typedef EnumPropsT<Tenum_t> Props;              ///< make easier access to our enumeration propeties
80
80
        typedef typename Props::storage storage_type;   ///< small storage type
93
93
        /** Assignment operator (from Tenum_t type) */
94
94
        FORCEINLINE TinyEnumT& operator = (enum_type e)
95
95
        {
96
 
                m_val = (storage_type)e; return *this;
 
96
                m_val = (storage_type)e;
 
97
                return *this;
 
98
        }
 
99
 
 
100
        /** Assignment operator (from Tenum_t type) */
 
101
        FORCEINLINE TinyEnumT& operator = (uint u)
 
102
        {
 
103
                m_val = (storage_type)u;
 
104
                return *this;
97
105
        }
98
106
 
99
107
        /** postfix ++ operator on tiny type */
112
120
        }
113
121
};
114
122
 
115
 
#endif /* HELPERS_HPP */
 
123
 
 
124
/** Template of struct holding enum types (on most archs, enums are stored in an int32). No math operators are provided. */
 
125
template <typename enum_type, typename storage_type>
 
126
struct SimpleTinyEnumT {
 
127
        storage_type m_val;  ///< here we hold the actual value in small (i.e. byte) form
 
128
 
 
129
        /** Cast operator - invoked then the value is assigned to the storage_type */
 
130
        FORCEINLINE operator enum_type () const
 
131
        {
 
132
                return (enum_type)this->m_val;
 
133
        }
 
134
 
 
135
        /** Assignment operator (from enum_type) */
 
136
        FORCEINLINE SimpleTinyEnumT &operator = (enum_type e)
 
137
        {
 
138
                this->m_val = (storage_type)e;
 
139
                return *this;
 
140
        }
 
141
 
 
142
        /** Assignment operator (from general uint) */
 
143
        FORCEINLINE SimpleTinyEnumT &operator = (uint u)
 
144
        {
 
145
                this->m_val = (storage_type)u;
 
146
                return *this;
 
147
        }
 
148
};
 
149
 
 
150
#endif /* ENUM_TYPE_HPP */