An element of a collection proxy. More...
#include <CollectionProxyElement.h>
Public Types | |
using | collection_proxy_t = CollProxy |
using | main_element_t = typename collection_proxy_t::main_element_t |
using | aux_elements_t = typename details::SubstituteWithAuxList< typename collection_proxy_t::aux_collections_t >::type |
Tuple of elements (expected to be tagged types). More... | |
Public Member Functions | |
CollectionProxyElement (std::size_t index, main_element_t const &main, aux_elements_t &&auxData) | |
main_element_t const * | operator-> () const |
Returns a pointer to the main element. More... | |
main_element_t const & | operator* () const |
Returns a reference to the main element. More... | |
std::size_t | index () const |
Returns the index of this element in the collection. More... | |
template<typename Tag > | |
auto | get () const -> decltype(auto) |
Returns the auxiliary data specified by type (Tag ). More... | |
template<typename Tag , typename T = Tag const&> | |
auto | getIf () const -> decltype(auto) |
Returns the auxiliary data specified by type (Tag ). More... | |
Static Public Member Functions | |
template<typename Tag > | |
static constexpr bool | has () |
Returns whether this class knowns about the specified type (Tag ). More... | |
Private Member Functions | |
template<typename Tag , typename > | |
auto | getIfHas (std::bool_constant< true >) const -> decltype(auto) |
template<typename Tag , typename T > | |
auto | getIfHas (std::bool_constant< false >) const -> T |
Private Attributes | |
std::size_t | fIndex |
Index of this element in the proxy. More... | |
main_element_t const * | fMain |
Pointer to the main object of the element. More... | |
aux_elements_t | fAuxData |
Data associated to the main object. More... | |
An element of a collection proxy.
CollProxy | the type of collection proxy this is the element of |
The collection proxy element represents, unsurprisingly, a single element of the collection proxy. It exposes all the connections between the components merged into the collection proxy, for a specific element.
The interface of a proxy element allows it to access the main and auxiliary data as follows:
*track
)track->Length()
)has()
method, static (track.has<recob::Hit>()
)get()
method; the data must be available or this call will not compile (track.get<recob::Hit>()
)getIf()
method; if the data is not available, an exception is thrownindex()
methodThe for loop block illustrates how to use some of them:
Please note that getIf()
method is not easy to use correctly. In this example, we rely on the knowledge that track.getIf()
would return a reference to a (non-temporary) object, and we take the address of that object: this is not necessarily the case (e.g., it is not the case for getIf<recob::Hit>()
).
A proxy element class can (and should) be derived from proxy::CollectionProxyElement
. On top of it, the derived class can extend or completely rewrite the interface:
Specialization is also possible, but discouraged.
A proxy::CollectionProxyElement
has knowledge of the type of collection proxy it's an element of, but it has no connection to a collection proxy object and in fact it never interacts with any, not even during construction.
Once the element is customized, a proxy::CollectionProxy
can use it by having it as first template argument:
A CollectionProxyMaker
specialization will have to make()
such objects.
CollProxy
. This class uses CollProxy
to discovers some types it needs, but it does not contain or link to CollProxy
itself. It should be possible therefore to have CollProxy
types and CollectionProxyElement
depend on a third, "trait" type delivering the relevant data types to both objects. Definition at line 162 of file CollectionProxyElement.h.
using proxy::CollectionProxyElement< CollProxy >::aux_elements_t = typename details::SubstituteWithAuxList <typename collection_proxy_t::aux_collections_t>::type |
Tuple of elements (expected to be tagged types).
Definition at line 170 of file CollectionProxyElement.h.
using proxy::CollectionProxyElement< CollProxy >::collection_proxy_t = CollProxy |
Definition at line 165 of file CollectionProxyElement.h.
using proxy::CollectionProxyElement< CollProxy >::main_element_t = typename collection_proxy_t::main_element_t |
Definition at line 166 of file CollectionProxyElement.h.
|
inline |
Constructor: sets the element index, the main element and steals auxiliary data.
Definition at line 175 of file CollectionProxyElement.h.
|
inline |
Returns the auxiliary data specified by type (Tag
).
Definition at line 190 of file CollectionProxyElement.h.
auto proxy::CollectionProxyElement< CollProxy >::getIf | ( | ) | const -> decltype(auto) |
Returns the auxiliary data specified by type (Tag
).
Tag | tag of the data to fetch (usually, its type) |
T | type to return (by default, a constant reference to Tag ) |
Tag
). std::logic_error | if the tag is not available. |
if constexpr
should be used instead (see the example below)This method is a get()
which forgives when the requested type is not available (because this proxy was configured not to hold it).
The difference with get()
is the following:
If the proxy tracks
has not been coded with recob::Hit
data, the code snippet will not compile, because get()
will not compile for tags that were not coded in. On the other end, if recob::Hit
is coded in tracks
but recob::SpacePoint
is not, the snippet will compile. In that case, if the has()
check had been omitted, getIt()
would throw a std::logic_error
exception when executed. With C++17, this will not be necessary any more by using "constexpr if":
recob::SpacePoint
) is not registered in the proxy, getIf()
has no clue of what the return value should be ("which is the type of
the data that does not exist?"). Definition at line 363 of file CollectionProxyElement.h.
|
private |
Definition at line 371 of file CollectionProxyElement.h.
|
private |
Definition at line 377 of file CollectionProxyElement.h.
|
inlinestatic |
Returns whether this class knowns about the specified type (Tag
).
Definition at line 271 of file CollectionProxyElement.h.
|
inline |
Returns the index of this element in the collection.
Definition at line 186 of file CollectionProxyElement.h.
|
inline |
Returns a reference to the main element.
Definition at line 183 of file CollectionProxyElement.h.
|
inline |
Returns a pointer to the main element.
Definition at line 180 of file CollectionProxyElement.h.
|
private |
Data associated to the main object.
Definition at line 280 of file CollectionProxyElement.h.
|
private |
Index of this element in the proxy.
Definition at line 275 of file CollectionProxyElement.h.
|
private |
Pointer to the main object of the element.
Definition at line 276 of file CollectionProxyElement.h.