annotate trunk/src/Support/Module.cc @ 284:fb52ca0e6339

-Profile module for taking slices of an SAI or SSI (or anything else for that matter) -Stub SSI module - not yet complete -Fixes to the module template
author tomwalters
date Fri, 19 Feb 2010 13:07:54 +0000
parents 41ea31faf90c
children 10d0803e37ec
rev   line source
tomwalters@268 1 // Copyright 2010, Thomas Walters
tomwalters@268 2 //
tomwalters@268 3 // AIM-C: A C++ implementation of the Auditory Image Model
tomwalters@268 4 // http://www.acousticscale.org/AIMC
tomwalters@268 5 //
tomwalters@268 6 // This program is free software: you can redistribute it and/or modify
tomwalters@268 7 // it under the terms of the GNU General Public License as published by
tomwalters@268 8 // the Free Software Foundation, either version 3 of the License, or
tomwalters@268 9 // (at your option) any later version.
tomwalters@268 10 //
tomwalters@268 11 // This program is distributed in the hope that it will be useful,
tomwalters@268 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
tomwalters@268 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
tomwalters@268 14 // GNU General Public License for more details.
tomwalters@268 15 //
tomwalters@268 16 // You should have received a copy of the GNU General Public License
tomwalters@268 17 // along with this program. If not, see <http://www.gnu.org/licenses/>.
tomwalters@268 18
tomwalters@268 19 /*! \file
tomwalters@268 20 * \brief Base class for all AIM-C modules.
tomwalters@268 21 */
tomwalters@268 22
tomwalters@268 23 /*! \author: Thomas Walters <tom@acousticscale.org>
tomwalters@268 24 * \date 2010/01/23
tomwalters@268 25 * \version \$Id$
tomwalters@268 26 */
tomwalters@268 27
tomwalters@268 28 #include "Support/Module.h"
tomwalters@268 29
tomwalters@268 30 #include <utility>
tomwalters@268 31
tomwalters@268 32 namespace aimc {
tomwalters@268 33 using std::pair;
tomwalters@268 34 Module::Module(Parameters *parameters) {
tomwalters@268 35 initialized_ = false;
tomwalters@268 36 targets_.clear();
tomwalters@268 37 parameters_ = parameters;
tomwalters@268 38 module_identifier_ = "MODULE IDENTIFIER NOT SET";
tomwalters@268 39 module_type_ = "MODULE TYPE NOT SET";
tomwalters@268 40 module_description_ = "MODULE DESCRIPTION NOT SET";
tomwalters@268 41 module_version_ = "MODULE VERSION NOT SET";
tomwalters@268 42 };
tomwalters@268 43
tomwalters@268 44 Module::~Module() {
tomwalters@268 45 };
tomwalters@268 46
tomwalters@268 47 bool Module::Initialize(const SignalBank &input) {
tomwalters@278 48 LOG_INFO_NN(_T("-> %s "), module_identifier_.c_str());
tomwalters@268 49 // Validate the input
tomwalters@268 50 if (!input.Validate()) {
tomwalters@278 51 LOG_ERROR(_T("Input SignalBank not valid"));
tomwalters@268 52 return false;
tomwalters@268 53 }
tomwalters@273 54 if (!InitializeInternal(input)) {
tomwalters@278 55 LOG_ERROR(_T("Initialization failed in module %s"),
tomwalters@278 56 module_identifier_.c_str());
tomwalters@268 57 return false;
tomwalters@268 58 }
tomwalters@268 59 // If the module has an output bank, then we can set up the targets
tomwalters@268 60 // of this module..
tomwalters@268 61 if (output_.initialized()) {
tomwalters@268 62 // Check that the output SignalBank has been set up correctly
tomwalters@268 63 if (!output_.Validate()) {
tomwalters@278 64 LOG_ERROR(_T("Output SignalBank not valid in module %s"),
tomwalters@278 65 module_identifier_.c_str());
tomwalters@268 66 return false;
tomwalters@268 67 }
tomwalters@268 68 // Iterate through all the targets of this module, initializing
tomwalters@268 69 // them if they have not already been initialized. If they have
tomwalters@268 70 // already been initialized, then they are assumed to have been
tomwalters@268 71 // set up to accept an input SignalBank of the correct form, but
tomwalters@268 72 // this is not checked.
tomwalters@268 73 set<Module*>::const_iterator it;
tomwalters@268 74 for (it = targets_.begin(); it != targets_.end(); ++it) {
tomwalters@268 75 if (!(*it)->initialized())
tomwalters@268 76 if (!(*it)->Initialize(output_))
tomwalters@268 77 return false;
tomwalters@268 78 }
tomwalters@278 79 } else {
tomwalters@278 80 LOG_INFO(_T("|"));
tomwalters@268 81 }
tomwalters@268 82 initialized_ = true;
tomwalters@268 83 return true;
tomwalters@268 84 }
tomwalters@268 85
tomwalters@275 86 void Module::Reset() {
tomwalters@275 87 if (!initialized_)
tomwalters@275 88 return;
tomwalters@275 89
tomwalters@275 90 ResetInternal();
tomwalters@275 91
tomwalters@275 92 // Iterate through all the targets of this module, resetting
tomwalters@275 93 // them.
tomwalters@275 94 set<Module*>::const_iterator it;
tomwalters@275 95 for (it = targets_.begin(); it != targets_.end(); ++it)
tomwalters@275 96 (*it)->Reset();
tomwalters@275 97 }
tomwalters@275 98
tomwalters@268 99 bool Module::initialized() const {
tomwalters@268 100 return initialized_;
tomwalters@268 101 }
tomwalters@268 102
tomwalters@268 103 bool Module::AddTarget(Module* target_module) {
tomwalters@268 104 if (target_module) {
tomwalters@268 105 pair<set<Module*>::iterator, bool> ret;
tomwalters@268 106 ret = targets_.insert(target_module);
tomwalters@268 107 return ret.second;
tomwalters@268 108 }
tomwalters@268 109 return false;
tomwalters@268 110 }
tomwalters@268 111
tomwalters@281 112 bool Module::RemoveTarget(Module* target_module) {
tomwalters@268 113 if (targets_.erase(target_module) != 0)
tomwalters@268 114 return true;
tomwalters@268 115 return false;
tomwalters@268 116 }
tomwalters@268 117
tomwalters@281 118 void Module::RemoveAllTargets() {
tomwalters@268 119 targets_.clear();
tomwalters@268 120 }
tomwalters@268 121
tomwalters@268 122 const SignalBank* Module::GetOutputBank() const {
tomwalters@268 123 return &output_;
tomwalters@268 124 }
tomwalters@268 125
tomwalters@268 126 void Module::PushOutput() {
tomwalters@268 127 if (output_.initialized()) {
tomwalters@268 128 set<Module*>::const_iterator it;
tomwalters@268 129 for (it = targets_.begin(); it != targets_.end(); ++it) {
tomwalters@268 130 (*it)->Process(output_);
tomwalters@268 131 }
tomwalters@268 132 }
tomwalters@268 133 }
tomwalters@280 134 } // namespace aimc
tomwalters@268 135