Xalan-C++ API Reference 1.12.0
ICUBridgeCollationCompareFunctorImpl.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
19#if !defined(ICUBRIDGE_COLLATIONCOMPAREFUNCTORIMPL_GUARD_1357924680)
20#define ICUBRIDGE_COLLATIONCOMPAREFUNCTORIMPL_GUARD_1357924680
21
22
23
25
26
27
29
30
31
33
34
35
36#include <unicode/coll.h>
37
38
39
40
41namespace XALAN_CPP_NAMESPACE {
42
43
44typedef U_ICU_NAMESPACE::Collator CollatorType;
45
47{
49 MemoryManager& theManager,
50 const XalanDOMString& theLocale,
51 CollatorType* theCollator) :
52 m_locale(theLocale, theManager),
53 m_collator(theCollator)
54 {
55 }
56
57 CollationCacheStruct(MemoryManager& theManager) :
58 m_locale(theManager),
59 m_collator(0)
60 {
61 }
62
64 MemoryManager& theManager) :
65 m_locale(other.m_locale,theManager),
66 m_collator(other.m_collator)
67 {
68 }
69 void
71 {
72 m_locale.swap(theOther.m_locale);
73
74 CollatorType* const theTemp = m_collator;
75
76 m_collator = theOther.m_collator;
77
78 theOther.m_collator = theTemp;
79 }
80
81#if defined(XALAN_NO_SELECTIVE_TEMPLATE_INSTANTIATION)
82 bool
83 operator<(const CollationCacheStruct& theRHS) const
84 {
85 return this < &theRHS;
86 }
87
88 bool
89 operator==(const CollationCacheStruct& theRHS) const
90 {
91 return this == &theRHS;
92 }
93#endif
94
96
98
100 {
101 CollatorDeleteFunctor(MemoryManager& theManager):
102 m_memoryManager(theManager)
103 {
104 }
105
106 void
108 {
109 delete theStruct.m_collator;
110 }
111 private:
112 MemoryManager& m_memoryManager;
113 };
114
116 {
117 CollatorFindFunctor(const XalanDOMChar* theLocale) :
118 m_locale(theLocale)
119 {
120 }
121
122 bool
124 {
125 return XalanDOMString::equals(theStruct.m_locale ,m_locale);
126 }
127
128 const XalanDOMChar* const m_locale;
129 };
130};
131
133
135{
136public:
137
138 /**
139 * Constructor.
140 *
141 * @param fCacheCollators If true, the instance will cache collators. This is not thread-safe, so each thread must have its own instance.
142 */
143 ICUBridgeCollationCompareFunctorImpl( MemoryManager& theManager ,
144 bool fCacheCollators = false);
145
147 create( MemoryManager& theManager,
148 bool fCacheCollators = false);
149
150
152
153 MemoryManager&
155 {
156 return m_collatorCache.getMemoryManager();
157 }
158
159 int
161 const XalanDOMChar* theLHS,
162 const XalanDOMChar* theRHS,
163 XalanCollationServices::eCaseOrder theCaseOrder = XalanCollationServices::eDefault) const;
164
165 int
167 const XalanDOMChar* theLHS,
168 const XalanDOMChar* theRHS,
169 const XalanDOMChar* theLocale,
170 XalanCollationServices::eCaseOrder theCaseOrder = XalanCollationServices::eDefault) const;
171
172 bool
173 isValid() const
174 {
175 return m_isValid;
176 }
177
178
180
181 enum { eCacheMax = 10 };
182
183private:
184
185 int
186 doDefaultCompare(
187 const XalanDOMChar* theLHS,
188 const XalanDOMChar* theRHS) const;
189
190 int
191 doCompare(
192 const XalanDOMChar* theLHS,
193 const XalanDOMChar* theRHS,
194 const XalanDOMChar* theLocale,
195 XalanCollationServices::eCaseOrder theCaseOrder) const;
196
197 int
198 doCompareCached(
199 const XalanDOMChar* theLHS,
200 const XalanDOMChar* theRHS,
201 const XalanDOMChar* theLocale,
202 XalanCollationServices::eCaseOrder theCaseOrder) const;
203
204 int
205 doCompare(
206 const CollatorType& theCollator,
207 const XalanDOMChar* theLHS,
208 const XalanDOMChar* theRHS) const;
209
210 int
211 doCompare(
212 CollatorType& theCollator,
213 const XalanDOMChar* theLHS,
214 const XalanDOMChar* theRHS,
215 XalanCollationServices::eCaseOrder theCaseOrder) const;
216
218 getCachedCollator(const XalanDOMChar* theLocale) const;
219
220 void
221 cacheCollator(
222 CollatorType* theCollator,
223 const XalanDOMChar* theLocale) const;
224
225
226 // Data members...
227 bool m_isValid;
228
229 CollatorType* m_defaultCollator;
230
231 XalanDOMString m_defaultCollatorLocaleName;
232
233 bool m_cacheCollators;
234
235 mutable CollatorCacheListType m_collatorCache;
236
238};
239
240
241
242}
243
244
245
246#endif // ICUBRIDGE_COLLATIONCOMPAREFUNCTORIMPL_GUARD_1357924680
#define XALAN_ICUBRIDGE_EXPORT
#define XALAN_USES_MEMORY_MANAGER(Type)
#define XALAN_CPP_NAMESPACE
Xalan-C++ namespace, including major and minor version.
ICUBridgeCollationCompareFunctorImpl(MemoryManager &theManager, bool fCacheCollators=false)
Constructor.
static ICUBridgeCollationCompareFunctorImpl * create(MemoryManager &theManager, bool fCacheCollators=false)
int operator()(const XalanDOMChar *theLHS, const XalanDOMChar *theRHS, XalanCollationServices::eCaseOrder theCaseOrder=XalanCollationServices::eDefault) const
int operator()(const XalanDOMChar *theLHS, const XalanDOMChar *theRHS, const XalanDOMChar *theLocale, XalanCollationServices::eCaseOrder theCaseOrder=XalanCollationServices::eDefault) const
Xalan implementation of a doubly linked list.
bool operator<(const XalanVector< Type > &theLHS, const XalanVector< Type > &theRHS)
U_ICU_NAMESPACE::Collator CollatorType
void swap(CollationCacheStruct &theOther)
CollationCacheStruct(const CollationCacheStruct &other, MemoryManager &theManager)
CollationCacheStruct(MemoryManager &theManager, const XalanDOMString &theLocale, CollatorType *theCollator)