-
Notifications
You must be signed in to change notification settings - Fork 0
/
json_class.hh
43 lines (35 loc) · 1.02 KB
/
json_class.hh
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
#ifndef JSONFILE_H
#define JSONFILE_H
#include "json.hpp"
#include <iostream>
#include <fstream>
// Para usar el mapa escribir:
// const Json_file map_of_runs=Json_file("mi_mapa.json");
// Y luego loopear en el objeto json_map como un iterable, por ejemplo:
// for (auto i:map_of_runs.json_map) {
// if (i["threshold"]>50 && i["threshold"]!=""){cout<<i["run"]<<" "<< i["threshold"]<<endl;}
class Json_file
{
public:
nlohmann::json json_map;
Json_file(){};
Json_file(std::string map_file)
{
std::ifstream i(map_file);
i >> json_map;
}
};
static bool check_json_file(std::string jsonpath)
{
//Check file exists:
std::ifstream f(jsonpath.c_str());
if (!f.good()) throw std::runtime_error("The Json file provided doesn't exist or can't be accessed");
return true;
}
static bool check_is_file_type(std::string file_path,std::string file_type=".json")
{
//Check file is a json:
if (file_path.find(file_type) != std::string::npos) return true;
else return false;
}
#endif