Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:03:54

0001 #ifndef DataFormats_Common_RefTraits_h
0002 #define DataFormats_Common_RefTraits_h
0003 
0004 #include <algorithm>
0005 
0006 namespace edm {
0007   template <typename C, typename T, typename F>
0008   class RefVector;
0009   template <typename T>
0010   class RefToBaseVector;
0011 
0012   namespace refhelper {
0013     template <typename C, typename T>
0014     struct FindUsingAdvance {
0015       typedef C const& first_argument_type;
0016       typedef unsigned int second_argument_type;
0017       typedef T const* result_type;
0018 
0019       result_type operator()(first_argument_type iContainer, second_argument_type iIndex) {
0020         typename C::const_iterator it = iContainer.begin();
0021         std::advance(it, static_cast<typename C::size_type>(iIndex));
0022         return it.operator->();
0023       }
0024     };
0025 
0026     template <typename REFV>
0027     struct FindRefVectorUsingAdvance {
0028       using first_argument_type = REFV const&;
0029       using second_argument_type = typename REFV::key_type;
0030       using result_type = typename REFV::member_type const*;
0031 
0032       result_type operator()(first_argument_type iContainer, second_argument_type iIndex) {
0033         typename REFV::const_iterator it = iContainer.begin();
0034         std::advance(it, iIndex);
0035         return it.operator->()->get();
0036       }
0037     };
0038 
0039     //Used in edm::Ref to set the default 'find' method to use based on the Container and 'contained' type
0040     template <typename C, typename T>
0041     struct FindTrait {
0042       typedef FindUsingAdvance<C, T> value;
0043     };
0044 
0045     template <typename C, typename T, typename F>
0046     struct FindTrait<RefVector<C, T, F>, T> {
0047       typedef FindRefVectorUsingAdvance<RefVector<C, T, F> > value;
0048     };
0049 
0050     template <typename T>
0051     struct FindTrait<RefToBaseVector<T>, T> {
0052       typedef FindRefVectorUsingAdvance<RefToBaseVector<T> > value;
0053     };
0054 
0055     template <typename C>
0056     struct ValueTrait {
0057       typedef typename C::value_type value;
0058     };
0059 
0060     template <typename C, typename T, typename F>
0061     struct ValueTrait<RefVector<C, T, F> > {
0062       typedef T value;
0063     };
0064 
0065     template <typename T>
0066     struct ValueTrait<RefToBaseVector<T> > {
0067       typedef T value;
0068     };
0069 
0070   }  // namespace refhelper
0071 
0072 }  // namespace edm
0073 #endif