getSwitchDataType

generate switch for all DataType elements

string
getSwitchDataType
pure
(
string subj
,
string fmt
,
string[string] except
)

Parameters

subj
Type: string

past as switch( subj )

fmt
Type: string

body of all cases past as formated with one argument (DataType) string

except
Type: string[string]

exception in selected cases

Examples

enum fmt = q{ auto dst = getTypedArray!(storeDataType!(%1$s))( info.comp, buffer ); auto src = flatData!real(vals); foreach( i, ref t; dst ) t = convertValue!(%1$s)( srci ); }; writeln( genSwitchDataType( "info.type", fmt, ["RAWBYTE": "can't operate RAWBYTE"] ) );

Output like this:

final switch( info.type ) { case DataType.RAWBYTE: throw new DataTypeException( "can't operate RAWBYTE" ); case DataType.BYTE: auto dst = getTypedArray!(storeDataType!(DataType.BYTE))( info.comp, buffer ); auto src = flatData!real(vals); foreach( i, ref t; dst ) t = convertValue!(DataType.BYTE)( srci ); break; case DataType.UBYTE: auto dst = getTypedArray!(storeDataType!(DataType.UBYTE))( info.comp, buffer ); auto src = flatData!real(vals); foreach( i, ref t; dst ) t = convertValue!(DataType.UBYTE)( srci ); break; ... }

Meta