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