OpenTTD: src/cmd_helper.h Source File

OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

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);
33 return IsInsideMM(masked, EnumPropsT<T>::begin, EnumPropsT<T>::end) ? (T)masked : EnumPropsT<T>::invalid;
34 }
35
36 #endif /* CMD_HELPER_H */