RINASim  October 2016
Documentation of framework for OMNeT++
Stats.h
Go to the documentation of this file.
1 // The MIT License (MIT)
2 //
3 // Copyright (c) 2015-2016 TSSG, Waterford Institute of Technology, PRISTINE project
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 // THE SOFTWARE.
22 
23 #ifndef __RINA_STATS_H_
24 #define __RINA_STATS_H_
25 
26 //Standard libraries
27 #include <omnetpp.h>
28 #include <algorithm>
29 #include <fstream>
30 class Stats
31 {
32  private:
33  // trim string for empty spaces in begining and at the end
34  inline std::string &trim(std::string &s)
35  {
36 
37  s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
38  s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end());
39  return s;
40  }
41 
42  private:
43  std::map<std::pair<unsigned int, unsigned int>, std::string> m_oData;
44 
45  unsigned int m_nCols;
46  unsigned int m_nRows;
47  const int MAX_LOAD = 100;
48 
49  public:
50  Stats();
51  virtual ~Stats();
52  //bool open( const char* filename, char delim);
53  bool open( );
54  void open_now( std::istream& istream, char delim);
55  bool save( );
56  //bool save( const char* pFile, char delim);
57  void save_now( std::ostream& ostream, char delim);
58  std::pair<unsigned int, unsigned int> searchPair(std::string str);
59  std::string toString(int i);
60  const char *filename;
61  char delim;
62  int toInt(std::string str);
63  int rowCount();
64  int getLoad(std::string apn);
65  void updateLoad(std::string apn, std::string api, std::string aen, std::string aei, bool increment);
66  void rowErase(unsigned int row);
67 
68  void clear();
69  std::string& operator()( unsigned int nCol, unsigned int nRow )
70  {
71  m_nCols = std::max( m_nCols, nCol+1 );
72  m_nRows = std::max( m_nRows, nRow+1 );
73  return m_oData[std::make_pair(nCol, nRow)];
74  }
75 
76  inline unsigned int GetRows() { return m_nRows; }
77  inline unsigned int GetCols() { return m_nCols; }
78 
79  std::string getBestApp(std::string srcApp, std::string dstApp, std::string allApps);
80 };
81 #endif
void rowErase(unsigned int row)
Definition: Stats.cc:197
Definition: Stats.h:30
virtual ~Stats()
Definition: Stats.cc:35
std::string getBestApp(std::string srcApp, std::string dstApp, std::string allApps)
Definition: Stats.cc:242
int toInt(std::string str)
Definition: Stats.cc:237
std::string & operator()(unsigned int nCol, unsigned int nRow)
Definition: Stats.h:69
const int MAX_LOAD
Definition: Stats.h:47
std::string & trim(std::string &s)
Definition: Stats.h:34
std::map< std::pair< unsigned int, unsigned int >, std::string > m_oData
Definition: Stats.h:43
Stats()
Definition: Stats.cc:26
int rowCount()
Definition: Stats.cc:217
unsigned int GetCols()
Definition: Stats.h:77
void open_now(std::istream &istream, char delim)
Definition: Stats.cc:56
void save_now(std::ostream &ostream, char delim)
Definition: Stats.cc:91
bool save()
Definition: Stats.cc:78
char delim
Definition: Stats.h:61
unsigned int GetRows()
Definition: Stats.h:76
int getLoad(std::string apn)
Definition: Stats.cc:116
void updateLoad(std::string apn, std::string api, std::string aen, std::string aei, bool increment)
Definition: Stats.cc:133
unsigned int m_nRows
Definition: Stats.h:46
unsigned int m_nCols
Definition: Stats.h:45
void clear()
Definition: Stats.cc:110
std::string toString(int i)
Definition: Stats.cc:230
const char * filename
Definition: Stats.h:60
std::pair< unsigned int, unsigned int > searchPair(std::string str)
Definition: Stats.cc:180
bool open()
Definition: Stats.cc:40