00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef _Body_h
00022 #define _Body_h
00023
00024 #include <iosfwd>
00025
00027
00028
00049 class _Body {
00050
00051 private:
00052
00056 mutable unsigned _counter;
00057
00058 protected:
00059
00063 virtual void ref_to( unsigned ) const {}
00069 virtual void unref_to( unsigned ) const {}
00070
00071 public:
00072
00076 _Body() : _counter( 0 ) {}
00080 _Body( const _Body & rhs ) : _counter( 0 ) {}
00084 _Body & operator=( const _Body & rhs ) { return *this; }
00088 virtual ~_Body() { if ( _counter ) throw( this ); }
00089
00090 public:
00091
00095 void ref() const {
00096 ref_to( ++_counter );
00097 }
00103 void unref() const {
00104 if ( ! _counter )
00105 throw( this );
00106 if ( --_counter )
00107 unref_to( _counter );
00108 else
00109 delete this;
00110 }
00111
00112 public:
00113
00118 static void ref( const _Body * obj_r ) {
00119 if ( obj_r )
00120 obj_r->ref();
00121 }
00126 static void unref( const _Body * obj_r ) {
00127 if ( obj_r )
00128 obj_r->unref();
00129 }
00130
00131 public:
00132
00136 unsigned refCount() const { return _counter; }
00137
00138 public:
00139
00144 virtual std::ostream & dumpOn( std::ostream & str ) const;
00145 };
00146
00150 std::ostream & operator<<( std::ostream & str, const _Body & obj );
00154 std::ostream & operator<<( std::ostream & str, const _Body * obj );
00155
00157
00158 #endif // _Body_h