~nordfriese/freerct/debian-building

« back to all changes in this revision

Viewing changes to src/enum_type.h

  • Committer: Benedikt Straub
  • Date: 2021-07-01 16:54:22 UTC
  • Revision ID: benedikt_straub-20210701165422-kwxa3y9ga23kirrr
Initial commit (da71e14)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is part of FreeRCT.
 
3
 * FreeRCT is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
 
4
 * FreeRCT is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
5
 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with FreeRCT. If not, see <http://www.gnu.org/licenses/>.
 
6
 */
 
7
 
 
8
/** @file enum_type.h Some enum templates. */
 
9
 
 
10
#ifndef ENUM_TYPE_H
 
11
#define ENUM_TYPE_H
 
12
 
 
13
/* Copied from OpenTTD. */
 
14
 
 
15
/**
 
16
 * Operators to allow to work with enum as with type safe bit set in C++.
 
17
 * @tparam mask_t Enum type.
 
18
 */
 
19
#define DECLARE_ENUM_AS_BIT_SET(mask_t) \
 
20
        inline mask_t  operator |  (mask_t  m1, mask_t m2) { return (mask_t)((int)m1 | m2); } \
 
21
        inline mask_t  operator &  (mask_t  m1, mask_t m2) { return (mask_t)((int)m1 & m2); } \
 
22
        inline mask_t  operator ^  (mask_t  m1, mask_t m2) { return (mask_t)((int)m1 ^ m2); } \
 
23
        inline mask_t &operator |= (mask_t &m1, mask_t m2) { m1 = m1 | m2; return m1; } \
 
24
        inline mask_t &operator &= (mask_t &m1, mask_t m2) { m1 = m1 & m2; return m1; } \
 
25
        inline mask_t &operator ^= (mask_t &m1, mask_t m2) { m1 = m1 ^ m2; return m1; } \
 
26
        inline mask_t  operator ~  (mask_t  m) { return (mask_t)(~(int)m); }
 
27
 
 
28
/** Add post-increment and post-decrement operators to an enum. */
 
29
#define DECLARE_POSTFIX_INCREMENT(type) \
 
30
        inline type operator ++(type& e, int) \
 
31
        { \
 
32
                type e_org = e; \
 
33
                e = (type)((int)e + 1); \
 
34
                return e_org; \
 
35
        } \
 
36
        inline type operator --(type& e, int) \
 
37
        { \
 
38
                type e_org = e; \
 
39
                e = (type)((int)e - 1); \
 
40
                return e_org; \
 
41
        }
 
42
 
 
43
#endif