X-Git-Url: http://git.home-dn.net/?p=manu%2Fsuphp.git;a=blobdiff_plain;f=src%2FIniSection.cpp;h=e04232463efda98fae0575a1ca176dbcc4309909;hp=4f80c3145c858eaf161b35126d7b848940b6087d;hb=849f4a7977b5780eacae8fad7a078d05f4a615ee;hpb=b0eaa3f1fbf491fdc8a3044cf20754f14254338a diff --git a/src/IniSection.cpp b/src/IniSection.cpp index 4f80c31..e042324 100644 --- a/src/IniSection.cpp +++ b/src/IniSection.cpp @@ -1,5 +1,5 @@ /* - suPHP - (c)2002-2005 Sebastian Marsching + suPHP - (c)2002-2008 Sebastian Marsching This file is part of suPHP. @@ -26,60 +26,64 @@ using namespace suPHP; -void suPHP::IniSection::putValue(std::string key, std::string value) { +void suPHP::IniSection::putValue(const std::string key, const std::string value) { std::pair p; p.first = key; p.second = value; this->entries.insert(p); } -std::vector suPHP::IniSection::getValues(std::string key) +const std::vector suPHP::IniSection::getValues(const std::string& key) const throw (KeyNotFoundException) { std::vector values; - for (std::multimap::iterator pos = - this->entries.find(key); - pos != this->entries.end(); pos++) { - values.push_back(pos->second); + std::pair::const_iterator, std::multimap::const_iterator> range = this->entries.equal_range(key); + for (std::multimap::const_iterator pos = + range.first; pos != range.second; pos++) { + values.push_back(pos->second); } if (values.size() == 0) { - throw KeyNotFoundException("No value for key " + key + " found", - __FILE__, __LINE__); + throw KeyNotFoundException("No value for key " + key + " found", + __FILE__, __LINE__); } return values; } -std::string suPHP::IniSection::getValue(std::string key) +std::string suPHP::IniSection::getValue(const std::string& key) const throw (KeyNotFoundException) { std::vector values; if (this->entries.find(key) != this->entries.end()) { - return this->entries.find(key)->second; + return this->entries.find(key)->second; } else { - throw KeyNotFoundException("No value for key " + key + " found", - __FILE__, __LINE__); + throw KeyNotFoundException("No value for key " + key + " found", + __FILE__, __LINE__); } } -std::vector suPHP::IniSection::getKeys() { +const std::vector suPHP::IniSection::getKeys() const { std::vector keys; - for (std::multimap::iterator pos = - this->entries.begin(); - pos != this->entries.end(); pos++) { - keys.push_back(pos->first); + for (std::multimap::const_iterator pos = + this->entries.begin(); + pos != this->entries.end(); pos++) { + keys.push_back(pos->first); } return keys; } -bool suPHP::IniSection::hasKey(std::string key) { +bool suPHP::IniSection::hasKey(const std::string& key) const { if (this->entries.find(key) != this->entries.end()) { - return true; + return true; } else { - return false; + return false; } } -std::vector suPHP::IniSection::operator[](std::string key) +const std::vector suPHP::IniSection::operator[](const std::string& key) const throw (KeyNotFoundException) { return this->getValues(key); } + +void suPHP::IniSection::removeValues(const std::string& key) { + this->entries.erase(key); +}