cmd_helper.h
00001
00002
00003 #ifndef CMD_HELPER_H
00004 #define CMD_HELPER_H
00005
00006 #include "direction_type.h"
00007 #include "road_type.h"
00008
00009
00010 template<uint N> static inline void ExtractValid();
00011 template<> inline void ExtractValid<1>() {}
00012
00013
00014 template<typename T> struct ExtractBits;
00015 template<> struct ExtractBits<Axis> { static const uint Count = 1; };
00016 template<> struct ExtractBits<DiagDirection> { static const uint Count = 2; };
00017 template<> struct ExtractBits<RoadBits> { static const uint Count = 4; };
00018
00019
00020 template<typename T, uint N, typename U> static inline T Extract(U v)
00021 {
00022
00023 ExtractValid<N + ExtractBits<T>::Count <= sizeof(U) * 8>();
00024 return (T)GB(v, N, ExtractBits<T>::Count);
00025 }
00026
00027 #endif