AssnsTraits.h
Go to the documentation of this file.
1 /**
2  * @file lardata/RecoBaseProxy/ProxyBase/AssnsTraits.h
3  * @brief Traits for _art_ associations.
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_ASSNSTRAITS_H
12 #define LARDATA_RECOBASEPROXY_PROXYBASE_ASSNSTRAITS_H
13 
14 // LArSoft libraries
15 #include "larcorealg/CoreUtils/MetaUtils.h" // util::is_not_same<>
16 
17 // framework libraries
20 
21 // C/C++ standard
22 #include <utility> // std::pair
23 
24 
25 namespace lar {
26 
27  namespace util {
28 
29  //--- BEGIN Traits for art associations ------------------------------------
30  /**
31  * @defgroup ArtAssociationsMetaprogramming Traits for art associations
32  * @ingroup Metaprogramming
33  *
34  * A small set of metaprogramming classes is meant to hide the small
35  * differences in interface currently in `art::Assns` (_art_ 2.10).
36  *
37  * These classes are all contained in the `lar::util` namespace.
38  */
39  /// @{
40 
41 
42  //--------------------------------------------------------------------------
43  // was proxy::details::hasMetadata
44  /// Trait: `value` true if `Assns` (association or its node) has metadata.
45  template <typename Assns>
47 
48  // was: proxy::details::AssnWithMetadata_v
49  /// Trait: true if `Assns` (association or its node) has metadata.
50  template <typename Assns>
52 
53 
54  // was: proxy::details::AssnsMetadataTypeStruct, proxy::details::AssnNodeMetadataType
55  /// Trait: `type` is metadata in `Assns` (association or its node).
56  template <typename Assns>
58 
59  // was: proxy::details::AssnsMetadata_t, proxy::details::AssnNodeMetadata_t
60  /// Trait: type of metadata in `Assns` (association or its node).
61  template <typename Assns>
63 
64 
65  //--------------------------------------------------------------------------
66  // FIXME simplify this code if issue #18769 is accepted
67  // was: proxy::details::AssnsIteratorTypeStruct
68  /// Trait: `type` is iterator of `Assns`.
69  template <typename Assns>
71 
72  /// Trait: type of iterator of `Assns`.
73  // was: proxy::details::AssnsIterator_t
74  template <typename Assns>
76 
77  //--------------------------------------------------------------------------
78  // was: proxy::details::AssnsNodeTraits
79  /**
80  * @brief Data types for the specified association type (or its node).
81  * @tparam Assns _art_ association type, or its node
82  *
83  * The trait class is expected to provide the following types:
84  * * `left_t`: type at the left side of the association
85  * * `right_t`: type at the right side of the association
86  * * `data_t`: type of data bound to the association
87  * * `leftptr_t`: _art_ pointer to the left side
88  * * `rightptr_t`: _art_ pointer to the right side
89  * * `dataptr_t`: pointer to the bound metadata
90  * * `assns_t`: type of the _art_ association object
91  * * `art_assns_node_t`: node in the associations list, representing a
92  * single connection between two objects and its metadata
93  *
94  * and the following constant value:
95  *
96  * * `hasMetadata`: shortcut to know whether this node supports any metadata
97  *
98  * The trait class is not defined for types other than `art::Assns` and its
99  * node type.
100  */
101  template <typename Assns>
102  struct assns_traits;
103 
104 
105  //--------------------------------------------------------------------------
106 
107  ///@}
108  //--- END Traits for art associations --------------------------------------
109 
110  } // namespace util
111 
112 } // namespace lar
113 
114 
115 
116 //------------------------------------------------------------------------------
117 //--- template implementation
118 //------------------------------------------------------------------------------
119 namespace lar {
120 
121  namespace util {
122 
123  namespace details {
124 
125  // was: proxy::details::isAssnMetadata
126  template <typename T>
128 
129 
130  template <typename Assns>
131  struct node_of;
132 
133  template <typename Assns>
134  using node_of_t = typename node_of<Assns>::type;
135 
136  template <typename L, typename R, typename D>
137  struct node_of<art::Assns<L, R, D>> {
139  };
140 
141  template <typename L, typename R>
142  struct node_of<art::Assns<L, R, void>> {
143  using type = std::pair<art::Ptr<L>, art::Ptr<R>>;
144  };
145 
146  } // namespace details
147 
148  //--------------------------------------------------------------------------
149  template <typename L, typename R, typename D>
150  struct assns_metadata_type<art::Assns<L, R, D>> {
151  using type = D;
152  };
153 
154  template <typename L, typename R, typename D>
155  struct assns_metadata_type<art::AssnsNode<L, R, D>> {
156  using type = D;
157  };
158 
159  template <typename L, typename R>
160  struct assns_metadata_type<std::pair<art::Ptr<L>, art::Ptr<R>>> {
161  using type = void;
162  };
163 
164 
165  //--------------------------------------------------------------------------
166  template <typename Assns>
167  struct assns_has_metadata
168  : details::isAssnMetadata<assns_metadata_t<Assns>>
169  {};
170 
171 
172  //--------------------------------------------------------------------------
173  template <typename L, typename R, typename D>
174  struct assns_iterator_type<art::Assns<L, R, D>> {
176  }; // struct assns_iterator_type
177 
178 
179  template <typename L, typename R>
180  struct assns_iterator_type<art::Assns<L, R, void>> {
182  };
183 
184 
185  //--------------------------------------------------------------------------
186  // was proxy::details::AssnsNodeTraitsBase
187  template <typename L, typename R, typename D>
188  struct assns_traits<art::Assns<L, R, D>> {
189 
190  using left_t = L; ///< Type at the left side of the association.
191  using right_t = R; ///< Type at the right side of the association.
192  using data_t = D; ///< Type of data bound to the association.
193  using leftptr_t = art::Ptr<left_t>; ///< Art pointer to the left side.
194  using rightptr_t = art::Ptr<right_t>; ///< Art pointer to the right side.
195  using dataptr_t = data_t const*; ///< Pointer to the bound metadata.
196 
197  using assns_t = art::Assns<L, R, D>; ///< Type of the association.
198 
199  /// Type of the association iterator.
201 
202  /// Type of a node (element) in the association.
204 
205  /// Shortcut to know whether this node supports any metadata,
206  static constexpr bool hasMetadata = details::isAssnMetadata<data_t>();
207 
208  }; // struct assns_traits<Assns<L,R,D>>
209 
210 
211  template <typename L, typename R, typename D>
212  struct assns_traits<art::AssnsNode<L, R, D>>
213  : public assns_traits<art::Assns<L, R, D>>
214  {};
215 
216  template <typename L, typename R>
217  struct assns_traits<std::pair<art::Ptr<L>, art::Ptr<R>>>
218  : public assns_traits<art::Assns<L, R>>
219  {};
220 
221 
222  //--------------------------------------------------------------------------
223 
224  } // namespace util
225 
226 } // namespace lar
227 
228 
229 #endif // LARDATA_RECOBASEPROXY_PROXYBASE_ASSNSTRAITS_H
Namespace for general, non-LArSoft-specific utilities.
Basic C++ metaprogramming utilities.
::util::is_not_same< T, void > isAssnMetadata
Definition: AssnsTraits.h:127
typename assns_metadata_type< Assns >::type assns_metadata_t
Trait: type of metadata in Assns (association or its node).
Definition: AssnsTraits.h:62
STL namespace.
Trait: type is metadata in Assns (association or its node).
Definition: AssnsTraits.h:57
#define D
Debug message.
Definition: tclscanner.cpp:775
details::node_of_t< assns_t > art_assns_node_t
Type of a node (element) in the association.
Definition: AssnsTraits.h:203
typename assns_iterator_type< Assns >::type assns_iterator_t
Trait: type of iterator of Assns.
Definition: AssnsTraits.h:75
Trait: value true if Assns (association or its node) has metadata.
Definition: AssnsTraits.h:46
L left_t
Type at the left side of the association.
Definition: AssnsTraits.h:190
std::negation< std::is_same< A, B >> is_not_same
The negation of std::is_same.
Definition: MetaUtils.h:183
constexpr bool assns_has_metadata_v
Trait: true if Assns (association or its node) has metadata.
Definition: AssnsTraits.h:51
R right_t
Type at the right side of the association.
Definition: AssnsTraits.h:191
Data types for the specified association type (or its node).
Definition: AssnsTraits.h:102
typename assns_iterator_type< assns_t >::type assns_iterator_t
Type of the association iterator.
Definition: AssnsTraits.h:200
LArSoft-specific namespace.
data_t const * dataptr_t
Pointer to the bound metadata.
Definition: AssnsTraits.h:195
typename node_of< Assns >::type node_of_t
Definition: AssnsTraits.h:134
typename art::const_AssnsIter< L, R, D, Direction::Forward > const_iterator
Definition: Assns.h:237
Trait: type is iterator of Assns.
Definition: AssnsTraits.h:70