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* pConfig): |
23 | _prefix(prefix), |
24 | _pConfig(pConfig) |
25 | { |
26 | poco_check_ptr (pConfig); |
27 | |
28 | _pConfig->duplicate(); |
29 | } |
30 | |
31 | |
32 | ConfigurationView::~ConfigurationView() |
33 | { |
34 | _pConfig->release(); |
35 | } |
36 | |
37 | |
38 | bool ConfigurationView::getRaw(const std::string& key, std::string& value) const |
39 | { |
40 | std::string translatedKey = translateKey(key); |
41 | return _pConfig->getRaw(translatedKey, value) || _pConfig->getRaw(key, value); |
42 | } |
43 | |
44 | |
45 | void ConfigurationView::setRaw(const std::string& key, const std::string& value) |
46 | { |
47 | std::string translatedKey = translateKey(key); |
48 | _pConfig->setRaw(translatedKey, value); |
49 | } |
50 | |
51 | |
52 | void ConfigurationView::enumerate(const std::string& key, Keys& range) const |
53 | { |
54 | std::string translatedKey = translateKey(key); |
55 | _pConfig->enumerate(translatedKey, range); |
56 | } |
57 | |
58 | |
59 | void ConfigurationView::removeRaw(const std::string& key) |
60 | { |
61 | std::string translatedKey = translateKey(key); |
62 | _pConfig->remove(translatedKey); |
63 | } |
64 | |
65 | |
66 | std::string ConfigurationView::translateKey(const std::string& key) const |
67 | { |
68 | std::string result = _prefix; |
69 | if (!result.empty() && !key.empty() && key[0] != '[') result += '.'; |
70 | result += key; |
71 | return result; |
72 | } |
73 | |
74 | |
75 | } } // namespace Poco::Util |
76 | |