-
Notifications
You must be signed in to change notification settings - Fork 0
/
SynapsisBase.cpp
63 lines (57 loc) · 1.54 KB
/
SynapsisBase.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
* File: SynapsisBase.cpp
* Author: teo
*
* Created on December 13, 2015, 4:16 PM
*/
#include "SynapsisBase.hpp"
Json::Value SynapsisBase::settingsRaw;
SynapsisBase::SynapsisBase() {
std::string configFile = "configs/default.json";
this->settingsRaw = this->getJson( 'f', &configFile );
}
SynapsisBase::SynapsisBase(const SynapsisBase& orig) {
}
SynapsisBase::~SynapsisBase() {
}
std::string SynapsisBase::getContFromFile(std::string source) {
std::ifstream in(source, std::ios::in | std::ios::binary);
if (in)
{
std::string contents;
in.seekg(0, std::ios::end);
contents.resize(in.tellg());
in.seekg(0, std::ios::beg);
in.read(&contents[0], contents.size());
in.close();
return(contents);
}
throw(errno);
}
Json::Value SynapsisBase::getSettingsRaw() {
return (this->settingsRaw);
}
Json::Value SynapsisBase::getJson(char type, std::string* sourceOrPath){
Json::Value v;
Json::Reader r;
if(type == 'f') {
std::ifstream in(*sourceOrPath, std::ios::in | std::ios::binary);
if (in) {
std::string contents;
in.seekg(0, std::ios::end);
contents.resize(in.tellg());
in.seekg(0, std::ios::beg);
in.read(&contents[0], contents.size());
in.close();
if(!r.parse(contents,v,false))
throw(errno);
}
}
else {
if(!r.parse(*sourceOrPath,v,false)) {
lall("Instruction in bad format ( no json ). Exit");
throw(errno);
}
}
return v;
}