35 using Map = std::unordered_map<T, AbstractNode::Pointer>;
40 std::function<T(MrProt &)>,
41 std::function<T(MrProt &, SeqLim &, SeqExpo &)>>;
46 std::string
const & key,
Map const & cases,
59 MrProt & protocol, SeqLim & limits, SeqExpo & exports)
override
61 auto child = this->_child(protocol, limits, exports);
62 return child->prepare(protocol, limits, exports);
72 MrProt & protocol, SeqLim & limits, SeqExpo & exports)
override
74 auto child = this->_child(protocol, limits, exports);
75 return child->run(protocol, limits, exports);
82 for(
auto && item: this->_cases)
84 auto & child = item.second;
96 return this->_child()->duration();
103 MrProtocolData::SeqExpoRFInfo
rfInfo()
const override
105 return this->_child()->rfInfo();
110 class Visitor:
public boost::static_visitor<
111 std::function<T(MrProt &, SeqLim &, SeqExpo &)>>
114 std::function<T(MrProt &, SeqLim &, SeqExpo &)> operator()(std::function<T()>
const & f)
const
116 return [&](MrProt &, SeqLim &, SeqExpo &){
return f(); };
119 std::function<T(MrProt &, SeqLim &, SeqExpo &)> operator()(std::function<T(MrProt &)>
const & f)
const
121 return [&](MrProt & p, SeqLim &, SeqExpo &){
return f(p); };
124 std::function<T(MrProt &, SeqLim &, SeqExpo &)> operator()(
125 std::function<T(MrProt &, SeqLim &, SeqExpo &)>
const & f)
const
136 mutable bool _hasCache;
137 mutable MrProt * _protocol;
138 mutable SeqLim * _limits;
139 mutable SeqExpo * _exports;
142 std::string
const & key,
Map const & cases,
149 AbstractNode::ConstPointer _child()
const
153 throw std::runtime_error(
"No cached data");
158 *this->_protocol, *this->_limits, *this->_exports);
162 AbstractNode::ConstPointer _child(
163 MrProt & protocol, SeqLim & limits, SeqExpo & exports)
const
165 this->_protocol = &protocol;
166 this->_limits = &limits;
167 this->_exports = &exports;
168 this->_hasCache =
true;
170 return this->_cases.at(
171 this->
type(this->_key) ==
typeid(T)
172 ? this->
get<T>(this->_key)
173 : boost::apply_visitor(Visitor(), this->
get<Function>(this->_key))(
174 protocol, limits, exports)
178 AbstractNode::Pointer _child()
182 throw std::runtime_error(
"No cached data");
187 *this->_protocol, *this->_limits, *this->_exports);
191 AbstractNode::Pointer _child(
192 MrProt & protocol, SeqLim & limits, SeqExpo & exports)
194 this->_protocol = &protocol;
195 this->_limits = &limits;
196 this->_exports = &exports;
197 this->_hasCache =
true;
199 return this->_cases.at(
200 this->
type(this->_key) ==
typeid(T)
201 ? this->
get<T>(this->_key)
202 : boost::apply_visitor(Visitor(), this->
get<Function>(this->_key))(
203 protocol, limits, exports)
NLSStatus prepare(MrProt &protocol, SeqLim &limits, SeqExpo &exports) override
Prepare the selected child, throw an exception if unknown value.
Definition Case.h:58
NLSStatus run(MrProt &protocol, SeqLim &limits, SeqExpo &exports) override
Run the selected child, throw an exception if unknown value.
Definition Case.h:71
boost::variant< std::function< T()>, std::function< T(MrProt &)>, std::function< T(MrProt &, SeqLim &, SeqExpo &)> > Function
Definition Case.h:38