Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

/magnus/back_end/global/RefCounter.h

Go to the documentation of this file.
00001 /*
00002  *   $Id: RefCounter.h,v 1.1.1.1 1995/11/20 17:54:39 rogern Exp $
00003  */
00004 
00005 // Copyright (C) 1994 The New York Group Theory Cooperative
00006 // See magnus/doc/COPYRIGHT for the full notice.
00007 
00008 // Contents: The reference counter class for the whole project.
00009 //
00010 // Principal Author: Stephane Collart
00011 //
00012 // Status: Complete
00013 //
00014 // Questions:
00015 //
00016 // * Should some SAFETY level check for overflow of the reference
00017 //   count? The problem is the quite high computational cost
00018 //
00019 // * Would it ever be necessary to provide for reference counts of more than
00020 //   an unsigned int?
00021 //
00022 // Revision History:
00023 //
00024 // * RefCounter, as a class used purely for derivation, no longer has public
00025 //   members; it exports its reference count manipulators protected, so that 
00026 //
00027 
00028 #ifndef _REF_COUNTER_H_
00029 #define _REF_COUNTER_H_
00030 
00031 
00032 #include "global.h"
00033 
00034 
00035 class RefCounter {
00036 
00037   //@rn Lippman says that this makes every instance of ObjectOf a friend,
00038   //@rn but gcc 2.6.3 refuses it and all obvious permutations.
00039   //@rn template <class T> friend class ObjectOf;
00040   
00041 //@rn Temporary kludge:
00042 //@rn protected:
00043 public:
00044 
00045   /////////////////////////////////////////////////////////////////////////
00046   //                                                                     //
00047   // Exported Type Handles                                               //
00048   //                                                                     //  
00049   /////////////////////////////////////////////////////////////////////////
00050 
00051   typedef unsigned int refCounterType;
00052   
00053   /////////////////////////////////////////////////////////////////////////
00054   //                                                                     //
00055   // Constructors                                                        //
00056   //                                                                     //  
00057   /////////////////////////////////////////////////////////////////////////
00058 
00059   RefCounter( ) : xrefs(0) { }
00060   //!< Default constructor
00061   /*!< a new reference counter is initialised
00062     with a ref count of 1 (ie 0 extra refs) */
00063 
00064   RefCounter( const RefCounter& rc ) : xrefs(0) { }
00065   //!< Copy constructor
00066   /*!< for derived representation classes whose copy constructor is generated
00067    by the compiler: a new (copied) representation also has an initial
00068    extra ref count of 0 */
00069 
00070   // Destructor provided by compiler
00071 
00072   /////////////////////////////////////////////////////////////////////////
00073   //                                                                     //
00074   // Reference Count Handles                                             //
00075   //                                                                     //  
00076   /////////////////////////////////////////////////////////////////////////
00077 
00078   bool lastRef( ) const { return xrefs == 0; }
00079   /*!< Returns true if reference counter xrefs is 0 */
00080   
00081   bool sharedRef( ) const { return xrefs != 0; }
00082   /*!< Returns true if reference counter xrefs is not equal to 0 */
00083 
00084   
00085   void addRef( ) const { ++((RefCounter*)this)->xrefs; }
00086   /*!< Increment the reference counter.
00087     addRef is logically constant */
00088     
00089   
00090   void delRef( ) const { --((RefCounter*)this)->xrefs; }
00091   /*!< Decreement the reference counter.
00092     delRef is logically const */
00093 
00094   #ifdef DEBUG
00095   refCounterType nxrefs( ) const { return xrefs; }
00096   #endif
00097   
00098 private:
00099   
00100   /////////////////////////////////////////////////////////////////////////
00101   //                                                                     //
00102   // Data Members                                                        //
00103   //                                                                     //  
00104   /////////////////////////////////////////////////////////////////////////
00105 
00106   refCounterType xrefs; //!< extra references (ie 0 means one ref)
00107 
00108   /////////////////////////////////////////////////////////////////////////
00109   //                                                                     //
00110   // Hidden Members                                                      //
00111   //                                                                     //  
00112   /////////////////////////////////////////////////////////////////////////
00113 
00114   RefCounter& operator = ( const RefCounter& );
00115   //!< disable assignment: normally representations are never assigned
00116 
00117 };
00118 
00119 #endif
00120 

Generated at Tue Jun 19 09:49:36 2001 for Magnus Classes by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001