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 // $Id: ESHandle.h,v 1.2 2011/01/28 21:53:19 wmtan Exp $
20 //
21 
22 // system include files
23 #include <typeinfo>
24 #include <vector>
25 #include "boost/shared_ptr.hpp"
26 
27 // user include files
29 
30 // forward declarations
31 namespace fwlite {
32  class Record;
33 
34  boost::shared_ptr<cms::Exception> eshandle_not_set_exception();
35 
36 template <class T>
37 class ESHandle
38 {
39  friend class fwlite::Record;
40 
41  public:
43 
44  // ---------- const member functions ---------------------
45  bool isValid() const { return 0!=m_data;}
46 
47  const T& operator*() const {
48  if(0!=m_exception.get()) {
49  throw *m_exception;
50  }
51  return *m_data;
52  }
53 
54  const T* operator->() const {
55  if(0!=m_exception.get()) {
56  throw *m_exception;
57  }
58  return m_data;
59 
60  }
61 
62  const std::type_info& typeInfo() const {
63  return typeid(T);
64  }
65  // ---------- static member functions --------------------
66 
67  // ---------- member functions ---------------------------
68 
69  private:
70  ESHandle(const void* iData) :
71  m_data(static_cast<const T*>(iData)),
72  m_exception() {}
73  ESHandle(cms::Exception* iException) :
74  m_data(0), m_exception(iException) {}
75  //ESHandle(const ESHandle&); // stop default
76 
77  //const ESHandle& operator=(const ESHandle&); // stop default
78 
79  // ---------- member data --------------------------------
80  const T* m_data;
81  boost::shared_ptr<cms::Exception> m_exception;
82 };
83 
84 }
85 #endif
const std::type_info & typeInfo() const
Definition: ESHandle.h:62
bool isValid() const
Definition: ESHandle.h:45
const T & operator*() const
Definition: ESHandle.h:47
const T * m_data
Definition: ESHandle.h:80
ESHandle(cms::Exception *iException)
Definition: ESHandle.h:73
ESHandle(const void *iData)
Definition: ESHandle.h:70
string const
Definition: compareJSON.py:14
boost::shared_ptr< cms::Exception > eshandle_not_set_exception()
Definition: ESHandle.cc:29
boost::shared_ptr< cms::Exception > m_exception
Definition: ESHandle.h:81
long double T
const T * operator->() const
Definition: ESHandle.h:54