LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
lar::ProviderPack< Providers > Class Template Reference

Container for a list of pointers to providers. More...

#include "ProviderPack.h"

Public Member Functions

 ProviderPack ()=default
 Default constructor: a null provider pointer for each type. More...
 
 ProviderPack (Providers const *...provider_ptrs)
 Constructor: stores a provider pointer for each type. More...
 
template<typename... OtherProviders>
 ProviderPack (ProviderPack< OtherProviders... > const &from)
 Constructor: extracts the providers from another parameter pack. More...
 
template<typename... OtherProviders>
 ProviderPack (OtherProviders const *...providers)
 Constructor: picks the providers from the specified ones. More...
 
template<typename... PackProviders, typename... OtherProviders>
 ProviderPack (ProviderPack< PackProviders... > const &fromPack, OtherProviders const *...providers)
 Constructor: picks the providers from a pack plus specified ones. More...
 
template<typename Provider >
Provider const * get () const
 Returns the provider with the specified type. More...
 
template<typename Provider >
void set (Provider const *provider_ptr)
 Sets the provider with the specified type. More...
 
template<typename... OtherProviders>
bool operator== (ProviderPack< OtherProviders... > const &other) const
 Returns whether other provider pack has all the same providers as this. More...
 
template<typename... OtherProviders>
bool operator!= (ProviderPack< OtherProviders... > const &other) const
 Returns whether other provider pack and this have different providers. More...
 

Static Public Member Functions

template<typename Provider >
static constexpr bool has ()
 Returns whether there is a provider with the specified type. More...
 
template<typename... OtherProviders>
static constexpr bool containsProviders ()
 Returns whether all our providers are in the OfferedProviders list. More...
 

Private Types

using this_type = ProviderPack< Providers... >
 alias of this class More...
 
using tuple_type = std::tuple< Providers const *... >
 type used for storage of the pointers More...
 

Private Attributes

tuple_type providers
 container of the pointers, type-safe More...
 

Detailed Description

template<typename... Providers>
class lar::ProviderPack< Providers >

Container for a list of pointers to providers.


Template Parameters
Providerstypes of the providers in the parameter pack

The pointers are stored as constant. Note that this container can host any type of objects, and it has "provider" in the name because the reason it was written was to provide a fast way to specify a set of LArSoft service providers. The only limitation is that there should be only one object per type. Pointed objects are not owned by this class.

A a;
B1 b; // derived from B
C c;
D d;
ProviderPack<A, B, C> pack(&a, &b, &c);
// obtain a constant pointer to b from pack:
B const* b_ptr = pack.get<B>();
if constexpr (pack.has<D>()) std::cerr << "Unexpected!" << std::endl;

(note that in the latter check constexpr is supported only since C++17).

Definition at line 111 of file ProviderPack.h.

Member Typedef Documentation

template<typename... Providers>
using lar::ProviderPack< Providers >::this_type = ProviderPack<Providers...>
private

alias of this class

Definition at line 115 of file ProviderPack.h.

template<typename... Providers>
using lar::ProviderPack< Providers >::tuple_type = std::tuple<Providers const*...>
private

type used for storage of the pointers

Definition at line 118 of file ProviderPack.h.

Constructor & Destructor Documentation

template<typename... Providers>
lar::ProviderPack< Providers >::ProviderPack ( )
default

Default constructor: a null provider pointer for each type.

template<typename... Providers>
lar::ProviderPack< Providers >::ProviderPack ( Providers const *...  provider_ptrs)
inline

Constructor: stores a provider pointer for each type.

Definition at line 125 of file ProviderPack.h.

125 : providers(provider_ptrs...) {}
tuple_type providers
container of the pointers, type-safe
Definition: ProviderPack.h:236
template<typename... Providers>
template<typename... OtherProviders>
lar::ProviderPack< Providers >::ProviderPack ( ProviderPack< OtherProviders... > const &  from)
inline

Constructor: extracts the providers from another parameter pack.

Template Parameters
OtherProviderslist of the providers of the source provider pack
Parameters
fromwhere to copy the information from

This constructor requires all the providers we need to be present in the source provider pack.

Definition at line 136 of file ProviderPack.h.

137  {
138  details::SetFrom<this_type, ProviderPack<OtherProviders...>, Providers...>(*this, from);
139  }
ProviderPack< Providers... > this_type
alias of this class
Definition: ProviderPack.h:115
ProviderPack()=default
Default constructor: a null provider pointer for each type.
template<typename... Providers>
template<typename... OtherProviders>
lar::ProviderPack< Providers >::ProviderPack ( OtherProviders const *...  providers)
inline

Constructor: picks the providers from the specified ones.

Template Parameters
OtherProviderslist of the type of providers offered
Parameters
providersall the providers needed (or more)

This constructor will pick, among the offered providers, the ones that are needed.

Definition at line 150 of file ProviderPack.h.

151  {
152  details::SetFrom<this_type, ProviderPack<OtherProviders...>, Providers...>(
153  *this, ProviderPack<OtherProviders...>(providers...));
154  }
ProviderPack< Providers... > this_type
alias of this class
Definition: ProviderPack.h:115
ProviderPack()=default
Default constructor: a null provider pointer for each type.
tuple_type providers
container of the pointers, type-safe
Definition: ProviderPack.h:236
template<typename... Providers>
template<typename... PackProviders, typename... OtherProviders>
lar::ProviderPack< Providers >::ProviderPack ( ProviderPack< PackProviders... > const &  fromPack,
OtherProviders const *...  providers 
)

