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 00019 #if !defined(ICUBRIDGE_COLLATIONCOMPAREFUNCTORIMPL_GUARD_1357924680) 00020 #define ICUBRIDGE_COLLATIONCOMPAREFUNCTORIMPL_GUARD_1357924680 00021 00022 00023 00024 #include <xalanc/ICUBridge/ICUBridgeDefinitions.hpp> 00025 00026 00027 00028 #include <xalanc/Include/XalanList.hpp> 00029 00030 00031 00032 #include <xalanc/XSLT/StylesheetExecutionContextDefault.hpp> 00033 00034 00035 00036 #include <unicode/coll.h> 00037 00038 00039 00040 00041 XALAN_CPP_NAMESPACE_BEGIN 00042 00043 00044 #if defined(XALAN_HAS_CPP_NAMESPACE) 00045 typedef U_ICU_NAMESPACE::Collator CollatorType; 00046 #else 00047 typedef Collator CollatorType; 00048 #endif 00049 00050 struct CollationCacheStruct 00051 { 00052 CollationCacheStruct( 00053 MemoryManager& theManager, 00054 const XalanDOMString& theLocale, 00055 CollatorType* theCollator) : 00056 m_locale(theLocale, theManager), 00057 m_collator(theCollator) 00058 { 00059 } 00060 00061 CollationCacheStruct(MemoryManager& theManager) : 00062 m_locale(theManager), 00063 m_collator(0) 00064 { 00065 } 00066 00067 CollationCacheStruct( const CollationCacheStruct& other, 00068 MemoryManager& theManager) : 00069 m_locale(other.m_locale,theManager), 00070 m_collator(other.m_collator) 00071 { 00072 } 00073 void 00074 swap(CollationCacheStruct& theOther) 00075 { 00076 m_locale.swap(theOther.m_locale); 00077 00078 CollatorType* const theTemp = m_collator; 00079 00080 m_collator = theOther.m_collator; 00081 00082 theOther.m_collator = theTemp; 00083 } 00084 00085 #if defined(XALAN_NO_SELECTIVE_TEMPLATE_INSTANTIATION) 00086 bool 00087 operator<(const CollationCacheStruct& theRHS) const 00088 { 00089 return this < &theRHS; 00090 } 00091 00092 bool 00093 operator==(const CollationCacheStruct& theRHS) const 00094 { 00095 return this == &theRHS; 00096 } 00097 #endif 00098 00099 XalanDOMString m_locale; 00100 00101 CollatorType* m_collator; 00102 00103 struct CollatorDeleteFunctor 00104 { 00105 CollatorDeleteFunctor(MemoryManager& theManager): 00106 m_memoryManager(theManager) 00107 { 00108 } 00109 00110 void 00111 operator()(CollationCacheStruct& theStruct) const 00112 { 00113 delete theStruct.m_collator; 00114 } 00115 private: 00116 MemoryManager& m_memoryManager; 00117 }; 00118 00119 struct CollatorFindFunctor 00120 { 00121 CollatorFindFunctor(const XalanDOMChar* theLocale) : 00122 m_locale(theLocale) 00123 { 00124 } 00125 00126 bool 00127 operator()(CollationCacheStruct& theStruct) const 00128 { 00129 return XalanDOMString::equals(theStruct.m_locale ,m_locale); 00130 } 00131 00132 const XalanDOMChar* const m_locale; 00133 }; 00134 }; 00135 00136 XALAN_USES_MEMORY_MANAGER(CollationCacheStruct) 00137 00138 class XALAN_ICUBRIDGE_EXPORT ICUBridgeCollationCompareFunctorImpl : public XalanCollationServices::CollationCompareFunctor 00139 { 00140 public: 00141 00142 /** 00143 * Constructor. 00144 * 00145 * @param fCacheCollators If true, the instance will cache collators. This is not thread-safe, so each thread must have its own instance. 00146 */ 00147 ICUBridgeCollationCompareFunctorImpl( MemoryManager& theManager , 00148 bool fCacheCollators = false); 00149 00150 static ICUBridgeCollationCompareFunctorImpl* 00151 create( MemoryManager& theManager, 00152 bool fCacheCollators = false); 00153 00154 00155 ~ICUBridgeCollationCompareFunctorImpl(); 00156 00157 MemoryManager& 00158 getMemoryManager()const 00159 { 00160 return m_collatorCache.getMemoryManager(); 00161 } 00162 00163 int 00164 operator()( 00165 const XalanDOMChar* theLHS, 00166 const XalanDOMChar* theRHS, 00167 XalanCollationServices::eCaseOrder theCaseOrder = XalanCollationServices::eDefault) const; 00168 00169 int 00170 operator()( 00171 const XalanDOMChar* theLHS, 00172 const XalanDOMChar* theRHS, 00173 const XalanDOMChar* theLocale, 00174 XalanCollationServices::eCaseOrder theCaseOrder = XalanCollationServices::eDefault) const; 00175 00176 bool 00177 isValid() const 00178 { 00179 return m_isValid; 00180 } 00181 00182 00183 typedef XalanList<CollationCacheStruct> CollatorCacheListType; 00184 00185 enum { eCacheMax = 10 }; 00186 00187 private: 00188 00189 int 00190 doDefaultCompare( 00191 const XalanDOMChar* theLHS, 00192 const XalanDOMChar* theRHS) const; 00193 00194 int 00195 doCompare( 00196 const XalanDOMChar* theLHS, 00197 const XalanDOMChar* theRHS, 00198 const XalanDOMChar* theLocale, 00199 XalanCollationServices::eCaseOrder theCaseOrder) const; 00200 00201 int 00202 doCompareCached( 00203 const XalanDOMChar* theLHS, 00204 const XalanDOMChar* theRHS, 00205 const XalanDOMChar* theLocale, 00206 XalanCollationServices::eCaseOrder theCaseOrder) const; 00207 00208 int 00209 doCompare( 00210 const CollatorType& theCollator, 00211 const XalanDOMChar* theLHS, 00212 const XalanDOMChar* theRHS) const; 00213 00214 int 00215 doCompare( 00216 CollatorType& theCollator, 00217 const XalanDOMChar* theLHS, 00218 const XalanDOMChar* theRHS, 00219 XalanCollationServices::eCaseOrder theCaseOrder) const; 00220 00221 CollatorType* 00222 getCachedCollator(const XalanDOMChar* theLocale) const; 00223 00224 void 00225 cacheCollator( 00226 CollatorType* theCollator, 00227 const XalanDOMChar* theLocale) const; 00228 00229 00230 // Data members... 00231 bool m_isValid; 00232 00233 CollatorType* m_defaultCollator; 00234 00235 XalanDOMString m_defaultCollatorLocaleName; 00236 00237 bool m_cacheCollators; 00238 00239 mutable CollatorCacheListType m_collatorCache; 00240 00241 static const StylesheetExecutionContextDefault::DefaultCollationCompareFunctor s_defaultFunctor; 00242 }; 00243 00244 00245 00246 XALAN_CPP_NAMESPACE_END 00247 00248 00249 00250 #endif // ICUBRIDGE_COLLATIONCOMPAREFUNCTORIMPL_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 |
|