[project @ 2005-01-12 05:36:40 by unknown_lamer]
[clinton/bobotpp.git] / source / BotConfig.H
1 // BotConfig.H -*- C++ -*-
2 // Copyright (C) 2004,2005 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 NOTE: The key is always UPPERCASE internally. Keys are converted
24 automagically to uppercase by the anything that
25
26 */
27
28 #include <map>
29 #include <list>
30 #include <string>
31
32 class BotConfig
33 {
34 public:
35 typedef std::string t_value;
36 typedef std::list<t_value> t_value_list;
37
38 typedef void (*t_watcher) (std::string key, t_value_list vals, bool appended);
39
40 typedef std::list<t_watcher> t_watcher_list;
41 typedef std::pair<t_value_list, t_watcher_list> t_option_values;
42
43 typedef std::map<std::string, t_option_values> t_options_db;
44
45
46 private:
47 t_options_db options_db;
48 std::string config_filename;
49
50 public:
51 BotConfig (std::string); // sets config_filename but DOES NOT read config!
52
53 bool read_config (); // true if read successfully. This also clears the option_db.
54 bool write_config (); // true if written succesfully
55
56 // Getters
57 t_option_values get_option_values (std::string key);
58
59
60
61 // Setters
62 void set_option_value (std::string key, t_value_list values,
63 bool append);
64
65
66 std::string set_config_file (std::string new_filename); // returns
67 // old
68 // filename
69
70 bool add_watcher (std::string key, t_watcher new_watcher); // t if key
71 // exists,
72 // f
73 // otherwise
74 bool clear_watchers (std::string key); // t if key exists, f
75 // otherwise
76
77 // Static Procedures (these are for convinience)
78 t_value_list get_option_value_list (t_option_values v)
79 { return v.first; }
80
81 t_watcher_list get_option_watcher_list (t_option_values v)
82 { return v.second; }
83 };