comparison libaudacious++/configdb.cxx @ 2118:36d4043b3df2 trunk

[svn] - add the starting point of some audacious C++ bindings
author nenolod
date Wed, 13 Dec 2006 22:46:29 -0800
parents
children
comparison
equal deleted inserted replaced
2117:5dc1bfb0ac99 2118:36d4043b3df2
1 #include "configdb.hh"
2
3 using namespace Audacious;
4
5 ConfValue::~ConfValue(void)
6 {
7 // make sure we don't leak any string data
8 if (this->strval != NULL)
9 g_free(this->strval);
10 }
11
12 std::string ConfValue::asString(void)
13 {
14 return this->strval;
15 }
16
17 gint ConfValue::asInt(void)
18 {
19 return this->intval;
20 }
21
22 bool ConfValue::asBool(void)
23 {
24 return this->boolval;
25 }
26
27 gfloat ConfValue::asFloat(void)
28 {
29 return this->floatval;
30 }
31
32 gdouble ConfValue::asDouble(void)
33 {
34 return this->dblval;
35 }
36
37 // *************************************************************************
38
39 ConfigDB::ConfigDB(void)
40 {
41 this->db = bmp_cfg_db_open();
42 }
43
44 ConfigDB::~ConfigDB(void)
45 {
46 bmp_cfg_db_close(this->db);
47 }
48
49 ConfValue *ConfigDB::GetValue(std::string &section, std::string &value, ConfigDB::ValueType type)
50 {
51 ConfValue *val = new ConfValue;
52
53 switch(type)
54 {
55 case String:
56 bmp_cfg_db_get_string(this->db, section.c_str(), value.c_str(), &val->strval);
57 break;
58
59 case Int:
60 bmp_cfg_db_get_int(this->db, section.c_str(), value.c_str(), &val->intval);
61 break;
62
63 case Bool:
64 gboolean tmp;
65
66 bmp_cfg_db_get_bool(this->db, section.c_str(), value.c_str(), &tmp);
67
68 if (tmp != 0)
69 val->boolval = true;
70 else
71 val->boolval = false;
72
73 break;
74
75 case Float:
76 bmp_cfg_db_get_float(this->db, section.c_str(), value.c_str(), &val->floatval);
77 break;
78
79 case Double:
80 bmp_cfg_db_get_double(this->db, section.c_str(), value.c_str(), &val->dblval);
81 break;
82
83 default:
84 g_warning("Unknown value passed to Audacious::ConfigDB::GetValue!");
85 break;
86 }
87
88 return val;
89 }
90
91 void ConfigDB::SetValue(std::string &section, std::string &name, std::string &value)
92 {
93 // XXX bmp_cfg_db_set_string should be const char
94 // because it's not, we have to do this:
95
96 gchar *foo = g_strdup(value.c_str());
97
98 bmp_cfg_db_set_string(this->db, section.c_str(), name.c_str(), foo);
99
100 g_free(foo);
101 }
102
103 void ConfigDB::SetValue(std::string &section, std::string &name, gint value)
104 {
105 bmp_cfg_db_set_int(this->db, section.c_str(), name.c_str(), value);
106 }
107
108 void ConfigDB::SetValue(std::string &section, std::string &name, bool value)
109 {
110 bmp_cfg_db_set_bool(this->db, section.c_str(), name.c_str(), value);
111 }
112
113 void ConfigDB::SetValue(std::string &section, std::string &name, gfloat value)
114 {
115 bmp_cfg_db_set_float(this->db, section.c_str(), name.c_str(), value);
116 }
117
118 void ConfigDB::SetValue(std::string &section, std::string &name, gdouble value)
119 {
120 bmp_cfg_db_set_double(this->db, section.c_str(), name.c_str(), value);
121 }