All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Types | List of all members
proxy::CollectionProxyBase< Element, MainColl, AuxColls > Class Template Reference

Base representation of a collection of proxied objects. More...

#include <CollectionProxy.h>

Inheritance diagram for proxy::CollectionProxyBase< Element, MainColl, AuxColls >:
proxy::details::MainCollectionProxy< MainColl >

Public Types

using element_proxy_t = Element< collection_proxy_t >
 Type of element of this collection proxy. More...
 
using aux_collections_t = std::tuple< AuxColls...>
 Tuple of all auxiliary data collections (wrappers). More...
 
using value_type = element_proxy_t
 Type of element of this collection proxy. More...
 
using const_iterator = details::IndexBasedIterator< collection_proxy_t >
 Type of iterator to this collection (constant). More...
 
using iterator = const_iterator
 Type of iterator to this collection (still constant). More...
 
using main_element_t = util::collection_value_t< MainColl >
 Type of the elements in the original collection. More...
 
using main_collection_t = MainColl
 Type of the original collection. More...
 
- Public Types inherited from proxy::details::MainCollectionProxy< MainColl >
using main_collection_t = MainColl
 Type of the original collection. More...
 
using main_element_t = util::collection_value_t< MainColl >
 Type of the elements in the original collection. More...
 

Public Member Functions

 CollectionProxyBase (main_collection_t const &main, AuxColls &&...aux)
 Constructor: uses the specified data. More...
 
element_proxy_t const operator[] (std::size_t i) const
 Returns the element of this collection with the specified index. More...
 
const_iterator begin () const
 Returns an iterator to the first element of the collection. More...
 
const_iterator end () const
 Returns an iterator past the last element of the collection. More...
 
bool empty () const
 Returns whether this collection is empty. More...
 
std::size_t size () const
 Returns the size of this collection. More...
 
template<typename AuxTag >
auto get () const -> decltype(auto)
 Returns the associated data proxy specified by AuxTag. More...
 
template<typename Tag , typename T = std::vector<Tag> const&>
auto getIf () const -> decltype(auto)
 Returns the auxiliary data specified by type (Tag). More...
 
- Public Member Functions inherited from proxy::details::MainCollectionProxy< MainColl >
 MainCollectionProxy (main_collection_t const &main)
 Constructor: wraps the specified collection. More...
 
main_collection_t const & main () const
 Returns the wrapped collection. More...
 
main_collection_t const & mainRef () const
 Returns a reference to the wrapped collection. More...
 
main_collection_t const * mainPtr () const
 Returns a pointer to the wrapped collection. More...
 

Static Public Member Functions

template<typename Tag >
static constexpr bool has ()
 Returns whether this class knowns about the specified type (Tag). More...
 

Protected Member Functions

template<typename AuxColl >
AuxColl const & aux () const
 Returns the auxiliary data specified by type. More...
 
template<typename AuxTag >
auto auxByTag () const -> decltype(auto)
 Returns the auxiliary data specified by type. More...
 
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
 
const_iterator makeIterator (std::size_t i) const
 Returns an iterator pointing to the specified index of this collection. More...
 
- Protected Member Functions inherited from proxy::details::MainCollectionProxy< MainColl >
this_tmainProxy ()
 Return this object as main collection proxy. More...
 
this_t const & mainProxy () const
 Return this object as main collection proxy. More...
 
auto getMainAt (std::size_t i) const -> decltype(auto)
 Returns the specified item in the original collection. More...
 

Private Types

using collection_proxy_t = CollectionProxyBase< Element, MainColl, AuxColls...>
 This type. More...
 
using main_collection_proxy_t = details::MainCollectionProxy< MainColl >
 Type of wrapper used for the main data product. More...
 

Additional Inherited Members

- Protected Types inherited from proxy::details::MainCollectionProxy< MainColl >
using this_t = MainCollectionProxy< main_collection_t >
 This type. More...
 

