Stride Reference Manual  1.0
ClusterType.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 2015, Willem L, Kuylen E, Stijven S & Broeckhove J
14  */
15 
21 #include "ClusterType.h"
22 
23 #include <boost/algorithm/string.hpp>
24 #include <map>
25 
26 namespace {
27 
29 using boost::to_upper;
30 using namespace std;
31 
32 map<ClusterType, string> g_cluster_type_name {
33  make_pair(ClusterType::Household, "household"),
34  make_pair(ClusterType::School, "school"),
35  make_pair(ClusterType::Work, "work"),
36  make_pair(ClusterType::PrimaryCommunity, "primary_community"),
37  make_pair(ClusterType::SecondaryCommunity, "secondary_community"),
38  make_pair(ClusterType::Null, "null")
39 };
40 
41 map<string, ClusterType> g_name_cluster_type {
42  make_pair("HOUSEHOLD", ClusterType::Household),
43  make_pair("SCHOOL", ClusterType::School),
44  make_pair("WORK", ClusterType::Work),
45  make_pair("PRIMARY_COMMUNITY", ClusterType::PrimaryCommunity),
46  make_pair("SECONDARY_COMMUNITY", ClusterType::SecondaryCommunity),
47  make_pair("NULL", ClusterType::Null)
48 };
49 
50 }
51 
52 namespace stride {
53 
54 string toString(ClusterType c) {
55  return (g_cluster_type_name.count(c) == 1) ? g_cluster_type_name[c] : "Null";
56 }
57 
58 bool isClusterType(const string& s) {
59  std::string t {s};
60  to_upper(t);
61  return (g_name_cluster_type.count(t) == 1);
62 }
63 
64 ClusterType toClusterType(const string& s) {
65  std::string t {s};
66  to_upper(t);
67  return (g_name_cluster_type.count(t) == 1) ? g_name_cluster_type[t] : ClusterType::Null;
68 }
69 
70 }
string toString(ClusterType c)
Converts a ClusterType value to corresponding name.
Definition: ClusterType.cpp:54
Time Dependent Person DataType.
Definition: NoBehaviour.h:17
ClusterType toClusterType(const string &s)
Converts a string with name to ClusterType value.
Definition: ClusterType.cpp:64
bool isClusterType(const string &s)
Check whether string is name of a ClusterType value.
Definition: ClusterType.cpp:58
Definition of ClusterType.
STL namespace.
ClusterType
Enumerates the cluster types.
Definition: ClusterType.h:28