r2840 - in trunk/libmutil: include/libmutil source

erik at minisip.org erik at minisip.org
Tue Oct 17 20:08:23 CEST 2006


Author: erik
Date: 2006-10-17 20:08:22 +0200 (Tue, 17 Oct 2006)
New Revision: 2840

Modified:
   trunk/libmutil/include/libmutil/MemObject.h
   trunk/libmutil/source/MemObject.cxx
Log:

 * Enable references to constant objects (MRef<const SomeType*>).
   
   We have not been able to use references to constant objects because
   the reference counter in MObject need updating. The following example
   would not compile:

        #include<libmutil/MemObject.h>

        class O : public MObject{ };
    
        int main(int argc, char **argv){
            MRef<const O*> o = new O;
            return 0;
        }

   This fix makes the reference counter mutable, and declares the modifying
   the reference counter as "const".



Modified: trunk/libmutil/include/libmutil/MemObject.h
===================================================================
--- trunk/libmutil/include/libmutil/MemObject.h	2006-10-17 14:19:48 UTC (rev 2839)
+++ trunk/libmutil/include/libmutil/MemObject.h	2006-10-17 18:08:22 UTC (rev 2840)
@@ -91,17 +91,17 @@
 		/**
 		Decrease the reference counter (thread-safe)
 		*/
-		int decRefCount();
+		int decRefCount() const;
 		
 		/**
 		Increase the reference counter (thread-safe)
 		*/
-		void incRefCount();
+		void incRefCount() const;
 
 		/**
 		Return the value of the reference counter
 		*/
-		int getRefCount();
+		int getRefCount() const;
 		
 		/**
 		 * If mutil has been configured with --enable-memdebug
@@ -120,7 +120,7 @@
 		/**
 		Reference counter ... 
 		*/
-		int refCount;
+		mutable int refCount;
 		
 		/**
 		Mutex, provides thread safety. 

Modified: trunk/libmutil/source/MemObject.cxx
===================================================================
--- trunk/libmutil/source/MemObject.cxx	2006-10-17 14:19:48 UTC (rev 2839)
+++ trunk/libmutil/source/MemObject.cxx	2006-10-17 18:08:22 UTC (rev 2840)
@@ -90,7 +90,7 @@
 }
 	
 
-int MObject::decRefCount(){
+int MObject::decRefCount() const{
 	int refRet;
 #ifdef MDEBUG
 	global.lock();
@@ -113,7 +113,7 @@
 	return refRet;
 }
 
-void MObject::incRefCount(){
+void MObject::incRefCount() const{
 #ifdef MDEBUG
 	global.lock();
 #else
@@ -134,7 +134,7 @@
 #endif
 }
 
-int MObject::getRefCount(){
+int MObject::getRefCount() const{
 	return refCount;
 }
 



More information about the Minisip-devel mailing list