00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef SORTKEY_H
00024 #define SORTKEY_H
00025
00026 #include "unicode/utypes.h"
00027
00028 #if U_SHOW_CPLUSPLUS_API
00029
00035 #if !UCONFIG_NO_COLLATION
00036
00037 #include "unicode/uobject.h"
00038 #include "unicode/unistr.h"
00039 #include "unicode/coll.h"
00040
00041 U_NAMESPACE_BEGIN
00042
00043
00044 class RuleBasedCollator;
00045 class CollationKeyByteSink;
00046
00101 class U_I18N_API CollationKey : public UObject {
00102 public:
00110 CollationKey();
00111
00112
00119 CollationKey(const uint8_t* values,
00120 int32_t count);
00121
00127 CollationKey(const CollationKey& other);
00128
00133 virtual ~CollationKey();
00134
00140 const CollationKey& operator=(const CollationKey& other);
00141
00148 UBool operator==(const CollationKey& source) const;
00149
00156 UBool operator!=(const CollationKey& source) const;
00157
00158
00165 UBool isBogus(void) const;
00166
00176 const uint8_t* getByteArray(int32_t& count) const;
00177
00178 #ifdef U_USE_COLLATION_KEY_DEPRECATES
00179
00186 uint8_t* toByteArray(int32_t& count) const;
00187 #endif
00188
00189 #ifndef U_HIDE_DEPRECATED_API
00190
00199 Collator::EComparisonResult compareTo(const CollationKey& target) const;
00200 #endif
00201
00212 UCollationResult compareTo(const CollationKey& target, UErrorCode &status) const;
00213
00234 int32_t hashCode(void) const;
00235
00240 virtual UClassID getDynamicClassID() const;
00241
00246 static UClassID U_EXPORT2 getStaticClassID();
00247
00248 private:
00254 uint8_t *reallocate(int32_t newCapacity, int32_t length);
00258 void setLength(int32_t newLength);
00259
00260 uint8_t *getBytes() {
00261 return (fFlagAndLength >= 0) ? fUnion.fStackBuffer : fUnion.fFields.fBytes;
00262 }
00263 const uint8_t *getBytes() const {
00264 return (fFlagAndLength >= 0) ? fUnion.fStackBuffer : fUnion.fFields.fBytes;
00265 }
00266 int32_t getCapacity() const {
00267 return (fFlagAndLength >= 0) ? (int32_t)sizeof(fUnion) : fUnion.fFields.fCapacity;
00268 }
00269 int32_t getLength() const { return fFlagAndLength & 0x7fffffff; }
00270
00275 CollationKey& setToBogus(void);
00280 CollationKey& reset(void);
00281
00285 friend class RuleBasedCollator;
00286 friend class CollationKeyByteSink;
00287
00288
00289
00290
00291
00292
00293
00299 int32_t fFlagAndLength;
00304 mutable int32_t fHashCode;
00309 union StackBufferOrFields {
00311 uint8_t fStackBuffer[32];
00312 struct {
00313 uint8_t *fBytes;
00314 int32_t fCapacity;
00315 } fFields;
00316 } fUnion;
00317 };
00318
00319 inline UBool
00320 CollationKey::operator!=(const CollationKey& other) const
00321 {
00322 return !(*this == other);
00323 }
00324
00325 inline UBool
00326 CollationKey::isBogus() const
00327 {
00328 return fHashCode == 2;
00329 }
00330
00331 inline const uint8_t*
00332 CollationKey::getByteArray(int32_t &count) const
00333 {
00334 count = getLength();
00335 return getBytes();
00336 }
00337
00338 U_NAMESPACE_END
00339
00340 #endif
00341
00342 #endif
00343
00344 #endif