CMSSW/ DataFormats/ Common/ interface/ Handle.h

001 #ifndef DataFormats_Common_Handle_h
002 #define DataFormats_Common_Handle_h
003 
004 /*----------------------------------------------------------------------
005   
006 Handle: Non-owning "smart pointer" for reference to Products and
007 their Provenances.
008 
009 This is a very preliminary version, and lacks safety features and
010 elegance.
011 
012 If the pointed-to Product or Provenance is destroyed, use of the
013 Handle becomes undefined. There is no way to query the Handle to
014 discover if this has happened.
015 
016 Handles can have:
017   -- Product and Provenance pointers both null;
018   -- Both pointers valid
019 
020 To check validity, one can use the isValid() function.
021 
022 If failedToGet() returns true then the requested data is not available
023 If failedToGet() returns false but isValid() is also false then no attempt 
024   to get data has occurred
025 
026 ----------------------------------------------------------------------*/
027 
028 #include <typeinfo>
029 
030 #include "DataFormats/Common/interface/HandleBase.h"
031 
032 namespace edm {
033 
034   template <typename T>
035   class Handle : public HandleBase {
036   public:
037     typedef T element_type;
038 
039     // Default constructed handles are invalid.
040     Handle();
041 
042     Handle(T const* prod, Provenance const* prov);
043     
044     Handle(boost::shared_ptr<cms::Exception> const&);
045 
046     ~Handle();
047 
048     T const* product() const;
049     T const* operator->() const; // alias for product()
050     T const& operator*() const;
051 
052   private:
053   };
054 
055   template <class T>
056   Handle<T>::Handle() : HandleBase()
057   { }
058 
059   template <class T>
060   Handle<T>::Handle(T const* prod, Provenance const* prov) : HandleBase(prod, prov) { 
061   }
062 
063   template <class T>
064     Handle<T>::Handle(boost::shared_ptr<cms::Exception> const& iWhyFailed) :
065     HandleBase(iWhyFailed)
066   { }
067  
068 
069   template <class T>
070   Handle<T>::~Handle() {}
071 
072   template <class T>
073   T const* 
074   Handle<T>::product() const { 
075     return static_cast<T const*>(productStorage());
076   }
077 
078   template <class T>
079   T const* 
080   Handle<T>::operator->() const {
081     return product();
082   }
083 
084   template <class T>
085   T const& 
086   Handle<T>::operator*() const {
087     return *product();
088   }
089 }
090 
091 #endif

-- DavidCockerill - 24-Aug-2010

Edit | Attach | Watch | Print version | History: r1 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r1 - 2010-08-24 - DavidCockerill
 
    • Cern Search Icon Cern Search
    • TWiki Search Icon TWiki Search
    • Google Search Icon Google Search

    Main All webs login

This site is powered by the TWiki collaboration platform Powered by PerlCopyright & 2008-2019 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback