Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:13:13

0001 #ifndef FWCore_Utilities_TypeToGet_h
0002 #define FWCore_Utilities_TypeToGet_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     FWCore/Utilities
0006 // Class  :     TypeToGet
0007 //
0008 /**\class TypeToGet TypeToGet.h "FWCore/Utilities/interface/TypeToGet.h"
0009 
0010  Description: [one line class summary]
0011 
0012  Usage:
0013     <usage>
0014 
0015 */
0016 //
0017 // Original Author:  Chris Jones
0018 //         Created:  Sat, 06 Apr 2013 14:45:01 GMT
0019 //
0020 
0021 // system include files
0022 
0023 // user include files
0024 #include "FWCore/Utilities/interface/TypeID.h"
0025 #include "FWCore/Utilities/interface/ProductKindOfType.h"
0026 
0027 // forward declarations
0028 namespace edm {
0029   template <typename T>
0030   class View;
0031 
0032   class TypeToGet {
0033   public:
0034     /**If the type is is a edm::View<T> then
0035      iID should be typeid(T) and iKind should be
0036      edm::ELEMENT_TYPE. Else TypeID should be the full type
0037      and iKind should be edm::ProductType **/
0038     TypeToGet(TypeID const& iID, KindOfType iKind) : m_type(iID), m_kind(iKind) {}
0039 
0040     TypeToGet() = delete;
0041     // ---------- const member functions ---------------------
0042     TypeID const& type() const { return m_type; }
0043     KindOfType kind() const { return m_kind; }
0044 
0045     // ---------- static member functions --------------------
0046     template <typename T>
0047     static TypeToGet make() {
0048       return TypeToGet(edm::TypeID(typeIdFor(static_cast<T*>(nullptr))), kindOfTypeFor(static_cast<T*>(nullptr)));
0049     }
0050 
0051   private:
0052     template <typename T>
0053     static std::type_info const& typeIdFor(T*) {
0054       return typeid(T);
0055     }
0056 
0057     template <typename T>
0058     static std::type_info const& typeIdFor(edm::View<T>*) {
0059       return typeid(T);
0060     }
0061 
0062     template <typename T>
0063     static KindOfType kindOfTypeFor(T*) {
0064       return PRODUCT_TYPE;
0065     }
0066 
0067     template <typename T>
0068     static KindOfType kindOfTypeFor(edm::View<T>*) {
0069       return ELEMENT_TYPE;
0070     }
0071 
0072     // ---------- member data --------------------------------
0073     TypeID m_type;
0074     KindOfType m_kind;
0075   };
0076 }  // namespace edm
0077 
0078 #endif