author | glx |
Sun, 15 Jun 2008 22:56:43 +0000 | |
branch | noai |
changeset 10973 | 8577bc56132c |
parent 10455 | 22c441f5adf9 |
permissions | -rw-r--r-- |
6460 | 1 |
/* $Id$ */ |
2 |
||
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
9723
diff
changeset
|
3 |
/** @file cmd_helper.h Helper functions to extract data from command parameters. */ |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
9723
diff
changeset
|
4 |
|
6460 | 5 |
#ifndef CMD_HELPER_H |
6 |
#define CMD_HELPER_H |
|
7 |
||
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
6460
diff
changeset
|
8 |
#include "direction_type.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
6460
diff
changeset
|
9 |
#include "road_type.h" |
6460 | 10 |
|
11 |
||
12 |
template<uint N> static inline void ExtractValid(); |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
6460
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 |