Stride Reference Manual  - generated for commit 9643b11
ContactType.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  * Copyright 2018, Jan Broeckhove and Bistromatics group.
15  */
16 
22 #include "ContactType.h"
23 
24 #include <boost/algorithm/string.hpp>
25 #include <map>
26 
27 namespace stride {
28 namespace ContactType {
29 
30 using namespace std;
31 using boost::to_upper;
32 
33 bool IsId(const string& s)
34 {
35  static map<string, Id> ids{
36  make_pair("HOUSEHOLD", Id::Household),
37  make_pair("SCHOOL", Id::K12School),
38  make_pair("SCHOOL", Id::College),
39  make_pair("WORKPLACE", Id::Workplace),
40  make_pair("PRIMARY_COMMUNITY", Id::PrimaryCommunity),
41  make_pair("SECONDARY_COMMUNITY", Id::SecondaryCommunity),
42  };
43  string t{s};
44  to_upper(t);
45  return (ids.count(t) == 1);
46 }
47 
48 Id ToId(const string& s)
49 {
50  static map<string, Id> ids{
51  make_pair("HOUSEHOLD", Id::Household),
52  make_pair("K12SCHOOL", Id::K12School),
53  make_pair("COLLEGE", Id::College),
54  make_pair("WORKPLACE", Id::Workplace),
55  make_pair("PRIMARY_COMMUNITY", Id::PrimaryCommunity),
56  make_pair("SECONDARY_COMMUNITY", Id::SecondaryCommunity),
57  };
58  string t{s};
59  to_upper(t);
60  return (ids.count(t) == 1) ? ids[t] : throw runtime_error("ContactType::ToId> not available:" + t);
61 }
62 
63 string ToString(Id c)
64 {
65  static map<Id, string> names{
66  make_pair(Id::Household, "Household"),
67  make_pair(Id::K12School, "K12School"),
68  make_pair(Id::College, "College"),
69  make_pair(Id::Workplace, "Workplace"),
70  make_pair(Id::PrimaryCommunity, "PrimaryCommunity"),
71  make_pair(Id::SecondaryCommunity, "SecondaryCommunity"),
72  };
73  return (names.count(c) == 1) ? names[c] : throw runtime_error("ContactType::ToString> not available:");
74 }
75 
76 } // namespace ContactType
77 } // namespace stride
bool IsId(const string &s)
Check whether string is name of a ContactPoolType::Id.
Definition: ContactType.cpp:33
Id
Enumerates the ContactPool types.
Definition: ContactType.h:34
Id ToId(const string &s)
Converts a string with name to Id.
Definition: ContactType.cpp:48
STL namespace.
Definition of ContactPool Id Type.
string ToString(Id c)
Converts a ContactPoolType::Id value to corresponding name.
Definition: ContactType.cpp:63
Namespace for the simulator and related classes.
Definition: Calendar.cpp:28