Maze Builder Docs 6.7.5
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
9namespace mazes {
10
16public:
18 explicit json_helper();
19
22
23 // Copy constructor
24 json_helper(const json_helper& other);
25
26 // Copy assignment operator
27 json_helper& operator=(const json_helper& other);
28
29 // Move constructor
30 json_helper(json_helper&& other) noexcept = default;
31
32 // Move assignment operator
33 json_helper& operator=(json_helper&& other) noexcept = default;
34
39 std::string from(const std::unordered_map<std::string, std::string>& map, int pretty_print = 4) const noexcept;
40
45 std::string from(const std::vector<std::unordered_map<std::string, std::string>>& arr, int pretty_print = 4) const noexcept;
46
51 bool from(const std::string& s, std::unordered_map<std::string, std::string>& m) const noexcept;
52
57 bool load(const std::string& filename, std::unordered_map<std::string, std::string>& m) const noexcept;
58
63 bool from_array(const std::string& s, std::vector<std::unordered_map<std::string, std::string>>& vm) const noexcept;
64
69 bool load_array(const std::string& filename, std::vector<std::unordered_map<std::string, std::string>>& vm) const noexcept;
70
71private:
73 class json_helper_impl;
74 std::unique_ptr<json_helper_impl> impl;
75};
76
77} // namespace mazes
78
79#endif // JSON_HELPER_H
JSON helper class.
Definition json_helper.h:15
json_helper()
Default constructor.
bool load(const std::string &filename, std::unordered_map< std::string, std::string > &m) const noexcept
Parse a JSON file into a C++ map from a file on disk.
bool from_array(const std::string &s, std::vector< std::unordered_map< std::string, std::string > > &vm) const noexcept
Parse a JSON array string into a vector of maps.
bool load_array(const std::string &filename, std::vector< std::unordered_map< std::string, std::string > > &vm) const noexcept
Load a JSON array file into a vector of maps.
std::string from(const std::unordered_map< std::string, std::string > &map, int pretty_print=4) const noexcept
Get the contents of a map as a string in JSON format.
~json_helper()
Destructor.
Namespace for the maze builder.
Definition algo_interface.h:9