[prev in list] [next in list] [prev in thread] [next in thread]
List: xalan-cvs
Subject: cvs commit: xml-xalan/c/src/xalanc/Include XalanMemMgrAutoPtr.hpp
From: dmitryh () apache ! org
Date: 2004-07-21 17:53:42
Message-ID: 20040721175342.53262.qmail () minotaur ! apache ! org
[Download RAW message or body]
dmitryh 2004/07/21 10:53:42
Modified: c/src/xalanc/Include XalanMemMgrAutoPtr.hpp
Log:
Revised version of AutoPnt for Memory Management
Revision Changes Path
1.2 +92 -104 xml-xalan/c/src/xalanc/Include/XalanMemMgrAutoPtr.hpp
Index: XalanMemMgrAutoPtr.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/xalanc/Include/XalanMemMgrAutoPtr.hpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XalanMemMgrAutoPtr.hpp 13 Jul 2004 16:39:49 -0000 1.1
+++ XalanMemMgrAutoPtr.hpp 21 Jul 2004 17:53:42 -0000 1.2
@@ -34,7 +34,6 @@
-
XALAN_CPP_NAMESPACE_BEGIN
@@ -47,43 +46,94 @@
{
public:
- typedef XERCES_CPP_NAMESPACE_QUALIFIER MemoryManager MemoryManagerType;
+ typedef XERCES_CPP_NAMESPACE_QUALIFIER MemoryManager MemoryManagerType;
+ typedef XALAN_STD_QUALIFIER pair<MemoryManagerType*, Type*> AutoPtrPairType;
+
+ class MemMgrAutoPtrData : public AutoPtrPairType
+ {
+ public:
+ MemMgrAutoPtrData():
+ AutoPtrPairType(0,0)
+ {
+ }
+
+ MemMgrAutoPtrData(
+ MemoryManagerType* memoryManager,
+ Type* dataPointer):
+ AutoPtrPairType(memoryManager, dataPointer)
+ {
+ invariants();
+ }
+
+
+ bool
+ isInitilized()const
+ {
+ return ( (first != 0) && (second != 0) )? true : false;
+ }
+
+ void
+ deallocate()
+ {
+ invariants();
+
+ if ( isInitilized() )
+ {
+ second->~Type();
+
+ first->deallocate(second);
+ }
+ }
+
+ void
+ reset( MemoryManagerType* _m_memoryManager ,
+ Type* _m_dataPointer )
+ {
+ invariants();
+
+ first = _m_memoryManager;
+
+ second = _m_dataPointer;
+ invariants();
+ }
+ private:
+ void
+ invariants()const
+ {
+ assert( isInitilized() ||
+ ( (first == 0) && (second ==0) ) );
+ }
+
+ };
+
+
XalanMemMgrAutoPtr(
- Type* thePointer = 0,
- MemoryManagerType* theManager = 0) :
- m_memoryManager(theManager),
- m_pointer(thePointer)
+ MemoryManagerType* theManager,
+ Type* ptr ) :
+ m_pointerInfo(theManager, ptr)
{
- invariants();
- }
+ }
+ XalanMemMgrAutoPtr() :
+ m_pointerInfo()
+ {
+ }
+
XalanMemMgrAutoPtr(const XalanMemMgrAutoPtr<Type>& theSource) :
- m_memoryManager(theSource.m_memoryManager),
- m_pointer(((XalanMemMgrAutoPtr<Type>&)theSource).release())
+ m_pointerInfo(((XalanMemMgrAutoPtr<Type>&)theSource).release())
{
- invariants();
}
+
XalanMemMgrAutoPtr<Type>&
operator=(XalanMemMgrAutoPtr<Type>& theRHS)
- {
- invariants();
-
- theRHS.invariants();
-
+ {
if (this != &theRHS)
{
+ m_pointerInfo.deallocate();
- if ( m_memoryManager != 0 && m_pointer != 0)
- {
- m_pointer->~Type();
-
- m_memoryManager->deallocate(m_pointer);
- }
-
-
- m_pointer = theRHS.release(m_memoryManager);
+ m_pointerInfo = theRHS.release();
}
return *this;
@@ -91,113 +141,51 @@
~XalanMemMgrAutoPtr()
{
- // See note in operator=() about this...
- if ( m_memoryManager != 0 && m_pointer!= 0 )
- {
- m_pointer->~Type();
-
- m_memoryManager->deallocate(m_pointer);
- }
+ m_pointerInfo.deallocate();
}
Type&
operator*() const
{
- return *m_pointer;
+ return *m_pointerInfo.second;
}
Type*
operator->() const
{
- return m_pointer;
+ return m_pointerInfo.second;
}
Type*
get() const
{
- return m_pointer;
+ return m_pointerInfo.second;
}
-/**
- * Release , similar to the auto_ptr release , but returns a memory manager the pointer comes from
- *
- * @param theManager parameter to receive the memory manager
- */
- Type*
- release( /* OUT */ MemoryManagerType** theManager)
- {
- invariants();
-
- Type* const temp = m_pointer;
-
- *theManager = m_memoryManager;
-
- m_pointer = 0;
-
- m_memoryManager = 0;
-
- return temp;
- }
-
-/**
- * Release , similar to the auto_ptr release. Note , that the Type* pointer can't be "deleted"
- */
- Type*
+ MemMgrAutoPtrData
release()
- {
- invariants();
-
- Type* const temp = m_pointer;
-
- m_pointer = 0;
-
- m_memoryManager = 0;
+ {
+ MemMgrAutoPtrData tmp = m_pointerInfo;
+
+ m_pointerInfo.reset( 0 , 0 );
- return temp;
+ return MemMgrAutoPtrData(tmp);
}
void
- reset( Type* thePointer = 0,
- MemoryManagerType* theManager = 0 )
- {
- // check the correctness before ...
- invariants();
-
- // See note in operator=() about this...
- if ( m_memoryManager != 0 && m_pointer!=0 )
- {
- m_pointer->~Type();
-
- m_memoryManager->deallocate(m_pointer);
- }
-
- m_memoryManager = theManager;
+ reset( MemoryManagerType* theManager = 0,
+ Type* thePointer = 0 )
+ {
+ m_pointerInfo.deallocate();
- m_pointer = thePointer;
-
- // check the correctness after ...
- invariants();
+ m_pointerInfo.reset ( theManager , thePointer );
}
private:
-#if defined(NDEBUG)
- void
- invariants() const
- {
- }
-#else
- void
- invariants() const
- {
- assert ( (m_pointer != 0 && m_memoryManager != 0 ) ||
- (m_pointer == 0 && m_memoryManager == 0 ) );
- }
-#endif
-// data members
- MemoryManagerType* m_memoryManager;
- Type* m_pointer;
+// data member
+ MemMgrAutoPtrData m_pointerInfo;
};
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic