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 
49 namespace 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 
113  XalanDestroy(
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 
144 private:
145 
148 };
149 
150 
152 
153 // Class that implements the XSLT function format-number using the ICU.
154 //
156 {
157 public:
158 
159  ICUFormatNumberFunctor(MemoryManager& theManager);
160 
161  static ICUFormatNumberFunctor*
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 
187  operator()(
188  const XalanDOMString& thePattern,
189  XalanDOMString& theResult,
190  MemoryManager& theManager) const;
191 
192  private:
193 
194  const XalanDecimalFormatSymbols& m_DFS;
195  };
196 
198 
199 private:
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 
238 private:
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
xalanc::DecimalFormatCacheStruct::DecimalFormatFindFunctor::DecimalFormatFindFunctor
DecimalFormatFindFunctor(const XalanDecimalFormatSymbols *theDFS)
Definition: ICUFormatNumberFunctor.hpp:130
XALAN_CPP_NAMESPACE
#define XALAN_CPP_NAMESPACE
Xalan-C++ namespace, including major and minor version.
Definition: XalanVersion.hpp:76
xalanc::XalanNode
Definition: XalanNode.hpp:38
xalanc::DecimalFormatCacheStruct::m_formatter
DecimalFormatType * m_formatter
Definition: ICUFormatNumberFunctor.hpp:97
xalanc::DecimalFormatCacheStruct::DecimalFormatDeleteFunctor
Definition: ICUFormatNumberFunctor.hpp:99
xalanc::DecimalFormatCacheStruct::DecimalFormatCacheStruct
DecimalFormatCacheStruct(const DecimalFormatCacheStruct &other, MemoryManager &theManager)
Definition: ICUFormatNumberFunctor.hpp:73
XALAN_USES_MEMORY_MANAGER
#define XALAN_USES_MEMORY_MANAGER(Type)
Definition: XalanMemoryManagement.hpp:589
xalanc::XalanDecimalFormatSymbols
Definition: XalanDecimalFormatSymbols.hpp:40
xalanc::ICUFormatNumberFunctor::UnlocalizePatternFunctor
Definition: ICUFormatNumberFunctor.hpp:178
xalanc::operator<
bool operator<(const XalanVector< Type > &theLHS, const XalanVector< Type > &theRHS)
Definition: XalanVector.hpp:1151
xalanc::DecimalFormatCacheStruct::DecimalFormatDeleteFunctor::operator()
void operator()(DecimalFormatCacheStruct &theStruct) const
Definition: ICUFormatNumberFunctor.hpp:109
xalanc::operator==
bool operator==(const XalanVector< Type > &theLHS, const XalanVector< Type > &theRHS)
Definition: XalanVector.hpp:1118
xalanc::DecimalFormatCacheStruct::DecimalFormatFindFunctor
Definition: ICUFormatNumberFunctor.hpp:128
XALAN_ICUBRIDGE_EXPORT
#define XALAN_ICUBRIDGE_EXPORT
Definition: ICUBridgeDefinitions.hpp:35
xalanc::DecimalFormatCacheStruct::m_DFS
XalanDecimalFormatSymbols m_DFS
Definition: ICUFormatNumberFunctor.hpp:95
xalanc::DecimalFormatCacheStruct
Definition: ICUFormatNumberFunctor.hpp:55
XalanDecimalFormatSymbols.hpp
xalanc::ICUFormatNumberFunctor
Definition: ICUFormatNumberFunctor.hpp:155
xalanc::DecimalFormatCacheStruct::DecimalFormatFindFunctor::m_DFS
const XalanDecimalFormatSymbols *const m_DFS
Definition: ICUFormatNumberFunctor.hpp:141
StylesheetExecutionContextDefault.hpp
XPathExecutionContext.hpp
xalanc::StylesheetExecutionContextDefault::FormatNumberFunctor
Definition: StylesheetExecutionContextDefault.hpp:703
xalanc::DecimalFormatCacheStruct::DecimalFormatCacheStruct
DecimalFormatCacheStruct(MemoryManager &theManager)
Definition: ICUFormatNumberFunctor.hpp:67
xalanc::FormatNumberFunctor
StylesheetExecutionContextDefault::FormatNumberFunctor FormatNumberFunctor
Definition: ICUFormatNumberFunctor.hpp:51
xalanc::DecimalFormatCacheStruct::DecimalFormatCacheStruct
DecimalFormatCacheStruct(MemoryManager &theManager, const XalanDecimalFormatSymbols &theDFS, DecimalFormatType *theFormatter)
Definition: ICUFormatNumberFunctor.hpp:57
xalanc::ICUFormatNumberFunctor::DecimalFormatCacheListType
XalanList< DecimalFormatCacheStruct > DecimalFormatCacheListType
Definition: ICUFormatNumberFunctor.hpp:197
xalanc::XPathExecutionContext
Definition: XPathExecutionContext.hpp:82
xalanc::XalanDestroy
void XalanDestroy(Type &theArg)
Definition: XalanMemoryManagement.hpp:150
ICUBridgeDefinitions.hpp
xalanc::XalanDOMString
Definition: XalanDOMString.hpp:45
xalanc::DecimalFormatCacheStruct::DecimalFormatDeleteFunctor::DecimalFormatDeleteFunctor
DecimalFormatDeleteFunctor(MemoryManager &theManager)
Definition: ICUFormatNumberFunctor.hpp:103
xalanc::DecimalFormatType
U_ICU_NAMESPACE::DecimalFormat DecimalFormatType
Definition: ICUFormatNumberFunctor.hpp:53
xalanc::DecimalFormatCacheStruct::DecimalFormatFindFunctor::operator()
bool operator()(DecimalFormatCacheStruct &theStruct) const
Definition: ICUFormatNumberFunctor.hpp:136
xalanc::XalanList< DecimalFormatCacheStruct >
xalanc::ICUFormatNumberFunctor::UnlocalizePatternFunctor::UnlocalizePatternFunctor
UnlocalizePatternFunctor(const XalanDecimalFormatSymbols &theDFS)
Definition: ICUFormatNumberFunctor.hpp:181
XalanMemMgrAutoPtr.hpp