Stochastic Loading Module
json_object.h
1 #ifndef _JSON_OBJECT_H_
2 #define _JSON_OBJECT_H_
3 
4 #include <iomanip>
5 #include <iostream>
6 // JSON for Modern C++ single-include header
7 #include <nlohmann_json/json.hpp>
8 
9 namespace utilities {
10 // Alias for JSON type
11  using json = nlohmann::json;
12 
16 class JsonObject {
17  public:
21  friend std::ostream& operator<<(std::ostream& out, const utilities::JsonObject& json_object);
22 
26  JsonObject();
27 
31  virtual ~JsonObject() {};
32 
38  inline bool operator==(const JsonObject& json_value) const {
39  return json_object_ == json_value.json_object_;
40  };
41 
47  inline bool operator!=(const JsonObject& json_value) const {
48  return !(*this == json_value);
49  };
50 
59  template <typename Tparam>
60  bool add_value(const std::string& key, const Tparam& value);
61 
68  template <typename Tparam>
69  Tparam get_value(const std::string& key) const;
70 
76  bool delete_key(const std::string& key);
77 
83  bool write_to_file(const std::string& output_location) const;
84 
88  void clear();
89 
94  bool is_empty() const;
95 
100  unsigned int get_size() const;
101 
106  json get_library_json() const {
107  return json_object_;
108  };
109 
110  protected:
115  JsonObject(json library_json);
116 
118 };
119 
126 inline std::ostream& operator<<(std::ostream& out, const utilities::JsonObject& json_object) {
127  out << std::setw(4) << json_object.json_object_;
128  return out;
129 };
130 } // namespace utilities
131 
132 #include "json_object.tcc"
133 
134 #endif // _JSON_OBJECT_H_
bool write_to_file(const std::string &output_location) const
Definition: json_object.cc:36
friend std::ostream & operator<<(std::ostream &out, const utilities::JsonObject &json_object)
Definition: json_object.h:126
Tparam get_value(const std::string &key) const
bool add_value(const std::string &key, const Tparam &value)
bool delete_key(const std::string &key)
Definition: json_object.cc:21
bool operator==(const JsonObject &json_value) const
Definition: json_object.h:38
bool operator!=(const JsonObject &json_value) const
Definition: json_object.h:47
unsigned int get_size() const
Definition: json_object.cc:72
json get_library_json() const
Definition: json_object.h:106
bool is_empty() const
Definition: json_object.cc:68