18 #ifndef TESTUTILS_PROVIDERLIST_H 19 #define TESTUTILS_PROVIDERLIST_H 1 22 #include "TestUtils/ProviderTestHelpers.h" 25 #include <unordered_map> 101 datum_t const*
get()
const {
return ptr.get(); }
107 operator bool()
const {
return valid(); }
166 template <
typename T>
173 template <
typename T>
176 template <
typename T>
182 {
using std::runtime_error::runtime_error; };
209 template <
typename T,
typename SetupProc,
typename... Args>
210 bool custom_setup_instance
214 auto it =
data.find(
k);
215 if (it !=
data.end())
return false;
217 pointer_t ptr = std::make_unique<concrete_type_t<T>>
218 (provSetup(std::forward<Args>(
args)...));
224 template <
typename T,
typename SetupProc,
typename... Args>
227 return custom_setup_instance<
T, SetupProc, Args...>(
229 std::forward<SetupProc>(provSetup),
230 std::forward<Args>(
args)...
234 template <
typename T,
typename... Args>
239 auto it =
data.find(
k);
240 if (it !=
data.end())
return false;
242 pointer_t ptr = std::make_unique<concrete_type_t<T>>
243 (setupProvider<T>(std::forward<Args>(
args)...));
251 template <
typename T,
typename... Args>
253 {
return setup_instance<T>(
"", std::forward<Args>(
args)...); }
267 template <
typename T>
271 auto it =
data.find(
k);
272 if (it !=
data.end())
return false;
275 = std::make_unique<concrete_type_t<T>>(
std::move(obj_ptr));
289 template <
typename T>
293 auto target_it =
data.find(
k);
294 if (target_it ==
data.end())
return false;
297 auto const* target_ptr = target_it->second.get();
298 for (
auto it =
data.begin(); it !=
data.end(); ++it)
299 if (it->second.get() == target_ptr)
data.erase(it);
305 template <
typename Prov,
typename Alias>
309 auto alias_k = key<Alias>(alias_label);
310 auto alias_it =
data.find(alias_k);
311 if (alias_it !=
data.end())
return false;
314 auto prov_elem = get_elem<Prov>(prov_label);
335 template <
typename T>
337 {
return get_elem<T>(
label).ref(); }
339 template <
typename T>
341 {
return get_elem<T>(
label).ref(); }
354 template <
typename T>
356 {
return get_elem<T>(
label).
get(); }
358 template <
typename T>
360 {
return get_elem<T>(
label).
get(); }
364 template <
typename T>
369 template <
typename T>
372 auto it = find<T>(
label);
373 return (it !=
data.end()) &&
bool(it->second);
379 std::unordered_map<key_type, pointer_t>
data;
382 template <
typename T>
386 template <
typename T>
391 template <
typename T>
393 {
return data.find(key<T>(label)); }
395 template <
typename T>
399 template <
typename T>
402 auto it = find<T>(
label);
403 if (it == data.end())
411 +
" [requested: " + type_name<T>() +
"]");
416 template <
typename T>
419 auto it = find<T>(
label);
420 if (it == data.end())
428 +
" [requested: " + type_name<T>() +
"]");
434 template <
typename T>
437 return typeid(std::decay_t<T>).hash_code()
438 ^ std::hash<std::string>()(label);
448 #endif // TESTUTILS_PROVIDERLIST_H
smart_pointer_t< details::MovableClassWrapperBase > pointer_t
Type of objects contained in the list.
Container of service providers accessed by type and optional label.
T const * getPointer(std::string label="") const
Retrieve the object of type T stored with the specified label.
MovableClassWrapper(MovableClassWrapper< U > const &from, share_t)
Share constructor (kind of copy)
Exception thrown on a request about an unregistered type.
concrete_type_t< T > & get_elem(std::string label="")
Exception thrown on a invalid type request.
MovableClassWrapper(std::unique_ptr< U > &&from)
datum_t const & ref() const
Returns a constant reference to the datum with the correct type.
virtual ~MovableClassWrapperBase()=default
bool known(std::string label="") const
Returns whether we have a slot for this object.
std::unordered_map< key_type, pointer_t > data
all our singletons
std::unique_ptr< T > smart_pointer_t
type of smart pointer we use to store elements
smart_pointer_t< concrete_type_t< T >> concrete_pointer_t
Type of smart pointer to typed list element.
datum_t & ref()
Returns a reference to the datum with the correct type.
bool acquire(std::unique_ptr< T > &&obj_ptr, std::string label="")
Registers and gets ownership of the specified object.
MovableClassWrapper()
Default constructor: no datum present (move one in later on)
bool erase(std::string label="")
Drops the object with the specified type and label.
bool valid() const
Returns whether there is a valid pointer.
concrete_type_t< T > const & get_elem(std::string label="") const
A base class with a virtual table.
std::shared_ptr< datum_t > pointer_t
pointer storing datum
bool set_alias(std::string alias_label="", std::string prov_label="")
Sets the Alias type as an alias of the Prov provider (with labels)
T * getPointer(std::string label="")
static std::string type_name(T const *ptr)
Convert a pointer to object into a (ugly) type name.
bool valid(std::string label="") const
Returns whether the specified object is available.
bool custom_setup(SetupProc &&provSetup, Args &&...args)
Construct and register an object of type T with specified arguments.
base exception class for ProviderList
bool setup(Args &&...args)
Construct and register an object of type T with specified arguments.
Exception thrown on when object is not available any more.
auto find(std::string label="")
auto find(std::string label="") const
static key_type key(std::string label="")
Extracts and returns the key out of a type and label.
static std::string type_name()
Convert a type into a (ugly) type name.
MovableClassWrapper(pointer_t &&from)
Constructor and assignment from a unique pointer: steal the content.
A class containing an owned object.
size_t key_type
type used for key in the internal registry
cet::coded_exception< error, detail::translate > exception