Mercurial > hg > aimc
diff src/Support/ModuleTree.cc @ 195:0db637cac96b
- Added as-yet-unfinished support for a proper configuraiton file format
- Added a couple of pythin scripts to generate HMM configuration files
- Variable name changes and other cosmetic things
- Added the option for the noise generation to do pink noise (untested)
author | tomwalters |
---|---|
date | Thu, 12 Aug 2010 11:28:11 +0000 |
parents | 3cdaa81c3aca |
children | 503b6f40d0aa |
line wrap: on
line diff
--- a/src/Support/ModuleTree.cc Thu Aug 12 09:15:49 2010 +0000 +++ b/src/Support/ModuleTree.cc Thu Aug 12 11:28:11 2010 +0000 @@ -24,152 +24,7 @@ * \version \$Id: $ */ -#include "Support/ModuleFactory.h" -#include "Support/Module.h" -#include "Support/ModuleTree.h" - namespace aimc { -using std::endl; -ModuleTree::ModuleTree() : root_module_(NULL), - initialized_(false) { + ParseConfigFile(string ) -} - -bool ModuleTree::LoadConfigFile(const string &filename) { - config_.Load(filename.c_str()); - return ConstructTree(); -} - -bool ModuleTree::LoadConfigText(const string &config) { - config_.Parse(config.c_str()); - return ConstructTree(); -} - -bool ModuleTree::ConstructTree() { - // Make two passes over the configuration file. - // The first pass creates all the named modules with their parameters. - bool done = false; - bool error = false; - int module_number = 1; - LOG_INFO("Parsing tree..."); - while (!done) { - char module_name_var[Parameters::MaxParamNameLength]; - char module_id_var[Parameters::MaxParamNameLength]; - char module_parameters_var[Parameters::MaxParamNameLength]; - sprintf(module_name_var, "module%d.name", module_number); - sprintf(module_id_var, "module%d.id", module_number); - sprintf(module_parameters_var, "module%d.parameters", module_number); - if (config_.IsSet(module_name_var)) { - string module_name(config_.GetString(module_name_var)); - LOG_INFO("Module number %d, name %s", module_number, module_name.c_str()); - if (config_.IsSet(module_id_var)) { - const char* id = config_.GetString(module_id_var); - const char* parameters = config_.DefaultString(module_parameters_var, ""); - linked_ptr<Parameters> params(new Parameters); - parameters_[module_name] = params; - parameters_[module_name]->Parse(parameters); - linked_ptr<Module> module(ModuleFactory::Create(id, parameters_[module_name].get())); - if (module.get() != NULL) { - module->set_instance_name(module_name); - modules_[module_name] = module; - } else { - LOG_ERROR("Module name: %s of type %s not created", module_name.c_str(), id); - done = true; - error = true; - } - if (module_number == 1) { - root_module_ = module.get(); - } - } else { - LOG_ERROR("id field missing for module named %s", module_name.c_str()); - error = true; - done = true; - } - } else { - done = true; - } - ++module_number; - } - // The second pass connects up all the modules into a tree. - char module_child_var[Parameters::MaxParamNameLength]; - char module_name_var[Parameters::MaxParamNameLength]; - LOG_INFO("A total of %d modules", modules_.size()); - for (unsigned int i = 1; i < modules_.size() + 1; ++i) { - int child_number = 1; - done = false; - sprintf(module_name_var, "module%d.name", i); - if (config_.IsSet(module_name_var)) { - string module_name(config_.GetString(module_name_var)); - while (!done) { - sprintf(module_child_var, "module%d.child%d", i, child_number); - LOG_INFO("Trying %s", module_child_var); - if (config_.IsSet(module_child_var)) { - string child(config_.GetString(module_child_var)); - if ((modules_.find(module_name) != modules_.end()) - && (modules_.find(child) != modules_.end())) { - modules_[module_name]->AddTarget(modules_[child].get()); - } else { - LOG_ERROR("Module name not found"); - } - } else { - done = true; - } - ++child_number; - } - } else { - LOG_ERROR("field missing for entry %s", module_name_var); - error = true; - break; - } - } - return !error; -} - -bool ModuleTree::Initialize(Parameters *global_parameters) { - if (root_module_ == NULL) { - return false; - } - // Dummy signal bank for the root module. - s_.Initialize(1, 1, 1); - initialized_ = root_module_->Initialize(s_, global_parameters); - return initialized_; -} - -void ModuleTree::Reset() { - if (root_module_ == NULL) { - return; - } - root_module_->Reset(); -} - -void ModuleTree::PrintConfiguration(ostream &out) { - if (root_module_ == NULL) { - return; - } - root_module_->PrintTargets(out); - root_module_->PrintConfiguration(out); -} - -void ModuleTree::Process() { - if (root_module_ == NULL) { - return; - } - if (!initialized_) { - LOG_ERROR(_T("Module tree not initialized.")); - return; - } - while (!root_module_->done()) { - root_module_->Process(s_); - } -} - -void ModuleTree::MakeDotGraph(ostream &out) { - if (root_module_ == NULL) { - return; - } - out << "digraph G {" << endl; - root_module_->PrintTargetsForDot(out); - out << "}" << endl; -} - -} // namespace aimc +} // namespace aimc \ No newline at end of file