# cmd_helper.h

Go to the documentation of this file.

    00001 /* $Id: cmd_helper.h 15718 2009-03-15 00:32:18Z rubidium $ */
    00002
    00005 #ifndef CMD_HELPER_H
    00006 #define CMD_HELPER_H
    00007
    00008 #include "direction_type.h"
    00009 #include "road_type.h"
    00010
    00011
    00012 template<uint N> static inline void ExtractValid();
    00013 template<> inline void ExtractValid<1>() {}
    00014
    00015
    00016 template<typename T> struct ExtractBits;
    00017 template<> struct ExtractBits<Axis>          { static const uint Count =  1; };
    00018 template<> struct ExtractBits<DiagDirection> { static const uint Count =  2; };
    00019 template<> struct ExtractBits<RoadBits>      { static const uint Count =  4; };
    00020
    00021
    00022 template<typename T, uint N, typename U> static inline T Extract(U v)
    00023 {
    00024   /* Check if there are enough bits in v */
    00025   ExtractValid<N + ExtractBits<T>::Count <= sizeof(U) * 8>();
    00026   return (T)GB(v, N, ExtractBits<T>::Count);
    00027 }
    00028
    00029 #endif