-
Notifications
You must be signed in to change notification settings - Fork 26
/
variable_string.h
54 lines (44 loc) · 1.44 KB
/
variable_string.h
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
#pragma once
#include <string>
#include <map>
#include <vector>
namespace Json
{
class Value;
}
struct variable_string
{
struct element_t
{
std::string text;
bool variable;
explicit element_t(const std::string & text);
explicit element_t(const std::string & text, bool variable);
};
struct context_t
{
std::map<std::string, std::string> variables;
context_t() = default;
context_t(const context_t &) = default;
context_t(const context_t &, const std::map<std::string, variable_string> &);
template<typename K>
static inline std::map<K, context_t> map(const context_t & parent, const std::map<K, std::map<std::string, variable_string>> & contexts)
{
std::map<K, context_t> out;
for (auto ctx : contexts)
{
out[ctx.first] = context_t(parent, ctx.second);
}
return out;
}
private:
friend struct variable_string;
std::string operator[](const std::string &) const;
};
std::vector<element_t> contents;
variable_string() = default;
explicit variable_string(const std::string & text);
explicit variable_string(const Json::Value & value);
std::string operator()(const context_t &) const;
};
bool apply_variable_string(variable_string & var, Json::Value & data, const std::string & name, std::string & error, bool append = false);