blob: a21ea86b510b82f8f74f9fe5bf5d3938b62e79a0 [file] [log] [blame]
dburgess82c46ff2011-10-07 02:40:51 +00001/*
2* Copyright 2009, 2010 Free Software Foundation, Inc.
3* Copyright 2010 Kestrel Signal Processing, Inc.
4*
5*
6* This software is distributed under the terms of the GNU Affero Public License.
7* See the COPYING file in the main directory for details.
8*
9* This use of this software may be subject to additional restrictions.
10* See the LEGAL file in the main directory for details.
11
12 This program is free software: you can redistribute it and/or modify
13 it under the terms of the GNU Affero General Public License as published by
14 the Free Software Foundation, either version 3 of the License, or
15 (at your option) any later version.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU Affero General Public License for more details.
21
22 You should have received a copy of the GNU Affero General Public License
23 along with this program. If not, see <http://www.gnu.org/licenses/>.
24
25*/
26
27
28
29#include "Configuration.h"
30#include <iostream>
kurtis.heimerlbcf60a82012-10-26 06:25:56 +000031#include <string>
dburgess82c46ff2011-10-07 02:40:51 +000032
33using namespace std;
34
kurtis.heimerl00913d72012-12-16 06:08:18 +000035ConfigurationTable gConfig("exampleconfig.db","test");
dburgess82c46ff2011-10-07 02:40:51 +000036
37void purgeConfig(void*,int,char const*, char const*, sqlite3_int64)
38{
39 //cout << "update hook" << endl;
40 gConfig.purge();
41}
42
43
44int main(int argc, char *argv[])
45{
46
47 gConfig.setUpdateHook(purgeConfig);
48
49 char *keys[5] = {"key1", "key2", "key3", "key4", "key5"};
50
51 for (int i=0; i<5; i++) {
52 gConfig.set(keys[i],i);
53 }
54
55 for (int i=0; i<5; i++) {
56 cout << "table[" << keys[i] << "]=" << gConfig.getStr(keys[i]) << endl;
57 cout << "table[" << keys[i] << "]=" << gConfig.getNum(keys[i]) << endl;
58 }
59
60 gConfig.unset("key1");
61 for (int i=0; i<5; i++) {
62 cout << "defined table[" << keys[i] << "]=" << gConfig.defines(keys[i]) << endl;
63 }
64
kurtis.heimerlbcf60a82012-10-26 06:25:56 +000065 gConfig.set("key5","100 200 300 400 ");
dburgess82c46ff2011-10-07 02:40:51 +000066 std::vector<unsigned> vect = gConfig.getVector("key5");
67 cout << "vect length " << vect.size() << ": ";
68 for (unsigned i=0; i<vect.size(); i++) cout << " " << vect[i];
69 cout << endl;
kurtis.heimerlbcf60a82012-10-26 06:25:56 +000070 std::vector<string> svect = gConfig.getVectorOfStrings("key5");
71 cout << "vect length " << svect.size() << ": ";
72 for (unsigned i=0; i<svect.size(); i++) cout << " " << svect[i] << ":";
73 cout << endl;
74
75 cout << "bool " << gConfig.getBool("booltest") << endl;
76 gConfig.set("booltest",1);
77 cout << "bool " << gConfig.getBool("booltest") << endl;
78 gConfig.set("booltest",0);
79 cout << "bool " << gConfig.getBool("booltest") << endl;
80
81 gConfig.getStr("newstring","new string value");
82 gConfig.getNum("numnumber",42);
83
84
85 SimpleKeyValue pairs;
86 pairs.addItems(" a=1 b=34 dd=143 ");
87 cout<< pairs.get("a") << endl;
88 cout<< pairs.get("b") << endl;
89 cout<< pairs.get("dd") << endl;
90
91 gConfig.set("fkey","123.456");
92 float fval = gConfig.getFloat("fkey");
93 cout << "fkey " << fval << endl;
94
95 cout << "search fkey:" << endl;
96 gConfig.find("fkey",cout);
97 gConfig.unset("fkey");
98 cout << "search fkey:" << endl;
99 gConfig.find("fkey",cout);
100 gConfig.remove("fkey");
101 cout << "search fkey:" << endl;
102 gConfig.find("fkey",cout);
103
kurtis.heimerl42267fd2012-11-11 10:15:43 +0000104 try {
105 gConfig.getNum("supposedtoabort");
106 } catch (ConfigurationTableKeyNotFound) {
107 cout << "ConfigurationTableKeyNotFound exception successfully caught." << endl;
108 }
dburgess82c46ff2011-10-07 02:40:51 +0000109}