// BotConfig.C -*- C++ -*-
-// Copyright (C) 2004 Clinton Ebadi
+// Copyright (C) 2004,2005 Clinton Ebadi
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
#include "BotConfig.H"
#include "Bot.H"
#include "StringTokenizer.H"
+#include "Utils.H"
#include <iostream>
#include <string>
#include <list>
: config_filename (cf)
{ }
-bool BotConfig::read_config ()
+bool
+BotConfig::read_config ()
{
std::ifstream config_file (config_filename.c_str ());
std::string current_line;
continue;
}
+ // This is broken because overwrites existing values
StringTokenizer st (current_line);
- std::string command = st.nextToken('=').trim().toUpper();
- StringTokenizer params (st.nextToken('=').trim());
+ 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 ());
- while (params.hasMoreTokens (','))
- {
- options_db[command].first.push_back (params.nextToken (',').trim());
- }
+ t_watcher_list ());
+ options_db[command].first.push_back (params.rest ());
+
}
return true;
}
-BotConfig::t_option_values BotConfig::get_option_values (std::string key)
+BotConfig::t_option_values
+BotConfig::get_option_values (std::string key)
{
t_options_db::const_iterator cf_iter =
options_db.find (key);
return t_option_values (); // Empty vector
}
-std::string BotConfig::set_config_file (std::string fname)
+std::string
+BotConfig::set_config_file (std::string fname)
{
std::string old_config_filename = config_filename;
config_filename = fname;
};
}
-void BotConfig::set_option_value (std::string key, t_value_list values,
+void
+BotConfig::set_option_value (std::string key, t_value_list values,
bool append)
{
t_options_db::iterator cf_iter = options_db.find (key);
else
cf_iter->second.first = values;
}
+ else
+ options_db[key] = t_option_values (values, t_watcher_list ());
// Call Watchers
std::for_each (cf_iter->second.second.begin (),
cf_iter->second.second.end (),
run_fun_ (key, values, append));
}
+
+bool
+BotConfig::add_watcher (std::string key, t_watcher new_watcher)
+{
+ t_options_db::iterator cf_iter = options_db.find (key);
+
+ if (cf_iter != options_db.end ())
+ {
+ cf_iter->second.second.push_front (new_watcher);
+ return true;
+ }
+ else
+ return false;
+}