Wittyshare  0.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
WsGlobalProperties.cpp
Go to the documentation of this file.
1 
14 #include "WsGlobalProperties.h"
15 
16 using namespace Json;
17 using namespace std;
18 #include <Include/WsGlobalConfig.h>
19 #include <boost/algorithm/string.hpp>
20 
22 
25 {
26 }
27 
29 {
30  if (m_instance == 0) {
32  LOG(DEBUG) << "WsGlobalProperties :: Created instance";
33  }
34  return m_instance;
35 }
36 
37 
38 std::string WsGlobalProperties::get(const std::string& section, const std::string& id, const std::string& def)
39 {
40  if (!m_parsed) {
42  cerr << "ERROR: WsGlobalProperties :: Could not parse main wittyshare-global.json file... Exiting application" << endl;
43  exit(-1);
44  }
45  }
46  Value val = m_root[section][id];
47  if (val == Value::null)
48  return def;
49  else return val.asString();
50 }
51 
52 std::string WsGlobalProperties::getAndReplace(const std::string& section, const std::string& id, const std::string& newVal, const std::string& def)
53 {
54  if (!m_parsed) {
56  cerr << "ERROR: WsGlobalProperties :: Could not parse main wittyshare-global.json file... Exiting application";
57  exit(-1);
58  }
59  }
60  Value val = m_root[section][id];
61  if (val == Value::null)
62  return def;
63  else {
64  string r = val.asString();
65  boost::replace_all(r, "$1", newVal);
66  return r;
67  }
68 }
69 
70 void WsGlobalProperties::set(const std::string& section, std::string key, std::string value)
71 {
72  if (!m_parsed)
74  cerr << "ERROR: WsGlobalProperties :: Could not parse main wittyshare-global.json file... Exiting application";
75  exit(-1);
76  }
77  m_root[section][key] = value;
78 }
Global properties.
#define DEBUG
Definition: WsLogger.h:27
Global properties class.
const int Failure
int parse(const std::string &path)
parse the Json config file
const std::string GlobalPropertiesPath
static WsGlobalProperties * m_instance
#define LOG
Definition: WsLogger.h:22
WsGlobalProperties()
Constructor.
Abstract Properties class.
std::string get(const std::string &section, const std::string &id, const std::string &def)
const std::string Value
Definition: WsRequestType.h:39
static WsGlobalProperties * instance()
void set(const std::string &section, std::string key, std::string value)
Changes or sets the propety with key 'key' to value 'value' If the property already exist...
std::string getAndReplace(const std::string &section, const std::string &id, const std::string &newVal, const std::string &def)
Search for property id and replaces the $1 in the string with newVal. If the property is not found...