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 */
46 conf
>> std::ws
>> vvalue
;
48 conf_map
[vname
] = vvalue
;
56 /* TODO: Implement saving */
57 int Configuration::Save(char *filename
){
63 std::string
Configuration::getString(char *key
, char *default_value
){
64 std::map
<std::string
, std::string
>::iterator it
;
67 if (conf_map
.find(key
) == conf_map
.end()){
68 return std::string(default_value
);
74 const char* Configuration::getCString(char *key
, char *default_value
){
75 if (conf_map
.find(key
) == conf_map
.end()){
79 return conf_map
[key
].c_str();
82 int Configuration::getInt(char *key
, int default_value
){
83 if (conf_map
.find(key
) == conf_map
.end()){
87 return atoi(conf_map
[key
].c_str());
90 float Configuration::getFloat(char *key
, float default_value
){
91 if (conf_map
.find(key
) == conf_map
.end()){
95 return atof(conf_map
[key
].c_str());
98 /* TODO: Fill setString */
99 void Configuration::setString(char *key
, char *value
){
100 conf_map
[key
] = std::string(value
);
103 /* TODO: Fill setInt */
104 void Configuration::setInt(char *key
, int value
){
107 sprintf(buffer
, "%i", value
);
108 conf_map
[key
] = std::string(buffer
);
111 /* TODO: Fill setFloat */
112 void Configuration::setFloat(char *key
, float value
){
115 sprintf(buffer
, "%f", value
);
116 conf_map
[key
] = std::string(buffer
);