From 4621e7aa3ee3b1dd2e987fd498ebf07ec558b19c Mon Sep 17 00:00:00 2001
From: Daniela Genius <genius@debussy.soc.lip6.fr>
Date: Tue, 10 Mar 2020 10:22:03 +0100
Subject: [PATCH] simulator

---
 .../c++2/src_simulator/sim/Simulator.cpp      | 79 +++++++++----------
 1 file changed, 37 insertions(+), 42 deletions(-)

diff --git a/simulators/c++2/src_simulator/sim/Simulator.cpp b/simulators/c++2/src_simulator/sim/Simulator.cpp
index 3950e6a793..6a6fd458f5 100644
--- a/simulators/c++2/src_simulator/sim/Simulator.cpp
+++ b/simulators/c++2/src_simulator/sim/Simulator.cpp
@@ -1131,9 +1131,8 @@ int countLineNumber(std::string& filename){
     std::string line;
     std::ifstream myfile(filename.c_str());
 
-    while (std::getline(myfile, line)){
-        if (line != "") ++number_of_lines;
-    }
+    while (std::getline(myfile, line))
+        ++number_of_lines;
     std::cout << "Number of lines in text file: " << number_of_lines << std::endl;
     return number_of_lines;
 }
@@ -1169,48 +1168,44 @@ ServerIF* Simulator::run(int iLen, char ** iArgs){
     std::vector<std::string> parameters = readFromFile(aArgString);
     std::string aNewCmd;
     int previousTransTime = 0;
-    if((parameters.size() != (lineNumber*4))){
-        std::cout << "Error: Wrong format, each line should contains 4 parameters.\n";
-    } else {
-        if(lineNumber != 0){
-            for (int i = 0; i < lineNumber; i++){
-                std::string channelName =_simComp->getChannelList(parameters[i*4+1]);
-                TMLChannel* t = _simComp->getChannelByName(channelName);
-                if(t != 0){
-                    aNewCmd += "1 5 " + parameters[i*4] + "; 6 " + to_string(t->getID()) + " 1 " + parameters[i*4+3] + "; ";
-                }
-                else {
-                    std::cout << "Error: Wrong channel name\n";
-                    previousTransTime++;
-                }
+    if(lineNumber != 0){
+        for (int i = 0; i < lineNumber; i++){
+            std::string channelName =_simComp->getChannelList(parameters[i*4+1]);
+            TMLChannel* t = _simComp->getChannelByName(channelName);
+            if(t != 0){
+                aNewCmd += "1 5 " + parameters[i*4] + "; 6 " + to_string(t->getID()) + " 1 " + parameters[i*4+3] + "; ";
             }
-            if(previousTransTime != lineNumber){
-                aNewCmd += "1 0; 7 1 test.html;  1 7 100 100 test";
-            } else {
-                aNewCmd = "1 0; 7 1 test.html;  1 7 100 100 test";
+            else {
+                std::cout << "Error: Wrong channel name\n";
+                previousTransTime++;
             }
+        }
+        if(previousTransTime != lineNumber){
+            aNewCmd += "1 0; 7 1 test.html;  1 7 100 100 test";
+        } else {
+            aNewCmd = "1 0; 7 1 test.html;  1 7 100 100 test";
+        }
 
-            std::cout<<"DecodeCommand "<< aNewCmd << std::endl;
-            std::ofstream aXmlOutFile1;
-            std::string aXmlFileName1 = getArgs("-oxml", "reply.xml", iLen, iArgs);
-            if (aXmlFileName1.empty()) aXmlOutFile1.open("/dev/null"); else aXmlOutFile1.open(aXmlFileName1.c_str());
-            if (aXmlOutFile1.is_open()){
-            std::string aNextCmd1;
-            std::istringstream iss1(aNewCmd+";");
-            getline(iss1, aNextCmd1, ';');
-            while (!(iss1.eof() || aNextCmd1.empty())){
-              std::cout << "next cmd to execute: \"" << aNextCmd1 << "\"\n";
-              decodeCommand(aNextCmd1, aXmlOutFile1);
-              getline(iss1, aNextCmd1, ';');
-            }
-            aXmlOutFile1.close();
-          } else{
-                std::cout << "XML output file could not be opened, aborting.\n";
-            }
-          } else {
-             std::cout << "Signal file contains nothing, aborting.\n";
-          }
-    }
+        std::cout<<"DecodeCommand "<< aNewCmd << std::endl;
+        std::ofstream aXmlOutFile1;
+        std::string aXmlFileName1 = getArgs("-oxml", "reply.xml", iLen, iArgs);
+        if (aXmlFileName1.empty()) aXmlOutFile1.open("/dev/null"); else aXmlOutFile1.open(aXmlFileName1.c_str());
+        if (aXmlOutFile1.is_open()){
+        std::string aNextCmd1;
+        std::istringstream iss1(aNewCmd+";");
+        getline(iss1, aNextCmd1, ';');
+        while (!(iss1.eof() || aNextCmd1.empty())){
+          std::cout << "next cmd to execute: \"" << aNextCmd1 << "\"\n";
+          decodeCommand(aNextCmd1, aXmlOutFile1);
+          getline(iss1, aNextCmd1, ';');
+        }
+        aXmlOutFile1.close();
+      } else{
+            std::cout << "XML output file could not be opened, aborting.\n";
+        }
+      } else {
+         std::cout << "Signal file contains nothing, aborting.\n";
+      }
   }
   aArgString =getArgs("-help", "help", iLen, iArgs);
   if (aArgString.empty()){
-- 
GitLab