2 libfmail: Generic Search Tree implementation
4 Copyright (C) 2007 Carlos Daniel Ruvalcaba Valenzuela <clsdaniel@gmail.com>
6 This program 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 This program 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 along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include <libfmail/configuration.h>
26 /* TODO: Do checking of file inputs */
27 Configuration::Configuration(char *filename
){
32 Configuration::~Configuration(){
35 int Configuration::Load(char *filename
){
37 std::string buffer
, vname
, eqop
, vvalue
;
39 /* Open Stream to file */
45 conf
>> std::ws
>> vvalue
;
47 conf_map
[vname
] = vvalue
;
53 /* TODO: Implement saving */
54 int Configuration::Save(char *filename
){
60 std::string
Configuration::getString(char *key
, char *default_value
){
61 std::map
<std::string
, std::string
>::iterator it
;
64 if (conf_map
.find(key
) == conf_map
.end()){
65 return std::string(default_value
);
71 const char* Configuration::getCString(char *key
, char *default_value
){
72 if (conf_map
.find(key
) == conf_map
.end()){
76 return conf_map
[key
].c_str();
79 int Configuration::getInt(char *key
, int default_value
){
80 if (conf_map
.find(key
) == conf_map
.end()){
84 return atoi(conf_map
[key
].c_str());
87 float Configuration::getFloat(char *key
, float default_value
){
88 if (conf_map
.find(key
) == conf_map
.end()){
92 return atof(conf_map
[key
].c_str());
95 /* TODO: Fill setString */
96 void Configuration::setString(char *key
, char *value
){
97 conf_map
[key
] = std::string(value
);
100 /* TODO: Fill setInt */
101 void Configuration::setInt(char *key
, int value
){
104 sprintf(buffer
, "%i", value
);
105 conf_map
[key
] = std::string(buffer
);
108 /* TODO: Fill setFloat */
109 void Configuration::setFloat(char *key
, float value
){
112 sprintf(buffer
, "%f", value
);
113 conf_map
[key
] = std::string(buffer
);