18#ifndef VOTCA_TOOLS_OBJECTFACTORY_H
19#define VOTCA_TOOLS_OBJECTFACTORY_H
29#include <boost/lexical_cast.hpp>
43template <
typename key_t,
typename T,
typename... args_t>
46 using creator_t = std::unique_ptr<T> (*)(args_t &&...);
61 template <
typename obj_t>
67 virtual std::unique_ptr<T>
Create(
const key_t &key, args_t &&...arguments);
71 std::vector<key_t> key;
74 key.push_back(pair.first);
83template <
class parent,
class T,
typename... args_t>
85 return std::make_unique<T>(std::forward<args_t>(args)...);
88template <
typename key_t,
typename T,
typename... args_t>
92 typename std::map<key_t, creator_t>::value_type(key, creator));
95template <
typename key_t,
typename T,
typename... args_t>
96template <
typename obj_t>
101template <
typename key_t,
typename T,
typename... args_t>
103 const key_t &key, args_t &&...arguments) {
104 typename std::map<key_t, creator_t>::const_iterator it = objects_.find(key);
105 if (it != objects_.end()) {
106 return (it->second)(std::forward<args_t>(arguments)...);
108 throw std::runtime_error(
109 "factory key " + boost::lexical_cast<std::string>(key) +
" not found.");
113template <
typename key_t,
typename T,
typename... args_t>
115 const key_t &id_)
const {
116 return (objects_.find(id_) != objects_.end());
base class for all analysis tools