author | rubidium |
Sun, 25 May 2008 19:17:03 +0000 | |
changeset 9354 | 845e07db4549 |
parent 9111 | 48ce04029fe4 |
permissions | -rw-r--r-- |
6134 | 1 |
/* $Id$ */ |
2 |
||
9111
48ce04029fe4
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
8128
diff
changeset
|
3 |
/** @file cmd_helper.h Helper functions to extract data from command parameters. */ |
48ce04029fe4
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
8128
diff
changeset
|
4 |
|
6134 | 5 |
#ifndef CMD_HELPER_H |
6 |
#define CMD_HELPER_H |
|
7 |
||
8100
6bc08f98ec16
(svn r11661) -Codechange: some header reworks in order to try to reduce the compile time of OpenTTD by reduce the amount of circular-ish dependencies.
rubidium
parents:
6134
diff
changeset
|
8 |
#include "direction_type.h" |
8102
906a3d3b6df1
(svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
8100
diff
changeset
|
9 |
#include "road_type.h" |
6134 | 10 |
|
11 |
||
12 |
template<uint N> static inline void ExtractValid(); |
|
8128
6856dfdd65f7
(svn r11689) -Fix: compilation error and most of warnings for gcc 4.3
smatz
parents:
8113
diff
changeset
|
13 |
template<> inline void ExtractValid<1>() {} |
6134 | 14 |
|
15 |
||
16 |
template<typename T> struct ExtractBits; |
|
17 |
template<> struct ExtractBits<Axis> { static const uint Count = 1; }; |
|
18 |
template<> struct ExtractBits<DiagDirection> { static const uint Count = 2; }; |
|
19 |
template<> struct ExtractBits<RoadBits> { static const uint Count = 4; }; |
|
20 |
||
21 |
||
22 |
template<typename T, uint N, typename U> static inline T Extract(U v) |
|
23 |
{ |
|
24 |
// Check if there are enough bits in v |
|
25 |
ExtractValid<N + ExtractBits<T>::Count <= sizeof(U) * 8>(); |
|
26 |
return (T)GB(v, N, ExtractBits<T>::Count); |
|
27 |
} |
|
28 |
||
29 |
#endif |