Stride Reference Manual  1.0
SimulatorRunMode.cpp
Go to the documentation of this file.
1 
2 #include "sim/SimulatorRunMode.h"
3 #include <map>
4 #include <boost/algorithm/string.hpp>
5 
6 using namespace stride;
7 using namespace std;
8 using boost::to_lower;
9 
10 
11 map<string, RunMode> SimulatorRunMode::g_name_run_mode {
12  make_pair("initial", RunMode::Initial),
13  make_pair("extend", RunMode::Extend),
14  make_pair("replay", RunMode::Replay),
15  make_pair("extract", RunMode::Extract)
16 };
17 
18 
20  vector<string> modes;
21  #ifdef HDF5_USED
22  for (auto map_entry : SimulatorRunMode::g_name_run_mode) {
23  modes.push_back(map_entry.first);
24  }
25  #else
26  // Only allow initial mode when hdf5 is disabled
27  modes.push_back("initial");
28  #endif
29  return modes;
30 }
31 
32 
34  to_lower(run_mode);
35  if (SimulatorRunMode::g_name_run_mode.count(run_mode) != 1) {
36  string error_string = "\033[0;31mError: \033[0;35m'" +
37  run_mode + "'" + "\033[0m" + " is not a valid run mode." +
38  "\nAccepted run mode(s):\n";
39  for (auto mode : SimulatorRunMode::getAcceptedModes())
40  error_string += "\t* " + mode + '\n';
41  throw std::runtime_error(error_string);
42  }
43 
44  // Exception when HDF5 is forced off -> only Initial mode is valid.
45  #ifndef HDF5_USED
47  throw std::runtime_error(string("\033[0;31m") + "Error: " + string("\033[0m") + "Only run mode " +
48  string("\033[0;35m") + "'Initial'" + string("\033[0m") + " is allowed when running without HDF5.\n");
49  }
50  #endif
51 
52  return SimulatorRunMode::g_name_run_mode[run_mode];
53 }
54 
Time Dependent Person DataType.
Definition: NoBehaviour.h:17
static RunMode getRunMode(string run_mode)
static map< string, RunMode > g_name_run_mode
static vector< string > getAcceptedModes()
STL namespace.