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
00033 #if !UCONFIG_NO_COLLATION
00034
00035 #include "unicode/uobject.h"
00036 #include "unicode/unistr.h"
00037 #include "unicode/coll.h"
00038
00039 U_NAMESPACE_BEGIN
00040
00041
00042 class RuleBasedCollator;
00043 class CollationKeyByteSink;
00044
00099 class U_I18N_API CollationKey : public UObject {
00100 public:
00108 CollationKey();
00109
00110
00117 CollationKey(const uint8_t* values,
00118 int32_t count);
00119
00125 CollationKey(const CollationKey& other);
00126
00131 virtual ~CollationKey();
00132
00138 const CollationKey& operator=(const CollationKey& other);
00139
00146 UBool operator==(const CollationKey& source) const;
00147
00154 UBool operator!=(const CollationKey& source) const;
00155
00156
00163 UBool isBogus(void) const;
00164
00174 const uint8_t* getByteArray(int32_t& count) const;
00175
00176 #ifdef U_USE_COLLATION_KEY_DEPRECATES
00177
00184 uint8_t* toByteArray(int32_t& count) const;
00185 #endif
00186
00187 #ifndef U_HIDE_DEPRECATED_API
00188
00197 Collator::EComparisonResult compareTo(const CollationKey& target) const;
00198 #endif
00199
00210 UCollationResult compareTo(const CollationKey& target, UErrorCode &status) const;
00211
00232 int32_t hashCode(void) const;
00233
00238 virtual UClassID getDynamicClassID() const;
00239
00244 static UClassID U_EXPORT2 getStaticClassID();
00245
00246 private:
00252 uint8_t *reallocate(int32_t newCapacity, int32_t length);
00256 void setLength(int32_t newLength);
00257
00258 uint8_t *getBytes() {
00259 return (fFlagAndLength >= 0) ? fUnion.fStackBuffer : fUnion.fFields.fBytes;
00260 }
00261 const uint8_t *getBytes() const {
00262 return (fFlagAndLength >= 0) ? fUnion.fStackBuffer : fUnion.fFields.fBytes;
00263 }
00264 int32_t getCapacity() const {
00265 return (fFlagAndLength >= 0) ? (int32_t)sizeof(fUnion) : fUnion.fFields.fCapacity;
00266 }
00267 int32_t getLength() const { return fFlagAndLength & 0x7fffffff; }
00268
00273 CollationKey& setToBogus(void);
00278 CollationKey& reset(void);
00279
00283 friend class RuleBasedCollator;
00284 friend class CollationKeyByteSink;
00285
00286
00287
00288
00289
00290
00291
00297 int32_t fFlagAndLength;
00302 mutable int32_t fHashCode;
00307 union StackBufferOrFields {
00309 uint8_t fStackBuffer[32];
00310 struct {
00311 uint8_t *fBytes;
00312 int32_t fCapacity;
00313 } fFields;
00314 } fUnion;
00315 };
00316
00317 inline UBool
00318 CollationKey::operator!=(const CollationKey& other) const
00319 {
00320 return !(*this == other);
00321 }
00322
00323 inline UBool
00324 CollationKey::isBogus() const
00325 {
00326 return fHashCode == 2;
00327 }
00328
00329 inline const uint8_t*
00330 CollationKey::getByteArray(int32_t &count) const
00331 {
00332 count = getLength();
00333 return getBytes();
00334 }
00335
00336 U_NAMESPACE_END
00337
00338 #endif
00339
00340 #endif