00001 #ifndef Common_TestHandle_h 00002 #define Common_TestHandle_h 00003 00004 /*---------------------------------------------------------------------- 00005 00006 $Id: TestHandle.h,v 1.1 2008/03/18 12:48:31 wmtan Exp $ 00007 00008 Version of Handle 00009 00010 ----------------------------------------------------------------------*/ 00011 00012 #include <algorithm> 00013 #include <stdexcept> 00014 #include <typeinfo> 00015 00016 #include "DataFormats/Provenance/interface/ProductID.h" 00017 #include "FWCore/Utilities/interface/EDMException.h" 00018 00019 namespace edm { 00020 template <class T> 00021 class TestHandle { 00022 public: 00023 typedef T element_type; 00024 // Default constructed handles are invalid. 00025 TestHandle(); 00026 00027 TestHandle(const TestHandle<T>& h); 00028 00029 TestHandle(T const* prod, ProductID const& id); 00030 00031 ~TestHandle(); 00032 00033 void swap(TestHandle<T>& other); 00034 00035 TestHandle<T>& operator=(const TestHandle<T>& rhs); 00036 00037 bool isValid() const; 00038 00039 T const* product() const; 00040 T const* operator->() const; // alias for product() 00041 T const& operator*() const; 00042 00043 ProductID id() const; 00044 00045 private: 00046 T const* prod_; 00047 ProductID id_; 00048 }; 00049 00050 template <class T> 00051 TestHandle<T>::TestHandle() : 00052 prod_(0), 00053 id_(0) 00054 { } 00055 00056 template <class T> 00057 TestHandle<T>::TestHandle(const TestHandle<T>& h) : 00058 prod_(h.prod_), 00059 id_(h.id_) 00060 { } 00061 00062 template <class T> 00063 TestHandle<T>::TestHandle(T const* theProduct, ProductID const& theId) : 00064 prod_(theProduct), 00065 id_(theId) { 00066 } 00067 00068 template <class T> 00069 TestHandle<T>::~TestHandle() { 00070 // Nothing to do -- we do not own the things to which we point. 00071 } 00072 00073 template <class T> 00074 void 00075 TestHandle<T>::swap(TestHandle<T>& other) { 00076 std::swap(prod_, other.prod_); 00077 std::swap(id_, other.id_); 00078 } 00079 00080 template <class T> 00081 TestHandle<T>& 00082 TestHandle<T>::operator=(const TestHandle<T>& rhs) { 00083 TestHandle<T> temp(rhs); 00084 this->swap(temp); 00085 return *this; 00086 } 00087 00088 template <class T> 00089 bool 00090 TestHandle<T>::isValid() const { 00091 return prod_ != 0 && id_ != ProductID(); 00092 } 00093 00094 template <class T> 00095 T const* 00096 TestHandle<T>::product() const { 00097 return prod_; 00098 } 00099 00100 template <class T> 00101 T const* 00102 TestHandle<T>::operator->() const { 00103 return product(); 00104 } 00105 00106 template <class T> 00107 T const& 00108 TestHandle<T>::operator*() const { 00109 return *product(); 00110 } 00111 00112 template <class T> 00113 ProductID 00114 TestHandle<T>::id() const { 00115 return id_; 00116 } 00117 00118 // Free swap function 00119 template <class T> 00120 inline 00121 void 00122 swap(TestHandle<T>& a, TestHandle<T>& b) 00123 { 00124 a.swap(b); 00125 } 00126 } 00127 00128 #endif