tomwalters@268: // Copyright 2010, Thomas Walters tomwalters@268: // tomwalters@268: // AIM-C: A C++ implementation of the Auditory Image Model tomwalters@268: // http://www.acousticscale.org/AIMC tomwalters@268: // tomwalters@268: // This program is free software: you can redistribute it and/or modify tomwalters@268: // it under the terms of the GNU General Public License as published by tomwalters@268: // the Free Software Foundation, either version 3 of the License, or tomwalters@268: // (at your option) any later version. tomwalters@268: // tomwalters@268: // This program is distributed in the hope that it will be useful, tomwalters@268: // but WITHOUT ANY WARRANTY; without even the implied warranty of tomwalters@268: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the tomwalters@268: // GNU General Public License for more details. tomwalters@268: // tomwalters@268: // You should have received a copy of the GNU General Public License tomwalters@268: // along with this program. If not, see . tomwalters@268: tomwalters@268: /*! \file tomwalters@268: * \brief Base class for all AIM-C modules. tomwalters@268: */ tomwalters@268: tomwalters@268: /*! \author: Thomas Walters tomwalters@268: * \date 2010/01/23 tomwalters@268: * \version \$Id$ tomwalters@268: */ tomwalters@268: tomwalters@268: #include "Support/Module.h" tomwalters@268: tomwalters@268: #include tomwalters@268: tomwalters@268: namespace aimc { tomwalters@268: using std::pair; tomwalters@268: Module::Module(Parameters *parameters) { tomwalters@268: initialized_ = false; tomwalters@268: targets_.clear(); tomwalters@268: parameters_ = parameters; tomwalters@268: module_identifier_ = "MODULE IDENTIFIER NOT SET"; tomwalters@268: module_type_ = "MODULE TYPE NOT SET"; tomwalters@268: module_description_ = "MODULE DESCRIPTION NOT SET"; tomwalters@268: module_version_ = "MODULE VERSION NOT SET"; tomwalters@268: }; tomwalters@268: tomwalters@268: Module::~Module() { tomwalters@268: }; tomwalters@268: tomwalters@268: bool Module::Initialize(const SignalBank &input) { tomwalters@268: // Validate the input tomwalters@268: if (!input.Validate()) { tomwalters@268: LOG_ERROR("Input SignalBank not valid"); tomwalters@268: return false; tomwalters@268: } tomwalters@268: if (!InitializeInternal(input)) { tomwalters@268: LOG_ERROR("Module initialization failed"); tomwalters@268: return false; tomwalters@268: } tomwalters@268: // If the module has an output bank, then we can set up the targets tomwalters@268: // of this module.. tomwalters@268: if (output_.initialized()) { tomwalters@268: // Check that the output SignalBank has been set up correctly tomwalters@268: if (!output_.Validate()) { tomwalters@268: LOG_ERROR("Output SignalBank not valid"); tomwalters@268: return false; tomwalters@268: } tomwalters@268: // Iterate through all the targets of this module, initializing tomwalters@268: // them if they have not already been initialized. If they have tomwalters@268: // already been initialized, then they are assumed to have been tomwalters@268: // set up to accept an input SignalBank of the correct form, but tomwalters@268: // this is not checked. tomwalters@268: set::const_iterator it; tomwalters@268: for (it = targets_.begin(); it != targets_.end(); ++it) { tomwalters@268: if (!(*it)->initialized()) tomwalters@268: if (!(*it)->Initialize(output_)) tomwalters@268: return false; tomwalters@268: } tomwalters@268: } tomwalters@268: initialized_ = true; tomwalters@268: return true; tomwalters@268: } tomwalters@268: tomwalters@268: bool Module::initialized() const { tomwalters@268: return initialized_; tomwalters@268: } tomwalters@268: tomwalters@268: bool Module::AddTarget(Module* target_module) { tomwalters@268: if (target_module) { tomwalters@268: pair::iterator, bool> ret; tomwalters@268: ret = targets_.insert(target_module); tomwalters@268: return ret.second; tomwalters@268: } tomwalters@268: return false; tomwalters@268: } tomwalters@268: tomwalters@268: bool Module::DeleteTarget(Module* target_module) { tomwalters@268: if (targets_.erase(target_module) != 0) tomwalters@268: return true; tomwalters@268: return false; tomwalters@268: } tomwalters@268: tomwalters@268: void Module::DeleteAllTargets() { tomwalters@268: targets_.clear(); tomwalters@268: } tomwalters@268: tomwalters@268: const SignalBank* Module::GetOutputBank() const { tomwalters@268: return &output_; tomwalters@268: } tomwalters@268: tomwalters@268: void Module::PushOutput() { tomwalters@268: if (output_.initialized()) { tomwalters@268: set::const_iterator it; tomwalters@268: for (it = targets_.begin(); it != targets_.end(); ++it) { tomwalters@268: (*it)->Process(output_); tomwalters@268: } tomwalters@268: } tomwalters@268: } tomwalters@268: } // namespace aimc tomwalters@268: