1 | // |
2 | // ConfigurationView.cpp |
3 | // |
4 | // Library: Util |
5 | // Package: Configuration |
6 | // Module: ConfigurationView |
7 | // |
8 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. |
9 | // and Contributors. |
10 | // |
11 | // SPDX-License-Identifier: BSL-1.0 |
12 | // |
13 | |
14 | |
15 | #include "Poco/Util/ConfigurationView.h" |
16 | |
17 | |
18 | namespace Poco { |
19 | namespace Util { |
20 | |
21 | |
22 | ConfigurationView::ConfigurationView(const std::string& prefix, AbstractConfiguration::Ptr pConfig): |
23 | _prefix(prefix), |
24 | _pConfig(pConfig) |
25 | { |
26 | poco_check_ptr (pConfig); |
27 | } |
28 | |
29 | |
30 | ConfigurationView::~ConfigurationView() |
31 | { |
32 | } |
33 | |
34 | |
35 | bool ConfigurationView::(const std::string& key, std::string& value) const |
36 | { |
37 | std::string translatedKey = translateKey(key); |
38 | return _pConfig->getRaw(translatedKey, value) || _pConfig->getRaw(key, value); |
39 | } |
40 | |
41 | |
42 | void ConfigurationView::setRaw(const std::string& key, const std::string& value) |
43 | { |
44 | std::string translatedKey = translateKey(key); |
45 | _pConfig->setRaw(translatedKey, value); |
46 | } |
47 | |
48 | |
49 | void ConfigurationView::enumerate(const std::string& key, Keys& range) const |
50 | { |
51 | std::string translatedKey = translateKey(key); |
52 | _pConfig->enumerate(translatedKey, range); |
53 | } |
54 | |
55 | |
56 | void ConfigurationView::removeRaw(const std::string& key) |
57 | { |
58 | std::string translatedKey = translateKey(key); |
59 | _pConfig->remove(translatedKey); |
60 | } |
61 | |
62 | |
63 | std::string ConfigurationView::translateKey(const std::string& key) const |
64 | { |
65 | std::string result = _prefix; |
66 | if (!result.empty() && !key.empty() && key[0] != '[') result += '.'; |
67 | result += key; |
68 | return result; |
69 | } |
70 | |
71 | |
72 | } } // namespace Poco::Util |
73 | |