• Main Page
  • Modules
  • Classes
  • Files
  • File List

D:/Projekt/ECF_trunk/ECF/cartesian/FunctionSet.cpp

00001 #include "FunctionSet.h"
00002 
00003 namespace cart {
00004 
00005     FunctionSet::FunctionSet(string gettype)
00006     {
00007         type = gettype;
00008         existFunc["+"] = true;
00009         existFunc["-"] = true;
00010         existFunc["*"] = true;
00011         existFunc["/"] = true;
00012         existFunc["sin"] = true;
00013         existFunc["cos"] = true;
00014         existFunc["AND"] = true;
00015         existFunc["OR"] = true;
00016         existFunc["NOT"] = true;
00017         existFunc["XOR"] = true;
00018         existFunc["XNOR"] = true;
00019     }
00020 
00021     bool FunctionSet::addFunction(string name)
00022     {
00023         if (!existFunc[name])
00024         {
00025             cerr << "FunctionSet error: Function " << name << " isn't implemented." << endl;
00026             return false;
00027         }
00028         
00029         if (type == "double")
00030         {
00031             if (name == "+")
00032             {
00033                 this->push_back((FunctionP) (new AddDouble));
00034             }
00035             else if (name == "-")
00036             {
00037                 this->push_back((FunctionP) (new SubDouble));
00038             }
00039             else if (name == "*")
00040             {
00041                 this->push_back((FunctionP) (new MulDouble));
00042             }
00043             else if (name == "/")
00044             {
00045                 this->push_back((FunctionP) (new DivDouble));
00046             }
00047             else if (name == "sin")
00048             {
00049                 this->push_back((FunctionP) (new SinDouble));
00050             }
00051             else if (name == "cos")
00052             {
00053                 this->push_back((FunctionP) (new CosDouble));
00054             }
00055             else
00056             {
00057                 cerr << "FunctionSet error: Unkown function name: " << name << endl;
00058                 return false;
00059             }
00060         }
00061         else if (type == "int")
00062         {
00063             if (name == "+")
00064             {
00065                 this->push_back((FunctionP) (new AddInt));
00066             }
00067             else if (name == "-")
00068             {
00069                 this->push_back((FunctionP) (new SubInt));
00070             }
00071             else if (name == "*")
00072             {
00073                 this->push_back((FunctionP) (new MulInt));
00074             }
00075             else if (name == "/")
00076             {
00077                 this->push_back((FunctionP) (new DivInt));
00078             }
00079             else if (name == "sin")
00080             {
00081                 this->push_back((FunctionP) (new SinInt));
00082             }
00083             else if (name == "cos")
00084             {
00085                 this->push_back((FunctionP) (new CosInt));
00086             }
00087             else
00088             {
00089                 cerr << "FunctionSet error: Unkown function name: " << name << endl;
00090                 return false;
00091             }
00092         }
00093         else if (type == "uint")
00094         {
00095             if (name == "AND")
00096             {
00097                 this->push_back((FunctionP) (new AndUint));
00098             }
00099             else if (name == "OR")
00100             {
00101                 this->push_back((FunctionP) (new OrUint));
00102             }
00103             else if (name == "NOT")
00104             {
00105                 this->push_back((FunctionP) (new NotUint));
00106             }
00107             else if (name == "XOR")
00108             {
00109                 this->push_back((FunctionP) (new XorUint));
00110             }
00111             else if (name == "XNOR")
00112             {
00113                 this->push_back((FunctionP) (new XnorUint));
00114             }
00115             else
00116             {
00117                 cerr << "FunctionSet error: Unkown function name: " << name << endl;
00118                 return false;
00119             }
00120         }
00121         else
00122         {
00123             cerr << "FunctionSet error: Unkown data type: " << type << endl;
00124             return false;
00125         }
00126 
00127         return true;
00128     }
00129 
00130     bool FunctionSet::addFunction(string name, uint numArgs)
00131     {
00132         if (!existFunc[name])
00133         {
00134             cerr << "FunctionSet error: Function " << name << " isn't implemented." << endl;
00135             return false;
00136         }
00137 
00138         if (type == "double")
00139         {
00140             if (name == "+")
00141             {
00142                 this->push_back((FunctionP) (new AddDouble(numArgs)));
00143             }
00144             else if (name == "-")
00145             {
00146                 this->push_back((FunctionP) (new SubDouble(numArgs)));
00147             }
00148             else if (name == "*")
00149             {
00150                 this->push_back((FunctionP) (new MulDouble(numArgs)));
00151             }
00152             else if (name == "/")
00153             {
00154                 this->push_back((FunctionP) (new DivDouble(numArgs)));
00155             }
00156             else
00157             {
00158                 cerr << "FunctionSet error: Unkown function name: " << name;
00159                 cerr << " for " << numArgs << " arguments." << endl;
00160                 return false;
00161             }
00162         }
00163         else if (type == "int")
00164         {
00165             if (name == "+")
00166             {
00167                 this->push_back((FunctionP) (new AddInt(numArgs)));
00168             }
00169             else if (name == "-")
00170             {
00171                 this->push_back((FunctionP) (new SubInt(numArgs)));
00172             }
00173             else if (name == "*")
00174             {
00175                 this->push_back((FunctionP) (new MulInt(numArgs)));
00176             }
00177             else if (name == "/")
00178             {
00179                 this->push_back((FunctionP) (new DivInt(numArgs)));
00180             }
00181             else
00182             {
00183                 cerr << "FunctionSet error: Unkown function name: " << name;
00184                 cerr << " for " << numArgs << " arguments." << endl;
00185                 return false;
00186             }
00187         }
00188         else if (type == "uint")
00189         {
00190             if (name == "AND")
00191             {
00192                 this->push_back((FunctionP) (new AndUint(numArgs)));
00193             }
00194             else if (name == "OR")
00195             {
00196                 this->push_back((FunctionP) (new OrUint(numArgs)));
00197             }
00198             else if (name == "XOR")
00199             {
00200                 this->push_back((FunctionP) (new XorUint(numArgs)));
00201             }
00202             else if (name == "XNOR")
00203             {
00204                 this->push_back((FunctionP) (new XnorUint(numArgs)));
00205             }
00206             else
00207             {
00208                 cerr << "FunctionSet error: Unkown function name: " << name;
00209                 cerr << " for " << numArgs << " arguments." << endl;
00210                 return false;
00211             }
00212         }
00213         else
00214         {
00215             cerr << "FunctionSet error: Unkown data type: " << type << endl;
00216             return false;
00217         }
00218 
00219         return true;
00220     }
00221 
00222     void FunctionSet::evaluate(voidP inputs, void* result, uint funcNum)
00223     {
00224         this->at(funcNum)->evaluate(inputs, result);
00225     }
00226 
00227 }

Generated on Tue Nov 4 2014 13:04:30 for ECF by  doxygen 1.7.1