Xalan-C++ API Reference 1.12.0
ICUFormatNumberFunctor.hpp
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18#if !defined(FUNCTIONICUFORMATNUMBERFUNCTOR_HEADER_GUARD_1357924680)
19#define FUNCTIONICUFORMATNUMBERFUNCTOR_HEADER_GUARD_1357924680
20
21
22
23// Base header file. Must be first.
25
26
27
29
30
31
33
34
35
37
38
39
41
42
43
44#include <unicode/decimfmt.h>
45
46
47
48
49namespace XALAN_CPP_NAMESPACE {
50
52
53 typedef U_ICU_NAMESPACE::DecimalFormat DecimalFormatType;
54
56{
58 MemoryManager& theManager,
59 const XalanDecimalFormatSymbols& theDFS,
60 DecimalFormatType* theFormatter) :
61
62 m_DFS(theDFS, theManager),
63 m_formatter(theFormatter)
64 {
65 }
66
67 DecimalFormatCacheStruct(MemoryManager& theManager) :
68 m_DFS(theManager),
69 m_formatter(0)
70 {
71 }
72
74 const DecimalFormatCacheStruct& other,
75 MemoryManager& theManager) :
76 m_DFS(other.m_DFS, theManager),
77 m_formatter(other.m_formatter)
78 {
79 }
80
81#if defined(XALAN_NO_SELECTIVE_TEMPLATE_INSTANTIATION)
82 bool
83 operator<(const DecimalFormatCacheStruct& theRHS) const
84 {
85 return this < &theRHS;
86 }
87
88 bool
89 operator==(const DecimalFormatCacheStruct& theRHS) const
90 {
91 return this == &theRHS;
92 }
93#endif
94
96
98
100 {
101 public:
102
103 DecimalFormatDeleteFunctor(MemoryManager& theManager) :
104 m_memoryManager(theManager)
105 {
106 }
107
108 void
110 {
111 assert(theStruct.m_formatter != 0);
112
114 m_memoryManager,
115 *theStruct.m_formatter);
116 }
117
118 private:
119
120 // Not implemented...
122 operator=(const DecimalFormatDeleteFunctor&);
123
124 // Data members.
125 MemoryManager& m_memoryManager;
126 };
127
129 {
131 m_DFS(theDFS)
132 {
133 }
134
135 bool
137 {
138 return theStruct.m_DFS == (*m_DFS);
139 }
140
142 };
143
144private:
145
148};
149
150
152
153// Class that implements the XSLT function format-number using the ICU.
154//
156{
157public:
158
159 ICUFormatNumberFunctor(MemoryManager& theManager);
160
162 create(MemoryManager& theManager);
163
164 virtual
166
167 virtual void
168 operator() (
169 XPathExecutionContext& executionContext,
170 double theNumber,
171 const XalanDOMString& thePattern,
172 const XalanDecimalFormatSymbols* theDFS,
173 XalanDOMString& theResult,
174 const XalanNode* context = 0,
175 const Locator* locator = 0) const;
176
177
179 {
180 public:
182 m_DFS(theDFS)
183 {
184 }
185
188 const XalanDOMString& thePattern,
189 XalanDOMString& theResult,
190 MemoryManager& theManager) const;
191
192 private:
193
194 const XalanDecimalFormatSymbols& m_DFS;
195 };
196
198
199private:
200
202 getCachedDecimalFormat(const XalanDecimalFormatSymbols &theDFS) const;
203
204 bool
205 doFormat(
206 double theNumber,
207 const XalanDOMString& thePattern,
208 XalanDOMString& theResult,
209 const XalanDecimalFormatSymbols* theDFS = 0) const;
210
211 bool
212 doICUFormat(
213 double theNumber,
214 const XalanDOMString& thePattern,
215 XalanDOMString& theResult,
216 DecimalFormatType* theFormatter = 0) const;
217
218 void
219 cacheDecimalFormat(
220 DecimalFormatType* theFormatter,
221 const XalanDecimalFormatSymbols& theDFS) const;
222
223 static DecimalFormatType*
224 createDecimalFormat(
225 const XalanDecimalFormatSymbols& theXalanDFS,
226 MemoryManager& theManager);
227
228 static DecimalFormatType*
229 createDecimalFormat(MemoryManager& theManager)
230 {
231 const XalanDecimalFormatSymbols theDFS(theManager);
232
233 return createDecimalFormat(theDFS, theManager);
234 }
235
236 enum { eCacheMax = 10u };
237
238private:
239
240 // These are not implemented...
241 ICUFormatNumberFunctor&
242 operator=(const ICUFormatNumberFunctor&);
243
244 bool
245 operator==(const ICUFormatNumberFunctor&) const;
246
247 typedef XalanMemMgrAutoPtr<DecimalFormatType> DFAutoPtrType;
248
249 // Data members...
250 mutable DecimalFormatCacheListType m_decimalFormatCache;
251
252 const DFAutoPtrType m_defaultDecimalFormat;
253
254 MemoryManager& m_memoryManager;
255};
256
257
258
259}
260
261
262
263#endif // FUNCTIONICUFORMATNUMBERFUNCTOR_HEADER_GUARD_1357924680
#define XALAN_ICUBRIDGE_EXPORT
#define XALAN_USES_MEMORY_MANAGER(Type)
#define XALAN_CPP_NAMESPACE
Xalan-C++ namespace, including major and minor version.
void operator()(DecimalFormatCacheStruct &theStruct) const
UnlocalizePatternFunctor(const XalanDecimalFormatSymbols &theDFS)
XalanDOMString & operator()(const XalanDOMString &thePattern, XalanDOMString &theResult, MemoryManager &theManager) const
ICUFormatNumberFunctor(MemoryManager &theManager)
XalanList< DecimalFormatCacheStruct > DecimalFormatCacheListType
static ICUFormatNumberFunctor * create(MemoryManager &theManager)
Xalan implementation of a doubly linked list.
U_ICU_NAMESPACE::DecimalFormat DecimalFormatType
bool operator<(const XalanVector< Type > &theLHS, const XalanVector< Type > &theRHS)
void XalanDestroy(Type &theArg)
DecimalFormatFindFunctor(const XalanDecimalFormatSymbols *theDFS)
bool operator()(DecimalFormatCacheStruct &theStruct) const
DecimalFormatCacheStruct(MemoryManager &theManager)
DecimalFormatCacheStruct(MemoryManager &theManager, const XalanDecimalFormatSymbols &theDFS, DecimalFormatType *theFormatter)
DecimalFormatCacheStruct(const DecimalFormatCacheStruct &other, MemoryManager &theManager)