Detailed Description

template<template< typename CollProxy > class Element, typename MainColl, typename... AuxColls>
class proxy::CollectionProxyBase< Element, MainColl, AuxColls >

Base representation of a collection of proxied objects.

Template Parameters
Elementtype of element of the collection proxy
MainColltype of the collection of the main data product
AuxCollstype of all included auxiliary data proxies
See Also
proxy::CollectionProxyElement

This object exposes a collection interface. The collection proxy is driven by a data product containing the main objects. The size of the collection proxy is the same as the one of this main data product, and all associated data is referring to its elements.

Thus, the elements of this collection proxy are objects that collect the information of a single element in the main data product and all the data associated with it.

The AuxColls types are tagged types: all must define a tag type. Their data is accessed specifying that tag, i.e. via get<Tag>(). Therefore, tags must be unique.

The type Element is expected to expose the same interface of CollectionProxyElement, from which it can derive. It is a template that needs to take as only argument the type of collection proxy it is the element of. This is a way to customize the interface of access to single element of proxy.

Note
This class depends on an Element type, which indirectly depends on this class for discovering some relevant data types. This is a circular dependency that might be solved by introducing a third class with the definition of the types that both classes need.

Definition at line 117 of file CollectionProxy.h.

Member Typedef Documentation

template<template< typename CollProxy > class Element, typename MainColl, typename... AuxColls>
using proxy::CollectionProxyBase< Element, MainColl, AuxColls >::aux_collections_t = std::tuple<AuxColls...>

Tuple of all auxiliary data collections (wrappers).

Definition at line 138 of file CollectionProxy.h.

template<template< typename CollProxy > class Element, typename MainColl, typename... AuxColls>
using proxy::CollectionProxyBase< Element, MainColl, AuxColls >::collection_proxy_t = CollectionProxyBase<Element, MainColl, AuxColls...>
private

This type.

Definition at line 122 of file CollectionProxy.h.

template<template< typename CollProxy > class Element, typename MainColl, typename... AuxColls>
using proxy::CollectionProxyBase< Element, MainColl, AuxColls >::const_iterator = details::IndexBasedIterator<collection_proxy_t>

Type of iterator to this collection (constant).

Definition at line 144 of file CollectionProxy.h.

template<template< typename CollProxy > class Element, typename MainColl, typename... AuxColls>
using proxy::CollectionProxyBase< Element, MainColl, AuxColls >::element_proxy_t = Element<collection_proxy_t>

Type of element of this collection proxy.

Definition at line 135 of file CollectionProxy.h.

template<template< typename CollProxy > class Element, typename MainColl, typename... AuxColls>
using proxy::CollectionProxyBase< Element, MainColl, AuxColls >::iterator = const_iterator

Type of iterator to this collection (still constant).

Definition at line 147 of file CollectionProxy.h.

template<template< typename CollProxy > class Element, typename MainColl, typename... AuxColls>
using proxy::CollectionProxyBase< Element, MainColl, AuxColls >::main_collection_proxy_t = details::MainCollectionProxy<MainColl>
private

Type of wrapper used for the main data product.

Definition at line 125 of file CollectionProxy.h.

template<template< typename CollProxy > class Element, typename MainColl, typename... AuxColls>
using proxy::details::MainCollectionProxy< MainColl >::main_collection_t = MainColl

Type of the original collection.

Definition at line 43 of file MainCollectionProxy.h.

template<template< typename CollProxy > class Element, typename MainColl, typename... AuxColls>
using proxy::details::MainCollectionProxy< MainColl >::main_element_t = util::collection_value_t<MainColl>

Type of the elements in the original collection.

Definition at line 46 of file MainCollectionProxy.h.

template<template< typename CollProxy > class Element, typename MainColl, typename... AuxColls>
using proxy::CollectionProxyBase< Element, MainColl, AuxColls >::value_type = element_proxy_t

