[project @ 2005-01-06 18:19:16 by unknown_lamer]
[clinton/bobotpp.git] / source / BotConfig.H
1 // BotConfig.H -*- C++ -*-
2 // Copyright (C) 2004 Clinton Ebadi
3
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // any later version.
8
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
17
18 /*
19 Config Database:
20 map<key,pair<list<string>,list<watcher>>
21 void watcher (key, options, appended?)
22
23 */
24
25 #include <map>
26 #include <list>
27 #include <string>
28
29 class BotConfig
30 {
31 public:
32 typedef std::string t_value;
33 typedef std::list<t_value> t_value_list;
34
35 typedef void (*t_watcher) (std::string, t_value_list, bool);
36
37 typedef std::list<t_watcher> t_watcher_list;
38 typedef std::pair<t_value_list, t_watcher_list> t_option_values;
39
40 typedef std::map<std::string, t_option_values> t_options_db;
41
42
43 private:
44 t_options_db options_db;
45 std::string config_filename;
46
47 public:
48 BotConfig (std::string);
49
50 bool read_config (); // true if read successfully
51 bool write_config (); // true if written succesfully
52
53 // Getters
54 t_option_values get_option_values (std::string key);
55
56
57
58 // Setters
59 void set_option_value (std::string key, t_value_list values,
60 bool append);
61
62
63 std::string set_config_file (std::string new_filename); // returns
64 // old
65 // filename
66
67 bool add_watcher (std::string key, t_watcher new_watcher); // t if key
68 // exists,
69 // f
70 // otherwise
71 bool clear_watchers (std::string key); // t if key exists, f
72 // otherwise
73
74 // Static Procedures (these are for convinience)
75 t_value_list get_option_value_list (t_option_values v)
76 { return v.first; }
77
78 t_watcher_list get_option_watcher_list (t_option_values v)
79 { return v.second; }
80 };