Stride Reference Manual  - generated for commit 9643b11
Id.cpp
Go to the documentation of this file.
1 /*
2  * This is free software: you can redistribute it and/or modify it
3  * under the terms of the GNU General Public License as published by
4  * the Free Software Foundation, either version 3 of the License, or
5  * any later version.
6  * The software is distributed in the hope that it will be useful,
7  * but WITHOUT ANY WARRANTY; without even the implied warranty of
8  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9  * GNU General Public License for more details.
10  * You should have received a copy of the GNU General Public License
11  * along with the software. If not, see <http://www.gnu.org/licenses/>.
12  *
13  * Copyright 2017, Kuylen E, Willem L, Broeckhove J
14  */
15 
21 #include "Id.h"
22 
23 #include <boost/algorithm/string.hpp>
24 #include <map>
25 
26 namespace stride {
27 namespace sim_event {
28 
29 using namespace std;
30 using boost::to_upper;
31 
32 bool IsType(const string& s)
33 {
34  static map<string, Id> ids{make_pair("ATSTART", Id::AtStart), make_pair("STEPPED", Id::Stepped),
35  make_pair("FINISHED", Id::Finished), make_pair("SETUPBEGIN", Id::SetupBegin),
36  make_pair("SETUPEND", Id::SetupEnd)};
37  string t{s};
38  to_upper(t);
39  return (ids.count(t) == 1);
40 }
41 
42 string ToString(Id c)
43 {
44  static map<Id, string> names{make_pair(Id::AtStart, "atstart"), make_pair(Id::Stepped, "stepped"),
45  make_pair(Id::Finished, "finished"), make_pair(Id::SetupBegin, "setupbegin"),
46  make_pair(Id::SetupEnd, "setupend")};
47  return (names.count(c) == 1) ? names[c] : "null";
48 }
49 
50 Id ToType(const string& s)
51 {
52  static map<string, Id> ids{make_pair("ATSTART", Id::AtStart), make_pair("STEPPED", Id::Stepped),
53  make_pair("FINISHED", Id::Finished), make_pair("SETUPBEGIN", Id::SetupBegin),
54  make_pair("SETUPEND", Id::SetupEnd)};
55  string t{s};
56  to_upper(t);
57  return (ids.count(t) == 1) ? ids[t] : throw runtime_error("EventId::ToString> not available:" + t);
58 }
59 
60 } // namespace sim_event
61 } // namespace stride
Id ToType(const string &s)
Converts a string with name to Id.
Definition: Id.cpp:50
Id
Enumerates the event.
Definition: Id.h:30
STL namespace.
string ToString(Id c)
Converts a ContactPoolType::Id value to corresponding name.
Definition: Id.cpp:42
bool IsType(const string &s)
Check whether string is name of a ContactPoolType::Id.
Definition: Id.cpp:32
Namespace for the simulator and related classes.
Definition: Calendar.cpp:28
Definition of EventId.