Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 10:49:27

0001 #ifndef DataFormats_Common_traits_h
0002 #define DataFormats_Common_traits_h
0003 
0004 /*----------------------------------------------------------------------
0005 
0006 Definition of traits templates used in the EDM.  
0007 
0008 
0009 ----------------------------------------------------------------------*/
0010 
0011 #include <deque>
0012 #include <limits>
0013 #include <list>
0014 #include <set>
0015 #include <string>
0016 #include <utility>
0017 #include <vector>
0018 
0019 namespace edm {
0020   //------------------------------------------------------------
0021   //
0022   // The trait struct template key_traits<K> is used to carry
0023   // information relevant to the type K when used as a 'key' in
0024   // RefVector and its related classes and templates.
0025   //
0026   // The general case works only for integral types K; for more
0027   // 'esoteric' types, one must introduce an explicit specialization.
0028   // That specialization must initialize the static data member
0029   // 'value'.
0030 
0031   template <class K>
0032   struct key_traits {
0033     typedef K key_type;
0034     static const key_type value;
0035   };
0036 
0037   template <class K>
0038   typename key_traits<K>::key_type const key_traits<K>::value =
0039       std::numeric_limits<typename key_traits<K>::key_type>::max();
0040 
0041   // Partial specialization for std::pair
0042 
0043   template <class U, class V>
0044   struct key_traits<std::pair<U, V> > {
0045     typedef std::pair<U, V> key_type;
0046     static const key_type value;
0047   };
0048 
0049   template <class U, class V>
0050   typename key_traits<std::pair<U, V> >::key_type const key_traits<std::pair<U, V> >::value =
0051       std::make_pair(key_traits<U>::value, key_traits<V>::value);
0052 
0053   // If we ever need to support instantiations of std::basic_string
0054   // other than std::string, this is the place to do it.
0055 
0056   // For value, we make a 1-character long string that contains an
0057   // unprintable character; we are hoping nobody ever uses such a
0058   // string as a legal key.
0059   template <>
0060   struct key_traits<std::string> {
0061     typedef std::string key_type;
0062     static const key_type value;
0063   };
0064 
0065   //------------------------------------------------------------
0066   //
0067   // DoNotSortUponInsertion is a base class. Derive your own class X
0068   // from DoNotSortUponInsertion when:
0069   //
0070   // 1. You want to use DetSetVector<X> as an EDProduct, but
0071   //
0072   // 2. You do *not* want the Event::put member template to cause the
0073   // DetSet<X> instances within the DetSetVector<X> to be sorted.
0074   //
0075   // DoNotSortUponInsertion has no behavior; it is used at compile
0076   // time to influence the behavior of Event::put.
0077   //
0078   // Usage:
0079   //    class MyClass : public edm::DoNotSortUponInsertion { ... }
0080   //
0081   struct DoNotSortUponInsertion {};
0082 
0083   //------------------------------------------------------------
0084   //
0085   // DoNotRecordParents is a base class. Derive your own (EDProduct)
0086   // class X from DoNotRecordParents when your class already keeps all
0087   // data that are relevant to parentage internally, and the
0088   // information kept by the event model would thus be redundant.
0089   //
0090   // DoNotRecordParents has no behavior; it is used at compile time to
0091   // influence the behavior of Event::put.
0092   //
0093   // Usage:
0094   //    class MyClass : public edm::DoNotRecordParents { ... }
0095   struct DoNotRecordParents {};
0096 
0097   // Other is a base class. NEVER USE IT. It is for the
0098   // core of the event model only.
0099   struct Other {};
0100 
0101   //------------------------------------------------------------
0102   //
0103   // The trait struct template has_fillView<T> is used to
0104   // indicate whether or not the type T has a member function
0105   //
0106   //      void T::fillView(std::vector<void const*>&) const
0107   //
0108   // We assume the 'general case' for T is to not support fillView.
0109   // Classes which do support fillView must specialize this trait.
0110   //
0111   //------------------------------------------------------------
0112 
0113   template <class T>
0114   struct has_fillView {
0115     static bool const value = false;
0116   };
0117 
0118   template <class T, class A>
0119   struct has_fillView<std::vector<T, A> > {
0120     static bool const value = true;
0121   };
0122 
0123   template <class A>
0124   struct has_fillView<std::vector<bool, A> > {
0125     static bool const value = false;
0126   };
0127 
0128   template <class T, class A>
0129   struct has_fillView<std::list<T, A> > {
0130     static bool const value = true;
0131   };
0132 
0133   template <class T, class A>
0134   struct has_fillView<std::deque<T, A> > {
0135     static bool const value = true;
0136   };
0137 
0138   template <class T, class A>
0139   struct has_fillView<std::set<T, A> > {
0140     static bool const value = true;
0141   };
0142 
0143   //------------------------------------------------------------
0144   //
0145   // The trait struct template has_setPtr<T> is used to
0146   // indicate whether or not the type T has a member function
0147   //
0148   //      void T::setPtr(const std::type_info&, void const*&) const
0149   //
0150   // We assume the 'general case' for T is to not support setPtr.
0151   // Classes which do support setPtr must specialize this trait.
0152   //
0153   //------------------------------------------------------------
0154 
0155   template <class T>
0156   struct has_setPtr {
0157     static bool const value = false;
0158   };
0159 
0160   template <class T, class A>
0161   struct has_setPtr<std::vector<T, A> > {
0162     static bool const value = true;
0163   };
0164 
0165   template <class A>
0166   struct has_setPtr<std::vector<bool, A> > {
0167     static bool const value = false;
0168   };
0169 
0170   template <class T, class A>
0171   struct has_setPtr<std::list<T, A> > {
0172     static bool const value = true;
0173   };
0174 
0175   template <class T, class A>
0176   struct has_setPtr<std::deque<T, A> > {
0177     static bool const value = true;
0178   };
0179 
0180   template <class T, class A>
0181   struct has_setPtr<std::set<T, A> > {
0182     static bool const value = true;
0183   };
0184 }  // namespace edm
0185 
0186 #endif