00001 /* 00002 * Copyright (C) {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 00086 class U_I18N_API CollationKey { 00087 public: 00095 CollationKey(); 00096 00097 00105 CollationKey(const uint8_t* values, 00106 int32_t count); 00107 00112 CollationKey(const CollationKey& other); 00117 ~CollationKey(); 00118 00123 const CollationKey& operator=(const CollationKey& other); 00124 00131 UBool operator==(const CollationKey& source) const; 00132 00139 UBool operator!=(const CollationKey& source) const; 00140 00141 00148 UBool isBogus(void) const; 00149 00158 const uint8_t* getByteArray(int32_t& count) const; 00159 00167 uint8_t* toByteArray(int32_t& count) const; 00168 00179 Collator::EComparisonResult compareTo(const CollationKey& target) const; 00180 00201 int32_t hashCode(void) const; 00202 00203 private: 00210 uint16_t* copyValues(int32_t &size) const; 00211 00212 void adopt(uint8_t *values, int32_t count); 00213 00217 CollationKey(int32_t count, uint8_t *values); 00218 00219 /* 00220 * Creates a collation key with a string. 00221 */ 00222 CollationKey(const UnicodeString& value); 00223 00224 int32_t storeBytes(int32_t cursor, uint32_t byteValue); 00225 int32_t storeUnicodeString(int32_t cursor, const UnicodeString &value); 00226 void reverseBytes(int32_t from, int32_t to); 00227 CollationKey& ensureCapacity(int32_t newSize); 00228 CollationKey& copyUnicodeString(const UnicodeString &value); 00229 CollationKey& setToBogus(void); 00230 CollationKey& reset(void); 00231 00232 friend class RuleBasedCollator; 00233 00234 static const int32_t kInvalidHashCode; 00235 static const int32_t kEmptyHashCode; 00236 00237 UBool fBogus; 00238 int32_t fCount; 00239 int32_t fCapacity; 00240 int32_t fHashCode; 00241 uint8_t* fBytes; 00242 }; 00243 00244 inline UBool 00245 CollationKey::operator!=(const CollationKey& other) const 00246 { 00247 return !(*this == other); 00248 } 00249 00250 inline UBool 00251 CollationKey::isBogus() const 00252 { 00253 return fBogus; 00254 } 00255 00256 inline const uint8_t* 00257 CollationKey::getByteArray(int32_t &count) const 00258 { 00259 count = fCount; 00260 return fBytes; 00261 } 00262 00263 inline UTextOffset 00264 CollationKey::storeBytes(UTextOffset cursor, uint32_t byteValue) 00265 { 00266 fBytes[cursor++] = (uint8_t) (byteValue >> 8); 00267 fBytes[cursor++] = (uint8_t) byteValue; 00268 00269 return cursor; 00270 } 00271 00272 #endif