Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

SP.h

Go to the documentation of this file.
00001 #ifndef FASTSHOWER_SP_H
00002 #define FASTSHOWER_SP_H
00003 
00004 #ifndef FASTSHOWER_IDEBUG_H
00005 #include "FastShowerUtils/IDebug.h"
00006 #endif
00007 
00008 #ifndef STD_STRING_H
00009 #define STD_STRING_H
00010 #include <string>
00011 #endif
00012 
00013 #include <iostream>
00014 #include "FastShowerUtils/IDebug.h"
00015 
00016 namespace FastShower{
00021   template <class Type>
00022   class SP{
00023   public:
00024     SP(): m_pointer(0){}
00025     ~SP() {delete m_pointer;}
00026     SP(Type* p);
00027     SP(const SP&);
00028     SP<Type>& operator=(const SP<Type>& rhs);
00029     SP<Type>& operator=(Type* rhs);
00030     operator Type*() const {
00031     //  IDebug* dbg = m_pointer;
00032     //  cout<<"casting  a "<<dbg->name()<<" "<<dbg->text()<<endl;
00033       return  m_pointer;}
00034     Type* operator->() const {
00035     //  IDebug* dbg = m_pointer;
00036     //  cout<<"dereferencing a "<<dbg->name()<<" "<<dbg->text()<<endl;
00037       return  m_pointer;}
00038     Type  operator*() const {return *m_pointer;}
00039   private:
00040     Type*       m_pointer;
00041   };
00042   template<class Type>
00043     inline 
00044     SP<Type>::SP(Type* p): m_pointer(p){
00045   }
00046   template<class Type>
00047     inline 
00048     SP<Type>::SP(const SP<Type>& rhs){
00049     m_pointer = (rhs.m_pointer==0)? 0:rhs->clone();
00050   }
00051   template<class Type>
00052     inline 
00053     SP<Type>& SP<Type>::operator=(Type* ptr){
00054     m_pointer = ptr;
00055     return *this;
00056   }
00057   template<class Type>
00058     inline 
00059     SP<Type>& SP<Type>::operator=(const SP<Type>& rhs){
00060     if(m_pointer != rhs.m_pointer){m_pointer = rhs->clone();}
00061     return *this;
00062   }
00063 }//namespace
00064 #endif
00065 
00066 

Generated on Tue Mar 18 11:50:06 2003 for FastShowerUtils by doxygen1.3-rc1