Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

_Body.h

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                                                                      |
00003 |                      __   __    ____ _____ ____                      |
00004 |                      \ \ / /_ _/ ___|_   _|___ \                     |
00005 |                       \ V / _` \___ \ | |   __) |                    |
00006 |                        | | (_| |___) || |  / __/                     |
00007 |                        |_|\__,_|____/ |_| |_____|                    |
00008 |                                                                      |
00009 |                               core system                            |
00010 |                                                    (C) SuSE Linux AG |
00011 \----------------------------------------------------------------------/
00012 
00013   File:       _Body.h
00014 
00015   Author:     Michael Andres <ma@suse.de>
00016   Maintainer: Michael Andres <ma@suse.de>
00017 
00018   Purpose: Handle/Body: Base for refcounted representation classes (Body)
00019 
00020 /-*/
00021 #ifndef _Body_h
00022 #define _Body_h
00023 
00024 #include <iosfwd>
00025 
00027 //
00028 //      CLASS NAME : _Body
00049 class _Body {
00050 
00051   private:
00052 
00056     mutable unsigned _counter;
00057 
00058   protected:
00059 
00063     virtual void ref_to( unsigned /* rep_cnt_r */ ) const {}
00069     virtual void unref_to( unsigned /* rep_cnt_r */ ) 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 ); // trigger derived classes
00097     }
00103     void unref() const {
00104       if ( ! _counter )
00105         throw( this );
00106       if ( --_counter )
00107         unref_to( _counter ); // trigger derived classes
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

Generated on Mon Mar 21 16:25:27 2005 for liby2util by  doxygen 1.4.1