author | smatz |
Fri, 13 Jun 2008 00:00:04 +0000 | |
changeset 10948 | 66145f71ebb9 |
parent 10429 | 1b99254f9607 |
permissions | -rw-r--r-- |
6460 | 1 |
/* $Id$ */ |
2 |
||
10429
1b99254f9607
(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:
8624
diff
changeset
|
3 |
/** @file cmd_helper.h Helper functions to extract data from command parameters. */ |
1b99254f9607
(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:
8624
diff
changeset
|
4 |
|
6460 | 5 |
#ifndef CMD_HELPER_H |
6 |
#define CMD_HELPER_H |
|
7 |
||
8596
27646407e0bc
(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:
6460
diff
changeset
|
8 |
#include "direction_type.h" |
8598
14ae80fe4c8f
(svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
8596
diff
changeset
|
9 |
#include "road_type.h" |
6460 | 10 |
|
11 |
||
12 |
template<uint N> static inline void ExtractValid(); |
|
8624
c5753e14d8dc
(svn r11689) -Fix: compilation error and most of warnings for gcc 4.3
smatz
parents:
8609
diff
changeset
|
13 |
template<> inline void ExtractValid<1>() {} |
6460 | 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 |