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 
41 namespace XALAN_CPP_NAMESPACE {
42 
43 
44 typedef 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 {
136 public:
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
160  operator()(
161  const XalanDOMChar* theLHS,
162  const XalanDOMChar* theRHS,
163  XalanCollationServices::eCaseOrder theCaseOrder = XalanCollationServices::eDefault) const;
164 
165  int
166  operator()(
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 
183 private:
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 
217  CollatorType*
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
xalanc::CollationCacheStruct::swap
void swap(CollationCacheStruct &theOther)
Definition: ICUBridgeCollationCompareFunctorImpl.hpp:70
xalanc::CollationCacheStruct::CollatorFindFunctor
Definition: ICUBridgeCollationCompareFunctorImpl.hpp:115
XALAN_CPP_NAMESPACE
#define XALAN_CPP_NAMESPACE
Xalan-C++ namespace, including major and minor version.
Definition: XalanVersion.hpp:76
xalanc::CollatorType
U_ICU_NAMESPACE::Collator CollatorType
Definition: ICUBridgeCollationCompareFunctorImpl.hpp:44
XALAN_USES_MEMORY_MANAGER
#define XALAN_USES_MEMORY_MANAGER(Type)
Definition: XalanMemoryManagement.hpp:589
xalanc::CollationCacheStruct::CollatorFindFunctor::operator()
bool operator()(CollationCacheStruct &theStruct) const
Definition: ICUBridgeCollationCompareFunctorImpl.hpp:123
xalanc::operator<
bool operator<(const XalanVector< Type > &theLHS, const XalanVector< Type > &theRHS)
Definition: XalanVector.hpp:1151
XalanList.hpp
xalanc::ICUBridgeCollationCompareFunctorImpl::getMemoryManager
MemoryManager & getMemoryManager() const
Definition: ICUBridgeCollationCompareFunctorImpl.hpp:154
xalanc::equals
equals(const XalanDOMChar *theLHS, const XalanDOMChar *theRHS, XalanDOMString::size_type theLength)
Compare the contents of two arrays for equality.
xalanc::operator==
bool operator==(const XalanVector< Type > &theLHS, const XalanVector< Type > &theRHS)
Definition: XalanVector.hpp:1118
xalanc::ICUBridgeCollationCompareFunctorImpl::isValid
bool isValid() const
Definition: ICUBridgeCollationCompareFunctorImpl.hpp:173
xalanc::CollationCacheStruct::CollationCacheStruct
CollationCacheStruct(const CollationCacheStruct &other, MemoryManager &theManager)
Definition: ICUBridgeCollationCompareFunctorImpl.hpp:63
xalanc::CollationCacheStruct::CollationCacheStruct
CollationCacheStruct(MemoryManager &theManager)
Definition: ICUBridgeCollationCompareFunctorImpl.hpp:57
xalanc::CollationCacheStruct::CollationCacheStruct
CollationCacheStruct(MemoryManager &theManager, const XalanDOMString &theLocale, CollatorType *theCollator)
Definition: ICUBridgeCollationCompareFunctorImpl.hpp:48
xalanc::XalanCollationServices::eCaseOrder
eCaseOrder
Definition: XalanCollationServices.hpp:40
XALAN_ICUBRIDGE_EXPORT
#define XALAN_ICUBRIDGE_EXPORT
Definition: ICUBridgeDefinitions.hpp:35
xalanc::CollationCacheStruct::CollatorFindFunctor::m_locale
const XalanDOMChar *const m_locale
Definition: ICUBridgeCollationCompareFunctorImpl.hpp:128
xalanc::StylesheetExecutionContextDefault::DefaultCollationCompareFunctor
Definition: StylesheetExecutionContextDefault.hpp:672
xalanc::CollationCacheStruct::CollatorFindFunctor::CollatorFindFunctor
CollatorFindFunctor(const XalanDOMChar *theLocale)
Definition: ICUBridgeCollationCompareFunctorImpl.hpp:117
xalanc::CollationCacheStruct::m_collator
CollatorType * m_collator
Definition: ICUBridgeCollationCompareFunctorImpl.hpp:97
StylesheetExecutionContextDefault.hpp
xalanc::CollationCacheStruct::CollatorDeleteFunctor::CollatorDeleteFunctor
CollatorDeleteFunctor(MemoryManager &theManager)
Definition: ICUBridgeCollationCompareFunctorImpl.hpp:101
xalanc::CollationCacheStruct::m_locale
XalanDOMString m_locale
Definition: ICUBridgeCollationCompareFunctorImpl.hpp:95
xalanc::ICUBridgeCollationCompareFunctorImpl::CollatorCacheListType
XalanList< CollationCacheStruct > CollatorCacheListType
Definition: ICUBridgeCollationCompareFunctorImpl.hpp:179
xalanc::ICUBridgeCollationCompareFunctorImpl
Definition: ICUBridgeCollationCompareFunctorImpl.hpp:134
xalanc::XalanCollationServices
Definition: XalanCollationServices.hpp:36
xalanc::CollationCacheStruct::CollatorDeleteFunctor
Definition: ICUBridgeCollationCompareFunctorImpl.hpp:99
ICUBridgeDefinitions.hpp
xalanc::XalanDOMString
Definition: XalanDOMString.hpp:45
xalanc::XalanList< CollationCacheStruct >
xalanc::CollationCacheStruct
Definition: ICUBridgeCollationCompareFunctorImpl.hpp:46
xalanc::CollationCacheStruct::CollatorDeleteFunctor::operator()
void operator()(CollationCacheStruct &theStruct) const
Definition: ICUBridgeCollationCompareFunctorImpl.hpp:107