2 suPHP - (c)2002-2008 Sebastian Marsching <sebastian@marsching.com>
4 This file is part of suPHP.
6 suPHP is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 suPHP is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with suPHP; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "KeyNotFoundException.hpp"
25 #include "IniSection.hpp"
27 using namespace suPHP
;
29 void suPHP::IniSection::putValue(const std::string key
, const std::string value
) {
30 std::pair
<std::string
, std::string
> p
;
33 this->entries
.insert(p
);
36 const std::vector
<std::string
> suPHP::IniSection::getValues(const std::string
& key
) const
37 throw (KeyNotFoundException
) {
38 std::vector
<std::string
> values
;
39 std::pair
<std::multimap
<const std::string
, const std::string
>::const_iterator
, std::multimap
<const std::string
, const std::string
>::const_iterator
> range
= this->entries
.equal_range(key
);
40 for (std::multimap
<const std::string
, const std::string
>::const_iterator pos
=
41 range
.first
; pos
!= range
.second
; pos
++) {
42 values
.push_back(pos
->second
);
44 if (values
.size() == 0) {
45 throw KeyNotFoundException("No value for key " + key
+ " found",
51 std::string
suPHP::IniSection::getValue(const std::string
& key
) const
52 throw (KeyNotFoundException
) {
53 std::vector
<std::string
> values
;
54 if (this->entries
.find(key
) != this->entries
.end()) {
55 return this->entries
.find(key
)->second
;
57 throw KeyNotFoundException("No value for key " + key
+ " found",
63 const std::vector
<std::string
> suPHP::IniSection::getKeys() const {
64 std::vector
<std::string
> keys
;
65 for (std::multimap
<const std::string
, const std::string
>::const_iterator pos
=
66 this->entries
.begin();
67 pos
!= this->entries
.end(); pos
++) {
68 keys
.push_back(pos
->first
);
73 bool suPHP::IniSection::hasKey(const std::string
& key
) const {
74 if (this->entries
.find(key
) != this->entries
.end()) {
82 const std::vector
<std::string
> suPHP::IniSection::operator[](const std::string
& key
) const
83 throw (KeyNotFoundException
) {
84 return this->getValues(key
);
87 void suPHP::IniSection::removeValues(const std::string
& key
) {
88 this->entries
.erase(key
);