X-Git-Url: http://git.hcoop.net/clinton/bobotpp.git/blobdiff_plain/a63393232f9a19067d58d12065255a10a053f723..HEAD:/source/BotConfig.C diff --git a/source/BotConfig.C b/source/BotConfig.C index 82a8035..3344964 100644 --- a/source/BotConfig.C +++ b/source/BotConfig.C @@ -13,7 +13,7 @@ // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "BotConfig.H" #include "Bot.H" @@ -56,15 +56,11 @@ BotConfig::read_config () continue; } - // This is broken because overwrites existing values StringTokenizer st (current_line); std::string command = Utils::to_upper (Utils::trim_str(st.next_token('='))); StringTokenizer params (Utils::trim_str (st.next_token('='))); - options_db[command] = t_option_values (t_value_list (), - t_watcher_list ()); - options_db[command].first.push_back (params.rest ()); - + set_option_value (command, params.rest (), true); } return true; } @@ -116,8 +112,7 @@ namespace run_fun_ (std::string k, BotConfig::t_value_list& vl, bool a) : key (k), vals (vl), appended (a) - {} - + { } void operator() (BotConfig::t_watcher w) { w (key, vals, appended); @@ -129,7 +124,9 @@ void BotConfig::set_option_value (std::string key, t_value_list values, bool append) { + key = Utils::to_upper (key); // keys are case insensitive t_options_db::iterator cf_iter = options_db.find (key); + if (cf_iter != options_db.end ()) { @@ -141,14 +138,23 @@ BotConfig::set_option_value (std::string key, t_value_list values, } else cf_iter->second.first = values; + + // call watchers + std::for_each (cf_iter->second.second.begin (), + cf_iter->second.second.end (), + run_fun_ (key, values, append)); } else options_db[key] = t_option_values (values, t_watcher_list ()); +} + +void +BotConfig::set_option_value (std::string key, t_value value, bool append) +{ + t_value_list value_list = t_value_list (); + value_list.push_front (value); - // Call Watchers - std::for_each (cf_iter->second.second.begin (), - cf_iter->second.second.end (), - run_fun_ (key, values, append)); + set_option_value (key, value_list, append); } bool