00001
00002 #include "zipios++/zipios-config.h"
00003
00004 #include "zipios++/meta-iostreams.h"
00005 #include <vector>
00006 #include <memory>
00007
00008 #include "zipios++/simplesmartptr.h"
00009
00010 #include <cassert>
00011
00012 using namespace zipios ;
00013
00014 using std::cerr ;
00015 using std::cout ;
00016 using std::endl ;
00017 using std::auto_ptr ;
00018 using std::ofstream ;
00019 using std::vector ;
00020
00021
00022 #ifndef DOXYGEN
00023
00024 namespace zipios {
00025
00026 class Bogus {
00027 public:
00028 Bogus(bool &isAlive) : _isAlive(isAlive) {}
00029 ~Bogus() { _isAlive = false; }
00030 protected:
00031
00032 friend class SimpleSmartPointer< Bogus > ;
00033 friend class SimpleSmartPointer< const Bogus > ;
00034
00035 void ref() const { _refcount.ref() ; }
00036 unsigned int unref() const { return _refcount.unref() ; }
00037 unsigned int getReferenceCount() const { return _refcount.getReferenceCount() ; }
00038 ReferenceCount< Bogus > _refcount ;
00039 bool &_isAlive;
00040 };
00041
00042 }
00043
00044 typedef SimpleSmartPointer< Bogus > SPBogus ;
00045
00046 #endif
00047
00048 int main() {
00049 bool isAlive = true;
00050 {
00051 Bogus *p = new Bogus(isAlive);
00052 SPBogus sp1( p ) ;
00053 assert( sp1.getReferenceCount() == 1 );
00054 {
00055 SPBogus sp2 ;
00056 sp2 = sp1 ;
00057 assert( sp1.getReferenceCount() == 2 );
00058 {
00059 SPBogus sp3 ;
00060 sp3 = p ;
00061 assert( sp1.getReferenceCount() == 3 );
00062 }
00063 assert( sp1.getReferenceCount() == 2 );
00064 assert( isAlive );
00065 }
00066 assert( sp1.getReferenceCount() == 1 );
00067 assert( isAlive );
00068 }
00069 assert( ! isAlive );
00070 return 0;
00071 }
00072
00073
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096