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