CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/DataFormats/Common/interface/RefTraits.h

Go to the documentation of this file.
00001 #ifndef DataFormats_Common_RefTraits_h
00002 #define DataFormats_Common_RefTraits_h
00003 
00004 #include <functional>
00005 #include <algorithm>
00006 
00007 namespace edm {
00008   template<typename C, typename T, typename F> class RefVector;
00009   template<typename T> class RefToBaseVector;
00010  
00011   namespace refhelper {
00012     template<typename C, typename T>
00013     struct FindUsingAdvance {
00014       typedef C const&              first_argument_type;
00015       typedef unsigned int          second_argument_type;
00016       typedef T const*              result_type;
00017 
00018       result_type operator()(first_argument_type iContainer, second_argument_type iIndex) {
00019         typename C::const_iterator it = iContainer.begin();
00020         std::advance(it, static_cast<typename C::size_type>(iIndex));
00021         return it.operator->();
00022       }
00023     };
00024     
00025     template<typename REFV>
00026     struct FindRefVectorUsingAdvance : public std::binary_function<REFV const&, 
00027                                                                    typename REFV::key_type, 
00028                                                                    typename REFV::member_type const*> {
00029       typedef FindRefVectorUsingAdvance<REFV> self;
00030       typename self::result_type operator()(typename self::first_argument_type iContainer,
00031                                             typename self::second_argument_type iIndex) {
00032         typename REFV::const_iterator it = iContainer.begin();
00033         std::advance(it, iIndex);
00034         return it.operator->()->get();;
00035       }
00036     };
00037     
00038     //Used in edm::Ref to set the default 'find' method to use based on the Container and 'contained' type
00039     template<typename C, typename T> 
00040     struct FindTrait {
00041       typedef FindUsingAdvance<C, T> value;
00042     };
00043 
00044     template<typename C, typename T, typename F>
00045      struct FindTrait<RefVector<C, T, F>, T> {
00046       typedef FindRefVectorUsingAdvance<RefVector<C, T, F> > value;
00047     };
00048 
00049     template<typename T>
00050      struct FindTrait<RefToBaseVector<T>, T> {
00051       typedef FindRefVectorUsingAdvance<RefToBaseVector<T> > value;
00052     };
00053 
00054     template<typename C>
00055     struct ValueTrait {
00056       typedef typename C::value_type value;
00057     };
00058 
00059     template<typename C, typename T, typename F>
00060     struct ValueTrait<RefVector<C, T, F> > {
00061       typedef T value;
00062     };
00063 
00064     template<typename T>
00065     struct ValueTrait<RefToBaseVector<T> > {
00066       typedef T value;
00067     };
00068 
00069   }
00070   
00071 }
00072 #endif