Xalan-C++ API Documentation

The Xalan C++ XSLT Processor Version 1.10

Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

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/Include/XalanMemMgrAutoPtr.hpp>
00027 
00028 
00029 
00030 #include <xalanc/PlatformSupport/XalanDecimalFormatSymbols.hpp>
00031 
00032 
00033 
00034 #include <xalanc/XSLT/StylesheetExecutionContextDefault.hpp>
00035 
00036 
00037 
00038 #include <xalanc/XPath/XPathExecutionContext.hpp>
00039 
00040 
00041 
00042 #include <unicode/decimfmt.h>
00043 
00044 
00045 
00046 
00047 XALAN_CPP_NAMESPACE_BEGIN
00048 
00049 typedef StylesheetExecutionContextDefault::FormatNumberFunctor FormatNumberFunctor;
00050 
00051 #if defined(XALAN_HAS_CPP_NAMESPACE)
00052     typedef U_ICU_NAMESPACE::DecimalFormat  DecimalFormatType;
00053 #else
00054     typedef DecimalFormat                   DecimalFormatType;
00055 #endif
00056 
00057 struct DecimalFormatCacheStruct
00058 {
00059     DecimalFormatCacheStruct(
00060         MemoryManagerType&                  theManager,
00061         const XalanDecimalFormatSymbols&    theDFS,
00062         DecimalFormatType*                  theFormatter) :
00063 
00064         m_DFS(theDFS, theManager),
00065         m_formatter(theFormatter)
00066     {
00067     }
00068 
00069     DecimalFormatCacheStruct(MemoryManagerType&     theManager) :
00070         m_DFS(theManager),
00071         m_formatter(0)
00072     {
00073     }
00074 
00075     DecimalFormatCacheStruct(
00076                 const DecimalFormatCacheStruct&     other,
00077                 MemoryManagerType&                  theManager) :
00078         m_DFS(other.m_DFS, theManager),
00079         m_formatter(other.m_formatter)
00080     {
00081     }
00082 
00083 #if defined(XALAN_NO_SELECTIVE_TEMPLATE_INSTANTIATION)
00084     bool
00085     operator<(const DecimalFormatCacheStruct&  theRHS) const
00086     {
00087         return this < &theRHS;
00088     }
00089 
00090     bool
00091     operator==(const DecimalFormatCacheStruct&  theRHS) const
00092     {
00093         return this == &theRHS;
00094     }
00095 #endif
00096 
00097     XalanDecimalFormatSymbols   m_DFS;
00098 
00099     DecimalFormatType * m_formatter;
00100 
00101     class DecimalFormatDeleteFunctor
00102     {
00103     public:
00104 
00105         DecimalFormatDeleteFunctor(MemoryManager&   theManager) :
00106             m_memoryManager(theManager)
00107         {
00108         }
00109 
00110         void
00111         operator()(DecimalFormatCacheStruct&    theStruct) const
00112         {
00113             assert(theStruct.m_formatter != 0);
00114 
00115             XalanDestroy(
00116                 m_memoryManager,
00117                 *theStruct.m_formatter);
00118         }
00119 
00120     private:
00121 
00122         // Not implemented...
00123         DecimalFormatDeleteFunctor&
00124         operator=(const DecimalFormatDeleteFunctor&);
00125 
00126         // Data members.
00127         MemoryManager&  m_memoryManager;
00128     };
00129 
00130     struct DecimalFormatFindFunctor
00131     {
00132         DecimalFormatFindFunctor(const XalanDecimalFormatSymbols*   theDFS) :
00133             m_DFS(theDFS)
00134             {
00135             }
00136 
00137         bool
00138         operator()(DecimalFormatCacheStruct&    theStruct) const
00139         {
00140             return theStruct.m_DFS == (*m_DFS);
00141         }
00142 
00143         const XalanDecimalFormatSymbols * const m_DFS;
00144     };
00145 
00146 private:
00147 
00148     DecimalFormatCacheStruct();
00149     DecimalFormatCacheStruct(const DecimalFormatCacheStruct& other);
00150 };
00151 
00152 
00153 XALAN_USES_MEMORY_MANAGER(DecimalFormatCacheStruct)
00154 
00155 // Class that implements the XSLT function format-number using the ICU.
00156 //
00157 class XALAN_ICUBRIDGE_EXPORT ICUFormatNumberFunctor : public FormatNumberFunctor
00158 {
00159 public:
00160 
00161     ICUFormatNumberFunctor(MemoryManagerType& theManager);
00162 
00163     static ICUFormatNumberFunctor*
00164     create(MemoryManagerType& theManager);
00165 
00166     virtual
00167     ~ICUFormatNumberFunctor();
00168 
00169     virtual void
00170     operator() (
00171         XPathExecutionContext&              executionContext,
00172         double                              theNumber,
00173         const XalanDOMString&               thePattern,
00174         const XalanDecimalFormatSymbols*    theDFS,
00175         XalanDOMString&                     theResult,
00176         const XalanNode*                    context = 0,
00177         const LocatorType*                  locator = 0) const;
00178     
00179 
00180     class UnlocalizePatternFunctor
00181     {
00182     public:
00183         UnlocalizePatternFunctor(const XalanDecimalFormatSymbols&   theDFS):
00184             m_DFS(theDFS)
00185         {
00186         }
00187 
00188         XalanDOMString&
00189         operator()(
00190                 const XalanDOMString&   thePattern,
00191                 XalanDOMString&         theResult,
00192                 MemoryManager&          theManager) const;
00193 
00194     private:
00195 
00196         const XalanDecimalFormatSymbols&    m_DFS;
00197     };
00198 
00199     typedef XalanList<DecimalFormatCacheStruct>         DecimalFormatCacheListType;
00200 
00201 private:
00202 
00203     DecimalFormatType*
00204     getCachedDecimalFormat(const XalanDecimalFormatSymbols &theDFS) const;
00205 
00206     bool
00207     doFormat(   
00208         double                              theNumber,
00209         const XalanDOMString&               thePattern,
00210         XalanDOMString&                     theResult,
00211         const XalanDecimalFormatSymbols*    theDFS = 0) const;
00212 
00213     bool
00214     doICUFormat(
00215         double                              theNumber,
00216         const XalanDOMString&               thePattern,
00217         XalanDOMString&                     theResult,
00218         DecimalFormatType*                  theFormatter = 0) const;
00219 
00220     void
00221     cacheDecimalFormat(
00222         DecimalFormatType*                  theFormatter,
00223         const XalanDecimalFormatSymbols&    theDFS) const;
00224 
00225     static DecimalFormat*
00226     createDecimalFormat(
00227         const XalanDecimalFormatSymbols&    theXalanDFS,
00228         MemoryManager&                      theManager);
00229 
00230     static DecimalFormat*
00231     createDecimalFormat(MemoryManager&  theManager)
00232     {
00233         const XalanDecimalFormatSymbols     theDFS(theManager);
00234 
00235         return createDecimalFormat(theDFS, theManager);
00236     }
00237 
00238     enum { eCacheMax = 10u };
00239 
00240 private:
00241 
00242     // These are not implemented...
00243     ICUFormatNumberFunctor&
00244     operator=(const ICUFormatNumberFunctor&);
00245 
00246     bool
00247     operator==(const ICUFormatNumberFunctor&) const;
00248 
00249     typedef XalanMemMgrAutoPtr<DecimalFormatType>   DFAutoPtrType;
00250 
00251     // Data members...
00252     mutable DecimalFormatCacheListType  m_decimalFormatCache;
00253 
00254     const DFAutoPtrType                 m_defaultDecimalFormat;
00255 
00256     MemoryManagerType&                  m_memoryManager;
00257 };
00258 
00259 
00260 
00261 XALAN_CPP_NAMESPACE_END
00262 
00263 
00264 
00265 #endif  // FUNCTIONICUFORMATNUMBERFUNCTOR_HEADER_GUARD_1357924680

Interpreting class diagrams

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

dot

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

Apache Logo