Public Member Functions | Static Public Member Functions | Private Types | Private Attributes | List of all members
gar::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 anothe parameter pack. More...
 
template<typename... OtherProviders>
 ProviderPack (OtherProviders const *...providers_tmp)
 Constructor: extracts the providers from anothe parameter pack. 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...
 

Static Public Member Functions

template<typename Provider >
static constexpr bool has ()
 Returns whether there is a provider with the specified type. 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 gar::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 GArSoft 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;
B b;
C c;
D d;
ProviderPack<A, B, C> pack(&a, &b, &c);

// obtain a constant pointerto b from pack:
B const* b_ptr = pack.get<B>();

if (pack.has<D>()) std::cerr << "Unexpected!" << std::endl;

(note that the latter check can be coded as a static assert)

Definition at line 90 of file ProviderPack.h.

Member Typedef Documentation

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

alias of this class

Definition at line 94 of file ProviderPack.h.

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

type used for storage of the pointers

Definition at line 97 of file ProviderPack.h.

Constructor & Destructor Documentation

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

Default constructor: a null provider pointer for each type.

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

Constructor: stores a provider pointer for each type.

Definition at line 104 of file ProviderPack.h.

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

Constructor: extracts the providers from anothe 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 116 of file ProviderPack.h.

117  {
118  details::SetFrom
119  <this_type, ProviderPack<OtherProviders...>, Providers...>
120  (*this, from);
121  }
ProviderPack()=default
Default constructor: a null provider pointer for each type.
ProviderPack< Providers... > this_type
alias of this class
Definition: ProviderPack.h:94
template<typename... Providers>
template<typename... OtherProviders>
gar::ProviderPack< Providers >::ProviderPack ( OtherProviders const *...  providers_tmp)
inline

Constructor: extracts the providers from anothe parameter pack.

Template Parameters
OtherProviderslist of the providers of the source provider pack
Parameters
providersall the providers needed (or more)

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

Definition at line 132 of file ProviderPack.h.

133  {
134  details::SetFrom
135  <this_type, ProviderPack<OtherProviders...>, Providers...>
136  (*this, ProviderPack<OtherProviders...>(providers_tmp...));
137  }
ProviderPack()=default
Default constructor: a null provider pointer for each type.
ProviderPack< Providers... > this_type
alias of this class
Definition: ProviderPack.h:94

Member Function Documentation

template<typename... Providers>
template<typename Provider >
Provider const* gar::ProviderPack< Providers >::get ( ) const
inline

Returns the provider with the specified type.

Definition at line 141 of file ProviderPack.h.

142  {
143  return std::get<details::index_with_type<Provider, Providers...>::value>
144  (providers);
145  } // get<>()
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115
tuple_type providers
container of the pointers, type-safe
Definition: ProviderPack.h:167
template<typename... Providers>
template<typename Provider >
static constexpr bool gar::ProviderPack< Providers >::has ( )
inlinestatic

Returns whether there is a provider with the specified type.

Definition at line 159 of file ProviderPack.h.

160  {
161  return details::index_with_type_impl<Provider, Providers...>::value
162  < sizeof...(Providers);
163  } // has<>()
template<typename... Providers>
template<typename Provider >
void gar::ProviderPack< Providers >::set ( Provider const *  provider_ptr)
inline

Sets the provider with the specified type.

Definition at line 150 of file ProviderPack.h.

151  {
152  std::get<details::index_with_type<Provider, Providers...>::value>
153  (providers)
154  = provider_ptr;
155  } // set<>()
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115
tuple_type providers
container of the pointers, type-safe
Definition: ProviderPack.h:167

Member Data Documentation

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

container of the pointers, type-safe

Definition at line 167 of file ProviderPack.h.


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