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
18namespace Poco {
19namespace Util {
20
21
22ConfigurationView::ConfigurationView(const std::string& prefix, AbstractConfiguration::Ptr pConfig):
23 _prefix(prefix),
24 _pConfig(pConfig)
25{
26 poco_check_ptr (pConfig);
27}
28
29
30ConfigurationView::~ConfigurationView()
31{
32}
33
34
35bool ConfigurationView::getRaw(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
42void 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
49void ConfigurationView::enumerate(const std::string& key, Keys& range) const
50{
51 std::string translatedKey = translateKey(key);
52 _pConfig->enumerate(translatedKey, range);
53}
54
55
56void ConfigurationView::removeRaw(const std::string& key)
57{
58 std::string translatedKey = translateKey(key);
59 _pConfig->remove(translatedKey);
60}
61
62
63std::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