mirror of
https://github.com/pocoproject/poco.git
synced 2024-12-13 18:45:10 +01:00
Merge pull request #330 from syvex/feature/MessageParams
Add has, get, and set methods to Poco::Message
This commit is contained in:
commit
ae10cf754b
@ -177,7 +177,24 @@ public:
|
||||
/// Returns the source file line of the statement
|
||||
/// generating the log message. May be 0
|
||||
/// if not set.
|
||||
|
||||
|
||||
bool has(const std::string& param) const;
|
||||
/// Returns true if a parameter with the given name exists.
|
||||
|
||||
const std::string& get(const std::string& param) const;
|
||||
/// Returns a const reference to the value of the parameter
|
||||
/// with the given name. Throws a NotFoundException if the
|
||||
/// parameter does not exist.
|
||||
|
||||
const std::string& get(const std::string& param, const std::string& defaultValue) const;
|
||||
/// Returns a const reference to the value of the parameter
|
||||
/// with the given name. If the parameter with the given name
|
||||
/// does not exist, then defaultValue is returned.
|
||||
|
||||
void set(const std::string& param, const std::string& value);
|
||||
/// Sets the value for a parameter. If the parameter does
|
||||
/// not exist, then it is created.
|
||||
|
||||
const std::string& operator [] (const std::string& param) const;
|
||||
/// Returns a const reference to the value of the parameter
|
||||
/// with the given name. Throws a NotFoundException if the
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user