src/cmd_helper.h
author translators
Fri, 05 Dec 2008 18:45:05 +0000
changeset 10406 a929a9e55ce9
parent 9111 48ce04029fe4
permissions -rw-r--r--
(svn r14657) -Update: WebTranslator2 update to 2008-12-05 18:44:56
afrikaans - 5 fixed by burgerd (5)
icelandic - 13 fixed by scrooge (13)
latvian - 101 fixed by Wersoo (101)
lithuanian - 4 fixed, 293 changed by linasmi (297)
malay - 40 fixed by Syed (40)
slovenian - 11 fixed by Necrolyte (11)
turkish - 78 fixed by Emin (78)
6134
871305fd9ab7 (svn r8876) -Fix
tron
parents:
diff changeset
     1
/* $Id$ */
871305fd9ab7 (svn r8876) -Fix
tron
parents:
diff changeset
     2
9111
48ce04029fe4 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 8128
diff changeset
     3
/** @file cmd_helper.h Helper functions to extract data from command parameters. */
48ce04029fe4 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 8128
diff changeset
     4
6134
871305fd9ab7 (svn r8876) -Fix
tron
parents:
diff changeset
     5
#ifndef CMD_HELPER_H
871305fd9ab7 (svn r8876) -Fix
tron
parents:
diff changeset
     6
#define CMD_HELPER_H
871305fd9ab7 (svn r8876) -Fix
tron
parents:
diff changeset
     7
8100
6bc08f98ec16 (svn r11661) -Codechange: some header reworks in order to try to reduce the compile time of OpenTTD by reduce the amount of circular-ish dependencies.
rubidium
parents: 6134
diff changeset
     8
#include "direction_type.h"
8102
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents: 8100
diff changeset
     9
#include "road_type.h"
6134
871305fd9ab7 (svn r8876) -Fix
tron
parents:
diff changeset
    10
871305fd9ab7 (svn r8876) -Fix
tron
parents:
diff changeset
    11
871305fd9ab7 (svn r8876) -Fix
tron
parents:
diff changeset
    12
template<uint N> static inline void ExtractValid();
8128
6856dfdd65f7 (svn r11689) -Fix: compilation error and most of warnings for gcc 4.3
smatz
parents: 8113
diff changeset
    13
template<> inline void ExtractValid<1>() {}
6134
871305fd9ab7 (svn r8876) -Fix
tron
parents:
diff changeset
    14
871305fd9ab7 (svn r8876) -Fix
tron
parents:
diff changeset
    15
871305fd9ab7 (svn r8876) -Fix
tron
parents:
diff changeset
    16
template<typename T> struct ExtractBits;
871305fd9ab7 (svn r8876) -Fix
tron
parents:
diff changeset
    17
template<> struct ExtractBits<Axis>          { static const uint Count =  1; };
871305fd9ab7 (svn r8876) -Fix
tron
parents:
diff changeset
    18
template<> struct ExtractBits<DiagDirection> { static const uint Count =  2; };
871305fd9ab7 (svn r8876) -Fix
tron
parents:
diff changeset
    19
template<> struct ExtractBits<RoadBits>      { static const uint Count =  4; };
871305fd9ab7 (svn r8876) -Fix
tron
parents:
diff changeset
    20
871305fd9ab7 (svn r8876) -Fix
tron
parents:
diff changeset
    21
871305fd9ab7 (svn r8876) -Fix
tron
parents:
diff changeset
    22
template<typename T, uint N, typename U> static inline T Extract(U v)
871305fd9ab7 (svn r8876) -Fix
tron
parents:
diff changeset
    23
{
871305fd9ab7 (svn r8876) -Fix
tron
parents:
diff changeset
    24
	// Check if there are enough bits in v
871305fd9ab7 (svn r8876) -Fix
tron
parents:
diff changeset
    25
	ExtractValid<N + ExtractBits<T>::Count <= sizeof(U) * 8>();
871305fd9ab7 (svn r8876) -Fix
tron
parents:
diff changeset
    26
	return (T)GB(v, N, ExtractBits<T>::Count);
871305fd9ab7 (svn r8876) -Fix
tron
parents:
diff changeset
    27
}
871305fd9ab7 (svn r8876) -Fix
tron
parents:
diff changeset
    28
871305fd9ab7 (svn r8876) -Fix
tron
parents:
diff changeset
    29
#endif