mhoyt 2004/10/16 17:25:58
Modified: c/src/xalanc/Include XalanDeque.hpp XalanList.hpp
XalanMap.hpp XalanMemoryManagement.hpp XalanSet.hpp
XalanVector.hpp
Log:
Intial integration to allow containers to hold the value of objects that
require a memory manager
Revision Changes Path
1.3 +1 -4 xml-xalan/c/src/xalanc/Include/XalanDeque.hpp
Index: XalanDeque.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/xalanc/Include/XalanDeque.hpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- XalanDeque.hpp 14 Oct 2004 19:09:28 -0000 1.2
+++ XalanDeque.hpp 17 Oct 2004 00:25:58 -0000 1.3
@@ -29,10 +29,7 @@
#include <xalanc/Include/XalanVector.hpp>
-
-
-
-#include <xercesc/framework/MemoryManager.hpp>
+#include <xalanc/Include/XalanMemoryManagement.hpp>
1.7 +21 -15 xml-xalan/c/src/xalanc/Include/XalanList.hpp
Index: XalanList.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/xalanc/Include/XalanList.hpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- XalanList.hpp 12 Oct 2004 18:29:06 -0000 1.6
+++ XalanList.hpp 17 Oct 2004 00:25:58 -0000 1.7
@@ -37,7 +37,7 @@
-#include <xercesc/framework/MemoryManager.hpp>
+#include <xalanc/Include/XalanMemoryManagement.hpp>
@@ -158,8 +158,6 @@
{
public:
- typedef XERCES_CPP_NAMESPACE_QUALIFIER MemoryManager
MemoryManagerType;
-
typedef Type value_type;
typedef value_type* pointer;
typedef const value_type* const_pointer;
@@ -210,6 +208,8 @@
typedef reverse_iterator_ reverse_iterator;
typedef const_reverse_iterator_ const_reverse_iterator;
+ typedef typename
MemoryManagedConstructionTraits<value_type>::Constructor Constructor;
+
XalanList(
MemoryManagerType* theManager = 0) :
m_memoryManager(theManager),
@@ -437,22 +437,28 @@
Node& constructNode(const value_type& data, iterator pos)
{
Node * newNode = 0;
-
- if (m_freeListHeadPtr != 0)
- {
- newNode = m_freeListHeadPtr;
- m_freeListHeadPtr = m_freeListHeadPtr->next;
- }
- else
- {
- newNode = allocate(1);
- }
-
- new (&*newNode) Node(data, *pos.node().prev, pos.node());
+ Node * nextFreeNode = 0;
+
+ if (m_freeListHeadPtr != 0)
+ {
+ newNode = m_freeListHeadPtr;
+ nextFreeNode = m_freeListHeadPtr->next;
+ }
+ else
+ {
+ m_freeListHeadPtr = allocate(1);
+ newNode = m_freeListHeadPtr;
+ }
+
+ Constructor::construct(&newNode->value, data, *m_memoryManager);
+ new (&newNode->prev) Node*(pos.node().prev);
+ new (&newNode->next) Node*(&(pos.node()));
pos.node().prev->next = newNode;
pos.node().prev = newNode;
+ m_freeListHeadPtr = nextFreeNode;
+
return *newNode;
}
1.8 +2 -3 xml-xalan/c/src/xalanc/Include/XalanMap.hpp
Index: XalanMap.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/xalanc/Include/XalanMap.hpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- XalanMap.hpp 30 Sep 2004 22:28:10 -0000 1.7
+++ XalanMap.hpp 17 Oct 2004 00:25:58 -0000 1.8
@@ -30,7 +30,7 @@
-#include <xercesc/framework/MemoryManager.hpp>
+#include <xalanc/Include/XalanMemoryManagement.hpp>
@@ -111,6 +111,7 @@
}
};
+
/**
* Xalan implementation of a hashtable.
*
@@ -129,8 +130,6 @@
* A non-empty bucket will point to its first entry. Remaining
* entries in the chain follow the first and have the same index value.
*/
-
- typedef XERCES_CPP_NAMESPACE_QUALIFIER MemoryManager
MemoryManagerType;
typedef Key key_type;
typedef Value data_type;
1.2 +42 -51 xml-xalan/c/src/xalanc/Include/XalanMemoryManagement.hpp
Index: XalanMemoryManagement.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/xalanc/Include/XalanMemoryManagement.hpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XalanMemoryManagement.hpp 11 Aug 2004 13:03:59 -0000 1.1
+++ XalanMemoryManagement.hpp 17 Oct 2004 00:25:58 -0000 1.2
@@ -28,63 +28,54 @@
XALAN_CPP_NAMESPACE_BEGIN
+
+
typedef XERCES_CPP_NAMESPACE_QUALIFIER MemoryManager
MemoryManagerType;
-class XalanMemoryManagement
+template <class C>
+struct ConstructWithNoMemoryManager
{
-public:
- static void*
- allocate( size_t size,
- MemoryManagerType* memoryManager )
- {
- void* theResult = 0;
-
- if ( memoryManager == 0 )
- {
- theResult = ::operator new ( size );
- }
- else
- {
- theResult = memoryManager->allocate( size );
- }
-
- return theResult;
- }
-
- static void
- deallocate( void* pDataPointer,
- MemoryManagerType* memoryManager )
- {
- if ( memoryManager == 0 )
- {
- ::operator delete ( pDataPointer );
- }
- else
- {
- memoryManager->deallocate( pDataPointer );
- }
-
- }
-
- static MemoryManagerType*
- chooseMemMgrForXerces( MemoryManagerType* memoryManager )
- {
- if ( memoryManager == 0 )
- {
- XALAN_USING_XERCES(XMLPlatformUtils)
-
- return XMLPlatformUtils::fgMemoryManager;
- }
- else
- {
- return memoryManager;
- }
- }
-
-
+ static C* construct(C* address, MemoryManagerType& /* mgr */)
+ {
+ return (C*) new (address) C();
+ }
+
+ static C* construct(C* address, const C& theRhs, MemoryManagerType& /*
mgr */)
+ {
+ return (C*) new (address) C(theRhs);
+ }
};
+
+template <class C>
+struct ConstructWithMemoryManager
+{
+ static C* construct(C* address, MemoryManagerType& mgr)
+ {
+ return (C*) new (address) C();
+ }
+
+ static C* construct(C* address, const C& theRhs, MemoryManagerType& mgr)
+ {
+ return (C*) new (address) C(theRhs, mgr);
+ }
+};
+
+template <class C>
+struct MemoryManagedConstructionTraits
+{
+ typedef ConstructWithNoMemoryManager<C> Constructor;
+};
+
+#define XALAN_USES_MEMORY_MANAGER(Type) \
+XALAN_USING_XALAN(MemoryManagedConstructionTraits) \
+XALAN_USING_XALAN(ConstructWithMemoryManager) \
+template<> \
+struct MemoryManagedConstructionTraits<Type> \
+ { \
+ typedef ConstructWithMemoryManager<Type> Constructor; \
+ };
1.3 +1 -3 xml-xalan/c/src/xalanc/Include/XalanSet.hpp
Index: XalanSet.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/xalanc/Include/XalanSet.hpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- XalanSet.hpp 2 Oct 2004 01:03:47 -0000 1.2
+++ XalanSet.hpp 17 Oct 2004 00:25:58 -0000 1.3
@@ -29,7 +29,7 @@
-#include <xercesc/framework/MemoryManager.hpp>
+#include <xalanc/Include/XalanMemoryManagement.hpp>
@@ -93,8 +93,6 @@
class XalanSet
{
public:
-
- typedef XERCES_CPP_NAMESPACE_QUALIFIER MemoryManager
MemoryManagerType;
typedef Value value_type;
1.7 +8 -28 xml-xalan/c/src/xalanc/Include/XalanVector.hpp
Index: XalanVector.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/xalanc/Include/XalanVector.hpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- XalanVector.hpp 28 Sep 2004 18:48:58 -0000 1.6
+++ XalanVector.hpp 17 Oct 2004 00:25:58 -0000 1.7
@@ -38,7 +38,7 @@
-#include <xercesc/framework/MemoryManager.hpp>
+#include <xalanc/Include/XalanMemoryManagement.hpp>
@@ -55,8 +55,6 @@
{
public:
- typedef XERCES_CPP_NAMESPACE_QUALIFIER MemoryManager
MemoryManagerType;
-
typedef Type value_type;
typedef value_type* pointer;
typedef const value_type* const_pointer;
@@ -108,6 +106,8 @@
typedef XalanVector<value_type> ThisType;
+ typedef typename
MemoryManagedConstructionTraits<value_type>::Constructor Constructor;
+
XalanVector(
MemoryManagerType* theManager = 0,
size_type initialAllocation = size_type(0)) :
@@ -274,7 +274,7 @@
while (theFirst != theLast)
{
- construct(thePointer, *theFirst);
+ Constructor::construct(thePointer, *theFirst,
*m_memoryManager);
++thePointer;
++m_size;
@@ -390,7 +390,7 @@
for (size_type index = 0; index < theCount; ++index)
{
- construct(thePointer, theData);
+ Constructor::construct(thePointer, theData,
*m_memoryManager);
++thePointer;
++m_size;
@@ -573,7 +573,7 @@
data != theEnd;
++data, ++m_size)
{
- construct(data, theValue);
+ Constructor::construct(data, theValue, *m_memoryManager);
}
}
@@ -914,26 +914,6 @@
}
static void
- construct(
- value_type* theAddress,
- const value_type& theValue)
- {
- new (theAddress) value_type(theValue);
- }
-
- static void
- construct(
- value_type* theFirst,
- value_type* theLast,
- const value_type* values)
- {
- for(; theFirst != theLast; ++theFirst, ++values)
- {
- construct(*values);
- }
- }
-
- static void
destroy(value_type& theValue)
{
theValue.~Type();
@@ -951,13 +931,13 @@
}
void
- doPushBack(value_type data)
+ doPushBack(const value_type& data)
{
invariants();
if (m_size < m_allocation)
{
- construct(endPointer(), data);
+ Constructor::construct(endPointer(), data, *m_memoryManager);
++m_size;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]