8 #ifndef DATATOOLS_FACTORY_H 9 #define DATATOOLS_FACTORY_H 21 #include <boost/function.hpp> 22 #include <boost/functional/factory.hpp> 23 #include <boost/scoped_ptr.hpp> 50 template <
class BaseType>
63 const std::type_info *
tinfo =
nullptr;
90 void set_label(
const std::string & label_);
96 bool has(
const std::string & id_)
const;
99 bool is_group(
const std::string & id_)
const;
114 const factory_record_type &
get_record(
const std::string & id_)
const;
119 const std::type_info & tinfo_,
120 const std::string & description_ =
"",
121 const std::string & category_ =
"");
124 template<
class DerivedType>
126 const std::string & description_ =
"",
127 const std::string & category_ =
"");
130 template<
class DerivedType>
134 bool fetch_type_id(
const std::type_info & tinfo_, std::string & id_)
const;
148 const std::vector<std::string> & imported_factories_);
151 void print(std::ostream & out_,
const std::string & indent_ =
"")
const;
154 virtual void tree_dump(std::ostream & out_ = std::clog,
155 const std::string& title_ =
"",
156 const std::string& indent_ =
"",
157 bool inherit_ =
false)
const;
173 #include <boost/type_traits/is_base_of.hpp> 179 template <
class BaseType,
class DerivedType>
187 _type_info_ = &
typeid(DerivedType);
188 _type_id_ = type_id_;
189 this->_trigger_factory_registration_();
196 this->_trigger_factory_unregistration_();
209 void _trigger_factory_registration_()
211 bool fatal = !boost::is_base_of<BaseType, DerivedType>::value;
214 "Class ID '" << _type_id_ <<
"' cannot be registered in register '" 215 << BaseType::grab_system_factory_register().get_label() <<
"' !");
216 BaseType::grab_system_factory_register().registration(_type_id_,
217 boost::factory<DerivedType*>(),
218 typeid(DerivedType));
223 void _trigger_factory_unregistration_()
225 if (BaseType::grab_system_factory_register().
has(_type_id_)) {
226 BaseType::grab_system_factory_register().unregistration(_type_id_);
233 const std::type_info * _type_info_ =
nullptr;
234 std::string _type_id_;
241 #endif // DATATOOLS_FACTORY_H
GENBB particle generator abstract base class.
Definition: i_genbb.h:59
Utility macros for exception handling.
#define DT_THROW_IF(Condition, ExceptionType, Message)
Definition: exception.h:76
Utilities for logging information.