CMS 3D CMS Logo

DeepCopyPointerByClone.h

Go to the documentation of this file.
00001 #ifndef DeepCopyPointerByClone_H
00002 #define DeepCopyPointerByClone_H
00003 
00008 template <class T>
00009 class DeepCopyPointerByClone {
00010 public:
00011   
00012   DeepCopyPointerByClone() : theData(0) {}
00013 
00014   DeepCopyPointerByClone( T* t) : theData(t) {}
00015 
00016   DeepCopyPointerByClone( const DeepCopyPointerByClone& other) {
00017     if (other.theData) theData = other->clone(); else theData = 0;
00018   }
00019 
00020   ~DeepCopyPointerByClone() { delete theData;}
00021 
00022   DeepCopyPointerByClone& operator=( const DeepCopyPointerByClone& other) {
00023     if ( theData != other.theData) {
00024       delete theData;
00025       if (other.theData) theData = other->clone(); else theData = 0;
00026     }
00027     return *this;
00028   }
00029 
00030   T&       operator*()       { return *theData;}
00031   const T& operator*() const { return *theData;}
00032 
00033   T*       operator->()       { return theData;}
00034   const T* operator->() const { return theData;}
00035 
00037   operator bool() const { return theData != 0;}
00038 
00040   bool operator==( const T* otherP) const { return theData == otherP;}
00041 
00042 private:
00043   T* theData;
00044 };
00045 
00046 #endif // DeepCopyPointerByClone_H

Generated on Tue Jun 9 17:30:49 2009 for CMSSW by  doxygen 1.5.4