CMS 3D CMS Logo

CloningPtr.h

Go to the documentation of this file.
00001 #ifndef DataFormats_Common_CloningPtr_h
00002 #define DataFormats_Common_CloningPtr_h
00003 // -*- C++ -*-
00004 //
00005 // Package:     Common
00006 // Class  :     CloningPtr
00007 // 
00016 //
00017 // Original Author:  Chris Jones
00018 //         Created:  Mon Apr  3 16:43:29 EDT 2006
00019 // $Id: CloningPtr.h,v 1.4 2007/12/21 22:42:30 wmtan Exp $
00020 //
00021 
00022 // system include files
00023 #include <algorithm>
00024 
00025 // user include files
00026 #include "DataFormats/Common/interface/ClonePolicy.h"
00027 
00028 // forward declarations
00029 namespace edm {
00030   template< class T, class P = ClonePolicy<T> >
00031   class CloningPtr {
00032 public:
00033     CloningPtr(): ptr_(0) {}
00034     CloningPtr(const T& iPtr) : ptr_(P::clone(iPtr)) {}
00035     CloningPtr(std::auto_ptr<T> iPtr) : ptr_(iPtr.release()) {}
00036     CloningPtr(const CloningPtr<T,P>& iPtr) : ptr_(P::clone(*(iPtr.ptr_))) {}
00037     
00038     const CloningPtr<T,P>& operator=(const CloningPtr<T,P>& iRHS) {
00039       CloningPtr<T,P> temp(iRHS);
00040       swap(temp);
00041       return *this;
00042     }
00043     
00044     void swap(CloningPtr<T,P>& iPtr) {
00045       std::swap(ptr_, iPtr.ptr_);
00046     }
00047     
00048     ~CloningPtr() { delete ptr_;}
00049     
00050     // ---------- const member functions ---------------------
00051     T& operator*() const { return *ptr_; }
00052     
00053     T* operator->() const { return ptr_; }
00054     
00055     T* get() const { return ptr_; }
00056     
00057 private:
00058     T* ptr_;
00059   };
00060 
00061   // Free swap function
00062   template <class T, class P>
00063   inline
00064   void
00065   swap(CloningPtr<T,P>& a, CloningPtr<T,P>& b) 
00066   {
00067     a.swap(b);
00068   }
00069 }
00070 #endif

Generated on Tue Jun 9 17:28:35 2009 for CMSSW by  doxygen 1.5.4