All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Static Public Member Functions | Private Types | Private Attributes | List of all members
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 114 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 118 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 121 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 129 of file ProviderPack.h.

129  : providers(provider_ptrs...)
130  {}
tuple_type providers
container of the pointers, type-safe
Definition: ProviderPack.h:251
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 141 of file ProviderPack.h.

142  {
143  details::SetFrom
144  <this_type, ProviderPack<OtherProviders...>, Providers...>
145  (*this, from);
146  }
ProviderPack< Providers...> this_type
alias of this class
Definition: ProviderPack.h:118
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 157 of file ProviderPack.h.

158  {
159  details::SetFrom
160  <this_type, ProviderPack<OtherProviders...>, Providers...>
161  (*this, ProviderPack<OtherProviders...>(providers...));
162  }
ProviderPack< Providers...> this_type
alias of this class
Definition: ProviderPack.h:118
ProviderPack()=default
Default constructor: a null provider pointer for each type.
tuple_type providers
container of the pointers, type-safe
Definition: ProviderPack.h:251
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 687 of file ProviderPack.h.

691  {
692 
693  // verify that the list of providers in argument is the exact one we need
694  static_assert(
695  details::are_same_types<Providers...>
696  ::template as<PackProviders..., OtherProviders...>(),
697  "The providers types in the arguments do not match the ones needed."
698  );
699 
700  // copy all the providers from the provider pack
701  details::SetFrom
702  <this_type, ProviderPack<PackProviders...>, PackProviders...>
703  (*this, fromPack);
704 
705  // put the other providers in a temporary parameter pack, and copy it
706  // (this is convenience, a direct implementation would be probably better)
707  details::SetFrom
708  <this_type, ProviderPack<OtherProviders...>, OtherProviders...>
709  (*this, makeProviderPack(providers...));
710 
711  } // ProviderPack<Providers...>::ProviderPack(ProviderPack, OtherProviders...)
ProviderPack< Providers...> this_type
alias of this class
Definition: ProviderPack.h:118
ProviderPack()=default
Default constructor: a null provider pointer for each type.
tuple_type providers
container of the pointers, type-safe
Definition: ProviderPack.h:251
ProviderPack< Providers...> makeProviderPack(Providers const *...providers)
Function to create a ProviderPack from the function arguments.
Definition: ProviderPack.h:272

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 736 of file ProviderPack.h.

736  {
737  return details::are_types_contained<Providers...>
738  ::template in<OfferedProviders...>();
739  } // ProviderPack<>::containsProviders()
if &&[-z"$BASH_VERSION"] then echo Attempting to switch to bash bash shellSwitch exit fi &&["$1"= 'shellSwitch'] shift declare a IncludeDirectives for Dir in
template<typename... Providers>
template<typename Provider >
Provider const* lar::ProviderPack< Providers >::get ( ) const
inline

Returns the provider with the specified type.

Definition at line 193 of file ProviderPack.h.

194  {
195  constexpr auto providerIndex
196  = details::findDerivedFrom<Provider, Providers...>();
197  return std::get<providerIndex>(providers);
198  } // get<>()
tuple_type providers
container of the pointers, type-safe
Definition: ProviderPack.h:251
constexpr std::size_t findDerivedFrom()
Definition: ProviderPack.h:598
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 212 of file ProviderPack.h.

213  { return details::hasDerivedFrom<Provider, Providers...>(); }
constexpr std::size_t hasDerivedFrom()
Definition: ProviderPack.h:77
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 729 of file ProviderPack.h.

730  { return !(*this == other); }
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 718 of file ProviderPack.h.

719  {
720  return details::ProviderPackComparer<
721  ProviderPack<Providers...>, ProviderPack<OtherProviders...>, Providers...
722  >::compare(*this, other);
723  }
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 203 of file ProviderPack.h.

204  {
205  constexpr auto providerIndex
206  = details::findDerivedFrom<Provider, Providers...>();
207  std::get<providerIndex>(providers) = provider_ptr;
208  } // set<>()
tuple_type providers
container of the pointers, type-safe
Definition: ProviderPack.h:251
constexpr std::size_t findDerivedFrom()
Definition: ProviderPack.h:598

Member Data Documentation

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

container of the pointers, type-safe

Definition at line 251 of file ProviderPack.h.


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