Mercurial > hg > aimc
diff trunk/src/Support/Module.cc @ 268:e14c70d1b171
- Initial add of support code and modules. Not everything is working yet.
author | tomwalters |
---|---|
date | Fri, 12 Feb 2010 12:31:23 +0000 |
parents | |
children | c26222c51fb7 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/trunk/src/Support/Module.cc Fri Feb 12 12:31:23 2010 +0000 @@ -0,0 +1,117 @@ +// Copyright 2010, Thomas Walters +// +// AIM-C: A C++ implementation of the Auditory Image Model +// http://www.acousticscale.org/AIMC +// +// 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 +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. + +/*! \file + * \brief Base class for all AIM-C modules. + */ + +/*! \author: Thomas Walters <tom@acousticscale.org> + * \date 2010/01/23 + * \version \$Id$ + */ + +#include "Support/Module.h" + +#include <utility> + +namespace aimc { +using std::pair; +Module::Module(Parameters *parameters) { + initialized_ = false; + targets_.clear(); + parameters_ = parameters; + module_identifier_ = "MODULE IDENTIFIER NOT SET"; + module_type_ = "MODULE TYPE NOT SET"; + module_description_ = "MODULE DESCRIPTION NOT SET"; + module_version_ = "MODULE VERSION NOT SET"; +}; + +Module::~Module() { +}; + +bool Module::Initialize(const SignalBank &input) { + // Validate the input + if (!input.Validate()) { + LOG_ERROR("Input SignalBank not valid"); + return false; + } + if (!InitializeInternal(input)) { + LOG_ERROR("Module initialization failed"); + return false; + } + // If the module has an output bank, then we can set up the targets + // of this module.. + if (output_.initialized()) { + // Check that the output SignalBank has been set up correctly + if (!output_.Validate()) { + LOG_ERROR("Output SignalBank not valid"); + return false; + } + // Iterate through all the targets of this module, initializing + // them if they have not already been initialized. If they have + // already been initialized, then they are assumed to have been + // set up to accept an input SignalBank of the correct form, but + // this is not checked. + set<Module*>::const_iterator it; + for (it = targets_.begin(); it != targets_.end(); ++it) { + if (!(*it)->initialized()) + if (!(*it)->Initialize(output_)) + return false; + } + } + initialized_ = true; + return true; +} + +bool Module::initialized() const { + return initialized_; +} + +bool Module::AddTarget(Module* target_module) { + if (target_module) { + pair<set<Module*>::iterator, bool> ret; + ret = targets_.insert(target_module); + return ret.second; + } + return false; +} + +bool Module::DeleteTarget(Module* target_module) { + if (targets_.erase(target_module) != 0) + return true; + return false; +} + +void Module::DeleteAllTargets() { + targets_.clear(); +} + +const SignalBank* Module::GetOutputBank() const { + return &output_; +} + +void Module::PushOutput() { + if (output_.initialized()) { + set<Module*>::const_iterator it; + for (it = targets_.begin(); it != targets_.end(); ++it) { + (*it)->Process(output_); + } + } +} +} // namespace aimc +