Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:03:52

0001 #ifndef DataFormats_Common_OrphanHandleBase_h
0002 #define DataFormats_Common_OrphanHandleBase_h
0003 
0004 /*----------------------------------------------------------------------
0005   
0006 OrphanHandle: Non-owning "smart pointer" for reference to EDProducts.
0007 
0008 This is a very preliminary version, and lacks safety features and
0009 elegance.
0010 
0011 If the pointed-to WrapperBase is destroyed, use of the OrphanHandle
0012 becomes undefined. There is no way to query the OrphanHandle to
0013 discover if this has happened.
0014 
0015 OrphanHandles can have:
0016   -- Product pointer null and id == 0;
0017   -- Product pointer valid and id != 0;
0018 
0019 To check validity, one can use the isValid() function.
0020 
0021 ----------------------------------------------------------------------*/
0022 
0023 #include "DataFormats/Provenance/interface/ProductID.h"
0024 #include <cassert>
0025 #include <algorithm>
0026 
0027 namespace edm {
0028   class OrphanHandleBase {
0029   public:
0030     OrphanHandleBase() : product_(), id_(ProductID()) {}
0031 
0032     OrphanHandleBase(void const* iProd, ProductID const& iId) : product_(iProd), id_(iId) { assert(iProd); }
0033 
0034     void clear() {
0035       product_ = nullptr;
0036       id_ = ProductID();
0037     }
0038 
0039     void swap(OrphanHandleBase& other) {
0040       using std::swap;
0041       swap(product_, other.product_);
0042       std::swap(id_, other.id_);
0043     }
0044 
0045     bool isValid() const { return product_ && id_ != ProductID(); }
0046 
0047     ProductID id() const;
0048 
0049   protected:
0050     void const* productStorage() const;
0051 
0052   private:
0053     void const* product_;
0054     ProductID id_;
0055   };
0056 
0057   // Free swap function
0058   inline void swap(OrphanHandleBase& a, OrphanHandleBase& b) { a.swap(b); }
0059 }  // namespace edm
0060 
0061 #endif