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