Xalan-C++ API Documentation

The Xalan C++ XSLT Processor Version 1.9

Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

ICUFormatNumberFunctor.hpp

Go to the documentation of this file.
00001 /*
00002  * Copyright 1999-2004 The Apache Software Foundation.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 #if !defined(FUNCTIONICUFORMATNUMBERFUNCTOR_HEADER_GUARD_1357924680)
00017 #define FUNCTIONICUFORMATNUMBERFUNCTOR_HEADER_GUARD_1357924680
00018 
00019 
00020 
00021 // Base header file.  Must be first.
00022 #include <xalanc/ICUBridge/ICUBridgeDefinitions.hpp>
00023 
00024 
00025 
00026 #include <xalanc/PlatformSupport/XalanDecimalFormatSymbols.hpp>
00027 
00028 
00029 
00030 #include <xalanc/XSLT/StylesheetExecutionContextDefault.hpp>
00031 
00032 
00033 
00034 #include <xalanc/XPath/XPathExecutionContext.hpp>
00035 
00036 
00037 
00038 #include <unicode/decimfmt.h>
00039 
00040 
00041 
00042 
00043 XALAN_CPP_NAMESPACE_BEGIN
00044 
00045 typedef StylesheetExecutionContextDefault::FormatNumberFunctor FormatNumberFunctor;
00046 
00047 #if defined(XALAN_HAS_CPP_NAMESPACE)
00048     typedef U_ICU_NAMESPACE::DecimalFormat  DecimalFormatType;
00049 #else
00050     typedef DecimalFormat                   DecimalFormatType;
00051 #endif
00052 
00053 struct DecimalFormatCacheStruct
00054 {
00055     DecimalFormatCacheStruct(
00056         MemoryManagerType&                  theManager,
00057         const XalanDecimalFormatSymbols&    theDFS,
00058         DecimalFormatType*                  theFormatter) :
00059 
00060         m_DFS(theDFS, theManager),
00061         m_formatter(theFormatter)
00062     {
00063     }
00064 
00065     DecimalFormatCacheStruct(MemoryManagerType& theManager) :
00066     m_DFS(theManager),
00067         m_formatter(0)
00068     {
00069     }
00070 
00071     DecimalFormatCacheStruct(const DecimalFormatCacheStruct& other, MemoryManagerType& theManager) :
00072     m_DFS(other.m_DFS, theManager),
00073         m_formatter(other.m_formatter)
00074     {
00075     }
00076 #if defined(XALAN_NO_SELECTIVE_TEMPLATE_INSTANTIATION)
00077     bool
00078         operator<(const DecimalFormatCacheStruct&  theRHS) const
00079     {
00080         return this < &theRHS;
00081     }
00082 
00083     bool
00084         operator==(const DecimalFormatCacheStruct&  theRHS) const
00085     {
00086         return this == &theRHS;
00087     }
00088 #endif
00089 
00090     XalanDecimalFormatSymbols   m_DFS;
00091 
00092     DecimalFormatType * m_formatter;
00093 
00094     struct DecimalFormatDeleteFunctor
00095     {
00096 
00097         void
00098             operator()(DecimalFormatCacheStruct&    theStruct) const
00099         {
00100             delete theStruct.m_formatter;
00101         }
00102     };
00103 
00104     struct DecimalFormatFindFunctor
00105     {
00106         DecimalFormatFindFunctor(const XalanDecimalFormatSymbols*   theDFS) :
00107             m_DFS(theDFS)
00108             {
00109             }
00110 
00111         bool
00112         operator()(DecimalFormatCacheStruct&    theStruct) const
00113         {
00114             return theStruct.m_DFS == (*m_DFS);
00115         }
00116 
00117         const XalanDecimalFormatSymbols * const m_DFS;
00118     };
00119 
00120 private:
00121 
00122     DecimalFormatCacheStruct();
00123     DecimalFormatCacheStruct(const DecimalFormatCacheStruct& other);
00124     
00125 };
00126 
00127 
00128 XALAN_USES_MEMORY_MANAGER(DecimalFormatCacheStruct)
00129 
00130 // Class that implements the XSLT function format-number using the ICU.
00131 //
00132 class XALAN_ICUBRIDGE_EXPORT ICUFormatNumberFunctor : public FormatNumberFunctor
00133 {
00134 public:
00135 
00136     ICUFormatNumberFunctor(MemoryManagerType& theManager);
00137 
00138     static ICUFormatNumberFunctor*
00139     create(MemoryManagerType& theManager);
00140 
00141     virtual
00142     ~ICUFormatNumberFunctor();
00143 
00144     virtual void
00145         operator() (
00146         XPathExecutionContext&              executionContext,
00147         double                              theNumber,
00148         const XalanDOMString&               thePattern,
00149         const XalanDecimalFormatSymbols*    theDFS,
00150         XalanDOMString&                     theResult,
00151         const XalanNode*                    context = 0,
00152         const LocatorType*                  locator = 0) const;
00153     
00154 
00155 
00156     class UnlocalizePatternFunctor
00157     {
00158     public:
00159         UnlocalizePatternFunctor(const XalanDecimalFormatSymbols&   theDFS):
00160             m_DFS(theDFS)
00161         {
00162         }
00163 
00164         XalanDOMString&
00165         operator()(const XalanDOMString&    thePattern, XalanDOMString& theResult) const;
00166 
00167     private:
00168         const XalanDecimalFormatSymbols& m_DFS;
00169     };
00170 
00171     typedef XalanList<DecimalFormatCacheStruct>         DecimalFormatCacheListType;
00172 
00173 
00174     DecimalFormatType * getCachedDecimalFormat(const XalanDecimalFormatSymbols &theDFS) const;
00175 
00176     bool
00177     doFormat(   
00178         double                              theNumber,
00179         const XalanDOMString&               thePattern,
00180         XalanDOMString&                     theResult,
00181         const XalanDecimalFormatSymbols*    theDFS = 0) const;
00182 
00183     bool
00184     doICUFormat(
00185         double                              theNumber,
00186         const XalanDOMString&               thePattern,
00187         XalanDOMString&                     theResult,
00188         DecimalFormatType*                  theFormatter = 0) const;
00189 
00190     void
00191     cacheDecimalFormat(
00192         DecimalFormatType*                  theFormatter,
00193         const XalanDecimalFormatSymbols&    theDFS) const;
00194 
00195     DecimalFormat *
00196     createDecimalFormat(
00197         const XalanDecimalFormatSymbols&    theXalanDFS) const;
00198 
00199     enum { eCacheMax = 10 };
00200 
00201     DecimalFormatType * m_defaultDecimalFormat;
00202     
00203     mutable DecimalFormatCacheListType m_decimalFormatCache;
00204 
00205     ICUFormatNumberFunctor&
00206     operator=(const ICUFormatNumberFunctor&);
00207 
00208     bool
00209     operator==(const ICUFormatNumberFunctor&) const;
00210 private:
00211              MemoryManagerType& m_memoryManager;
00212 };
00213 
00214 XALAN_CPP_NAMESPACE_END
00215 
00216 #endif  // FUNCTIONICUFORMATNUMBERFUNCTOR_HEADER_GUARD_1357924680

Interpreting class diagrams

Doxygen and GraphViz are used to generate this API documentation from the Xalan-C header files.

Xalan-C++ XSLT Processor Version 1.9
Copyright © 1999-2004 The Apache Software Foundation. All Rights Reserved.