CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/FWCore/Framework/interface/GenericObjectOwner.h

Go to the documentation of this file.
00001 #ifndef FWCore_Framework_GenericObjectOwner_h
00002 #define FWCore_Framework_GenericObjectOwner_h
00003 // -*- C++ -*-
00004 //
00005 // Package:     Framework
00006 // Class  :     GenericObjectOwner
00007 // 
00016 //
00017 // Original Author:  Chris Jones
00018 //         Created:  Sun Feb  3 19:43:16 EST 2008
00019 //
00020 
00021 // system include files
00022 #include <string>
00023 #include "Reflex/Object.h"
00024 
00025 // user include files
00026 #include "FWCore/Framework/interface/Event.h"
00027 
00028 // forward declarations
00029 namespace edm {
00030 class GenericObjectOwner
00031 {
00032 
00033    public:
00034       GenericObjectOwner(): m_ownData(false){}
00035       explicit GenericObjectOwner(Reflex::Object const& iObject,
00036                                   bool iOwnData=true):
00037          m_object(iObject), m_ownData(iOwnData) {}
00038       ~GenericObjectOwner();
00039 
00040       // ---------- const member functions ---------------------
00041       Reflex::Object object() const;
00042    
00043       // ---------- static member functions --------------------
00044 
00045       // ---------- member functions ---------------------------
00046       void swap(GenericObjectOwner&);
00047       void release();
00048    
00049    private:
00050       GenericObjectOwner(GenericObjectOwner const&); // stop default
00051 
00052       GenericObjectOwner const& operator=(GenericObjectOwner const&); // stop default
00053 
00054       // ---------- member data --------------------------------
00055       Reflex::Object m_object;
00056       bool m_ownData;
00057 };
00058 
00059    //Need to specialize OrphanHandle because we don't actually have a long lived GenericObjectOwner
00060    template <>
00061    class OrphanHandle<GenericObjectOwner> {
00062    public:
00063       // Default constructed handles are invalid.
00064       OrphanHandle() {}
00065       
00066       OrphanHandle(OrphanHandle<GenericObjectOwner> const& h):
00067       prod_(h.prod_.object(),false), id_(h.id_) {}
00068       
00069       OrphanHandle(Reflex::Object const& prod, ProductID const& id):
00070       prod_(prod,false), id_(id) {}
00071       
00072       //~OrphanHandle();
00073       
00074       void swap(OrphanHandle<GenericObjectOwner>& other){
00075          prod_.swap(other.prod_);
00076          std::swap(id_,other.id_);
00077       }
00078       
00079       
00080       OrphanHandle<GenericObjectOwner>& operator=(OrphanHandle<GenericObjectOwner> const& rhs)
00081       {
00082          OrphanHandle<GenericObjectOwner> temp(rhs);
00083          swap(temp);
00084          return *this;
00085       }
00086       
00087       bool isValid() const {return 0 !=prod_.object().Address();}
00088          
00089       GenericObjectOwner const* product() const {return &prod_;}
00090       GenericObjectOwner const* operator->() const {return product();}
00091       GenericObjectOwner const& operator*() const {return prod_;}
00092       
00093       ProductID id() const {return id_;}
00094          
00095          
00096       private:
00097          GenericObjectOwner prod_;
00098          ProductID id_;
00099       };
00100       
00101    template<>
00102    OrphanHandle<GenericObjectOwner> 
00103    Event::put<GenericObjectOwner>(std::auto_ptr<GenericObjectOwner> product, std::string const& productInstanceName);
00104    
00105 }
00106 #endif