Stride Reference Manual  1.0
TransportFacilityReader.cpp
Go to the documentation of this file.
2 #include "StringUtils.h"
3 
4 #include <string>
5 #include <vector>
6 #include <utility>
7 #include <fstream>
8 #include <stdexcept>
9 
10 using namespace std;
11 using namespace stride;
12 using namespace util;
13 
14 vector<pair<string, string>> TransportFacilityReader::readFacilities(string filename) {
15  ifstream my_file(filename.c_str());
16  if (!my_file.good()) {
17  throw invalid_argument("Invalid facility file.");
18  }
19 
20  vector<pair<string, string>> result;
21 
22  string line;
23  getline(my_file, line); // Skip the header
24  while (getline(my_file, line)) {
25  result.push_back(parseFacility(line));
26  }
27 
28  return result;
29 }
30 
31 pair<string, string> TransportFacilityReader::parseFacility(string row) {
32  vector<string> values = StringUtils::split(row, ",");
33 
34  if (values.size() != 2) {
35  throw invalid_argument("Facility file has rows containing " + StringUtils::toString(values.size()) +
36  " elements, it should be 2.");
37  }
38 
39  return make_pair(values[0], values[1]);
40 }
string toString(ClusterType c)
Converts a ClusterType value to corresponding name.
Definition: ClusterType.cpp:54
Time Dependent Person DataType.
Definition: NoBehaviour.h:17
Conversion from or to string.
STL namespace.