Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-19 01:43:39

0001 #ifndef FWCore_Framework_CacheHandle_h
0002 #define FWCore_Framework_CacheHandle_h
0003 
0004 /** \class edm::CacheHandle
0005 
0006 \author W. David Dagenhart, created 25 March, 2021
0007 
0008 */
0009 
0010 #include "FWCore/Utilities/interface/Exception.h"
0011 
0012 namespace edm {
0013 
0014   template <typename T>
0015   class CacheHandle {
0016   public:
0017     CacheHandle() : data_(nullptr) {}
0018     CacheHandle(T const* data) : data_(data) {}
0019 
0020     T const* get() const {
0021       if (!isValid()) {
0022         throw cms::Exception("InvalidCache") << "CacheHandle is invalid";
0023       }
0024       return data_;
0025     }
0026     T const* operator->() const { return get(); }
0027     T const& operator*() const { return *get(); }
0028 
0029     bool isValid() const { return data_ != nullptr; }
0030 
0031   private:
0032     T const* data_;
0033   };
0034 }  // namespace edm
0035 #endif