OpenTTD Source  1.11.0-beta2
cmd_helper.h
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * OpenTTD 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  * OpenTTD 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 OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6  */
7 
10 #ifndef CMD_HELPER_H
11 #define CMD_HELPER_H
12 
13 #include "core/enum_type.hpp"
14 #include "core/bitmath_func.hpp"
15 
24 template<typename T, uint S, uint N, typename U> static inline T Extract(U v)
25 {
26  /* Check if there are enough bits in v */
27  static_assert(N == EnumPropsT<T>::num_bits);
28  static_assert(S + N <= sizeof(U) * 8);
29  static_assert(EnumPropsT<T>::end <= (1 << N));
30  U masked = GB(v, S, N);
32 }
33 
34 #endif /* CMD_HELPER_H */
GB
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
Definition: bitmath_func.hpp:32
IsInsideMM
static bool IsInsideMM(const T x, const size_t min, const size_t max)
Checks if a value is in an interval.
Definition: math_func.hpp:204
bitmath_func.hpp
EnumPropsT
Informative template class exposing basic enumeration properties used by several other templates belo...
Definition: enum_type.hpp:48
enum_type.hpp
Extract
static T Extract(U v)
Extracts a given type from a value.
Definition: cmd_helper.h:24