Decoded: OpenTTD (2003) v1.8 (2018) Source file: enum_type.hpp Line-by-line code walkthrough by MaiZure enum_type.hpp defines enum containers Original code: https://github.com/MaiZure/OpenTTD-1.8/blob/master/src/core/enum_type.hpp 1 COMMENT (*) 2 BLANK (-) 3 * 4 * 5 * 6 * 7 * 8 * 9 - 10 * 11 - 12 Header guard 13 Header guard 14 - 15 * 16 Defines macro DECLARE_POSTFIX_INCREMENT to generate increment and decrement operators. Needs to be a macro to generate in the proper namespace. 17 Overloads the postfix increment operator with two arguments: the enum and the int type (mandatory for postfix) 18 BLOCK START - Postfix increment overload for enums 19 Stores the original enum 20 Increments the enum 21 Returns the original enum 22 BLOCK END - Postfix increment overload for enums 23 Defines the postfix decrement with two arguments: the enum and int type (mandatory for postfix) 24 BLOCK START - Postfix decrement overload for enum 25 Stores the original enum 26 Increments the enum 27 Returns the original enum 28 BLOCK END - Postfix decrement overload for enum 29 - 30 - 31 - 32 * 33 Defines macro DECLARE_ENUM_AS_BIT_SET with argument for type 34 Overloads the OR operator using two mask types 35 Overloads the AND operator using two mask types 36 Overloads the XOR operator using two mask types 37 Overloads the OR assignment operator using two mask types 38 Overloads the AND assignment operator using two mask types 39 Overloads the XOR assignment operator using two mask types 40 Overloads the NOT operator with a type 41 - 42 - 43 * 44 * 45 * 46 * 47 * 48 * 49 * 50 * 51 * 52 Forward declaration of the class template of EnumPropT 53 - 54 * 55 * 56 * 57 * 58 * 59 * 60 * 61 * 62 * 63 * 64 * 65 Sets up a template with 2 type parameters, 3 other parameters and 1 default parameter 66 BLOCK START - MakeEnumPropsT, helper class to generate properties 67 Creates a typedef to expose the enum type 68 Creates a typedef to expose the storage type 69 Defines Tbegin as the lowest track value, note static class member 70 Defines end as the first invalid value (static) 71 Defines invalid as an invalid value 72 Defines the number of bits to store the enum 73 BLOCK END - MakeEnumPropsT 74 * 75 * 76 * 77 * 78 * 79 * 80 * 81 * 82 * 83 * 84 * 85 * 86 Forward declares TinyEnumT class template 87 - 88 * 89 Sets up a class template with one type parameter 90 BLOCK START - TinyEnumT, specialized enum container with updated operators 91 Creates a typedef exposing the enum type 92 Creates a typedef to easily access the properties template class 93 Creates a typedef for the property storage type 94 Defines a static storage for the first enum value 95 Defines a static storage for the first invalid enum valid 96 Defines the last enum value 97 - 98 Stores the enum value with the desired storage format 99 - 100 * 101 Overloads the cast operator for the enum type 102 BLOCK START - TinyEnumT type() overload 103 Returns the enum value after cast 104 BLOCK END - TinyEnumT type() overload 105 - 106 * 107 Overloads the assignment operator for enum type 108 BLOCK START - TinyEnumT = (type) overload 109 Casts and stores the input value 110 Returns a pointer to this enum object 111 BLOCK END - TinyEnumT = (type) overload 112 - 113 * 114 Overloads the assignment operator for unsigned int type 115 BLOCK START - TinyEnumT = (uint) overload 116 Casts and stores the input value 117 Returns a pointer to this enum object 118 BLOCK END - TinyEnumT = (uint) overload 119 - 120 * 121 Overloads the postfix increment operator 122 BLOCK START - TinyEnumT postfix ++ operator overload 123 Stores the original value 124 Increments and tests for the end value of the enum and wraps if needed 125 Return the pointer to the original value 126 BLOCK END - TinyEnumT postfix ++ operator overload 127 - 128 * 129 Overloads the prefix increment operator 130 BLOCK START - TinyEnumT prefix ++ operator overload 131 Increment and test for enum wrap. Wrap if necessary 132 Return pointer to self 133 BLOCK END - TinyEnumT prefix ++ operator overload 134 BLOCK END - TinyEnumT 135 - 136 - 137 * 138 Sets up a template with two type parameters: enum and storage type 139 BLOCK START - SimpleTinyEnumT, skinnier enum container than TinyEnumT 140 Declares the enum value as the storage type 141 * 142 * 143 Overloads the cast operator 144 BLOCK START - SimpleTinyEnumT type() overload 145 Returns the casted value 146 BLOCK END - SimpleTinyEnumT type() overload 147 - 148 * 149 Overloads the assignment operator for an input type 150 BLOCK START - SimpleTinyEnumT = (type) overload 151 Saves the input value as the desired storage type 152 Returns this enum object 153 BLOCK END - SimpleTinyEnumT = (type) overload 154 - 155 * 156 Overloads the assignment operator for an input unsigned int 157 BLOCK START - SimpleTinyEnumT = (uint) overload 158 Saves the input value as the desired storage type 159 Returns this enum object 160 BLOCK END - SimpleTinyEnumT = (uint) overload 161 - 162 * 163 Overloads the OR assignment operator 164 BLOCK START - SimpleTinyEnumT |= overload 165 Stores the result of a bitwise OR after cast 166 Returns pointer to this object 167 BLOCK END - SimpleTinyEnumT |= overload 168 - 169 * 170 Overloads the AND assignment operator 171 BLOCK START - SimpleTinyEnumT &= overload 172 Stores the result of a bitwise AND after cast 173 Returns pointer to this object 174 BLOCK END - SimpleTinyEnumT &= overload 175 BLOCK END - SimpleTinyEnumT 176 - 177 Header guard