1 /** 2 * Copyright: © 2012-2014 Anton Gushcha 3 * License: Subject to the terms of the MIT license, as written in the included LICENSE file. 4 * Authors: NCrashed <ncrashed@gmail.com>, 5 * LeMarwin <lemarwin42@gmail.com>, 6 * Nazgull09 <nazgull90@gmail.com> 7 */ 8 module devol.std.typepod; 9 10 import std.random; 11 import std.conv; 12 13 public 14 { 15 import devol.argument; 16 import devol.type; 17 import devol.std.argpod; 18 } 19 20 alias TypePod!bool TypeBool; 21 alias TypePod!int TypeInt; 22 alias TypePod!float TypeFloat; 23 alias TypePod!long TypeLong; 24 alias TypePod!double TypeDouble; 25 alias TypePod!char TypeChar; 26 alias TypePod!uint TypeUInt; 27 28 class TypePod(T) : Type 29 { 30 this() 31 { 32 super("Type"~T.stringof); 33 } 34 35 override ArgPod!T getNewArg() 36 { 37 auto arg = new ArgPod!T(); 38 arg = T.init; 39 return arg; 40 } 41 42 override ArgPod!T getNewArg(string min, string max, string[] exVal) 43 { 44 auto arg = new ArgPod!T(); 45 46 bool except( T val, string[] ex) 47 { 48 foreach( s; ex) 49 if (to!T(s) == val) 50 return true; 51 return false; 52 } 53 54 static if ( !is(T == bool) ) 55 { 56 do 57 { 58 arg = uniform!("[]")(to!T(min), to!T(max)); 59 } while( except( arg.val, exVal) ); 60 } else 61 { 62 do 63 { 64 arg = (uniform!("[]")(0, 1)) == 1; 65 } while( except( arg.val, exVal) ); 66 } 67 return arg; 68 } 69 }