Salome HOME
Merge GUI developments from BR_GUI
[tools/hxx2salome.git] / CppExamples / COMPO_CXX_SRC / src / CALCUL / CALCUL_CXX / main.cxx
diff --git a/CppExamples/COMPO_CXX_SRC/src/CALCUL/CALCUL_CXX/main.cxx b/CppExamples/COMPO_CXX_SRC/src/CALCUL/CALCUL_CXX/main.cxx
new file mode 100644 (file)
index 0000000..ffb9534
--- /dev/null
@@ -0,0 +1,48 @@
+#include "Calc.hxx"
+#include <iostream>
+#include <fstream>
+#include<sstream>
+
+using namespace std;
+int main(int argc, char ** argv)
+{
+    if (argc != 2)
+    {
+       cerr << "Usage : " << argv[0]
+           << "Calc.exe file.in" << endl << endl
+           << "-> lit le fichier file.in et exĂ©cute les commandes" << endl;
+       exit(-1);
+    }
+    ifstream in(argv[1], ios::in);
+    CALCUL myCalc;
+    int i1,i2;
+    string name;
+
+
+    string buf_ligne; // pour lire une ligne
+    while ( getline(in, buf_ligne) ) // parse le fichier d'entree
+    {
+       if( (buf_ligne.find("MUL")) != string::npos)
+       {
+           istringstream buf(buf_ligne.c_str());
+           buf >> name >> i1 >> i2;
+           cout << "MUL(" << i1 << "," << i2 << ")=" << myCalc.mul(i1,i2) << endl;
+       }
+       else if (buf_ligne.find("ADD") != string::npos)
+       {
+           istringstream buf(buf_ligne.c_str());
+           buf >> name >> i1 >> i2;
+           cout << "ADD(" << i1 << "," << i2 << ")=" << myCalc.add(i1,i2) << endl;
+       }
+       else if (buf_ligne.find("FACT") != string::npos)
+       {
+           istringstream buf(buf_ligne.c_str());
+           buf >> name >> i1;
+           cout << "FACT(" << i1 << ")=" << myCalc.fact(i1) << endl;
+       }
+    }
+           
+
+    in.close();
+
+}