CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ESHandle.h
Go to the documentation of this file.
1 #ifndef DataFormats_FWLite_ESHandle_h
2 #define DataFormats_FWLite_ESHandle_h
3 // -*- C++ -*-
4 //
5 // Package: FWLite
6 // Class : ESHandle
7 //
16 //
17 // Original Author: Chris Jones
18 // Created: Mon Dec 14 15:16:07 CST 2009
19 //
20 
21 // system include files
22 #include <memory>
23 #include <typeinfo>
24 #include <vector>
25 
26 // user include files
28 
29 // forward declarations
30 namespace fwlite {
31  class Record;
32 
33  std::shared_ptr<cms::Exception> eshandle_not_set_exception();
34 
35 template <class T>
36 class ESHandle
37 {
38  friend class fwlite::Record;
39 
40  public:
42 
43  // ---------- const member functions ---------------------
44  bool isValid() const { return 0!=m_data;}
45 
46  const T& operator*() const {
47  if(0!=m_exception.get()) {
48  throw *m_exception;
49  }
50  return *m_data;
51  }
52 
53  const T* operator->() const {
54  if(0!=m_exception.get()) {
55  throw *m_exception;
56  }
57  return m_data;
58 
59  }
60 
61  const std::type_info& typeInfo() const {
62  return typeid(T);
63  }
64  // ---------- static member functions --------------------
65 
66  // ---------- member functions ---------------------------
67 
68  private:
69  ESHandle(const void* iData) :
70  m_data(static_cast<const T*>(iData)),
71  m_exception() {}
72  ESHandle(cms::Exception* iException) :
73  m_data(0), m_exception(iException) {}
74  //ESHandle(const ESHandle&); // stop default
75 
76  //const ESHandle& operator=(const ESHandle&); // stop default
77 
78  // ---------- member data --------------------------------
79  const T* m_data;
80  std::shared_ptr<cms::Exception> m_exception;
81 };
82 
83 }
84 #endif
std::shared_ptr< cms::Exception > eshandle_not_set_exception()
Definition: ESHandle.cc:28
std::shared_ptr< cms::Exception > m_exception
Definition: ESHandle.h:80
const std::type_info & typeInfo() const
Definition: ESHandle.h:61
bool isValid() const
Definition: ESHandle.h:44
const T & operator*() const
Definition: ESHandle.h:46
const T * m_data
Definition: ESHandle.h:79
ESHandle(cms::Exception *iException)
Definition: ESHandle.h:72
ESHandle(const void *iData)
Definition: ESHandle.h:69
string const
Definition: compareJSON.py:14
long double T
const T * operator->() const
Definition: ESHandle.h:53