Added queue subscribe IPC documentation
[fmail.git] / src / configuration.cpp
blobe412e77854c4b297a33f9fc4b856f124921e69ff
1 /*
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.
21 #include <string>
22 #include <map>
23 #include <fstream>
24 #include <libfmail/configuration.h>
26 /* TODO: Do checking of file inputs */
27 Configuration::Configuration(char *filename){
28 if (filename)
29 this->Load(filename);
32 Configuration::~Configuration(){
35 int Configuration::Load(char *filename){
36 std::fstream conf;
37 std::string buffer, vname, eqop, vvalue;
39 /* Open Stream to file */
40 conf.open(filename);
42 while (!conf.eof()){
43 conf >> vname;
44 conf >> eqop;
45 conf >> std::ws >> vvalue;
46 if (eqop == "=")
47 conf_map[vname] = vvalue;
50 return 0;
53 /* TODO: Implement saving */
54 int Configuration::Save(char *filename){
55 if (filename)
56 return 0;
57 return 1;
60 std::string Configuration::getString(char *key, char *default_value){
61 std::map<std::string, std::string>::iterator it;
62 std::string ret;
64 if (conf_map.find(key) == conf_map.end()){
65 return std::string(default_value);
68 return conf_map[key];
71 const char* Configuration::getCString(char *key, char *default_value){
72 if (conf_map.find(key) == conf_map.end()){
73 return default_value;
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()){
81 return default_value;
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()){
89 return default_value;
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){
102 char buffer[32];
104 sprintf(buffer, "%i", value);
105 conf_map[key] = std::string(buffer);
108 /* TODO: Fill setFloat */
109 void Configuration::setFloat(char *key, float value){
110 char buffer[32];
112 sprintf(buffer, "%f", value);
113 conf_map[key] = std::string(buffer);