Jpp  master_rocky-40-g5f0272dcd
the software that should make you happy
JSon.hh
Go to the documentation of this file.
1 #ifndef __JSON__JSON__
2 #define __JSON__JSON__
3 
4 #include <fstream>
5 #include <iomanip>
6 
7 #include "nlohmann/json.hpp"
8 
9 
10 /**
11  * \author mdejong
12  */
13 
14 namespace JSON {}
15 namespace JPP { using namespace JSON; }
16 
17 namespace JSON {
18 
19  using nlohmann::json;
20 
21 
22  /**
23  * Load json data from input file.
24  *
25  * \param file_name file name
26  * \param object json data
27  */
28  inline void load(const std::string& file_name, json& object)
29  {
30  using namespace std;
31 
32  ifstream in(file_name.c_str());
33 
34  in >> object;
35 
36  in.close();
37  }
38 
39 
40  /**
41  * Store json data to output file.
42  *
43  * \param file_name file name
44  * \param object json data
45  */
46  inline void store(const std::string& file_name, const json& object)
47  {
48  using namespace std;
49 
50  ofstream out(file_name.c_str());
51 
52  out << setw(2) << setprecision(8) << object;
53 
54  out.close();
55  }
56 
57 
58  /**
59  * Auxiliary class to load json data from file.
60  */
61  struct JSon :
62  public json
63  {
64  /**
65  * Constructor.
66  *
67  * \param file_name file name
68  */
69  JSon(const std::string& file_name)
70  {
71  load(file_name, *this);
72  }
73  };
74 }
75 
76 #endif
nlohmann::json json
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary classes and methods for detector calibration.
void store(const std::string &file_name, const json &object)
Store json data to output file.
Definition: JSon.hh:46
void load(const std::string &file_name, json &object)
Load json data from input file.
Definition: JSon.hh:28
Definition: JSTDTypes.hh:14
Auxiliary class to load json data from file.
Definition: JSon.hh:63
JSon(const std::string &file_name)
Constructor.
Definition: JSon.hh:69