dmitryh 2004/11/08 10:12:23
Modified: c/src/xalanc/XalanDOM XalanCDATASection.hpp
XalanCharacterData.hpp XalanComment.hpp
XalanDOMInit.cpp XalanDOMInit.hpp
XalanDOMString.cpp XalanDOMString.hpp XalanText.hpp
Log:
Initial implementation on the pluggable memory management
Revision Changes Path
1.5 +4 -3 xml-xalan/c/src/xalanc/XalanDOM/XalanCDATASection.hpp
Index: XalanCDATASection.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/xalanc/XalanDOM/XalanCDATASection.hpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- XalanCDATASection.hpp 26 Feb 2004 23:00:31 -0000 1.4
+++ XalanCDATASection.hpp 8 Nov 2004 18:12:23 -0000 1.5
@@ -444,10 +444,11 @@
* <br>DOMSTRING_SIZE_ERR: Raised if the specified range of text
does not
* fit into a <code>XalanDOMString</code>.
*/
- virtual XalanDOMString
+ virtual XalanDOMString&
substringData(
- unsigned int offset,
- unsigned int count) const = 0;
+ unsigned int offset,
+ unsigned int count,
+ XalanDOMString& theResult) const = 0;
//@}
/** @name Functions that set or change data. */
1.5 +3 -2 xml-xalan/c/src/xalanc/XalanDOM/XalanCharacterData.hpp
Index: XalanCharacterData.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/xalanc/XalanDOM/XalanCharacterData.hpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- XalanCharacterData.hpp 26 Feb 2004 23:00:31 -0000 1.4
+++ XalanCharacterData.hpp 8 Nov 2004 18:12:23 -0000 1.5
@@ -443,10 +443,11 @@
* <br>DOMSTRING_SIZE_ERR: Raised if the specified range of text
does not
* fit into a <code>XalanDOMString</code>.
*/
- virtual XalanDOMString
+ virtual XalanDOMString&
substringData(
unsigned int offset,
- unsigned int count) const = 0;
+ unsigned int count,
+ XalanDOMString& theResult) const = 0;
//@}
/** @name Functions that set or change data. */
1.5 +3 -2 xml-xalan/c/src/xalanc/XalanDOM/XalanComment.hpp
Index: XalanComment.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/xalanc/XalanDOM/XalanComment.hpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- XalanComment.hpp 26 Feb 2004 23:00:31 -0000 1.4
+++ XalanComment.hpp 8 Nov 2004 18:12:23 -0000 1.5
@@ -444,10 +444,11 @@
* <br>DOMSTRING_SIZE_ERR: Raised if the specified range of text
does not
* fit into a <code>XalanDOMString</code>.
*/
- virtual XalanDOMString
+ virtual XalanDOMString&
substringData(
unsigned int offset,
- unsigned int count) const = 0;
+ unsigned int count,
+ XalanDOMString& theResult) const = 0;
//@}
/** @name Functions that set or change data. */
1.5 +3 -3 xml-xalan/c/src/xalanc/XalanDOM/XalanDOMInit.cpp
Index: XalanDOMInit.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/xalanc/XalanDOM/XalanDOMInit.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- XalanDOMInit.cpp 26 Feb 2004 23:00:31 -0000 1.4
+++ XalanDOMInit.cpp 8 Nov 2004 18:12:23 -0000 1.5
@@ -26,13 +26,13 @@
-XalanDOMInit::XalanDOMInit()
+XalanDOMInit::XalanDOMInit(MemoryManagerType& theManager)
{
++s_initCounter;
if (s_initCounter == 1)
{
- initialize();
+ initialize(theManager);
}
}
@@ -51,7 +51,7 @@
void
-XalanDOMInit::initialize()
+XalanDOMInit::initialize(MemoryManagerType& /* theManager */)
{
}
1.5 +3 -2 xml-xalan/c/src/xalanc/XalanDOM/XalanDOMInit.hpp
Index: XalanDOMInit.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/xalanc/XalanDOM/XalanDOMInit.hpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- XalanDOMInit.hpp 26 Feb 2004 23:00:31 -0000 1.4
+++ XalanDOMInit.hpp 8 Nov 2004 18:12:23 -0000 1.5
@@ -22,6 +22,7 @@
// Base include file. Must be first.
#include <xalanc/XalanDOM/XalanDOMDefinitions.hpp>
+#include <xalanc/Include/XalanMemoryManagement.hpp>
XALAN_CPP_NAMESPACE_BEGIN
@@ -33,7 +34,7 @@
public:
explicit
- XalanDOMInit();
+ XalanDOMInit(MemoryManagerType& theManager);
~XalanDOMInit();
@@ -47,7 +48,7 @@
static void
- initialize();
+ initialize(MemoryManagerType& theManager);
static void
terminate();
1.11 +75 -36 xml-xalan/c/src/xalanc/XalanDOM/XalanDOMString.cpp
Index: XalanDOMString.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/xalanc/XalanDOM/XalanDOMString.cpp,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- XalanDOMString.cpp 5 Aug 2004 23:38:38 -0000 1.10
+++ XalanDOMString.cpp 8 Nov 2004 18:12:23 -0000 1.11
@@ -22,7 +22,7 @@
-#include <xalanc/Include/XalanAutoPtr.hpp>
+#include <xalanc/Include/XalanMemMngArrayAllocate.hpp>
@@ -32,7 +32,7 @@
XALAN_CPP_NAMESPACE_BEGIN
-
+//#define XALAN_USE_XERCES_LOCAL_CODEPAGE_TRANSCODERS
const XalanDOMChar XalanDOMString::s_empty = 0;
@@ -42,8 +42,8 @@
-XalanDOMString::XalanDOMString() :
- m_data(),
+XalanDOMString::XalanDOMString(MemoryManagerType& theManager) :
+ m_data(theManager),
m_size(0)
{
}
@@ -52,9 +52,10 @@
XalanDOMString::XalanDOMString(
const XalanDOMString& theSource,
+ MemoryManagerType& theManager,
size_type
theStartPosition,
size_type theCount) :
- m_data(),
+ m_data(theManager),
m_size(0)
{
if (theSource.length() != 0)
@@ -67,8 +68,9 @@
XalanDOMString::XalanDOMString(
const XalanDOMChar* theString,
+ MemoryManagerType& theManager,
size_type theCount) :
- m_data(),
+ m_data(theManager),
m_size(0)
{
assert(theString != 0);
@@ -82,9 +84,10 @@
XalanDOMString::XalanDOMString(
- const char* theString,
- size_type theCount) :
- m_data(),
+ const char* theString,
+ MemoryManagerType& theManager,
+ size_type theCount) :
+ m_data(theManager),
m_size(0)
{
assert(theString != 0);
@@ -97,17 +100,32 @@
invariants();
}
+XalanDOMString*
+XalanDOMString::clone(MemoryManagerType& theManager)
+{
+ typedef XalanDOMString ThisType;
+
+ XalanMemMgrAutoPtr<ThisType, false> theGuard( theManager ,
(ThisType*)theManager.allocate(sizeof(ThisType)));
+
+ ThisType* theResult = theGuard.get();
+
+ new (theResult) ThisType(*this, theManager);
+ theGuard.release();
+
+ return theResult;
+}
XalanDOMString::XalanDOMString(
- size_type theCount,
- XalanDOMChar theChar) :
- m_data(),
+ size_type theCount,
+ XalanDOMChar theChar,
+ MemoryManagerType& theManager) :
+ m_data(theManager),
m_size(0)
{
if (theCount != 0)
{
- XalanDOMCharVectorType(theCount + 1, theChar).swap(m_data);
+ XalanDOMCharVectorType(theCount + 1, theChar,
theManager).swap(m_data);
// Null-terminate it...
m_data.back() = 0;
@@ -350,7 +368,7 @@
}
else
{
- XalanDOMCharVectorType theTempVector;
+ XalanDOMCharVectorType
theTempVector(getMemoryManager());
doTranscode(theString, theLength, theTempVector, false);
@@ -623,22 +641,29 @@
return doCompare(c_str() + thePosition1, theCount1, theString,
theCount2);
}
-
-
-XalanDOMString::CharVectorType
-XalanDOMString::transcode() const
+template<class Type>
+reset_func(XalanDOMString& obj, MemoryManagerType& theManager, Type
string)
{
- invariants();
+ assert( string != 0 );
- CharVectorType theResult;
+ XalanDOMString tmpString(string, theManager);
- transcode(theResult);
-
- return theResult;
+ obj.swap(tmpString);
}
+void
+XalanDOMString::reset(MemoryManagerType& theManager,
+ const char* theString)
+{
+ reset_func(*this, theManager, theString);
+}
-
+void
+XalanDOMString::reset(MemoryManagerType& theManager,
+ const XalanDOMChar* theString)
+{
+ reset_func(*this, theManager, theString);
+}
void
XalanDOMString::transcode(CharVectorType& theResult) const
{
@@ -807,7 +832,7 @@
XalanDOMString::size_type theRealSourceStringLength =
theSourceStringLength;
- XalanArrayAutoPtr<SourceType> theGuard;
+ XalanMemMgrAutoPtrArray<SourceType> theGuard;
if (theSourceStringIsNullTerminated == true)
{
@@ -815,7 +840,11 @@
}
else
{
- theGuard.reset(new SourceType[theRealSourceStringLength + 1]);
+ typedef XalanMemMngArrayAllocate<SourceType> ArrayAllocateSourceType;
+
+ theGuard.reset( &( theTargetVector.getMemoryManager()),
+
ArrayAllocateSourceType::allocate(theRealSourceStringLength + 1,
theTargetVector.getMemoryManager()));
+
assert(theGuard.get() != 0);
for (XalanDOMString::size_type index = 0; index <
theRealSourceStringLength; ++index)
@@ -847,7 +876,8 @@
fSuccess = XMLString::transcode(
theRealSourceString,
&*theTargetVector.begin(),
- theTargetVector.size() - 1);
+ theTargetVector.size() - 1,
+ & (theTargetVector.getMemoryManager()));
if (fSuccess == false)
{
@@ -926,7 +956,7 @@
// If our char sizes are not the same, or the input string is not
null-terminated,
// we have to use a temporary buffer.
- XalanArrayAutoPtr<wchar_t> theTempSourceJanitor;
+ XalanMemMgrAutoPtrArray<wchar_t> theTempSourceJanitor;
#if !defined(XALAN_XALANDOMCHAR_USHORT_MISMATCH)
// This is a short-cut for when the theSourceString is mull-terminated
_and_
@@ -943,7 +973,10 @@
theSourceStringLength = length(theSourceString);
}
- theTempSourceJanitor.reset(new wchar_t[theSourceStringLength +
1]);
+ theTempSourceJanitor.reset(
+ &(theTargetVector.getMemoryManager()),
+ XalanMemMngArrayAllocate<wchar_t>::allocate(
theSourceStringLength + 1, theTargetVector.getMemoryManager()),
+ theSourceStringLength + 1);
for (size_t index = 0; index < theSourceStringLength;
++index)
{
@@ -1054,7 +1087,7 @@
terminate);
}
#else
- XalanArrayAutoPtr<char> tempString;
+ XalanMemMgrAutoPtrArray<char> tempString;
if (theSourceStringIsNullTerminated == true)
{
@@ -1062,7 +1095,10 @@
}
else
{
- tempString.reset(new char[theSourceStringLength + 1]);
+ tempString.reset(
+ &(theTargetVector.getMemoryManager()),
+ XalanMemMngArrayAllocate<char>::allocate( theSourceStringLength
+ 1, theTargetVector.getMemoryManager()),
+ theSourceStringLength + 1);
#if defined(XALAN_STRICT_ANSI_HEADERS)
std::strncpy(tempString.get(), theSourceString,
theSourceStringLength);
@@ -1154,12 +1190,15 @@
-XALAN_DOM_EXPORT_FUNCTION(const XalanDOMString)
-TranscodeFromLocalCodePage(const CharVectorType& theSourceString)
+XALAN_DOM_EXPORT_FUNCTION(const XalanDOMString&)
+TranscodeFromLocalCodePage(const CharVectorType& theSourceString,
+ XalanDOMString& result)
{
if (theSourceString.empty() == true)
{
- return XalanDOMString();
+ result.erase();
+
+ return result;
}
else
{
@@ -1169,11 +1208,11 @@
if (theSourceString[theSize - 1] ==
CharVectorType::value_type(0))
{
- return
TranscodeFromLocalCodePage(&*theSourceString.begin(), size_type(theSize) - 1);
+ return
TranscodeFromLocalCodePage(&*theSourceString.begin(), result ,
size_type(theSize) - 1);
}
else
{
- return
TranscodeFromLocalCodePage(&*theSourceString.begin(), size_type(theSize));
+ return
TranscodeFromLocalCodePage(&*theSourceString.begin(), result ,
size_type(theSize));
}
}
}
1.10 +72 -104 xml-xalan/c/src/xalanc/XalanDOM/XalanDOMString.hpp
Index: XalanDOMString.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/xalanc/XalanDOM/XalanDOMString.hpp,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- XalanDOMString.hpp 12 Oct 2004 21:28:07 -0000 1.9
+++ XalanDOMString.hpp 8 Nov 2004 18:12:23 -0000 1.10
@@ -62,26 +62,33 @@
enum { npos = -1 };
#endif
- XalanDOMString();
+ XalanDOMString(MemoryManagerType& theManager);
explicit
XalanDOMString(
- const char* theString,
- size_type theCount = size_type(npos));
+ const char* theString,
+ MemoryManagerType& theManager,
+ size_type theCount = size_type(npos));
XalanDOMString(
const XalanDOMString& theSource,
+ MemoryManagerType& theManager,
size_type
theStartPosition = 0,
size_type theCount =
size_type(npos));
explicit
XalanDOMString(
const XalanDOMChar* theString,
+ MemoryManagerType& theManager,
size_type theCount =
size_type(npos));
XalanDOMString(
size_type theCount,
- XalanDOMChar theChar);
+ XalanDOMChar theChar,
+ MemoryManagerType& theManager);
+
+ XalanDOMString*
+ clone(MemoryManagerType& theManager);
~XalanDOMString()
{
@@ -556,18 +563,6 @@
iterator theFirstPosition,
iterator theLastPosition);
- XalanDOMString
- substr(
- size_type thePosition = 0,
- size_type theCount = size_type(npos)) const
- {
- assert(theCount == size_type(npos) && thePosition < length() ||
- thePosition + theCount <= length());
-
- invariants();
-
- return XalanDOMString(*this, thePosition, theCount);
- }
XalanDOMString&
substr(
@@ -625,25 +620,12 @@
const XalanDOMChar* theString,
size_type theCount2 =
size_type(npos)) const;
- int
- compare(const char* theString) const
- {
- invariants();
-
- return compare(XalanDOMString(theString));
- }
- int
- compare(
- size_type thePosition1,
- size_type theCount1,
- const char* theString,
- size_type theCount2 = size_type(npos))
const
- {
- invariants();
+ void
+ reset(MemoryManagerType& theManager, const char* theString);
- return compare(thePosition1, theCount1,
XalanDOMString(theString, theCount2));
- }
+ void
+ reset(MemoryManagerType& theManager, const XalanDOMChar* theString);
class TranscodingError : public XalanDOMException
{
@@ -660,15 +642,7 @@
}
};
- /**
- * Transcode the string to the local code page. If the string
- * cannot be properly transcoded, and the transcoder can detect
- * the error a TranscodingError exception is thrown.
- *
- * @return A null-terminated CharVectorType instance.
- */
- CharVectorType
- transcode() const;
+
/**
* Transcode the string to the local code page. If the string
@@ -680,6 +654,12 @@
void
transcode(CharVectorType& theResult) const;
+ MemoryManagerType&
+ getMemoryManager()
+ {
+ return m_data.getMemoryManager();
+ }
+
size_type
hash() const
{
@@ -801,6 +781,10 @@
}
private:
+ // not defined
+ XalanDOMString();
+ XalanDOMString(const XalanDOMString&);
+
XalanDOMCharVectorType m_data;
@@ -872,58 +856,71 @@
-inline XalanDOMString
-operator+(
+inline XalanDOMString&
+add(
const XalanDOMString& theLHS,
- const XalanDOMString& theRHS)
+ const XalanDOMString& theRHS,
+ XalanDOMString& result)
{
- XalanDOMString theTemp(theLHS);
+ result.assign(theLHS);
- return theTemp += theRHS;
+ return result += theRHS;
}
-inline XalanDOMString
-operator+(
+inline XalanDOMString&
+add(
const XalanDOMString& theLHS,
- const XalanDOMChar* theRHS)
+ const XalanDOMChar* theRHS,
+ XalanDOMString& result)
{
- XalanDOMString theTemp(theLHS);
+ result.assign(theLHS);
- return theTemp += theRHS;
+ return result += theRHS;
}
-inline XalanDOMString
-operator+(
+inline XalanDOMString&
+add(
const XalanDOMChar* theLHS,
- const XalanDOMString& theRHS)
+ const XalanDOMString& theRHS,
+ XalanDOMString& result)
{
- XalanDOMString theTemp(theLHS);
+ result.assign(theLHS);
- return theTemp += theRHS;
+ return result += theRHS;
}
-inline const XalanDOMString
-operator+(
+inline const XalanDOMString&
+add(
const char* theLHS,
- const XalanDOMString& theRHS)
+ const XalanDOMString& theRHS,
+ XalanDOMString& result)
{
- return XalanDOMString(theLHS) + theRHS;
+ result.assign(theLHS);
+
+ result.append(theRHS);
+
+ return result;
}
-inline const XalanDOMString
-operator+(
+inline const XalanDOMString&
+add(
const XalanDOMString& theLHS,
- const char* theRHS)
+ const char* theRHS,
+ XalanDOMString& result)
{
- return theLHS + XalanDOMString(theRHS);
+ result.assign(theLHS);
+
+ result.append(theRHS);
+
+ return result;
}
@@ -971,23 +968,6 @@
CharVectorType& targetVector,
bool terminate =
false);
-/**
- * Convert XalanDOMString to C++ standard library
- * vector, transcoding to the default local code
- * page. Null-terminate the sttring...
- *
- * @param theSourceString source string
- * @return The transcoded string.
- */
-inline const CharVectorType
-TranscodeToLocalCodePage(const XalanDOMChar* theSourceString)
-{
- CharVectorType theResult;
-
- TranscodeToLocalCodePage(theSourceString, theResult, true);
-
- return theResult;
-}
@@ -1011,24 +991,6 @@
-/**
- * Convert XalanDOMString to C++ standard library
- * vector, transcoding to the default local code
- * page.
- *
- * @param thetheSourceString source string
- * @return The transcoded string.
- */
-inline const CharVectorType
-TranscodeToLocalCodePage(const XalanDOMString& theSourceString)
-{
- CharVectorType theResult;
-
- TranscodeToLocalCodePage(theSourceString, theResult, true);
-
- return theResult;
-}
-
/**
@@ -1039,12 +1001,15 @@
* @param theSourceStringLength The source string length.
* @return The new string.
*/
-inline const XalanDOMString
+inline const XalanDOMString&
TranscodeFromLocalCodePage(
const char*
theSourceString,
+ XalanDOMString& result,
XalanDOMString::size_type theSourceStringLength =
XalanDOMString::npos)
{
- return XalanDOMString(theSourceString, theSourceStringLength);
+ result.assign(theSourceString, theSourceStringLength);
+
+ return result;
}
@@ -1090,9 +1055,12 @@
* @param theSourceString source string
* @return The transcoded string.
*/
-XALAN_DOM_EXPORT_FUNCTION(const XalanDOMString)
-TranscodeFromLocalCodePage(const CharVectorType& theSourceString);
+XALAN_DOM_EXPORT_FUNCTION(const XalanDOMString&)
+TranscodeFromLocalCodePage(const CharVectorType& theSourceString,
+ XalanDOMString& result);
+
+XALAN_USES_MEMORY_MANAGER(XalanDOMString)
XALAN_CPP_NAMESPACE_END
1.5 +3 -2 xml-xalan/c/src/xalanc/XalanDOM/XalanText.hpp
Index: XalanText.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/xalanc/XalanDOM/XalanText.hpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- XalanText.hpp 26 Feb 2004 23:00:31 -0000 1.4
+++ XalanText.hpp 8 Nov 2004 18:12:23 -0000 1.5
@@ -444,10 +444,11 @@
* <br>DOMSTRING_SIZE_ERR: Raised if the specified range of text
does not
* fit into a <code>XalanDOMString</code>.
*/
- virtual XalanDOMString
+ virtual XalanDOMString&
substringData(
unsigned int offset,
- unsigned int count) const = 0;
+ unsigned int count,
+ XalanDOMString& theResult) const = 0;
//@}
/** @name Functions that set or change data. */
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]