0.6.0-1 release
[manu/suphp.git] / src / IniSection.cpp
1 /*
2     suPHP - (c)2002-2005 Sebastian Marsching <sebastian@marsching.com>
3
4     This file is part of suPHP.
5
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.
10
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.
15
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
19 */
20
21 #include <string>
22
23 #include "KeyNotFoundException.hpp"
24
25 #include "IniSection.hpp"
26
27 using namespace suPHP;
28
29 void suPHP::IniSection::putValue(std::string key, std::string value) {
30     std::pair<std::string, std::string> p;
31     p.first = key;
32     p.second = value;
33     this->entries.insert(p);
34 }
35
36 std::vector<std::string> suPHP::IniSection::getValues(std::string key)
37     throw (KeyNotFoundException) {
38     std::vector<std::string> values;
39     for (std::multimap<std::string, std::string>::iterator pos = 
40              this->entries.find(key); 
41          pos != this->entries.end(); pos++) {
42         values.push_back(pos->second);
43     }
44     if (values.size() == 0) {
45         throw KeyNotFoundException("No value for key " + key + " found", 
46                                    __FILE__, __LINE__);
47     }
48     return values;
49 }
50
51 std::string suPHP::IniSection::getValue(std::string key)
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;
56     } else {
57         throw KeyNotFoundException("No value for key " + key + " found", 
58                                    __FILE__, __LINE__);
59     }
60     
61 }
62
63 std::vector<std::string> suPHP::IniSection::getKeys() {
64     std::vector<std::string> keys;
65     for (std::multimap<std::string, std::string>::iterator pos =
66              this->entries.begin();
67          pos != this->entries.end(); pos++) {
68         keys.push_back(pos->first);
69     }
70     return keys;
71 }
72
73 bool suPHP::IniSection::hasKey(std::string key) {
74     if (this->entries.find(key) != this->entries.end()) {
75         return true;
76     } else {
77         return false;
78     }
79     
80 }
81
82 std::vector<std::string> suPHP::IniSection::operator[](std::string key) 
83     throw (KeyNotFoundException) {
84     return this->getValues(key);
85 }