Return-Path: Delivered-To: apmail-xml-xalan-cvs-archive@www.apache.org Received: (qmail 57739 invoked from network); 8 Nov 2004 18:06:23 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 8 Nov 2004 18:06:23 -0000 Received: (qmail 2608 invoked by uid 500); 8 Nov 2004 18:06:23 -0000 Delivered-To: apmail-xml-xalan-cvs-archive@xml.apache.org Received: (qmail 2543 invoked by uid 500); 8 Nov 2004 18:06:22 -0000 Mailing-List: contact xalan-cvs-help@xml.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: Reply-To: Delivered-To: mailing list xalan-cvs@xml.apache.org Received: (qmail 2529 invoked by uid 99); 8 Nov 2004 18:06:22 -0000 X-ASF-Spam-Status: No, hits=-10.0 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Mon, 08 Nov 2004 10:06:21 -0800 Received: (qmail 57715 invoked by uid 1837); 8 Nov 2004 18:06:20 -0000 Date: 8 Nov 2004 18:06:20 -0000 Message-ID: <20041108180620.57714.qmail@minotaur.apache.org> From: dmitryh@apache.org To: xml-xalan-cvs@apache.org Subject: cvs commit: xml-xalan/c/src/xalanc/ICUBridge ICUBridge.cpp ICUBridge.hpp ICUBridgeCollationCompareFunctor.cpp ICUBridgeCollationCompareFunctor.hpp ICUBridgeCollationCompareFunctorImpl.cpp ICUBridgeCollationCompareFunctorImpl.hpp ICUFormatNumberFunctor.cpp ICUFormatNumberFunctor.hpp ICUXalanNumberFormatFactory.cpp ICUXalanNumberFormatFactory.hpp ICUXalanNumberFormatProxy.cpp ICUXalanNumberFormatProxy.hpp X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N dmitryh 2004/11/08 10:06:20 Modified: c/src/xalanc/ICUBridge ICUBridge.cpp ICUBridge.hpp ICUBridgeCollationCompareFunctor.cpp ICUBridgeCollationCompareFunctor.hpp ICUBridgeCollationCompareFunctorImpl.cpp ICUBridgeCollationCompareFunctorImpl.hpp ICUFormatNumberFunctor.cpp ICUFormatNumberFunctor.hpp ICUXalanNumberFormatFactory.cpp ICUXalanNumberFormatFactory.hpp ICUXalanNumberFormatProxy.cpp ICUXalanNumberFormatProxy.hpp Log: Initial implementation on the pluggable memory management Revision Changes Path 1.7 +32 -57 xml-xalan/c/src/xalanc/ICUBridge/ICUBridge.cpp Index: ICUBridge.cpp =================================================================== RCS file: /home/cvs/xml-xalan/c/src/xalanc/ICUBridge/ICUBridge.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- ICUBridge.cpp 31 Jul 2004 06:05:03 -0000 1.6 +++ ICUBridge.cpp 8 Nov 2004 18:06:19 -0000 1.7 @@ -34,7 +34,7 @@ -typedef XalanVector UCharVectorType; +typedef XalanVector UCharVectorType; @@ -66,7 +66,8 @@ const UnicodeString -ICUBridge::XalanDOMCharStringToUnicodeString(const XalanDOMChar* theString) +ICUBridge::XalanDOMCharStringToUnicodeString(MemoryManagerType& theManager, + const XalanDOMChar* theString) { if (theString == 0) { @@ -74,16 +75,25 @@ } else { - return XalanDOMCharStringToUnicodeString(theString, length(theString)); + return XalanDOMCharStringToUnicodeString(theManager, theString, length(theString)); } } +#if defined(XALAN_XALANDOMCHAR_USHORT_MISMATCH) const UnicodeString ICUBridge::XalanDOMCharStringToUnicodeString( + MemoryManagerType& theManager, + const XalanDOMChar* theString, + XalanDOMString::size_type theLength) +#else +const UnicodeString +ICUBridge::XalanDOMCharStringToUnicodeString( + MemoryManagerType& /* theManager */, const XalanDOMChar* theString, XalanDOMString::size_type theLength) +#endif { assert(theString != 0); @@ -110,7 +120,7 @@ else { // Create a buffer to copy out the UnicodeString data... - UCharVectorType theBuffer; + UCharVectorType theBuffer(theManager); // Resize the buffer appropriately... theBuffer.resize(theLength); @@ -134,16 +144,19 @@ const UnicodeString -ICUBridge::XalanDOMStringToUnicodeString(const XalanDOMString& theString) +ICUBridge::XalanDOMStringToUnicodeString(MemoryManagerType& theManager, + const XalanDOMString& theString) { // Just call up to the XalanDOMChar* version... - return XalanDOMCharStringToUnicodeString(c_wstr(theString), length(theString)); + return XalanDOMCharStringToUnicodeString(theManager, c_wstr(theString), length(theString)); } -const XalanDOMString -ICUBridge::UnicodeStringToXalanDOMString(const UnicodeString& theString) +XalanDOMString& +ICUBridge::UnicodeStringToXalanDOMString( + const UnicodeString& theString, + XalanDOMString& theResult) { const int32_t theLength = theString.length(); @@ -151,7 +164,7 @@ // If XalanDOMChar is larger than the ICU's UChar, we have to more work... // Create a buffer... - XalanDOMCharVectorType theBuffer; + XalanDOMCharVectorType theBuffer(theResult.getMemoryManager()); // Reserve the appropriate amount of space... theBuffer.reserve(theLength); @@ -162,7 +175,9 @@ theBuffer.push_back(theString[i]); } - return XalanDOMString(&theBuffer[0], theBuffer.size()); + theResult.assign(&theBuffer[0], theBuffer.size()); + + return theResult; #else @@ -173,12 +188,14 @@ // Extract the data... theString.extract(0, theLength, theBuffer); - return XalanDOMString(theBuffer, theLength); + theResult.assign(theBuffer, theLength); + + return theResult; } else { // Create a buffer to copy out the UnicodeString data... - UCharVectorType theBuffer; + UCharVectorType theBuffer(theResult.getMemoryManager()); // Resize the buffer appropriately... theBuffer.resize(theLength); @@ -188,55 +205,13 @@ assert(theLength == int32_t(theBuffer.size())); - return XalanDOMString(&theBuffer[0], theLength); + theResult.assign(&theBuffer[0], theLength); + + return theResult; } #endif } - -void -ICUBridge::UnicodeStringToXalanDOMString( - const UnicodeString& theString, - XalanDOMString& theResult) -{ -#if defined(XALAN_XALANDOMCHAR_USHORT_MISMATCH) - - // If XalanDOMChar is larger than the ICU's UChar, we have to more work. - // Don't bother to provide the optimized version, just call to the - // previous function. - - theResult = UnicodeStringToXalanDOMString(theString); - -#else - - const int32_t theLength = theString.length(); - - if (theStackBufferSize > theLength) - { - UChar theBuffer[theStackBufferSize]; - - // Extract the data... - theString.extract(0, theLength, theBuffer); - - theResult = XalanDOMString(theBuffer, theLength); - } - else - { - typedef XalanVector UCharVectorType; - - // Create a buffer to copy out the UnicodeString data... - UCharVectorType theBuffer; - - // Resize the buffer appropriately... - theBuffer.resize(theLength); - - // Extract the data... - theString.extract(0, theLength, &theBuffer[0]); - - theResult = XalanDOMString(&theBuffer[0], theBuffer.size()); - } -#endif -} XALAN_CPP_NAMESPACE_END 1.7 +6 -6 xml-xalan/c/src/xalanc/ICUBridge/ICUBridge.hpp Index: ICUBridge.hpp =================================================================== RCS file: /home/cvs/xml-xalan/c/src/xalanc/ICUBridge/ICUBridge.hpp,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- ICUBridge.hpp 12 Mar 2004 22:27:12 -0000 1.6 +++ ICUBridge.hpp 8 Nov 2004 18:06:19 -0000 1.7 @@ -40,20 +40,20 @@ public: static const UnicodeString - XalanDOMCharStringToUnicodeString(const XalanDOMChar* theString); + XalanDOMCharStringToUnicodeString(MemoryManagerType& theManager, + const XalanDOMChar* theString); static const UnicodeString XalanDOMCharStringToUnicodeString( + MemoryManagerType& theManager, const XalanDOMChar* theString, XalanDOMString::size_type theLHSLength); static const UnicodeString - XalanDOMStringToUnicodeString(const XalanDOMString& theString); + XalanDOMStringToUnicodeString(MemoryManagerType& theManager, + const XalanDOMString& theString); - static const XalanDOMString - UnicodeStringToXalanDOMString(const UnicodeString& theString); - - static void + static XalanDOMString& UnicodeStringToXalanDOMString( const UnicodeString& theString, XalanDOMString& theResult); 1.6 +21 -3 xml-xalan/c/src/xalanc/ICUBridge/ICUBridgeCollationCompareFunctor.cpp Index: ICUBridgeCollationCompareFunctor.cpp =================================================================== RCS file: /home/cvs/xml-xalan/c/src/xalanc/ICUBridge/ICUBridgeCollationCompareFunctor.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- ICUBridgeCollationCompareFunctor.cpp 26 Feb 2004 23:07:12 -0000 1.5 +++ ICUBridgeCollationCompareFunctor.cpp 8 Nov 2004 18:06:19 -0000 1.6 @@ -21,22 +21,40 @@ #include "ICUBridge.hpp" #include "ICUBridgeCollationCompareFunctorImpl.hpp" +#include XALAN_CPP_NAMESPACE_BEGIN -ICUBridgeCollationCompareFunctor::ICUBridgeCollationCompareFunctor(bool fCacheCollators) : - m_impl(new ICUBridgeCollationCompareFunctorImpl(fCacheCollators)) +ICUBridgeCollationCompareFunctor::ICUBridgeCollationCompareFunctor( + MemoryManagerType& theManager, bool fCacheCollators) : + m_impl(ICUBridgeCollationCompareFunctorImpl::create(theManager, fCacheCollators)) { } +ICUBridgeCollationCompareFunctor* +ICUBridgeCollationCompareFunctor::create (MemoryManagerType& theManager , bool fCacheCollators) +{ + typedef ICUBridgeCollationCompareFunctor ThisType; + + XalanMemMgrAutoPtr theGuard( theManager , (ThisType*)theManager.allocate(sizeof(ThisType))); + + ThisType* theResult = theGuard.get(); + + new (theResult) ThisType(theManager, fCacheCollators); + theGuard.release(); + + return theResult; +} ICUBridgeCollationCompareFunctor::~ICUBridgeCollationCompareFunctor() { - delete m_impl; + MemoryManagerType& theManager = m_impl->getMemoryManager(); + + destroyObjWithMemMgr(m_impl, theManager); } 1.6 +5 -1 xml-xalan/c/src/xalanc/ICUBridge/ICUBridgeCollationCompareFunctor.hpp Index: ICUBridgeCollationCompareFunctor.hpp =================================================================== RCS file: /home/cvs/xml-xalan/c/src/xalanc/ICUBridge/ICUBridgeCollationCompareFunctor.hpp,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- ICUBridgeCollationCompareFunctor.hpp 26 Feb 2004 23:07:12 -0000 1.5 +++ ICUBridgeCollationCompareFunctor.hpp 8 Nov 2004 18:06:19 -0000 1.6 @@ -44,7 +44,11 @@ * * @param fCacheCollators If true, the instance will cache collators. This is not thread-safe, so each thread must have its own instance. */ - ICUBridgeCollationCompareFunctor(bool fCacheCollators = false); + ICUBridgeCollationCompareFunctor(MemoryManagerType& theManager, + bool fCacheCollators = false); + + static ICUBridgeCollationCompareFunctor* + create(MemoryManagerType& theManager, bool fCacheCollators = false); virtual ~ICUBridgeCollationCompareFunctor(); 1.6 +26 -12 xml-xalan/c/src/xalanc/ICUBridge/ICUBridgeCollationCompareFunctorImpl.cpp Index: ICUBridgeCollationCompareFunctorImpl.cpp =================================================================== RCS file: /home/cvs/xml-xalan/c/src/xalanc/ICUBridge/ICUBridgeCollationCompareFunctorImpl.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- ICUBridgeCollationCompareFunctorImpl.cpp 26 Feb 2004 23:07:12 -0000 1.5 +++ ICUBridgeCollationCompareFunctorImpl.cpp 8 Nov 2004 18:06:19 -0000 1.6 @@ -26,7 +26,7 @@ #include - +#include #include #include @@ -41,13 +41,12 @@ -inline ICUBridgeCollationCompareFunctorImpl::CollatorType* +inline CollatorType* createCollator( UErrorCode& theStatus, const Locale& theLocale, XalanDOMString* theLocaleName = 0) { - typedef ICUBridgeCollationCompareFunctorImpl::CollatorType CollatorType; if (theLocaleName != 0) { @@ -67,7 +66,7 @@ -inline ICUBridgeCollationCompareFunctorImpl::CollatorType* +inline CollatorType* createCollator( UErrorCode& theStatus, XalanDOMString* theLocaleName = 0) @@ -95,12 +94,13 @@ -ICUBridgeCollationCompareFunctorImpl::ICUBridgeCollationCompareFunctorImpl(bool fCacheCollators) : +ICUBridgeCollationCompareFunctorImpl::ICUBridgeCollationCompareFunctorImpl(MemoryManagerType& theManager, + bool fCacheCollators) : m_isValid(false), m_defaultCollator(0), - m_defaultCollatorLocaleName(), + m_defaultCollatorLocaleName(theManager), m_cacheCollators(fCacheCollators), - m_collatorCache() + m_collatorCache(theManager) { UErrorCode theStatus = U_ZERO_ERROR; @@ -112,7 +112,21 @@ } } +ICUBridgeCollationCompareFunctorImpl* +ICUBridgeCollationCompareFunctorImpl::create (MemoryManagerType& theManager , bool fCacheCollators) +{ + typedef ICUBridgeCollationCompareFunctorImpl ThisType; + + XalanMemMgrAutoPtr theGuard( theManager , (ThisType*)theManager.allocate(sizeof(ThisType))); + + ThisType* theResult = theGuard.get(); + new (theResult) ThisType(theManager, fCacheCollators); + + theGuard.release(); + + return theResult; +} ICUBridgeCollationCompareFunctorImpl::~ICUBridgeCollationCompareFunctorImpl() { @@ -123,7 +137,7 @@ for_each( m_collatorCache.begin(), m_collatorCache.end(), - CollationCacheStruct::CollatorDeleteFunctor()); + CollationCacheStruct::CollatorDeleteFunctor(getMemoryManager())); } @@ -196,7 +210,7 @@ -inline ICUBridgeCollationCompareFunctorImpl::CollatorType* +inline CollatorType* createCollator( const XalanDOMChar* theLocale, UErrorCode& theStatus) @@ -229,7 +243,7 @@ theBuffer[i] = char(theLocale[i]); } #endif - return ICUBridgeCollationCompareFunctorImpl::CollatorType::createInstance( + return CollatorType::createInstance( Locale::createFromName(theBuffer), theStatus); } @@ -388,7 +402,7 @@ -ICUBridgeCollationCompareFunctorImpl::CollatorType* +CollatorType* ICUBridgeCollationCompareFunctorImpl::getCachedCollator(const XalanDOMChar* theLocale) const { XALAN_USING_STD(find_if) @@ -462,7 +476,7 @@ theNonConstCache.pop_back(); } - theNonConstCache.push_front(CollatorCacheListType::value_type()); + theNonConstCache.push_front(CollatorCacheListType::value_type(getMemoryManager())); CollatorCacheListType::value_type& theEntry = theNonConstCache.front(); 1.6 +108 -84 xml-xalan/c/src/xalanc/ICUBridge/ICUBridgeCollationCompareFunctorImpl.hpp Index: ICUBridgeCollationCompareFunctorImpl.hpp =================================================================== RCS file: /home/cvs/xml-xalan/c/src/xalanc/ICUBridge/ICUBridgeCollationCompareFunctorImpl.hpp,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- ICUBridgeCollationCompareFunctorImpl.hpp 26 Feb 2004 23:07:12 -0000 1.5 +++ ICUBridgeCollationCompareFunctorImpl.hpp 8 Nov 2004 18:06:19 -0000 1.6 @@ -23,7 +23,7 @@ -#include +#include @@ -39,6 +39,99 @@ XALAN_CPP_NAMESPACE_BEGIN +#if defined(XALAN_HAS_CPP_NAMESPACE) +typedef U_ICU_NAMESPACE::Collator CollatorType; +#else +typedef Collator CollatorType; +#endif + +struct CollationCacheStruct +{ + CollationCacheStruct( + MemoryManagerType& theManager, + const XalanDOMString& theLocale, + CollatorType* theCollator) : + m_locale(theLocale, theManager), + m_collator(theCollator) + { + } + + CollationCacheStruct(MemoryManagerType& theManager) : + m_locale(theManager), + m_collator(0) + { + } + + CollationCacheStruct( const CollationCacheStruct& other, + MemoryManagerType& theManager) : + m_locale(other.m_locale,theManager), + m_collator(other.m_collator) + { + } + void + swap(CollationCacheStruct& theOther) + { + m_locale.swap(theOther.m_locale); + + CollatorType* const theTemp = m_collator; + + m_collator = theOther.m_collator; + + theOther.m_collator = theTemp; + } + +#if defined(XALAN_NO_SELECTIVE_TEMPLATE_INSTANTIATION) + bool + operator<(const CollationCacheStruct& theRHS) const + { + return this < &theRHS; + } + + bool + operator==(const CollationCacheStruct& theRHS) const + { + return this == &theRHS; + } +#endif + + XalanDOMString m_locale; + + CollatorType* m_collator; + + struct CollatorDeleteFunctor + { + CollatorDeleteFunctor(MemoryManagerType& theManager): + m_memoryManager(theManager) + { + } + + void + operator()(CollationCacheStruct& theStruct) const + { + delete theStruct.m_collator; + } + private: + MemoryManagerType& m_memoryManager; + }; + + struct CollatorFindFunctor + { + CollatorFindFunctor(const XalanDOMChar* theLocale) : + m_locale(theLocale) + { + } + + bool + operator()(CollationCacheStruct& theStruct) const + { + return XalanDOMString::equals(theStruct.m_locale ,m_locale); + } + + const XalanDOMChar* const m_locale; + }; +}; + +XALAN_USES_MEMORY_MANAGER(CollationCacheStruct) class XALAN_ICUBRIDGE_EXPORT ICUBridgeCollationCompareFunctorImpl : public XalanCollationServices::CollationCompareFunctor { @@ -49,10 +142,22 @@ * * @param fCacheCollators If true, the instance will cache collators. This is not thread-safe, so each thread must have its own instance. */ - ICUBridgeCollationCompareFunctorImpl(bool fCacheCollators = false); + ICUBridgeCollationCompareFunctorImpl( MemoryManagerType& theManager , + bool fCacheCollators = false); + + static ICUBridgeCollationCompareFunctorImpl* + create( MemoryManagerType& theManager, + bool fCacheCollators = false); + ~ICUBridgeCollationCompareFunctorImpl(); + MemoryManagerType& + getMemoryManager()const + { + return m_collatorCache.getMemoryManager(); + } + int operator()( const XalanDOMChar* theLHS, @@ -72,89 +177,8 @@ return m_isValid; } -#if defined(XALAN_HAS_CPP_NAMESPACE) - typedef U_ICU_NAMESPACE::Collator CollatorType; -#else - typedef Collator CollatorType; -#endif - - struct CollationCacheStruct - { - CollationCacheStruct( - const XalanDOMString& theLocale, - CollatorType* theCollator) : - m_locale(theLocale), - m_collator(theCollator) - { - } - - CollationCacheStruct() : - m_locale(), - m_collator(0) - { - } - - void - swap(CollationCacheStruct& theOther) - { - m_locale.swap(theOther.m_locale); - - CollatorType* const theTemp = m_collator; - - m_collator = theOther.m_collator; - - theOther.m_collator = theTemp; - } -#if defined(XALAN_NO_SELECTIVE_TEMPLATE_INSTANTIATION) - bool - operator<(const CollationCacheStruct& theRHS) const - { - return this < &theRHS; - } - - bool - operator==(const CollationCacheStruct& theRHS) const - { - return this == &theRHS; - } -#endif - - XalanDOMString m_locale; - - CollatorType* m_collator; - - struct CollatorDeleteFunctor - { - void - operator()(CollationCacheStruct& theStruct) const - { - delete theStruct.m_collator; - } - }; - - struct CollatorFindFunctor - { - CollatorFindFunctor(const XalanDOMChar* theLocale) : - m_locale(theLocale) - { - } - - bool - operator()(CollationCacheStruct& theStruct) const - { - return XalanDOMString::equals(theStruct.m_locale ,m_locale); - } - - const XalanDOMChar* const m_locale; - }; - }; - -#if defined(XALAN_NO_STD_NAMESPACE) - typedef list CollatorCacheListType; -#else - typedef std::list CollatorCacheListType; -#endif + typedef XalanList CollatorCacheListType; enum { eCacheMax = 10 }; 1.6 +39 -16 xml-xalan/c/src/xalanc/ICUBridge/ICUFormatNumberFunctor.cpp Index: ICUFormatNumberFunctor.cpp =================================================================== RCS file: /home/cvs/xml-xalan/c/src/xalanc/ICUBridge/ICUFormatNumberFunctor.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- ICUFormatNumberFunctor.cpp 21 Apr 2004 16:23:05 -0000 1.5 +++ ICUFormatNumberFunctor.cpp 8 Nov 2004 18:06:19 -0000 1.6 @@ -46,14 +46,32 @@ -ICUFormatNumberFunctor::ICUFormatNumberFunctor() +ICUFormatNumberFunctor::ICUFormatNumberFunctor(MemoryManagerType& theManager) : + m_decimalFormatCache(theManager), + m_memoryManager(theManager) + { - XalanDecimalFormatSymbols defaultXalanDFS; + XalanDecimalFormatSymbols defaultXalanDFS(theManager); m_defaultDecimalFormat = createDecimalFormat(defaultXalanDFS); } +ICUFormatNumberFunctor* +ICUFormatNumberFunctor::create(MemoryManagerType& theManager) +{ + typedef ICUFormatNumberFunctor ThisType; + + XalanMemMgrAutoPtr theGuard( theManager , (ThisType*)theManager.allocate(sizeof(ThisType))); + + ThisType* theResult = theGuard.get(); + + new (theResult) ThisType(theManager); + theGuard.release(); + + return theResult; +} + ICUFormatNumberFunctor::~ICUFormatNumberFunctor() { @@ -80,8 +98,10 @@ { if (!doFormat(theNumber, thePattern, theResult, theDFS)) { + XalanDOMString buffer(executionContext.getMemoryManager()); + executionContext.warn( - XalanMessageLoader::getMessage(XalanMessages::FormatNumberFailed), + XalanMessageLoader::getMessage(XalanMessages::FormatNumberFailed, buffer), context, locator); } @@ -89,7 +109,7 @@ -ICUFormatNumberFunctor::DecimalFormatType * +DecimalFormatType * ICUFormatNumberFunctor::getCachedDecimalFormat(const XalanDecimalFormatSymbols &theDFS) const { XALAN_USING_STD(find_if) @@ -152,7 +172,11 @@ return doICUFormat(theNumber,thePattern,theResult); } - XalanDOMString nonLocalPattern = UnlocalizePatternFunctor(*theDFS)(thePattern); + XalanDOMString nonLocalPattern(theResult.getMemoryManager()); + + UnlocalizePatternFunctor formatter(*theDFS); + + formatter(thePattern, nonLocalPattern); DecimalFormatType* theFormatter = getCachedDecimalFormat(*theDFS); @@ -185,7 +209,7 @@ -ICUFormatNumberFunctor::DecimalFormatType * +DecimalFormatType * ICUFormatNumberFunctor::createDecimalFormat( const XalanDecimalFormatSymbols& theXalanDFS) const { @@ -203,11 +227,11 @@ theDFS->setSymbol(DecimalFormatSymbols::kDigitSymbol, UChar(theXalanDFS.getDigit())); theDFS->setSymbol(DecimalFormatSymbols::kPatternSeparatorSymbol, UChar(theXalanDFS.getPatternSeparator())); - theDFS->setSymbol(DecimalFormatSymbols::kInfinitySymbol, ICUBridge::XalanDOMStringToUnicodeString(theXalanDFS.getInfinity())); - theDFS->setSymbol(DecimalFormatSymbols::kNaNSymbol, ICUBridge::XalanDOMStringToUnicodeString(theXalanDFS.getNaN())); + theDFS->setSymbol(DecimalFormatSymbols::kInfinitySymbol, ICUBridge::XalanDOMStringToUnicodeString(m_memoryManager, theXalanDFS.getInfinity())); + theDFS->setSymbol(DecimalFormatSymbols::kNaNSymbol, ICUBridge::XalanDOMStringToUnicodeString(m_memoryManager,theXalanDFS.getNaN())); theDFS->setSymbol(DecimalFormatSymbols::kMinusSignSymbol, UChar(theXalanDFS.getMinusSign())); - theDFS->setSymbol(DecimalFormatSymbols::kCurrencySymbol, ICUBridge::XalanDOMStringToUnicodeString(theXalanDFS.getCurrencySymbol())); - theDFS->setSymbol(DecimalFormatSymbols::kIntlCurrencySymbol, ICUBridge::XalanDOMStringToUnicodeString(theXalanDFS.getInternationalCurrencySymbol())); + theDFS->setSymbol(DecimalFormatSymbols::kCurrencySymbol, ICUBridge::XalanDOMStringToUnicodeString(m_memoryManager, theXalanDFS.getCurrencySymbol())); + theDFS->setSymbol(DecimalFormatSymbols::kIntlCurrencySymbol, ICUBridge::XalanDOMStringToUnicodeString(m_memoryManager, theXalanDFS.getInternationalCurrencySymbol())); theDFS->setSymbol(DecimalFormatSymbols::kMonetarySeparatorSymbol, UChar(theXalanDFS.getMonetaryDecimalSeparator())); // Construct a DecimalFormat. Note that we release the XalanAutoPtr, since the @@ -252,7 +276,7 @@ } - theNonConstCache.push_front(DecimalFormatCacheListType::value_type()); + theNonConstCache.push_front(DecimalFormatCacheListType::value_type(m_memoryManager)); DecimalFormatCacheListType::value_type& theEntry = theNonConstCache.front(); @@ -284,7 +308,7 @@ } } - theFormatter->applyPattern(ICUBridge::XalanDOMStringToUnicodeString(thePattern),theStatus); + theFormatter->applyPattern(ICUBridge::XalanDOMStringToUnicodeString(m_memoryManager, thePattern),theStatus); if (U_SUCCESS(theStatus)) { @@ -297,12 +321,11 @@ return U_SUCCESS(theStatus) ? true : false; } -XalanDOMString -ICUFormatNumberFunctor::UnlocalizePatternFunctor::operator()(const XalanDOMString& thePattern) const +XalanDOMString& +ICUFormatNumberFunctor::UnlocalizePatternFunctor::operator()(const XalanDOMString& thePattern, XalanDOMString& theResult) const { - XalanDOMString theResult; - XalanDecimalFormatSymbols defaultDFS; + XalanDecimalFormatSymbols defaultDFS( theResult.getMemoryManager()); XalanDOMString::const_iterator iterator = thePattern.begin(); 1.4 +88 -76 xml-xalan/c/src/xalanc/ICUBridge/ICUFormatNumberFunctor.hpp Index: ICUFormatNumberFunctor.hpp =================================================================== RCS file: /home/cvs/xml-xalan/c/src/xalanc/ICUBridge/ICUFormatNumberFunctor.hpp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- ICUFormatNumberFunctor.hpp 10 Mar 2004 20:45:30 -0000 1.3 +++ ICUFormatNumberFunctor.hpp 8 Nov 2004 18:06:19 -0000 1.4 @@ -39,20 +39,98 @@ -#include - - XALAN_CPP_NAMESPACE_BEGIN typedef StylesheetExecutionContextDefault::FormatNumberFunctor FormatNumberFunctor; + +#if defined(XALAN_HAS_CPP_NAMESPACE) + typedef U_ICU_NAMESPACE::DecimalFormat DecimalFormatType; +#else + typedef DecimalFormat DecimalFormatType; +#endif + +struct DecimalFormatCacheStruct +{ + DecimalFormatCacheStruct( + MemoryManagerType& theManager, + const XalanDecimalFormatSymbols& theDFS, + DecimalFormatType* theFormatter) : + + m_DFS(theDFS, theManager), + m_formatter(theFormatter) + { + } + + DecimalFormatCacheStruct(MemoryManagerType& theManager) : + m_DFS(theManager), + m_formatter(0) + { + } + + DecimalFormatCacheStruct(const DecimalFormatCacheStruct& other, MemoryManagerType& theManager) : + m_DFS(other.m_DFS, theManager), + m_formatter(other.m_formatter) + { + } +#if defined(XALAN_NO_SELECTIVE_TEMPLATE_INSTANTIATION) + bool + operator<(const DecimalFormatCacheStruct& theRHS) const + { + return this < &theRHS; + } + + bool + operator==(const DecimalFormatCacheStruct& theRHS) const + { + return this == &theRHS; + } +#endif + + XalanDecimalFormatSymbols m_DFS; + + DecimalFormatType * m_formatter; + + struct DecimalFormatDeleteFunctor + { + + void + operator()(DecimalFormatCacheStruct& theStruct) const + { + delete theStruct.m_formatter; + } + }; + + struct DecimalFormatFindFunctor + { + DecimalFormatFindFunctor(const XalanDecimalFormatSymbols* theDFS) : + m_DFS(theDFS) + { + } + + bool + operator()(DecimalFormatCacheStruct& theStruct) const + { + return theStruct.m_DFS == (*m_DFS); + } + + const XalanDecimalFormatSymbols * const m_DFS; + }; +}; + + +XALAN_USES_MEMORY_MANAGER(DecimalFormatCacheStruct) + // Class that implements the XSLT function format-number using the ICU. // class XALAN_ICUBRIDGE_EXPORT ICUFormatNumberFunctor : public FormatNumberFunctor { public: - ICUFormatNumberFunctor(); + ICUFormatNumberFunctor(MemoryManagerType& theManager); + + static ICUFormatNumberFunctor* + create(MemoryManagerType& theManager); virtual ~ICUFormatNumberFunctor(); @@ -67,11 +145,7 @@ const XalanNode* context = 0, const LocatorType* locator = 0) const; -#if defined(XALAN_HAS_CPP_NAMESPACE) - typedef U_ICU_NAMESPACE::DecimalFormat DecimalFormatType; -#else - typedef DecimalFormat DecimalFormatType; -#endif + class UnlocalizePatternFunctor { @@ -81,78 +155,15 @@ { } - XalanDOMString - operator()(const XalanDOMString& thePattern) const; + XalanDOMString& + operator()(const XalanDOMString& thePattern, XalanDOMString& theResult) const; private: const XalanDecimalFormatSymbols& m_DFS; }; - struct DecimalFormatCacheStruct - { - DecimalFormatCacheStruct( - const XalanDecimalFormatSymbols& theDFS, - DecimalFormatType* theFormatter): - m_DFS(theDFS), - m_formatter(theFormatter) - { - } + typedef XalanList DecimalFormatCacheListType; - DecimalFormatCacheStruct() : - m_DFS(), - m_formatter(0) - { - } - -#if defined(XALAN_NO_SELECTIVE_TEMPLATE_INSTANTIATION) - bool - operator<(const DecimalFormatCacheStruct& theRHS) const - { - return this < &theRHS; - } - - bool - operator==(const DecimalFormatCacheStruct& theRHS) const - { - return this == &theRHS; - } -#endif - - XalanDecimalFormatSymbols m_DFS; - - DecimalFormatType * m_formatter; - - struct DecimalFormatDeleteFunctor - { - void - operator()(DecimalFormatCacheStruct& theStruct) const - { - delete theStruct.m_formatter; - } - }; - - struct DecimalFormatFindFunctor - { - DecimalFormatFindFunctor(const XalanDecimalFormatSymbols* theDFS) : - m_DFS(theDFS) - { - } - - bool - operator()(DecimalFormatCacheStruct& theStruct) const - { - return theStruct.m_DFS == (*m_DFS); - } - - const XalanDecimalFormatSymbols * const m_DFS; - }; - }; - -#if defined(XALAN_NO_STD_NAMESPACE) - typedef list DecimalFormatCacheListType; -#else - typedef std::list DecimalFormatCacheListType; -#endif DecimalFormatType * getCachedDecimalFormat(const XalanDecimalFormatSymbols &theDFS) const; @@ -190,7 +201,8 @@ bool operator==(const ICUFormatNumberFunctor&) const; - +private: + mutable MemoryManagerType& m_memoryManager; }; XALAN_CPP_NAMESPACE_END 1.5 +14 -3 xml-xalan/c/src/xalanc/ICUBridge/ICUXalanNumberFormatFactory.cpp Index: ICUXalanNumberFormatFactory.cpp =================================================================== RCS file: /home/cvs/xml-xalan/c/src/xalanc/ICUBridge/ICUXalanNumberFormatFactory.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- ICUXalanNumberFormatFactory.cpp 26 Feb 2004 23:07:12 -0000 1.4 +++ ICUXalanNumberFormatFactory.cpp 8 Nov 2004 18:06:19 -0000 1.5 @@ -26,8 +26,9 @@ -ICUXalanNumberFormatFactory::ICUXalanNumberFormatFactory() : - StylesheetExecutionContextDefault::XalanNumberFormatFactory() +ICUXalanNumberFormatFactory::ICUXalanNumberFormatFactory(MemoryManagerType& theManager) : + StylesheetExecutionContextDefault::XalanNumberFormatFactory(), + m_memoryManager(theManager) { } @@ -42,7 +43,17 @@ XalanNumberFormat* ICUXalanNumberFormatFactory::create() { - return new ICUXalanNumberFormatProxy; + typedef ICUXalanNumberFormatProxy ThisType; + + XalanMemMgrAutoPtr theGuard( m_memoryManager , (ThisType*)m_memoryManager.allocate(sizeof(ThisType))); + + ThisType* theResult = theGuard.get(); + + new (theResult) ThisType(m_memoryManager); + + theGuard.release(); + + return theResult; } 1.5 +3 -1 xml-xalan/c/src/xalanc/ICUBridge/ICUXalanNumberFormatFactory.hpp Index: ICUXalanNumberFormatFactory.hpp =================================================================== RCS file: /home/cvs/xml-xalan/c/src/xalanc/ICUBridge/ICUXalanNumberFormatFactory.hpp,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- ICUXalanNumberFormatFactory.hpp 26 Feb 2004 23:07:12 -0000 1.4 +++ ICUXalanNumberFormatFactory.hpp 8 Nov 2004 18:06:19 -0000 1.5 @@ -37,13 +37,15 @@ { public: - ICUXalanNumberFormatFactory(); + ICUXalanNumberFormatFactory(MemoryManagerType& theManager); virtual ~ICUXalanNumberFormatFactory(); virtual XalanNumberFormat* create(); +private: + MemoryManagerType& m_memoryManager; }; 1.5 +26 -88 xml-xalan/c/src/xalanc/ICUBridge/ICUXalanNumberFormatProxy.cpp Index: ICUXalanNumberFormatProxy.cpp =================================================================== RCS file: /home/cvs/xml-xalan/c/src/xalanc/ICUBridge/ICUXalanNumberFormatProxy.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- ICUXalanNumberFormatProxy.cpp 26 Feb 2004 23:07:12 -0000 1.4 +++ ICUXalanNumberFormatProxy.cpp 8 Nov 2004 18:06:19 -0000 1.5 @@ -25,10 +25,11 @@ U_NAMESPACE_USE - #include +#include + #include "ICUBridge.hpp" @@ -38,150 +39,87 @@ -ICUXalanNumberFormatProxy::ICUXalanNumberFormatProxy() : - XalanNumberFormat(), +ICUXalanNumberFormatProxy::ICUXalanNumberFormatProxy(MemoryManagerType& theManager) : + XalanNumberFormat(theManager), m_decimalFormat(0) { UErrorCode theResult = U_ZERO_ERROR; - m_decimalFormat = new DecimalFormat(theResult); + new DecimalFormatType(theResult); } ICUXalanNumberFormatProxy::~ICUXalanNumberFormatProxy() { - delete m_decimalFormat; -} - + delete m_decimalFormat; - -XalanDOMString -ICUXalanNumberFormatProxy::format(double theValue) -{ - UnicodeString theUnicodeResult; - - m_decimalFormat->format(theValue, theUnicodeResult); - - return ICUBridge::UnicodeStringToXalanDOMString(theUnicodeResult); } -void -ICUXalanNumberFormatProxy::format( - double theValue, - XalanDOMString& theResult) +XalanDOMString& +ICUXalanNumberFormatProxy::format(double theValue, + XalanDOMString& theResult) { UnicodeString theUnicodeResult; m_decimalFormat->format(theValue, theUnicodeResult); - ICUBridge::UnicodeStringToXalanDOMString(theUnicodeResult, theResult); + return ICUBridge::UnicodeStringToXalanDOMString(theUnicodeResult, theResult); } -XalanDOMString -ICUXalanNumberFormatProxy::format(int theValue) +XalanDOMString& +ICUXalanNumberFormatProxy::format(int theValue, + XalanDOMString& theResult) { UnicodeString theUnicodeResult; m_decimalFormat->format(int32_t(theValue), theUnicodeResult); - return ICUBridge::UnicodeStringToXalanDOMString(theUnicodeResult); + return ICUBridge::UnicodeStringToXalanDOMString(theUnicodeResult, theResult); } -void -ICUXalanNumberFormatProxy::format( - int theValue, - XalanDOMString& theResult) -{ - UnicodeString theUnicodeResult; - - m_decimalFormat->format(int32_t(theValue), theUnicodeResult); - - ICUBridge::UnicodeStringToXalanDOMString(theUnicodeResult, theResult); -} - - -XalanDOMString -ICUXalanNumberFormatProxy::format(unsigned int theValue) +XalanDOMString& +ICUXalanNumberFormatProxy::format(unsigned int theValue, XalanDOMString& theResult) { UnicodeString theUnicodeResult; m_decimalFormat->format(int32_t(theValue), theUnicodeResult); - return ICUBridge::UnicodeStringToXalanDOMString(theUnicodeResult); + return ICUBridge::UnicodeStringToXalanDOMString(theUnicodeResult, theResult); } - -void -ICUXalanNumberFormatProxy::format( - unsigned int theValue, - XalanDOMString& theResult) +XalanDOMString& +ICUXalanNumberFormatProxy::format(long theValue, + XalanDOMString& theResult) { UnicodeString theUnicodeResult; m_decimalFormat->format(int32_t(theValue), theUnicodeResult); - ICUBridge::UnicodeStringToXalanDOMString(theUnicodeResult, theResult); + return ICUBridge::UnicodeStringToXalanDOMString(theUnicodeResult, theResult); } -XalanDOMString -ICUXalanNumberFormatProxy::format(long theValue) -{ - UnicodeString theUnicodeResult; - m_decimalFormat->format(int32_t(theValue), theUnicodeResult); - return ICUBridge::UnicodeStringToXalanDOMString(theUnicodeResult); -} - - - -void -ICUXalanNumberFormatProxy::format( - long theValue, - XalanDOMString& theResult) -{ - UnicodeString theUnicodeResult; - - m_decimalFormat->format(int32_t(theValue), theUnicodeResult); - - ICUBridge::UnicodeStringToXalanDOMString(theUnicodeResult, theResult); -} - - - -XalanDOMString -ICUXalanNumberFormatProxy::format(unsigned long theValue) -{ - UnicodeString theUnicodeResult; - - m_decimalFormat->format(int32_t(theValue), theUnicodeResult); - - return ICUBridge::UnicodeStringToXalanDOMString(theUnicodeResult); -} - - - -void -ICUXalanNumberFormatProxy::format( - unsigned long theValue, - XalanDOMString& theResult) +XalanDOMString& +ICUXalanNumberFormatProxy::format(unsigned long theValue, + XalanDOMString& theResult) { UnicodeString theUnicodeResult; m_decimalFormat->format(int32_t(theValue), theUnicodeResult); - ICUBridge::UnicodeStringToXalanDOMString(theUnicodeResult, theResult); + return ICUBridge::UnicodeStringToXalanDOMString(theUnicodeResult, theResult); } @@ -222,7 +160,7 @@ theNewSymbols->setSymbol( DecimalFormatSymbols::kGroupingSeparatorSymbol, - ICUBridge::XalanDOMStringToUnicodeString(s)); + ICUBridge::XalanDOMStringToUnicodeString(getMemoryManager(), s)); m_decimalFormat->adoptDecimalFormatSymbols(theNewSymbols); } 1.5 +18 -33 xml-xalan/c/src/xalanc/ICUBridge/ICUXalanNumberFormatProxy.hpp Index: ICUXalanNumberFormatProxy.hpp =================================================================== RCS file: /home/cvs/xml-xalan/c/src/xalanc/ICUBridge/ICUXalanNumberFormatProxy.hpp,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- ICUXalanNumberFormatProxy.hpp 26 Feb 2004 23:07:12 -0000 1.4 +++ ICUXalanNumberFormatProxy.hpp 8 Nov 2004 18:06:19 -0000 1.5 @@ -42,50 +42,32 @@ public: explicit - ICUXalanNumberFormatProxy(); + ICUXalanNumberFormatProxy(MemoryManagerType& theManager); virtual ~ICUXalanNumberFormatProxy(); - virtual XalanDOMString - format(double theValue); + virtual XalanDOMString& + format(double theValue, + XalanDOMString& theResult); - virtual void - format( - double theValue, - XalanDOMString& theResult); - virtual XalanDOMString - format(int theValue); + virtual XalanDOMString& + format(int theValue, + XalanDOMString& theResult); - virtual void - format( - int theValue, - XalanDOMString& theResult); - virtual XalanDOMString - format(unsigned int theValue); + virtual XalanDOMString& + format(unsigned int theValue, XalanDOMString& theResult); - virtual void - format( - unsigned int theValue, - XalanDOMString& theResult); - virtual XalanDOMString - format(long theValue); + virtual XalanDOMString& + format(long theValue, XalanDOMString& theResult); - virtual void - format( - long theValue, - XalanDOMString& theResult); - virtual XalanDOMString - format(unsigned long theValue); + virtual XalanDOMString& + format(unsigned long theValue, XalanDOMString& theResult); - virtual void - format( - unsigned long theValue, - XalanDOMString& theResult); virtual bool isGroupingUsed() const; @@ -102,10 +84,13 @@ private: #if defined(XALAN_HAS_CPP_NAMESPACE) - U_ICU_NAMESPACE::DecimalFormat* m_decimalFormat; + typedef U_ICU_NAMESPACE::DecimalFormat DecimalFormatType; #else - DecimalFormat* m_decimalFormat; + typedef DecimalFormat* DecimalFormatType; #endif + + DecimalFormatType* m_decimalFormat; + }; --------------------------------------------------------------------- To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org For additional commands, e-mail: xalan-cvs-help@xml.apache.org