comparison trunk/src/Support/Module.cc @ 402:69466da9745e

- Massive refactoring to make module tree stuff work. In theory we now support configuration files again. The graphics stuff is untested as yet.
author tomwalters
date Mon, 18 Oct 2010 04:42:28 +0000
parents b71ec2cbe55b
children
comparison
equal deleted inserted replaced
401:b71ec2cbe55b 402:69466da9745e
29 #include <utility> 29 #include <utility>
30 30
31 namespace aimc { 31 namespace aimc {
32 using std::pair; 32 using std::pair;
33 using std::ostream; 33 using std::ostream;
34 using std::endl;
34 Module::Module(Parameters *parameters) { 35 Module::Module(Parameters *parameters) {
35 initialized_ = false; 36 initialized_ = false;
36 targets_.clear(); 37 targets_.clear();
37 parameters_ = parameters; 38 parameters_ = parameters;
38 module_identifier_ = "MODULE IDENTIFIER NOT SET"; 39 module_identifier_ = "MODULE IDENTIFIER NOT SET";
39 module_type_ = "MODULE TYPE NOT SET"; 40 module_type_ = "MODULE TYPE NOT SET";
40 module_description_ = "MODULE DESCRIPTION NOT SET"; 41 module_description_ = "MODULE DESCRIPTION NOT SET";
41 module_version_ = "MODULE VERSION NOT SET"; 42 module_version_ = "MODULE VERSION NOT SET";
43 instance_name_ = "";
44 done_ = false;
42 }; 45 };
43 46
44 Module::~Module() { 47 Module::~Module() {
45 }; 48 };
46 49
47 bool Module::Initialize(const SignalBank &input, 50 bool Module::Initialize(const SignalBank &input,
48 Parameters *global_parameters) { 51 Parameters *global_parameters) {
52 if (global_parameters == NULL) {
53 return false;
54 }
49 global_parameters_ = global_parameters; 55 global_parameters_ = global_parameters;
50 // Validate the input 56 // Validate the input
51 if (!input.Validate()) { 57 if (!input.Validate()) {
52 LOG_ERROR(_T("Input SignalBank not valid")); 58 LOG_ERROR(_T("Input SignalBank not valid"));
53 return false; 59 return false;
71 // already been initialized, then they are assumed to have been 77 // already been initialized, then they are assumed to have been
72 // set up to accept an input SignalBank of the correct form, but 78 // set up to accept an input SignalBank of the correct form, but
73 // this is not checked. 79 // this is not checked.
74 set<Module*>::const_iterator it; 80 set<Module*>::const_iterator it;
75 for (it = targets_.begin(); it != targets_.end(); ++it) { 81 for (it = targets_.begin(); it != targets_.end(); ++it) {
76 if (!(*it)->initialized()) 82 //if (!(*it)->initialized())
77 if (!(*it)->Initialize(output_, global_parameters_)) 83 if (!(*it)->Initialize(output_, global_parameters_))
78 return false; 84 return false;
79 } 85 }
80 } 86 }
81 initialized_ = true; 87 initialized_ = true;
104 if (target_module) { 110 if (target_module) {
105 pair<set<Module*>::iterator, bool> ret; 111 pair<set<Module*>::iterator, bool> ret;
106 ret = targets_.insert(target_module); 112 ret = targets_.insert(target_module);
107 result = ret.second; 113 result = ret.second;
108 if (result) { 114 if (result) {
109 if(initialized_) { 115 if (initialized_) {
110 if(output_.initialized()) { 116 if (output_.initialized()) {
111 if (!target_module->initialized()) { 117 if (!target_module->initialized()) {
112 target_module->Initialize(output_, global_parameters_); 118 target_module->Initialize(output_, global_parameters_);
113 } 119 }
114 } 120 }
115 } 121 }
139 (*it)->Process(output_); 145 (*it)->Process(output_);
140 } 146 }
141 } 147 }
142 } 148 }
143 149
144 void Module::PrintTargets(ostream &out) { 150 void Module::PrintTargetsForDot(ostream &out) {
145 out << id(); 151 //string parameters_string = parameters_->WriteString();
146 if (targets_.size() > 0) { 152 out << " " << instance_name() << " [shape = none, margin = 0, label = <" << endl;
147 out << "->("; 153 out << " <TABLE BORDER=\"0\" CELLBORDER=\"1\" CELLSPACING=\"0\" CELLPADDING=\"4\"> " << endl;
148 set<Module*>::const_iterator it; 154 out << " <TR><TD>" << instance_name() << "</TD></TR><TR><TD>" << id();
149 for (it = targets_.begin(); it != targets_.end(); ++it) { 155 out << "</TD></TR></TABLE>>]" << ";" << endl;
150 (*it)->PrintTargets(out); 156 // <TD><TR>" << parameters_string << "</TD></TR>
151 if (targets_.size() > 1) { 157 set<Module*>::const_iterator it;
152 out << ","; 158 for (it = targets_.begin(); it != targets_.end(); ++it) {
153 } 159 out << " " << instance_name() << " -> " << (*it)->instance_name() << ";" << endl;
154 } 160 (*it)->PrintTargetsForDot(out);
155 out << ")";
156 } 161 }
157 } 162 }
158 163
159 void Module::PrintVersions(ostream &out) { 164 void Module::PrintTargets(ostream &out) {
160 out << version() << "\n";
161 set<Module*>::const_iterator it; 165 set<Module*>::const_iterator it;
162 for (it = targets_.begin(); it != targets_.end(); ++it) { 166 for (it = targets_.begin(); it != targets_.end(); ++it) {
163 (*it)->PrintVersions(out); 167 out << " " << instance_name() << " -> " << (*it)->instance_name() << ";" << endl;
168 (*it)->PrintTargets(out);
169 }
170 }
171
172 void Module::PrintConfiguration(ostream &out) {
173 out << "# " << id() << endl;
174 out << "# " << instance_name() << endl;
175 out << "# " << version() << endl;
176 string parameters_string = parameters_->WriteString();
177 out << parameters_string << endl;
178 set<Module*>::const_iterator it;
179 for (it = targets_.begin(); it != targets_.end(); ++it) {
180 (*it)->PrintConfiguration(out);
164 } 181 }
165 } 182 }
166 } // namespace aimc 183 } // namespace aimc
167 184