00001 /* 00002 * Copyright © {1996-1999}, International Business Machines Corporation and others. All Rights Reserved. 00003 ***************************************************************************************** 00004 */ 00005 //=============================================================================== 00006 // 00007 // File sortkey.h 00008 // 00009 // 00010 // 00011 // Created by: Helena Shih 00012 // 00013 // Modification History: 00014 // 00015 // Date Name Description 00016 // 00017 // 6/20/97 helena Java class name change. 00018 // 8/18/97 helena Added internal API documentation. 00019 // 6/26/98 erm Changed to use byte arrays and memcmp. 00020 //=============================================================================== 00021 00022 #ifndef SORTKEY_H 00023 #define SORTKEY_H 00024 00025 00026 #include "unicode/utypes.h" 00027 #include "unicode/unistr.h" 00028 #include "unicode/coll.h" 00029 00030 /* forward declaration */ 00031 class RuleBasedCollator; 00032 00084 class U_I18N_API CollationKey { 00085 public: 00093 CollationKey(); 00101 CollationKey(const uint8_t* values, 00102 int32_t count); 00103 00108 CollationKey(const CollationKey& other); 00113 ~CollationKey(); 00114 00119 const CollationKey& operator=(const CollationKey& other); 00120 00127 UBool operator==(const CollationKey& source) const; 00128 00135 UBool operator!=(const CollationKey& source) const; 00136 00137 00144 UBool isBogus(void) const; 00145 00154 const uint8_t* getByteArray(int32_t& count) const; 00155 00163 uint8_t* toByteArray(int32_t& count) const; 00164 00175 Collator::EComparisonResult compareTo(const CollationKey& target) const; 00176 00197 int32_t hashCode(void) const; 00198 00199 private: 00206 uint16_t* copyValues(int32_t &size) const; 00207 00208 /* 00209 * Creates a collation key with a string. 00210 */ 00211 CollationKey(const UnicodeString& value); 00212 00213 int32_t storeBytes(int32_t cursor, uint32_t byteValue); 00214 int32_t storeUnicodeString(int32_t cursor, const UnicodeString &value); 00215 void reverseBytes(int32_t from, int32_t to); 00216 CollationKey& ensureCapacity(int32_t newSize); 00217 CollationKey& copyUnicodeString(const UnicodeString &value); 00218 CollationKey& setToBogus(void); 00219 CollationKey& reset(void); 00220 00221 friend class RuleBasedCollator; 00222 00223 static const int32_t kInvalidHashCode; 00224 static const int32_t kEmptyHashCode; 00225 00226 UBool fBogus; 00227 int32_t fCount; 00228 int32_t fCapacity; 00229 int32_t fHashCode; 00230 uint8_t* fBytes; 00231 }; 00232 00233 inline UBool 00234 CollationKey::operator!=(const CollationKey& other) const 00235 { 00236 return !(*this == other); 00237 } 00238 00239 inline UBool 00240 CollationKey::isBogus() const 00241 { 00242 return fBogus; 00243 } 00244 00245 inline const uint8_t* 00246 CollationKey::getByteArray(int32_t &count) const 00247 { 00248 count = fCount; 00249 return fBytes; 00250 } 00251 00252 inline UTextOffset 00253 CollationKey::storeBytes(UTextOffset cursor, uint32_t byteValue) 00254 { 00255 fBytes[cursor++] = (uint8_t) (byteValue >> 8); 00256 fBytes[cursor++] = (uint8_t) byteValue; 00257 00258 return cursor; 00259 } 00260 00261 #endif