8 #ifndef DATATOOLS_FACTORY_INL_H 9 #define DATATOOLS_FACTORY_INL_H 15 template <
typename BaseType>
25 template <
typename BaseType>
30 if (flags_ & verbose) {
39 template <
typename BaseType>
48 template <
typename BaseType>
54 template <
typename BaseType>
61 template <
typename BaseType>
67 template <
typename BaseType>
74 template <
typename BaseType>
77 for (
typename factory_map_type::const_iterator i = _registered_.begin();
78 i != _registered_.end();
80 ids_.push_back(i->first);
85 template <
typename BaseType>
88 return _registered_.find(id_) != _registered_.end();
91 template <
typename BaseType>
94 for (
typename factory_map_type::iterator i = _registered_.begin();
95 i != _registered_.end();
97 if (i->second.fact !=
nullptr) {
98 DT_LOG_INFORMATION(_logging_,
"Destroying registered allocator/functor '" << i->first <<
"'");
101 _registered_.clear();
105 template <
typename BaseType>
114 template <
typename BaseType>
118 typename factory_map_type::iterator found = _registered_.find(id_);
119 DT_THROW_IF(found == _registered_.end(), std::logic_error,
120 "Class ID '" << id_ <<
"' is not registered !");
121 return found->second.fact;
124 template <
typename BaseType>
128 typename factory_map_type::const_iterator found = _registered_.find(id_);
129 DT_THROW_IF(found == _registered_.end(), std::logic_error,
130 "Class ID '" << id_ <<
"' is not registered !");
131 return found->second.fact;
134 template <
typename BaseType>
138 typename factory_map_type::const_iterator found = _registered_.find(id_);
139 DT_THROW_IF(found == _registered_.end(), std::logic_error,
140 "Class ID '" << id_ <<
"' is not registered !");
141 return found->second;
144 template <
typename BaseType>
148 for (
typename factory_map_type::const_iterator i = _registered_.begin();
149 i != _registered_.end();
151 if (&tinfo_ == i->second.tinfo) {
159 template <
typename BaseType>
160 template<
class DerivedType>
164 bool fatal = !boost::is_base_of<BaseType, DerivedType>::value;
167 "Class ID '" << id_ <<
"' is not registrable!");
171 for (
typename factory_map_type::const_iterator i = _registered_.begin();
172 i != _registered_.end();
174 if (&
typeid(DerivedType) == i->second.tinfo) {
182 template <
typename BaseType>
183 template <
typename DerivedType>
185 const std::string & description_,
186 const std::string & category_)
189 boost::factory<DerivedType*>(),
196 template <
typename BaseType>
199 const std::type_info & tinfo_,
200 const std::string & description_,
201 const std::string & category_)
203 DT_LOG_NOTICE(_logging_,
"Registration of class with ID '" << id_ <<
"'");
204 typename factory_map_type::const_iterator found = _registered_.find(id_);
205 DT_THROW_IF(found != _registered_.end(), std::logic_error,
206 "Class ID '" << id_ <<
"' is already registered !");
207 factory_record_type record;
208 record.type_id = id_;
209 record.description = description_;
210 record.category = category_;
211 record.fact = factory_;
212 record.tinfo = &tinfo_;
213 _registered_[id_] = record;
217 template <
typename BaseType>
220 DT_LOG_NOTICE(_logging_,
"Unregistration of class with ID '" << id_ <<
"'");
221 typename factory_map_type::const_iterator found = _registered_.find(id_);
222 DT_THROW_IF(found == _registered_.end(), std::logic_error,
223 "Class ID '" << id_ <<
"' is not registered !");
224 _registered_.erase(id_);
228 template <
typename BaseType>
231 DT_LOG_NOTICE(_logging_,
"Importing registered factories from register '" << other_.
get_label() <<
"'...");
232 for (
typename factory_map_type::const_iterator i = other_._registered_.begin();
233 i != other_._registered_.end();
235 const factory_record_type & the_out_factory_record = i->second;
236 this->registration(i->first,
237 the_out_factory_record.fact,
238 *the_out_factory_record.tinfo,
239 the_out_factory_record.description,
240 the_out_factory_record.category);
246 template <
typename BaseType>
248 const std::vector<std::string> & imported_factories_)
250 DT_LOG_NOTICE(_logging_,
"Importing registered factories from register '" << other_.
get_label() <<
"'...");
251 for (
typename factory_map_type::const_iterator i = other_._registered_.begin();
252 i != other_._registered_.end();
254 if (std::find(imported_factories_.begin(),
255 imported_factories_.end(),
256 i->first) != imported_factories_.end()) {
257 const factory_record_type & the_out_factory_record = i->second;
258 this->registration(i->first,
259 the_out_factory_record.fact,
260 *the_out_factory_record.tinfo,
261 the_out_factory_record.description,
262 the_out_factory_record.category);
269 template <
typename BaseType>
271 const std::string & indent_)
const 273 std::ostringstream title_oss;
274 title_oss <<
"List of registered allocators/functors for label \"" 277 this->
tree_dump(out_, title_oss.str(), indent_);
281 template <
typename BaseType>
283 const std::string & title_,
284 const std::string & indent_,
287 if (!title_.empty()) { out_ << indent_ << title_ << std::endl; }
289 out_ << indent_ << i_tree_dumpable::tag
291 << _label_ <<
"'" << std::endl;
293 out_ << indent_ << i_tree_dumpable::tag
294 <<
"Logging threshold : " 298 <<
"Registered factories : " << _registered_.size() << std::endl;
300 for (
typename factory_map_type::const_iterator i = _registered_.begin();
301 i != _registered_.end();
305 typename factory_map_type::const_iterator j = i;
307 if (j == _registered_.end()) {
308 out_ << i_tree_dumpable::last_tag;
310 out_ << i_tree_dumpable::tag;
312 out_ <<
"ID: \"" << i->first <<
"\" @ " << &i->second.fact;
313 if (!i->second.description.empty()) {
314 out_ <<
": " << i->second.description;
316 if (!i->second.category.empty()) {
317 out_ <<
" (" << i->second.category <<
')';
326 #endif // DATATOOLS_FACTORY_INL_H
#define DT_LOG_INFORMATION(Priority, Message)
Definition: logger_macros.h:136
void reset(pg_entry_type &entry_)
#define DT_LOG_NOTICE(Priority, Message)
Definition: logger_macros.h:118
#define DT_THROW_IF(Condition, ExceptionType, Message)
Definition: exception.h:76