blob: c27046bf3215ffd29e6ac2af23178205e4cd54e9 (
plain)
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
|
#ifndef SIBS_CONF_HPP
#define SIBS_CONF_HPP
#include "Result.hpp"
#include "StringView.hpp"
#include "utils.hpp"
#include <vector>
#include <cassert>
namespace sibs
{
class ConfigValue
{
public:
enum class Type
{
NONE,
SINGLE,
LIST
};
ConfigValue() : type(Type::NONE) {}
ConfigValue(StringView value) :
type(Type::SINGLE)
{
values.push_back(value);
}
ConfigValue(const std::vector<StringView> &_values) :
type(Type::LIST),
values(_values)
{
}
bool isSingle() const { return type == Type::SINGLE; }
bool isList() const { return type == Type::LIST; }
StringView asSingle() const
{
assert(isSingle());
return values[0];
}
const std::vector<StringView> asList() const
{
assert(isList());
return values;
}
private:
Type type;
std::vector<StringView> values;
};
class Parser;
class ConfigCallback
{
friend class Parser;
protected:
virtual void processObject(StringView name) = 0;
virtual void processField(StringView name, const ConfigValue &value) = 0;
virtual void finished() = 0;
};
class Config
{
public:
static Result<bool> readFromFile(const char *filepath, const ConfigCallback &callback);
};
}
#endif //SIBS_CONF_HPP
|