Type of element of this collection proxy.

Definition at line 141 of file CollectionProxy.h.

Constructor & Destructor Documentation

template<template< typename CollProxy > class Element, typename MainColl, typename... AuxColls>
proxy::CollectionProxyBase< Element, MainColl, AuxColls >::CollectionProxyBase ( main_collection_t const &  main,
AuxColls &&...  aux 
)
inline

Constructor: uses the specified data.

Parameters
mainthe original main data product collection
auxall auxiliary data collections and structures

The auxiliary data structures are stolen (moved) from the arguments. They are expected to be wrappers around the original associated data, not owning the auxiliary data itself.

Definition at line 158 of file CollectionProxy.h.

159  : main_collection_proxy_t(main), AuxColls(std::move(aux))...
160  {}
main_collection_t const & main() const
Returns the wrapped collection.
details::MainCollectionProxy< MainColl > main_collection_proxy_t
Type of wrapper used for the main data product.
AuxColl const & aux() const
Returns the auxiliary data specified by type.

Member Function Documentation

template<template< typename CollProxy > class Element, typename MainColl, typename... AuxColls>
template<typename AuxColl >
AuxColl const& proxy::CollectionProxyBase< Element, MainColl, AuxColls >::aux ( ) const
inlineprotected

Returns the auxiliary data specified by type.

Definition at line 267 of file CollectionProxy.h.

267 { return static_cast<AuxColl const&>(*this); }
template<template< typename CollProxy > class Element, typename MainColl, typename... AuxColls>
template<typename AuxTag >
auto proxy::CollectionProxyBase< Element, MainColl, AuxColls >::auxByTag ( ) const -> decltype(auto)
inlineprotected

Returns the auxiliary data specified by type.

Definition at line 271 of file CollectionProxy.h.

272  { return aux<util::type_with_tag_t<AuxTag, aux_collections_t>>(); }
template<template< typename CollProxy > class Element, typename MainColl, typename... AuxColls>
const_iterator proxy::CollectionProxyBase< Element, MainColl, AuxColls >::begin ( ) const
inline

Returns an iterator to the first element of the collection.

Definition at line 179 of file CollectionProxy.h.

179 { return makeIterator(0U); }
const_iterator makeIterator(std::size_t i) const
Returns an iterator pointing to the specified index of this collection.
template<template< typename CollProxy > class Element, typename MainColl, typename... AuxColls>
bool proxy::CollectionProxyBase< Element, MainColl, AuxColls >::empty ( ) const
inline

Returns whether this collection is empty.

Definition at line 185 of file CollectionProxy.h.

185 { return main().empty(); }
main_collection_t const & main() const
Returns the wrapped collection.
template<template< typename CollProxy > class Element, typename MainColl, typename... AuxColls>
const_iterator proxy::CollectionProxyBase< Element, MainColl, AuxColls >::end ( ) const
inline

Returns an iterator past the last element of the collection.

Definition at line 182 of file CollectionProxy.h.

182 { return makeIterator(size()); }
const_iterator makeIterator(std::size_t i) const
Returns an iterator pointing to the specified index of this collection.
std::size_t size() const
Returns the size of this collection.
template<template< typename CollProxy > class Element, typename MainColl, typename... AuxColls>
template<typename AuxTag >
auto proxy::CollectionProxyBase< Element, MainColl, AuxColls >::get ( ) const -> decltype(auto)
inline

Returns the associated data proxy specified by AuxTag.

Definition at line 193 of file CollectionProxy.h.

193 { return auxByTag<AuxTag>(); }
template<template< typename CollProxy > class Element, typename MainColl , typename... AuxColls>
template<typename Tag , typename T >
auto proxy::CollectionProxyBase< Element, MainColl, AuxColls >::getIf ( ) const -> decltype(auto)

Returns the auxiliary data specified by type (Tag).

