OpenTTD
cmd_helper.h
Go to the documentation of this file.
1 /* $Id: cmd_helper.h 23742 2012-01-03 21:58:26Z rubidium $ */
2 
3 /*
4  * This file is part of OpenTTD.
5  * 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.
6  * 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.
7  * 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/>.
8  */
9 
12 #ifndef CMD_HELPER_H
13 #define CMD_HELPER_H
14 
15 #include "core/enum_type.hpp"
16 #include "core/bitmath_func.hpp"
17 
26 template<typename T, uint S, uint N, typename U> static inline T Extract(U v)
27 {
28  /* Check if there are enough bits in v */
29  assert_tcompile(N == EnumPropsT<T>::num_bits);
30  assert_tcompile(S + N <= sizeof(U) * 8);
31  assert_tcompile(EnumPropsT<T>::end <= (1 << N));
32  U masked = GB(v, S, N);
34 }
35 
36 #endif /* CMD_HELPER_H */
static bool IsInsideMM(const T x, const uint min, const uint max)
Checks if a value is in an interval.
Definition: math_func.hpp:266
Functions related to bit mathematics.
static T Extract(U v)
Extracts a given type from a value.
Definition: cmd_helper.h:26
Type (helpers) for enums.
Informative template class exposing basic enumeration properties used by several other templates belo...
Definition: enum_type.hpp:52
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.