Add has, get, and set methods to Poco::Message for better control over accessing logging parameters.

This commit is contained in:
Mike Naquin
2013-11-18 14:04:11 -06:00
parent cc224cdd52
commit 4ede322f9d
2 changed files with 64 additions and 1 deletions

View File

@@ -223,6 +223,52 @@ void Message::setSourceLine(int line)
}
bool Message::has(const std::string& param) const
{
return _pMap && (_pMap->find(param) != _pMap->end());
}
const std::string& Message::get(const std::string& param) const
{
if (_pMap)
{
StringMap::const_iterator it = _pMap->find(param);
if (it != _pMap->end())
return it->second;
}
throw NotFoundException();
}
const std::string& Message::get(const std::string& param, const std::string& defaultValue) const
{
if (_pMap)
{
StringMap::const_iterator it = _pMap->find(param);
if (it != _pMap->end())
return it->second;
}
return defaultValue;
}
void Message::set(const std::string& param, const std::string& value)
{
if (!_pMap)
_pMap = new StringMap;
std::pair<StringMap::iterator, bool> result =
_pMap->insert(std::make_pair(param, value));
if (!result.second)
{
result.first->second = value;
}
}
const std::string& Message::operator [] (const std::string& param) const
{
if (_pMap)