author | richk |
Tue, 17 Jun 2008 13:41:57 +0000 | |
branch | NewGRF_ports |
changeset 10995 | 311b38c7f9a7 |
parent 10724 | 68a692eacf22 |
permissions | -rw-r--r-- |
6460 | 1 |
/* $Id$ */ |
2 |
||
10724
68a692eacf22
(svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents:
6872
diff
changeset
|
3 |
/** @file cmd_helper.h Helper functions to extract data from command parameters. */ |
68a692eacf22
(svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents:
6872
diff
changeset
|
4 |
|
6460 | 5 |
#ifndef CMD_HELPER_H |
6 |
#define CMD_HELPER_H |
|
7 |
||
6872
1c4a4a609f85
(svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
6460
diff
changeset
|
8 |
#include "direction_type.h" |
1c4a4a609f85
(svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
6460
diff
changeset
|
9 |
#include "road_type.h" |
6460 | 10 |
|
11 |
||
12 |
template<uint N> static inline void ExtractValid(); |
|
6872
1c4a4a609f85
(svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
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 |