cmd_helper.h

00001 /* $Id: cmd_helper.h 11689 2007-12-23 21:02:40Z smatz $ */
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   // Check if there are enough bits in v
00023   ExtractValid<N + ExtractBits<T>::Count <= sizeof(U) * 8>();
00024   return (T)GB(v, N, ExtractBits<T>::Count);
00025 }
00026 
00027 #endif

Generated on Mon Sep 22 20:34:15 2008 for openttd by  doxygen 1.5.6