Template Parameters
Tagtag of the data to fetch (usually, its type)
Texact type returned by the method (by default a vector of tags)
Returns
the auxiliary data specified by type (Tag).
Exceptions
std::logic_errorif the tag is not available.
See Also
get(), has()
Deprecated:
C++17 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 (tracks.has<recob::Hit>()) {
auto hits = tracks.get<recob::Hit>();
// ...
}
auto spacepoints = tracks.getIf<recob::SpacePoint>();
// ...
}

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":

if constexpr (tracks.has<recob::Hit>()) {
auto hits = tracks.get<recob::Hit>();
// ...
}
if constexpr (tracks.has<recob::SpacePoint>()) {
auto spacepoints = tracks.get<recob::SpacePoint>();
// ...
}
Note
If the wrapped data product is something different than a vector of space points (which in the example is likely, if space points are associated to tracks), the almost-correct type of return value needs to be specified as second template parameter T.
Warning
This functionality is not trivial to use! It's mostly meant for implementation of higher level wrappers.
Deprecated:
Use C++17 constexpr if instead.

Definition at line 413 of file CollectionProxy.h.

415  { return getIfHas<Tag, T>(std::bool_constant<has<Tag>()>{}); }
template<template< typename CollProxy > class Element, typename MainColl , typename... AuxColls>
template<typename Tag , typename >
auto proxy::CollectionProxyBase< Element, MainColl, AuxColls >::getIfHas ( std::bool_constant< true ) const -> decltype(auto)
protected

Definition at line 425 of file CollectionProxy.h.

426  { return get<Tag>(); }
template<template< typename CollProxy > class Element, typename MainColl , typename... AuxColls>
template<typename Tag , typename T >
auto proxy::CollectionProxyBase< Element, MainColl, AuxColls >::getIfHas ( std::bool_constant< false >  ) const -> T
protected

Definition at line 435 of file CollectionProxy.h.

436  {
437  throw std::logic_error
438  ("Tag '" + lar::debug::demangle<Tag>() + "' not available.");
439  }
template<template< typename CollProxy > class Element, typename MainColl, typename... AuxColls>
template<typename Tag >
static constexpr bool proxy::CollectionProxyBase< Element, MainColl, AuxColls >::has ( )
inlinestatic

Returns whether this class knowns about the specified type (Tag).

Definition at line 256 of file CollectionProxy.h.

257  { return util::has_tag_v<Tag, aux_collections_t>; }
template<template< typename CollProxy > class Element, typename MainColl, typename... AuxColls>
const_iterator proxy::CollectionProxyBase< Element, MainColl, AuxColls >::makeIterator ( std::size_t  i) const
inlineprotected

Returns an iterator pointing to the specified index of this collection.

Definition at line 281 of file CollectionProxy.h.

281 { return { *this, i }; }
template<template< typename CollProxy > class Element, typename MainColl, typename... AuxColls>
element_proxy_t const proxy::CollectionProxyBase< Element, MainColl, AuxColls >::operator[] ( std::size_t  i) const
inline

Returns the element of this collection with the specified index.

Parameters
ithe index in the collection
Returns
a value representing an element of the collection

The returned value is an object created on the spot, not a reference to an existing structure. The structure exposes the i-th element in the main collection, plus all objects that are associated to it.

Definition at line 172 of file CollectionProxy.h.

173  {
174  return details::makeCollectionProxyElement<element_proxy_t>
175  (i, getMainAt(i), aux<AuxColls>().operator[](i)...);
176  }
auto getMainAt(std::size_t i) const -> decltype(auto)
Returns the specified item in the original collection.
template<template< typename CollProxy > class Element, typename MainColl, typename... AuxColls>
std::size_t proxy::CollectionProxyBase< Element, MainColl, AuxColls >::size ( ) const
inline

Returns the size of this collection.

Definition at line 188 of file CollectionProxy.h.

188 { return main().size(); }
main_collection_t const & main() const
Returns the wrapped collection.

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