RefCounter.h

Go to the documentation of this file.
00001 
00002 #ifndef _REF_COUNTER_H_
00003 #define _REF_COUNTER_H_
00004 
00005 
00006 #pragma warning(disable:4786)
00007 
00008 
00009 class RefCounter {
00010 
00011 public:
00012 
00014   //                                                                     //
00015   // Exported Type Handles                                               //
00016   //                                                                     //  
00018 
00019   typedef unsigned int refCounterType;
00020   
00022   //                                                                     //
00023   // Constructors                                                        //
00024   //                                                                     //  
00026 
00027   RefCounter( ) : xrefs(0) { }
00028   // a new reference counter is initialised
00029   // with a ref count of 1 (ie 0 extra refs)
00030 
00031   RefCounter( const RefCounter& rc ) : xrefs(0) { }
00032   // for derived representation classes whose copy constructor is generated
00033   // by the compiler: a new (copied) representation also has an initial
00034   // extra ref count of 0
00035 
00036   // Destructor provided by compiler
00037 
00039   //                                                                     //
00040   // Reference Count Handles                                             //
00041   //                                                                     //  
00043 
00044   bool lastRef( ) const { return xrefs == 0; }
00045   
00046   bool sharedRef( ) const { return xrefs != 0; }
00047   
00048   void addRef( ) const { ++((RefCounter*)this)->xrefs; }
00049   // addRef is logically const
00050   
00051   void delRef( ) const { --((RefCounter*)this)->xrefs; }
00052   // delRef is logically const
00053 
00054   #ifdef DEBUG
00055   refCounterType nxrefs( ) const { return xrefs; }
00056   #endif
00057   
00058 private:
00059   
00061   //                                                                     //
00062   // Data Members                                                        //
00063   //                                                                     //  
00065 
00066   refCounterType xrefs; // extra references (ie 0 means one ref)
00067 
00069   //                                                                     //
00070   // Hidden Members                                                      //
00071   //                                                                     //  
00073 
00074   RefCounter& operator = ( const RefCounter& );
00075   // disable assignment: normally representations are never assigned
00076 
00077 };
00078 
00079 #endif
00080 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on Mon Sep 26 18:43:45 2011 for CRyptography And Groups (CRAG) by  doxygen 1.6.1