author | rubidium |
Sun, 06 Apr 2008 12:26:40 +0000 | |
branch | noai |
changeset 9867 | b7d9ffe24f81 |
parent 9723 | eee46cb39750 |
child 10455 | 22c441f5adf9 |
permissions | -rw-r--r-- |
6460 | 1 |
/* $Id$ */ |
2 |
||
3 |
#ifndef CMD_HELPER_H |
|
4 |
#define CMD_HELPER_H |
|
5 |
||
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
6460
diff
changeset
|
6 |
#include "direction_type.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
6460
diff
changeset
|
7 |
#include "road_type.h" |
6460 | 8 |
|
9 |
||
10 |
template<uint N> static inline void ExtractValid(); |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
6460
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 |