-
Notifications
You must be signed in to change notification settings - Fork 0
/
inputparser.cpp
33 lines (28 loc) · 988 Bytes
/
inputparser.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
#include <exception>
#include <fstream>
#include <iostream>
#include "inputparser.h"
rasp4home::InputParser::InputParser(std::string input)
{
std::ifstream file(input);
if(!file.is_open()){
std::cout << "[InputParser] : File not found" << std::endl;
throw std::invalid_argument("File not found");
}
database = nlohmann::json::parse(file);
}
template<typename T>
T rasp4home::InputParser::get(std::string request)
{
try
{
return database.at(request);
}
catch (std::exception &e) {
std::cout << "[InputParser] Failure to get value for key: [" << request << "]" << "(" << e.what() << ")" << std::endl;
throw std::invalid_argument(std::string{"Failure to get value for "} + request);
}
}
template int rasp4home::InputParser::get<int>(std::string request);
template std::string rasp4home::InputParser::get<std::string>(std::string request);
template bool rasp4home::InputParser::get<bool>(std::string request);