stlPtrWrapper.h

00001 #ifndef STLPTRWRAPPER_H
00002 #define STLPTRWRAPPER_H
00003 
00004 // --8<--8<--8<--8<--
00005 //
00006 // Copyright (C) 2006 Smithsonian Astrophysical Observatory
00007 //
00008 // This file is part of paramxx
00009 //
00010 // paramxx is free software; you can redistribute it and/or
00011 // modify it under the terms of the GNU General Public License
00012 // as published by the Free Software Foundation; either version 2
00013 // of the License, or (at your option) any later version.
00014 //
00015 // paramxx is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 // GNU General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU General Public License
00021 // along with this program; if not, write to the 
00022 //       Free Software Foundation, Inc. 
00023 //       51 Franklin Street, Fifth Floor
00024 //       Boston, MA  02110-1301, USA
00025 //
00026 // -->8-->8-->8-->8--
00027 
00028 #include <algorithm>
00029 
00030 using namespace std;
00031 
00035 template <class Type>
00036 class stlPtrWrapper {
00037 
00038   friend ostream& operator << ( ostream& os, stlPtrWrapper<Type>& a ) {
00039     os << a( );
00040     return os;
00041   }
00042 
00043   friend ostream& operator << ( ostream& os, stlPtrWrapper<Type>* a ) {
00044     os << (*a)( );
00045     return os;
00046   }
00047 
00048   friend bool operator == (const stlPtrWrapper<Type>& xw1,
00049                            const stlPtrWrapper<Type>& xw2) {
00050     return (xw1.operator()() && xw2.operator()()) ? xw1() == xw2() : false;
00051   }
00052 
00053   friend bool operator < (const stlPtrWrapper<Type>& xw1,
00054                           const stlPtrWrapper<Type>& xw2) {
00055     return (xw1() && xw2()) ? xw1() < xw2() : false;
00056   }
00057 
00058 public:
00059 
00060   stlPtrWrapper( Type x = 0 ) : val( x ) { }
00061 
00062   stlPtrWrapper( const stlPtrWrapper<Type>& xxx ) : val( xxx.val ) {  }
00063 
00064   // purposely left blank
00065   ~stlPtrWrapper() { }
00066 
00067   stlPtrWrapper& operator = ( const stlPtrWrapper<Type>& rhs ) {
00068 
00069     if ( this == &rhs ) 
00070       return *this;
00071 
00072     val = rhs.val;
00073     return *this;
00074 
00075   }
00076   
00077   const Type operator( ) () const { return val; }
00078 
00079   Type operator( ) () { return val; }
00080 
00081 private:
00082 
00083   Type val;
00084 
00085 };
00086 
00087 #endif

Generated on Thu Oct 2 17:54:19 2008 for paramxx by  doxygen 1.5.6