tron@6134: /* $Id$ */ tron@6134: rubidium@9111: /** @file cmd_helper.h Helper functions to extract data from command parameters. */ rubidium@9111: tron@6134: #ifndef CMD_HELPER_H tron@6134: #define CMD_HELPER_H tron@6134: rubidium@8100: #include "direction_type.h" rubidium@8102: #include "road_type.h" tron@6134: tron@6134: tron@6134: template static inline void ExtractValid(); smatz@8128: template<> inline void ExtractValid<1>() {} tron@6134: tron@6134: tron@6134: template struct ExtractBits; tron@6134: template<> struct ExtractBits { static const uint Count = 1; }; tron@6134: template<> struct ExtractBits { static const uint Count = 2; }; tron@6134: template<> struct ExtractBits { static const uint Count = 4; }; tron@6134: tron@6134: tron@6134: template static inline T Extract(U v) tron@6134: { tron@6134: // Check if there are enough bits in v tron@6134: ExtractValid::Count <= sizeof(U) * 8>(); tron@6134: return (T)GB(v, N, ExtractBits::Count); tron@6134: } tron@6134: tron@6134: #endif