2012-04-29 18:52:25 +00:00
|
|
|
//
|
|
|
|
// MapConfiguration.cpp
|
|
|
|
//
|
|
|
|
// $Id: //poco/1.4/Util/src/MapConfiguration.cpp#1 $
|
|
|
|
//
|
|
|
|
// Library: Util
|
|
|
|
// Package: Configuration
|
|
|
|
// Module: MapConfiguration
|
|
|
|
//
|
|
|
|
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
|
|
|
// and Contributors.
|
|
|
|
//
|
2014-05-04 21:02:42 +02:00
|
|
|
// SPDX-License-Identifier: BSL-1.0
|
2012-04-29 18:52:25 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
#include "Poco/Util/MapConfiguration.h"
|
|
|
|
#include <set>
|
|
|
|
|
|
|
|
|
|
|
|
namespace Poco {
|
|
|
|
namespace Util {
|
|
|
|
|
|
|
|
|
|
|
|
MapConfiguration::MapConfiguration()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MapConfiguration::~MapConfiguration()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MapConfiguration::clear()
|
|
|
|
{
|
|
|
|
_map.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MapConfiguration::getRaw(const std::string& key, std::string& value) const
|
|
|
|
{
|
|
|
|
StringMap::const_iterator it = _map.find(key);
|
|
|
|
if (it != _map.end())
|
|
|
|
{
|
|
|
|
value = it->second;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MapConfiguration::setRaw(const std::string& key, const std::string& value)
|
|
|
|
{
|
|
|
|
_map[key] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MapConfiguration::enumerate(const std::string& key, Keys& range) const
|
|
|
|
{
|
2015-12-21 09:05:00 +01:00
|
|
|
std::set<std::string> keySet;
|
2012-04-29 18:52:25 +00:00
|
|
|
std::string prefix = key;
|
|
|
|
if (!prefix.empty()) prefix += '.';
|
|
|
|
std::string::size_type psize = prefix.size();
|
|
|
|
for (StringMap::const_iterator it = _map.begin(); it != _map.end(); ++it)
|
|
|
|
{
|
|
|
|
if (it->first.compare(0, psize, prefix) == 0)
|
|
|
|
{
|
|
|
|
std::string subKey;
|
2015-12-21 09:05:00 +01:00
|
|
|
std::string::size_type pos = it->first.find('.', psize);
|
|
|
|
if (pos == std::string::npos)
|
2012-04-29 18:52:25 +00:00
|
|
|
subKey = it->first.substr(psize);
|
|
|
|
else
|
2015-12-21 09:05:00 +01:00
|
|
|
subKey = it->first.substr(psize, pos - psize);
|
|
|
|
if (keySet.find(subKey) == keySet.end())
|
2012-04-29 18:52:25 +00:00
|
|
|
{
|
|
|
|
range.push_back(subKey);
|
2015-12-21 09:05:00 +01:00
|
|
|
keySet.insert(subKey);
|
2012-04-29 18:52:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MapConfiguration::removeRaw(const std::string& key)
|
|
|
|
{
|
|
|
|
std::string prefix = key;
|
|
|
|
if (!prefix.empty()) prefix += '.';
|
|
|
|
std::string::size_type psize = prefix.size();
|
|
|
|
StringMap::iterator it = _map.begin();
|
|
|
|
StringMap::iterator itCur;
|
|
|
|
while (it != _map.end())
|
|
|
|
{
|
|
|
|
itCur = it++;
|
|
|
|
if ((itCur->first == key) || (itCur->first.compare(0, psize, prefix) == 0))
|
|
|
|
{
|
|
|
|
_map.erase(itCur);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MapConfiguration::iterator MapConfiguration::begin() const
|
|
|
|
{
|
|
|
|
return _map.begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MapConfiguration::iterator MapConfiguration::end() const
|
|
|
|
{
|
|
|
|
return _map.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} } // namespace Poco::Util
|