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 this() 27 { 28 inttype = cast(TypePod!int)(TypeMng.getSingleton().getType("Typeint")); 29 assert(inttype, "We need int type!"); 30 31 mRetType = inttype; 32 super("+","Summ of two args",ArgsStyle.BINAR_STYLE); 33 34 ArgInfo a1; 35 a1.type = inttype; 36 a1.min = "-1000"; 37 a1.max = "+1000"; 38 39 args ~= a1; 40 args ~= a1; 41 } 42 43 override Argument apply(IndAbstract ind, Line line, WorldAbstract world) 44 { 45 debug writeln("Plus: Getting return type"); 46 auto ret = inttype.getNewArg(); 47 48 debug writeln("Plus: casting arugments"); 49 auto a1 = cast(ArgPod!int)(line[0]); 50 auto a2 = cast(ArgPod!int)(line[1]); 51 52 debug writeln( line[0].type.name ); 53 debug writeln( line[0].type.name ); 54 55 assert( a1 !is null, "Critical error: Operator plus, argument 1 isn't a right value!"); 56 assert( a2 !is null, "Critical error: Operator plus, argument 2 isn't a right value!"); 57 58 debug writeln("Plus: adding arguments"); 59 ret = a1.val + a2.val; 60 debug writeln("Plus: succes"); 61 return ret; 62 } 63 } 64 65 unittest 66 { 67 /*auto tm = new TypeMng(); 68 tm.registerType!(TypePod!int)(); 69 70 auto pOp = new Plus(); 71 auto ind = new Individ(); 72 73 class DummyWorld : WorldAbstract 74 { 75 void init() {} 76 } 77 auto world = new DummyWorld(); 78 79 auto a1 = pOp.inttype.getNewArg(); 80 a1.val = 10; 81 auto a2 = pOp.inttype.getNewArg(); 82 a2.val = 23; 83 84 auto line = new Line(); 85 line.op = pOp; 86 line[0] = a1; 87 line[1] = a2; 88 assert( line.compile( ind, world ).val == );*/ 89 }