From f59bce334148763520b9c71f1fa9d681e9e795ce Mon Sep 17 00:00:00 2001 From: unknown_lamer Date: Fri, 7 Jan 2005 18:19:38 +0000 Subject: [PATCH] [project @ 2005-01-07 18:19:38 by unknown_lamer] Call watchers from BotConfig::set_watcher_list (BotConfig is almost done) --- ChangeLog | 5 +++++ source/BotConfig.C | 30 +++++++++++++++++++++++++----- source/BotConfig.H | 2 +- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index ebb93ca..ccd7642 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2005-01-07 Clinton Ebadi + + * source/BotConfig.C (set_option_value): call watcher list + (run_fun_): Added to support watcher list calling + 2005-01-06 Clinton Ebadi * source/BotConfig.C (set_option_value): Fuck you STL diff --git a/source/BotConfig.C b/source/BotConfig.C index dd478a9..87c3edd 100644 --- a/source/BotConfig.C +++ b/source/BotConfig.C @@ -99,17 +99,34 @@ namespace : lst (l) {} - void operator()(BotConfig::t_value val) + void operator() (BotConfig::t_value val) { lst->push_back (val); } }; + + struct run_fun_ + { + std::string key; + BotConfig::t_value_list& vals; + bool appended; + + 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); + } + }; } void BotConfig::set_option_value (std::string key, t_value_list values, bool append) { t_options_db::iterator cf_iter = options_db.find (key); + if (cf_iter != options_db.end ()) { if (append) @@ -118,9 +135,12 @@ void BotConfig::set_option_value (std::string key, t_value_list values, std::for_each (values.begin (), values.end (), push_back_ (&cf_iter->second.first)); } - else - cf_iter->second.first = 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)); +} diff --git a/source/BotConfig.H b/source/BotConfig.H index 14dcefe..5d6c61d 100644 --- a/source/BotConfig.H +++ b/source/BotConfig.H @@ -32,7 +32,7 @@ public: typedef std::string t_value; typedef std::list t_value_list; - typedef void (*t_watcher) (std::string, t_value_list, bool); + typedef void (*t_watcher) (std::string key, t_value_list vals, bool appended); typedef std::list t_watcher_list; typedef std::pair t_option_values; -- 2.20.1