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 class Bogus {
00025 public:
00026 Bogus(bool &isAlive) : _isAlive(isAlive) {}
00027 ~Bogus() { _isAlive = false; }
00028 protected:
00029 friend SimpleSmartPointer< Bogus > ;
00030 friend SimpleSmartPointer< const Bogus > ;
00031
00032 void ref() const { _refcount.ref() ; }
00033 unsigned int unref() const { return _refcount.unref() ; }
00034 unsigned int getReferenceCount() const { return _refcount.getReferenceCount() ; }
00035 ReferenceCount< Bogus > _refcount ;
00036 bool &_isAlive;
00037 };
00038
00039 typedef SimpleSmartPointer< Bogus > SPBogus ;
00040
00041 #endif
00042
00043 int main() {
00044 bool isAlive = true;
00045 {
00046 Bogus *p = new Bogus(isAlive);
00047 SPBogus sp1( p ) ;
00048 assert( sp1.getReferenceCount() == 1 );
00049 {
00050 SPBogus sp2 ;
00051 sp2 = sp1 ;
00052 assert( sp1.getReferenceCount() == 2 );
00053 {
00054 SPBogus sp3 ;
00055 sp3 = p ;
00056 assert( sp1.getReferenceCount() == 3 );
00057 }
00058 assert( sp1.getReferenceCount() == 2 );
00059 assert( isAlive );
00060 }
00061 assert( sp1.getReferenceCount() == 1 );
00062 assert( isAlive );
00063 }
00064 assert( ! isAlive );
00065 }
00066
00067
00073 00074 00075 00076 00077 00078 00079 00080 00081 00082 00083 00084 00085 00086 00087 00088 00089 00090