-
Notifications
You must be signed in to change notification settings - Fork 1
/
access.cpp
193 lines (168 loc) · 7.45 KB
/
access.cpp
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
// Copyright (C) High-Performance Computing Center Stuttgart (https://www.hlrs.de/)
// SPDX-License-Identifier: LGPL-2.1-or-later
#include "access.h"
#include "value.h"
#include "array.h"
#include "file.h"
#include "detail/manager.h"
#include <iostream>
#include <cstdlib>
#include <cassert>
#ifdef CONFIG_NAMESPACE
namespace CONFIG_NAMESPACE {
#endif
namespace config {
using namespace detail;
Bridge::~Bridge() = default;
bool Access::isInitialized()
{
return Manager::exists();
}
Access::Access(): Logger("Access")
{
m_manager = detail::Manager::the();
m_manager->acquire();
}
Access::Access(const std::string &host, const std::string &cluster, int rank): Logger("Access")
{
if (Manager::exists()) {
assert(Manager::the());
m_manager = Manager::the();
if (host != m_manager->hostname() || cluster != m_manager->cluster() || rank != m_manager->rank()) {
if (rank == -1) {
debug() << "not changing rank " << m_manager->rank() << " to " << rank << std::endl;
} else if (m_manager->rank() == -1) {
m_manager->setRank(rank);
} else {
error() << "cannot configure for host=" << host << ", cluster=" << cluster << ":" << rank
<< ", already configured for " << m_manager->hostname() << " in " << m_manager->cluster() << ":"
<< m_manager->rank() << std::endl;
assert(m_manager->hostname() == host);
assert(m_manager->cluster() == cluster);
assert(m_manager->rank() == rank);
m_manager->handleError();
}
}
} else {
m_manager = new Manager(host, cluster, rank);
assert(Manager::the());
}
m_manager->acquire();
}
const std::string &Access::hostname() const
{
assert(m_manager);
return m_manager->hostname();
}
const std::string &Access::cluster() const
{
assert(m_manager);
return m_manager->cluster();
}
void Access::setPrefix(const std::string &dir)
{
assert(m_manager);
m_manager->setPrefix(dir);
}
void Access::setErrorHandler(std::function<void()> handler)
{
}
bool Access::setWorkspaceBridge(Bridge *bridge)
{
assert(m_manager);
if (m_bridge)
return false;
m_bridge = bridge;
m_manager->setWorkspaceBridge(m_bridge);
return true;
}
bool Access::removeWorkspaceBridge(Bridge *bridge)
{
assert(m_manager);
if (m_bridge != bridge)
return false;
m_manager->removeWorkspaceBridge(m_bridge);
m_bridge = nullptr;
return true;
}
bool Access::save()
{
if (!m_manager) {
return false;
}
return m_manager->saveAllAutosave();
}
Access::~Access()
{
if (m_manager) {
removeWorkspaceBridge(m_bridge);
m_manager->release();
}
m_manager = nullptr;
}
std::unique_ptr<File> Access::file(const std::string &path) const
{
return std::make_unique<File>(path, m_manager);
}
template<class V>
std::unique_ptr<Value<V>> Access::value(const std::string &path, const std::string §ion, const std::string &name)
{
return std::make_unique<Value<V>>(path, section, name, m_manager);
}
template<class V>
std::unique_ptr<Value<V>> Access::value(const std::string &path, const std::string §ion, const std::string &name,
const V &def, Flag flags)
{
return std::make_unique<Value<V>>(path, section, name, def, m_manager, flags);
}
template<class V>
std::unique_ptr<Array<V>> Access::array(const std::string &path, const std::string §ion, const std::string &name)
{
return std::make_unique<Array<V>>(path, section, name, m_manager);
}
template<class V>
std::unique_ptr<Array<V>> Access::array(const std::string &path, const std::string §ion, const std::string &name,
const std::vector<V> &def, Flag flags)
{
return std::make_unique<Array<V>>(path, section, name, def, m_manager, flags);
}
template std::unique_ptr<Value<bool>> Access::value(const std::string &path, const std::string §ion,
const std::string &name);
template std::unique_ptr<Value<int64_t>> Access::value(const std::string &path, const std::string §ion,
const std::string &name);
template std::unique_ptr<Value<double>> Access::value(const std::string &path, const std::string §ion,
const std::string &name);
template std::unique_ptr<Value<std::string>> Access::value(const std::string &path, const std::string §ion,
const std::string &name);
template std::unique_ptr<Value<bool>> Access::value(const std::string &path, const std::string §ion,
const std::string &name, const bool &def, Flag flags);
template std::unique_ptr<Value<int64_t>> Access::value(const std::string &path, const std::string §ion,
const std::string &name, const int64_t &def, Flag flags);
template std::unique_ptr<Value<double>> Access::value(const std::string &path, const std::string §ion,
const std::string &name, const double &def, Flag flags);
template std::unique_ptr<Value<std::string>> Access::value(const std::string &path, const std::string §ion,
const std::string &name, const std::string &def,
Flag flags);
template std::unique_ptr<Array<bool>> Access::array(const std::string &path, const std::string §ion,
const std::string &name);
template std::unique_ptr<Array<int64_t>> Access::array(const std::string &path, const std::string §ion,
const std::string &name);
template std::unique_ptr<Array<double>> Access::array(const std::string &path, const std::string §ion,
const std::string &name);
template std::unique_ptr<Array<std::string>> Access::array(const std::string &path, const std::string §ion,
const std::string &name);
template std::unique_ptr<Array<bool>> Access::array(const std::string &path, const std::string §ion,
const std::string &name, const std::vector<bool> &def, Flag flags);
template std::unique_ptr<Array<int64_t>> Access::array(const std::string &path, const std::string §ion,
const std::string &name, const std::vector<int64_t> &def,
Flag flags);
template std::unique_ptr<Array<double>> Access::array(const std::string &path, const std::string §ion,
const std::string &name, const std::vector<double> &def,
Flag flags);
template std::unique_ptr<Array<std::string>> Access::array(const std::string &path, const std::string §ion,
const std::string &name, const std::vector<std::string> &def,
Flag flags);
} // namespace config
#ifdef CONFIG_NAMESPACE
}
#endif