blob: 45669b3a227b397ebd4480f856120e4203900390 (
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
75
76
77
78
79
|
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
module;
#include <string>
#include <forward_list>
#include <toml.hpp>
import katja.database;
import katja.repository;
export module katja.configuration;
import katja.component;
export namespace katja
{
struct repository_configuration
{
std::string path;
};
class configuration
{
public:
using repositories_t = std::forward_list<std::pair<std::string, repository_configuration>>;
private:
repositories_t repositories;
public:
void add(const std::string& name, repository_configuration&& repository)
{
this->repositories.emplace_front(name, std::move(repository));
}
repositories_t::iterator begin()
{
return this->repositories.begin();
}
repositories_t::iterator end()
{
return this->repositories.end();
}
repositories_t::const_iterator cbegin()
{
return this->repositories.cbegin();
}
repositories_t::const_iterator cend()
{
return this->repositories.cend();
}
};
}
TOML11_DEFINE_CONVERSION_NON_INTRUSIVE(katja::repository_configuration, path);
export namespace katja
{
configuration read_configuration()
{
auto raw_root = toml::parse("katja.toml");
configuration result;
for (const auto& [root_name, root_value] : raw_root.as_table())
{
auto repository_value = toml::get<repository_configuration>(root_value);
result.add(root_name, std::move(repository_value));
}
return result;
}
}
|