author | convert-repo |
Mon, 07 Apr 2008 16:21:55 +0000 | |
changeset 10076 | dfd70e42c4ae |
parent 8624 | c5753e14d8dc |
child 10429 | 1b99254f9607 |
permissions | -rw-r--r-- |
6460 | 1 |
/* $Id$ */ |
2 |
||
3 |
#ifndef CMD_HELPER_H |
|
4 |
#define CMD_HELPER_H |
|
5 |
||
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
|
6 |
#include "direction_type.h" |
8598
14ae80fe4c8f
(svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
8596
diff
changeset
|
7 |
#include "road_type.h" |
6460 | 8 |
|
9 |
||
10 |
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
|
11 |
template<> inline void ExtractValid<1>() {} |
6460 | 12 |
|
13 |
||
14 |
template<typename T> struct ExtractBits; |
|
15 |
template<> struct ExtractBits<Axis> { static const uint Count = 1; }; |
|
16 |
template<> struct ExtractBits<DiagDirection> { static const uint Count = 2; }; |
|
17 |
template<> struct ExtractBits<RoadBits> { static const uint Count = 4; }; |
|
18 |
||
19 |
||
20 |
template<typename T, uint N, typename U> static inline T Extract(U v) |
|
21 |
{ |
|
22 |
// Check if there are enough bits in v |
|
23 |
ExtractValid<N + ExtractBits<T>::Count <= sizeof(U) * 8>(); |
|
24 |
return (T)GB(v, N, ExtractBits<T>::Count); |
|
25 |
} |
|
26 |
||
27 |
#endif |