CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/DataFormats/Common/interface/Handle.h

Go to the documentation of this file.
00001 #ifndef DataFormats_Common_Handle_h
00002 #define DataFormats_Common_Handle_h
00003 
00004 /*----------------------------------------------------------------------
00005   
00006 Handle: Non-owning "smart pointer" for reference to Products and
00007 their Provenances.
00008 
00009 This is a very preliminary version, and lacks safety features and
00010 elegance.
00011 
00012 If the pointed-to Product or Provenance is destroyed, use of the
00013 Handle becomes undefined. There is no way to query the Handle to
00014 discover if this has happened.
00015 
00016 Handles can have:
00017   -- Product and Provenance pointers both null;
00018   -- Both pointers valid
00019 
00020 To check validity, one can use the isValid() function.
00021 
00022 If failedToGet() returns true then the requested data is not available
00023 If failedToGet() returns false but isValid() is also false then no attempt 
00024   to get data has occurred
00025 
00026 ----------------------------------------------------------------------*/
00027 
00028 #include <typeinfo>
00029 
00030 #include "DataFormats/Common/interface/HandleBase.h"
00031 
00032 namespace edm {
00033 
00034   template <typename T>
00035   class Handle : public HandleBase {
00036   public:
00037     typedef T element_type;
00038 
00039     // Default constructed handles are invalid.
00040     Handle();
00041 
00042     Handle(T const* prod, Provenance const* prov);
00043     
00044     Handle(boost::shared_ptr<cms::Exception> const&);
00045 
00046     ~Handle();
00047 
00048     T const* product() const;
00049     T const* operator->() const; // alias for product()
00050     T const& operator*() const;
00051 
00052   private:
00053   };
00054 
00055   template <class T>
00056   Handle<T>::Handle() : HandleBase()
00057   { }
00058 
00059   template <class T>
00060   Handle<T>::Handle(T const* prod, Provenance const* prov) : HandleBase(prod, prov) { 
00061   }
00062 
00063   template <class T>
00064     Handle<T>::Handle(boost::shared_ptr<cms::Exception> const& iWhyFailed) :
00065     HandleBase(iWhyFailed)
00066   { }
00067  
00068 
00069   template <class T>
00070   Handle<T>::~Handle() {}
00071 
00072   template <class T>
00073   T const* 
00074   Handle<T>::product() const { 
00075     return static_cast<T const*>(productStorage());
00076   }
00077 
00078   template <class T>
00079   T const* 
00080   Handle<T>::operator->() const {
00081     return product();
00082   }
00083 
00084   template <class T>
00085   T const& 
00086   Handle<T>::operator*() const {
00087     return *product();
00088   }
00089 }
00090 
00091 #endif