Maze Builder Docs 8.2.1
Loading...
Searching...
No Matches
json_helper.h
Go to the documentation of this file.
1#ifndef JSON_HELPER_H
2#define JSON_HELPER_H
3
4#include <string>
5#include <memory>
6#include <unordered_map>
7#include <vector>
8
11namespace mazes
12{
17 {
18 public:
20 explicit json_helper();
21
24
25 // Copy constructor
26 json_helper(const json_helper& other);
27
28 // Copy assignment operator
29 json_helper& operator=(const json_helper& other);
30
31 // Move constructor
32 json_helper(json_helper&& other) noexcept = default;
33
34 // Move assignment operator
35 json_helper& operator=(json_helper&& other) noexcept = default;
36
41 static std::string from(const std::unordered_map<std::string, std::string>& map,
42 int pretty_print = 4) noexcept;
43
48 static std::string from(const std::vector<std::unordered_map<std::string, std::string>>& arr,
49 int pretty_print = 4) noexcept;
50
55 static bool from(const std::string& s, std::unordered_map<std::string, std::string>& m) noexcept;
56
61 static bool load(const std::string& filename, std::unordered_map<std::string, std::string>& m) noexcept;
62
67 static bool from_array(const std::string& s,
68 std::vector<std::unordered_map<std::string, std::string>>& vm) noexcept;
69
74 static bool load_array(const std::string& filename,
75 std::vector<std::unordered_map<std::string, std::string>>& vm) noexcept;
76
77 private:
79 class json_helper_impl;
80 std::unique_ptr<json_helper_impl> impl;
81 };
82} // namespace mazes
83
84#endif // JSON_HELPER_H
JSON helper class.
Definition json_helper.h:17
json_helper()
Default constructor.
static std::string from(const std::unordered_map< std::string, std::string > &map, int pretty_print=4) noexcept
Get the contents of a map as a string in JSON format.
static bool load(const std::string &filename, std::unordered_map< std::string, std::string > &m) noexcept
Parse a JSON file into a C++ map from a file on disk.
static bool load_array(const std::string &filename, std::vector< std::unordered_map< std::string, std::string > > &vm) noexcept
Load a JSON array file into a vector of maps.
static bool from_array(const std::string &s, std::vector< std::unordered_map< std::string, std::string > > &vm) noexcept
Parse a JSON array string into a vector of maps.
~json_helper()
Destructor.