-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathHardCodedModuleFactory.cc
More file actions
160 lines (128 loc) · 5.01 KB
/
Copy pathHardCodedModuleFactory.cc
File metadata and controls
160 lines (128 loc) · 5.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
For more information, please see: http://software.sci.utah.edu
The MIT License
Copyright (c) 2020 Scientific Computing and Imaging Institute,
University of Utah.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
/// @todo Documentation HardCodedModuleFactory.cc
#include <iostream>
#include <boost/assign.hpp>
#include <Modules/Factory/HardCodedModuleFactory.h>
#include <Dataflow/Network/ModuleDescription.h>
#include <Dataflow/Network/Module.h>
#include <Dataflow/Network/ModuleBuilder.h>
#include <Dataflow/Network/SimpleSourceSink.h>
#include <Modules/Factory/ModuleDescriptionLookup.h>
using namespace SCIRun::Core::Algorithms;
using namespace SCIRun::Dataflow::Networks;
using namespace SCIRun::Modules;
using namespace Factory;
using namespace boost::assign;
ModuleDescriptionLookup::ModuleDescriptionLookup() : includeTestingModules_(false)
{
/// @todo: is BUILD_TESTING off when we build releases?
#ifdef BUILD_TESTING
includeTestingModules_ = true;
#endif
/// @todo: make EVEN MORE generic...macros? xml?
/// @todo: at least remove duplication of Name,Package,Category here since we should be able to infer from header somehow.
addEssentialModules();
/// @todo: possibly use different build setting for these.
if (includeTestingModules_)
{
addTestingModules();
}
addBrainSpecificModules();
addMoreModules();
addGeneratedModules();
}
ModuleDescription ModuleDescriptionLookup::lookupDescription(const ModuleLookupInfo& info) const
{
auto iter = moduleLookup_.find(info);
if (iter == moduleLookup_.end())
{
/// @todo: log
std::ostringstream ostr;
ostr << "Error: Undefined module \"" << info.module_name_ << "\"";
logCritical("ModuleDescriptionLookup error: Undefined module \"{}\"", info.module_name_);
THROW_INVALID_ARGUMENT(ostr.str());
}
return iter->second;
}
namespace SCIRun {
namespace Modules {
namespace Factory {
class HardCodedModuleFactoryImpl
{
public:
ModuleDescriptionLookup lookup;
};
}}}
HardCodedModuleFactory::HardCodedModuleFactory() : impl_(new HardCodedModuleFactoryImpl)
{
ModuleBuilder::use_sink_type(boost::factory<SimpleSink*>());
ModuleBuilder::use_source_type(boost::factory<SimpleSource*>());
}
void HardCodedModuleFactory::setStateFactory(ModuleStateFactoryHandle stateFactory)
{
DefaultModuleFactories::defaultStateFactory_ = stateFactory_ = stateFactory;
}
void HardCodedModuleFactory::setAlgorithmFactory(AlgorithmFactoryHandle algoFactory)
{
DefaultModuleFactories::defaultAlgoFactory_ = algoFactory;
}
void HardCodedModuleFactory::setReexecutionFactory(ReexecuteStrategyFactoryHandle reexFactory)
{
DefaultModuleFactories::defaultReexFactory_ = reexFactory;
}
ModuleHandle HardCodedModuleFactory::create(const ModuleDescription& desc) const
{
ModuleBuilder builder;
if (desc.maker_)
builder.using_func(desc.maker_);
else
builder.with_name(desc.lookupInfo_.module_name_);
for (const auto& input : desc.input_ports_)
{
builder.add_input_port(Port::ConstructionParams(input.id, input.datatype, input.isDynamic));
}
builder.add_input_port(Port::ConstructionParams(ProgrammablePortId(), "MetadataObject", false));
for (const auto& output : desc.output_ports_)
{
builder.add_output_port(Port::ConstructionParams(output.id, output.datatype, output.isDynamic));
}
builder.setInfoStrings(desc);
return builder.setStateDefaults().build();
}
ModuleDescription HardCodedModuleFactory::lookupDescription(const ModuleLookupInfo& info) const
{
return impl_->lookup.lookupDescription(info);
}
const ModuleDescriptionMap& HardCodedModuleFactory::getAllAvailableModuleDescriptions() const
{
return impl_->lookup.descMap_;
}
const DirectModuleDescriptionLookupMap& HardCodedModuleFactory::getDirectModuleDescriptionLookupMap() const
{
return impl_->lookup.moduleLookup_;
}
bool HardCodedModuleFactory::moduleImplementationExists(const std::string& name) const
{
auto map = getDirectModuleDescriptionLookupMap();
return map.find(ModuleLookupInfo(name, "", "")) != map.end();
}