1 #ifndef PMPL_METHOD_SET_H_
2 #define PMPL_METHOD_SET_H_
10 #include <boost/mpl/list.hpp>
11 #include <boost/mpl/next_prior.hpp>
22 template <
typename Method>
57 template <
typename Method>
67 typedef typename std::map<std::string, OwningPointer>
MethodMap;
70 typedef typename std::map<std::string, FactoryType>
FactoryMap;
82 template <
typename MethodTypeList>
84 const std::string& _name);
109 void Print(std::ostream& _os)
const;
131 template <typename First, typename Last>
132 void AddToUniverse(First, Last);
135 template <typename Last>
136 void AddToUniverse(Last, Last);
155 template <typename Method>
156 template <typename MethodTypeList>
159 const std::
string& _name) : m_library(_p), m_name(_name) {
160 AddToUniverse(
typename boost::mpl::begin<MethodTypeList>::type(),
161 typename boost::mpl::end<MethodTypeList>::type());
165 template <
typename Method>
169 for(
auto& child : _node)
174 template <
typename Method>
178 auto iter = m_universe.find(_node.
Name());
181 if(iter == m_universe.end())
189 template <
typename Method>
197 template <
typename Method>
201 auto iter = m_universe.find(_e->m_name);
204 if(iter == m_universe.end())
206 <<
"method type '" << _e->m_name <<
"'.";
208 if(m_elements.count(_label))
210 <<
"label '" << _label <<
"'.";
215 _e->SetMPLibrary(m_library);
216 _e->SetLabel(_label);
217 m_elements[_label] = _e;
221 template <
typename Method>
226 auto iter = m_elements.find(_label);
228 if(iter == m_elements.end()) {
229 std::ostringstream choices;
232 <<
"in set " << m_name <<
"."
236 return iter->second.get();
240 template <
typename Method>
244 for(
auto& elem : m_elements)
245 elem.second->Initialize();
249 template <
typename Method>
252 Print(std::ostream& _os)
const {
255 _os <<
"\n" << m_name <<
" has these methods available:";
256 for(
const auto& elem : m_elements)
258 << ++count <<
") '" << elem.first <<
"' (" << elem.second->m_name <<
")";
264 template <
typename Method>
269 return m_elements.begin();
273 template <
typename Method>
278 return m_elements.end();
282 template <
typename Method>
286 begin() const noexcept {
287 return m_elements.begin();
291 template <
typename Method>
295 end() const noexcept {
296 return m_elements.end();
301 template <
typename Method>
302 template <
typename First,
typename Last>
306 using FirstType =
typename boost::mpl::deref<First>::type;
309 AddToUniverse(
typename boost::mpl::next<First>::type(), Last());
313 template <
typename Method>
314 template <
typename Last>
#define WHERE
Macro for retrieving info about file, function, and line number.
Definition: RuntimeUtils.h:32
Definition: MPLibrary.h:47
Definition: MethodSet.h:58
void Initialize()
Definition: MethodSet.h:243
std::map< std::string, OwningPointer > MethodMap
Definition: MethodSet.h:67
MethodPointer GetMethod(const std::string &_label)
Definition: MethodSet.h:224
void AddMethod(XMLNode &_node)
Definition: MethodSet.h:177
std::map< std::string, FactoryType > FactoryMap
Definition: MethodSet.h:70
void Print(std::ostream &_os) const
Display the instantiated methods.
Definition: MethodSet.h:252
MethodSet(MPLibrary *const _p, const MethodTypeList &_mtl, const std::string &_name)
Definition: MethodSet.h:158
MethodMap::iterator iterator
Definition: MethodSet.h:72
std::shared_ptr< Method > OwningPointer
Definition: MethodSet.h:66
Method * MethodPointer
Definition: MethodSet.h:65
MethodMap::const_iterator const_iterator
Definition: MethodSet.h:73
std::function< OwningPointer(XMLNode &)> FactoryType
Definition: MethodSet.h:69
iterator end() noexcept
Definition: MethodSet.h:277
void ParseXML(XMLNode &_node)
Add the appropriate methods from an XML node.
Definition: MethodSet.h:168
iterator begin() noexcept
Definition: MethodSet.h:268
const std::string & Name() const
Get the XMLNode name.
Definition: XMLNode.cpp:90
Creates new method instances from an XML node.
Definition: MethodSet.h:23
OwningPointer operator()(XMLNode &_node) const
Definition: MethodSet.h:34
std::shared_ptr< Method > OwningPointer
Definition: MethodSet.h:28
Definition: PMPLExceptions.h:38
Definition: PMPLExceptions.h:62