MainCollectionProxy.h
Go to the documentation of this file.
1 /**
2  * @file lardata/RecoBaseProxy/ProxyBase/MainCollectionProxy.h
3  * @brief Utilities for the main collection of a collection proxy.
4  * @author Gianluca Petrillo (petrillo@fnal.gov)
5  * @date July 27, 2017
6  * @see lardata/RecoBaseProxy/ProxyBase.h
7  *
8  * This library is header-only.
9  */
10 
11 #ifndef LARDATA_RECOBASEPROXY_PROXYBASE_MAINCOLLECTIONPROXY_H
12 #define LARDATA_RECOBASEPROXY_PROXYBASE_MAINCOLLECTIONPROXY_H
13 
14 // LArSoft libraries
15 #include "larcorealg/CoreUtils/ContainerMeta.h" // util::collection_value_t, ...
16 
17 // C/C++ standard
18 #include <cstdlib> // std::size_t
19 
20 
21 
22 namespace proxy {
23 
24  //----------------------------------------------------------------------------
25  namespace details {
26 
27  //--------------------------------------------------------------------------
28  //--- stuff for the main collection
29  //--------------------------------------------------------------------------
30  /**
31  * @brief Wrapper for the main collection of a proxy.
32  * @tparam MainColl type of the collection being wrapped
33  *
34  * The wrapper contains a pointer to the original collection, which must
35  * persist. The original collection is not modified.
36  *
37  * The `MainColl` type must expose a random access container interface.
38  */
39  template <typename MainColl>
41 
42  /// Type of the original collection.
43  using main_collection_t = MainColl;
44 
45  /// Type of the elements in the original collection.
47 
48  /// Constructor: wraps the specified collection.
50 
51  /// Returns the wrapped collection.
52  main_collection_t const& main() const { return mainRef(); }
53 
54  /// Returns a reference to the wrapped collection.
55  main_collection_t const& mainRef() const { return *fMain; }
56 
57  /// Returns a pointer to the wrapped collection.
58  main_collection_t const* mainPtr() const { return fMain; }
59 
60 
61  protected:
62  /// This type.
64 
65  /// Return this object as main collection proxy.
66  this_t& mainProxy() { return *this; }
67 
68  /// Return this object as main collection proxy.
69  this_t const& mainProxy() const { return *this; }
70 
71  /// Returns the specified item in the original collection.
72  auto getMainAt(std::size_t i) const -> decltype(auto)
73  { return fMain->operator[](i); }
74 
75  private:
76  main_collection_t const* fMain; /// Pointer to the original collection.
77 
78  }; // struct MainCollectionProxy<>
79 
80 
81  //--------------------------------------------------------------------------
82 
83  } // namespace details
84 
85 } // namespace proxy
86 
87 
88 #endif // LARDATA_RECOBASEPROXY_PROXYBASE_MAINCOLLECTIONPROXY_H
util::collection_value_t< MainColl > main_element_t
Type of the elements in the original collection.
main_collection_t const & main() const
Returns the wrapped collection.
main_collection_t const * mainPtr() const
Returns a pointer to the wrapped collection.
Wrapper for the main collection of a proxy.
this_t & mainProxy()
Return this object as main collection proxy.
MainColl main_collection_t
Type of the original collection.
this_t const & mainProxy() const
Return this object as main collection proxy.
MainCollectionProxy(main_collection_t const &main)
Constructor: wraps the specified collection.
auto getMainAt(std::size_t i) const -> decltype(auto)
Returns the specified item in the original collection.
main_collection_t const & mainRef() const
Returns a reference to the wrapped collection.
typename collection_value_type< Coll >::type collection_value_t
Type contained in the collection Coll.
Definition: ContainerMeta.h:65
C++ metaprogramming utilities for dealing with containers.