cmd_helper.h

Go to the documentation of this file.
00001 /* $Id: cmd_helper.h 17248 2009-08-21 20:21:05Z rubidium $ */
00002 
00003 /*
00004  * This file is part of OpenTTD.
00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
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   /* Check if there are enough bits in v */
00032   ExtractValid<N + ExtractBits<T>::Count <= sizeof(U) * 8>();
00033   return (T)GB(v, N, ExtractBits<T>::Count);
00034 }
00035 
00036 #endif

Generated on Wed Mar 31 22:43:21 2010 for OpenTTD by  doxygen 1.6.1