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.plus; 9 10 import std.stdio; 11 12 import devol.typemng; 13 14 public 15 { 16 import devol.individ; 17 import devol.world; 18 import devol.operator; 19 import devol.std.typepod; 20 } 21 22 class Plus : Operator 23 { 24 TypePod!int inttype; 25 26 enum description = "Arithmetic operator that adds two arguments and returns the result."; 27 28 this() 29 { 30 inttype = cast(TypePod!int)(TypeMng.getSingleton().getType("Typeint")); 31 assert(inttype, "We need int type!"); 32 33 mRetType = inttype; 34 super("+", description, ArgsStyle.BINAR_STYLE); 35 36 ArgInfo a1; 37 a1.type = inttype; 38 a1.min = "-1000"; 39 a1.max = "+1000"; 40 41 args ~= a1; 42 args ~= a1; 43 } 44 45 /// TODO: enable adding not only ints 46 override Argument apply(IndAbstract ind, Line line, WorldAbstract world) 47 { 48 //debug writeln("Plus: Getting return type"); 49 auto ret = inttype.getNewArg(); 50 51 //debug writeln("Plus: casting arugments"); 52 auto a1 = cast(ArgPod!int)(line[0]); 53 auto a2 = cast(ArgPod!int)(line[1]); 54 55 //debug writeln( line[0].type.name ); 56 //debug writeln( line[0].type.name ); 57 58 assert( a1 !is null, "Critical error: Operator plus, argument 1 isn't a right value!"); 59 assert( a2 !is null, "Critical error: Operator plus, argument 2 isn't a right value!"); 60 61 //debug writeln("Plus: adding arguments"); 62 ret = a1.val + a2.val; 63 //debug writeln("Plus: succes"); 64 return ret; 65 } 66 } 67 68 unittest 69 { 70 /*auto tm = new TypeMng(); 71 tm.registerType!(TypePod!int)(); 72 73 auto pOp = new Plus(); 74 auto ind = new Individ(); 75 76 class DummyWorld : WorldAbstract 77 { 78 void init() {} 79 } 80 auto world = new DummyWorld(); 81 82 auto a1 = pOp.inttype.getNewArg(); 83 a1.val = 10; 84 auto a2 = pOp.inttype.getNewArg(); 85 a2.val = 23; 86 87 auto line = new Line(); 88 line.op = pOp; 89 line[0] = a1; 90 line[1] = a2; 91 assert( line.compile( ind, world ).val == );*/ 92 }