LCOV - code coverage report
Current view: top level - builds/barbot/Cosmos/src/ModelGenerator/GspnParser - Gspn-Reader.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 52 62 83.9 %
Date: 2021-06-16 15:43:28 Functions: 8 11 72.7 %

          Line data    Source code
       1             : /*******************************************************************************
       2             :  *                                                                             *
       3             :  * Cosmos:(C)oncept et (O)utils (S)tatistique pour les (Mo)deles               *
       4             :  * (S)tochastiques                                                             *
       5             :  *                                                                             *
       6             :  * Copyright (C) 2009-2012 LSV & LACL                                          *
       7             :  * Authors: Paolo Ballarini & Hilal Djafri                                     *
       8             :  * Website: http://www.lsv.ens-cachan.fr/Software/cosmos                       *
       9             :  *                                                                             *
      10             :  * This program is free software; you can redistribute it and/or modify        *
      11             :  * it under the terms of the GNU General Public License as published by        *
      12             :  * the Free Software Foundation; either version 3 of the License, or           *
      13             :  * (at your option) any later version.                                         *
      14             :  *                                                                             *
      15             :  * This program is distributed in the hope that it will be useful,             *
      16             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of              *
      17             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               *
      18             :  * GNU General Public License for more details.                                *
      19             :  *                                                                             *
      20             :  * You should have received a copy of the GNU General Public License along     *
      21             :  * with this program; if not, write to the Free Software Foundation, Inc.,     *
      22             :  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.                 *
      23             :  *******************************************************************************
      24             :  */
      25             : 
      26             : #include "Gspn-Reader.hpp"
      27             : #include "Gspn_gmlparser.hpp"
      28             : 
      29             : #include "string.h"
      30             : 
      31             : #include <string>
      32             : #include <sstream>
      33             : #include <fstream>
      34             : #include <set>
      35             : #include <algorithm>
      36             : 
      37             : using namespace std;
      38             : 
      39             : 
      40          34 : Gspn_Reader::Gspn_Reader(parameters &Q):spn(new GspnType()),P(Q) {
      41          34 :   trace_scanning = false;
      42          34 :   trace_parsing = false;
      43          34 : }
      44             : 
      45          34 : Gspn_Reader::~Gspn_Reader() {
      46          34 : }
      47             : 
      48          11 : int Gspn_Reader::parse(string& expr) {
      49             : 
      50          11 :   scan_expression(expr);
      51             : 
      52          11 :   IndexDist["UNIFORM"] = UNIFORM;
      53          11 :   IndexDist["EXPONENTIAL"] = EXPONENTIAL;
      54          11 :   IndexDist["DETERMINISTIC"] = DETERMINISTIC;
      55          11 :   IndexDist["LOGNORMAL"] = LOGNORMAL;
      56          11 :   IndexDist["TRIANGLE"] = TRIANGLE;
      57          11 :   IndexDist["GEOMETRIC"] = GEOMETRIC;
      58          11 :   IndexDist["ERLANG"] = ERLANG;
      59          11 :   IndexDist["GAMMA"] =GAMMA;
      60          11 :   IndexDist["IMMEDIATE"] = IMMEDIATE;
      61          11 :   IndexDist["USERDEFINED"] = USERDEFINE;
      62             : 
      63             : 
      64          22 :   gspn::Gspn_parser parser(*this);
      65             : 
      66          11 :   parser.set_debug_level(trace_parsing);
      67             : 
      68          11 :   int res = parser.parse();
      69          11 :   scan_end();
      70          22 :   return res;
      71             : }
      72             : 
      73          11 : int Gspn_Reader::parse_file(string &filename) {
      74          22 :   string str;
      75             : 
      76          22 :   ifstream file(filename.c_str(), ios::in);
      77          11 :   if (file) {
      78             : 
      79        1053 :     while (!file.eof()) {
      80             : 
      81        1042 :       string str2;
      82         521 :       getline(file, str2);
      83         521 :       str = str + "\n" + str2;
      84             :     }
      85          11 :     file.close();
      86             : 
      87          11 :     int x = parse(str);
      88             : 
      89          11 :     if (x) cout << "Parsing GSPN Description file failed" << endl;
      90             : 
      91          11 :     return x;
      92             :   } else {
      93           0 :     cout << "Can't open : " << filename << endl;
      94           0 :     return 1;
      95             :   }
      96             : }
      97             : 
      98             : //#include "Gspn_gmlparser.cpp";
      99          23 : int Gspn_Reader::parse_gml_file(parameters &P) {
     100          46 :   ifstream ifile(P.PathGspn.c_str());
     101          23 :   if(ifile){
     102             :     //cout << "parse GML:" << filename << endl;
     103          23 :     spn->nbpass=0;
     104             :     //first pass declaration and place.
     105          23 :     MyModelHandler* handler = new MyModelHandler(*spn);
     106          46 :     ModelHandlerPtr handlerPtr(handler);
     107          46 :     ExpatModelParser parser = ExpatModelParser(handlerPtr);
     108          23 :     parser.parse_file(P.PathGspn);
     109             : 
     110          23 :     spn->nbpass=1;
     111             :     //second pass transitions and arcs.
     112          46 :     ModelHandlerPtr handlerPtr2(new MyModelHandler(*spn,handler->IsPlace,handler->Gml2Place,handler->Gml2Trans));
     113          46 :     ExpatModelParser parser2 = ExpatModelParser(handlerPtr2);
     114             : 
     115          23 :     parser2.parse_file(P.PathGspn);
     116             : 
     117             :     //cout << "end parse GML:"<< spn->pl << endl;
     118          23 :     if (P.RareEvent)addSinkTrans();
     119          46 :     return 0;
     120             :   }else{
     121           0 :     cout << "File " << P.PathGspn << " does not exist!" << endl;
     122           0 :     exit(EXIT_FAILURE);
     123             :   }
     124             : 
     125             : }
     126             : 
     127             : void
     128           0 : Gspn_Reader::error(const gspn::location& l, const std::string& m) {
     129           0 :   std::cerr << l << ": " << m << std::endl;
     130           0 : }
     131             : 
     132             : void
     133           0 : Gspn_Reader::error(const std::string& m) {
     134           0 :   std::cerr << m << std::endl;
     135           0 : }
     136             : 
     137             : 
     138           1 : void Gspn_Reader::addSinkTrans(){
     139           1 :   spn->outArcsStruct.insert(make_pair(spn->arckey(spn->tr-1, spn->pl-1), arc(1)));
     140         106 : }

Generated by: LCOV version 1.13