-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjse.h
More file actions
88 lines (65 loc) · 3.16 KB
/
jse.h
File metadata and controls
88 lines (65 loc) · 3.16 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#pragma once
#include <nlohmann/json.hpp>
#include <string>
#include <memory>
namespace jse
{
using json = nlohmann::json;
using string = std::string;
class JSE
{
public:
// verify the input json against the set of rules in specs
bool verify_json(const json &input, const json &rules);
// enriches a given json with default values
json inject_defaults(const json &input, const json &rules);
// enriches a given json spec with included json specs
json inject_include(const json &rules);
// log to string
std::string log2str();
// Working directory
string cwd = ".";
// if strict == false, a json is valid even if it has entries not validated by a rule
bool strict = false;
// do not check the existance of the file pointed in file nodes
bool skip_file_check = true;
// additional directories which can be used for relative paths
std::vector<string> include_directories;
// additional rules that can be used
std::unordered_map<std::string, json> embedded_rules;
// automatic boxing for primitive types
// if all rules fail for a basic type, try boxing it once and try again
bool boxing_primitive = true;
// message list
typedef std::pair<std::string, std::string> log_item;
std::vector<log_item> log;
private:
// Verify a node pointed by
bool verify_json(const string &pointer, json &input, const json &rules);
// Dispatcher for rule verification
bool verify_rule(const json &input, const json &rule);
// Type-specific rule handlers
bool verify_rule_file(const json &input, const json &rule);
bool verify_rule_folder(const json &input, const json &rule);
bool verify_rule_float(const json &input, const json &rule);
bool verify_rule_int(const json &input, const json &rule);
bool verify_rule_string(const json &input, const json &rule);
bool verify_rule_object(const json &input, const json &rule);
bool verify_rule_bool(const json &input, const json &rule);
bool verify_rule_list(const json &input, const json &rule);
bool verify_rule_include(const json &input, const json &rule);
// Collect all rules having a default
json collect_default_rules(const json &rules);
// Collect all rules having a default for a given pointer
json collect_default_rules(const string &pointer, const json &rules);
// Collect all rules having a given pointer
std::vector<json> collect_pointer(const string &pointer, const json &rules);
// Find the first rule matching a pointer
json find_valid_rule(const string &pointer, const json &input, const json &rules);
// Utils
bool contained_in_list(string item, const json &list);
// Checks if a given json pointer is a subset of a pointer string (containing wildcards).
// If it is, the second return parameter is an instantiated pointer
std::tuple<bool, string> is_subset_pointer(const string &json_pointer, const string &pointer);
};
} // namespace jse