[project @ 2005-06-28 10:57:28 by unknown_lamer]
[clinton/bobotpp.git] / source / BotConfig.H
CommitLineData
6b59e728 1// BotConfig.H -*- C++ -*-
a6339323 2// Copyright (C) 2004,2005 Clinton Ebadi
6b59e728 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
39b022cb 16// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
6b59e728 17
18/*
19 Config Database:
20 map<key,pair<list<string>,list<watcher>>
21 void watcher (key, options, appended?)
22
a6339323 23 NOTE: The key is always UPPERCASE internally. Keys are converted
24 automagically to uppercase by the anything that
25
6b59e728 26*/
27
28#include <map>
29#include <list>
30#include <string>
31
32class BotConfig
33{
34public:
35 typedef std::string t_value;
36 typedef std::list<t_value> t_value_list;
37
f59bce33 38 typedef void (*t_watcher) (std::string key, t_value_list vals, bool appended);
6b59e728 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
46private:
47 t_options_db options_db;
48 std::string config_filename;
49
50public:
a6339323 51 BotConfig (std::string); // sets config_filename but DOES NOT read config!
6b59e728 52
a6339323 53 bool read_config (); // true if read successfully. This also clears the option_db.
6b59e728 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);
f0dad759 64 // Convinience proc
65 void set_option_value (std::string key, t_value value, bool append);
6b59e728 66
67 std::string set_config_file (std::string new_filename); // returns
68 // old
69 // filename
70
71 bool add_watcher (std::string key, t_watcher new_watcher); // t if key
72 // exists,
73 // f
74 // otherwise
75 bool clear_watchers (std::string key); // t if key exists, f
76 // otherwise
77
78 // Static Procedures (these are for convinience)
79 t_value_list get_option_value_list (t_option_values v)
80 { return v.first; }
81
82 t_watcher_list get_option_watcher_list (t_option_values v)
83 { return v.second; }
84};