annotate src/Support/Module.cc @ 1:bc394a985042

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