Constructor: picks the providers from a pack plus specified ones.

Template Parameters
FromPackparameter pack to start from
OtherProviderslist of the type of providers offered
Parameters
fromPackproviders to be picked
providersall the remaining providers needed (or more)
See also
expandProviderPack()

This constructor will pick all the providers from the specified pack, and the ones from the other providers. This constructor can be used to "expand" from another provider:

A a;
B b;
C c;
D d;
ProviderPack<A, D> pack(&a, &d);
ProviderPack<A, B, C, D> largerPack(pack, &c, &b);

Definition at line 616 of file ProviderPack.h.

References lar::makeProviderPack().

618  {
619 
620  // verify that the list of providers in argument is the exact one we need
621  static_assert(
622  details::are_same_types<Providers...>::template as<PackProviders..., OtherProviders...>(),
623  "The providers types in the arguments do not match the ones needed.");
624 
625  // copy all the providers from the provider pack
626  details::SetFrom<this_type, ProviderPack<PackProviders...>, PackProviders...>(*this, fromPack);
627 
628  // put the other providers in a temporary parameter pack, and copy it
629  // (this is convenience, a direct implementation would be probably better)
630  details::SetFrom<this_type, ProviderPack<OtherProviders...>, OtherProviders...>(
631  *this, makeProviderPack(providers...));
632 
633  } // ProviderPack<Providers...>::ProviderPack(ProviderPack, OtherProviders...)
ProviderPack< Providers... > this_type
alias of this class
Definition: ProviderPack.h:115
ProviderPack()=default
Default constructor: a null provider pointer for each type.
tuple_type providers
container of the pointers, type-safe
Definition: ProviderPack.h:236
ProviderPack< Providers... > makeProviderPack(Providers const *...providers)
Function to create a ProviderPack from the function arguments.
Definition: ProviderPack.h:256

Member Function Documentation

template<typename... Providers>
template<typename... OfferedProviders>
constexpr bool lar::ProviderPack< Providers >::containsProviders ( )
static

Returns whether all our providers are in the OfferedProviders list.

Template Parameters
OfferedProviderslist of offered providers

This static function returns true if all the providers in this provider pack are included among the OfferedProviders list. That list can contain additional provider types, which will not affect the result.

Usage example:

using providers_t
  = lar::ProviderPack<geo::GeometryCore, detinfo::LArProperties>;
static_assert(
  providers_t::containsProviders
    <detinfo::LArProperties, detinfo::DetectorProperties>(),
  "Not all the required providers are present."
  );

In this example, the assertion will fail because of the absence of detinfo::DetectorProperties from providers_t.

Definition at line 655 of file ProviderPack.h.

References in.

656  {
657  return details::are_types_contained<Providers...>::template in<OfferedProviders...>();
658  } // ProviderPack<>::containsProviders()
ifstream in
Definition: comparison.C:7
template<typename... Providers>
template<typename Provider >
Provider const* lar::ProviderPack< Providers >::get ( ) const
inline
template<typename... Providers>
template<typename Provider >
static constexpr bool lar::ProviderPack< Providers >::has ( )
inlinestatic

Returns whether there is a provider with the specified type.

Definition at line 198 of file ProviderPack.h.

References lar::details::hasDerivedFrom(), util::details::operator!=(), util::details::operator==(), and fhicl::other.

199  {
200  return details::hasDerivedFrom<Provider, Providers...>();
201  }
constexpr std::size_t hasDerivedFrom()
Definition: ProviderPack.h:75
template<typename... Providers>
template<typename... OtherProviders>
bool lar::ProviderPack< Providers >::operator!= ( ProviderPack< OtherProviders... > const &  other) const

Returns whether other provider pack and this have different providers.

Definition at line 647 of file ProviderPack.h.

References fhicl::other.

648  {
649  return !(*this == other);
650  }
template<typename... Providers>
template<typename... OtherProviders>
bool lar::ProviderPack< Providers >::operator== ( ProviderPack< OtherProviders... > const &  other) const

Returns whether other provider pack has all the same providers as this.

Definition at line 638 of file ProviderPack.h.

639  {
640  return details::ProviderPackComparer<ProviderPack<Providers...>,
641  ProviderPack<OtherProviders...>,
642  Providers...>::compare(*this, other);
643  }
ProviderPack()=default
Default constructor: a null provider pointer for each type.
template<typename... Providers>
template<typename Provider >
void lar::ProviderPack< Providers >::set ( Provider const *  provider_ptr)
inline

Sets the provider with the specified type.

Definition at line 190 of file ProviderPack.h.

References lar::details::findDerivedFrom().

191  {
192  constexpr auto providerIndex = details::findDerivedFrom<Provider, Providers...>();
193  std::get<providerIndex>(providers) = provider_ptr;
194  } // set<>()
tuple_type providers
container of the pointers, type-safe
Definition: ProviderPack.h:236
constexpr std::size_t findDerivedFrom()
Definition: ProviderPack.h:539

Member Data Documentation

template<typename... Providers>
tuple_type lar::ProviderPack< Providers >::providers
private

container of the pointers, type-safe

Definition at line 236 of file ProviderPack.h.


The documentation for this class was generated from the following file: