equal
deleted
inserted
replaced
|
1 /* $Id$ */ |
|
2 |
|
3 #ifndef CMD_HELPER_H |
|
4 #define CMD_HELPER_H |
|
5 |
|
6 #include "direction.h" |
|
7 #include "macros.h" |
|
8 #include "road.h" |
|
9 |
|
10 |
|
11 template<uint N> static inline void ExtractValid(); |
|
12 template<> static inline void ExtractValid<1>() {} |
|
13 |
|
14 |
|
15 template<typename T> struct ExtractBits; |
|
16 template<> struct ExtractBits<Axis> { static const uint Count = 1; }; |
|
17 template<> struct ExtractBits<DiagDirection> { static const uint Count = 2; }; |
|
18 template<> struct ExtractBits<RoadBits> { static const uint Count = 4; }; |
|
19 |
|
20 |
|
21 template<typename T, uint N, typename U> static inline T Extract(U v) |
|
22 { |
|
23 // Check if there are enough bits in v |
|
24 ExtractValid<N + ExtractBits<T>::Count <= sizeof(U) * 8>(); |
|
25 return (T)GB(v, N, ExtractBits<T>::Count); |
|
26 } |
|
27 |
|
28 #endif |