1//
2// MapConfiguration.cpp
3//
4// Library: Util
5// Package: Configuration
6// Module: MapConfiguration
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/MapConfiguration.h"
16#include <set>
17
18
19namespace Poco {
20namespace Util {
21
22
23MapConfiguration::MapConfiguration()
24{
25}
26
27
28MapConfiguration::~MapConfiguration()
29{
30}
31
32
33void MapConfiguration::copyTo(AbstractConfiguration& config)
34{
35 for (iterator it = _map.begin(); it != _map.end(); ++it)
36 {
37 config.setString(it->first, it->second);
38 }
39}
40
41
42void MapConfiguration::clear()
43{
44 _map.clear();
45}
46
47
48bool MapConfiguration::getRaw(const std::string& key, std::string& value) const
49{
50 StringMap::const_iterator it = _map.find(key);
51 if (it != _map.end())
52 {
53 value = it->second;
54 return true;
55 }
56 else return false;
57}
58
59
60void MapConfiguration::setRaw(const std::string& key, const std::string& value)
61{
62 _map[key] = value;
63}
64
65
66void MapConfiguration::enumerate(const std::string& key, Keys& range) const
67{
68 std::set<std::string> keySet;
69 std::string prefix = key;
70 if (!prefix.empty()) prefix += '.';
71 std::string::size_type psize = prefix.size();
72 for (StringMap::const_iterator it = _map.begin(); it != _map.end(); ++it)
73 {
74 if (it->first.compare(0, psize, prefix) == 0)
75 {
76 std::string subKey;
77 std::string::size_type pos = it->first.find('.', psize);
78 if (pos == std::string::npos)
79 subKey = it->first.substr(psize);
80 else
81 subKey = it->first.substr(psize, pos - psize);
82 if (keySet.find(subKey) == keySet.end())
83 {
84 range.push_back(subKey);
85 keySet.insert(subKey);
86 }
87 }
88 }
89}
90
91
92void MapConfiguration::removeRaw(const std::string& key)
93{
94 std::string prefix = key;
95 if (!prefix.empty()) prefix += '.';
96 std::string::size_type psize = prefix.size();
97 StringMap::iterator it = _map.begin();
98 StringMap::iterator itCur;
99 while (it != _map.end())
100 {
101 itCur = it++;
102 if ((itCur->first == key) || (itCur->first.compare(0, psize, prefix) == 0))
103 {
104 _map.erase(itCur);
105 }
106 }
107}
108
109
110MapConfiguration::iterator MapConfiguration::begin() const
111{
112 return _map.begin();
113}
114
115
116MapConfiguration::iterator MapConfiguration::end() const
117{
118 return _map.end();
119}
120
121
122} } // namespace Poco::Util
123