00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef SORTKEY_H
00022 #define SORTKEY_H
00023
00024 #include "unicode/utypes.h"
00025
00031 #if !UCONFIG_NO_COLLATION
00032
00033 #include "unicode/uobject.h"
00034 #include "unicode/unistr.h"
00035 #include "unicode/coll.h"
00036
00037 U_NAMESPACE_BEGIN
00038
00039
00040 class RuleBasedCollator;
00041 class CollationKeyByteSink;
00042
00097 class U_I18N_API CollationKey : public UObject {
00098 public:
00106 CollationKey();
00107
00108
00115 CollationKey(const uint8_t* values,
00116 int32_t count);
00117
00123 CollationKey(const CollationKey& other);
00124
00129 virtual ~CollationKey();
00130
00136 const CollationKey& operator=(const CollationKey& other);
00137
00144 UBool operator==(const CollationKey& source) const;
00145
00152 UBool operator!=(const CollationKey& source) const;
00153
00154
00161 UBool isBogus(void) const;
00162
00172 const uint8_t* getByteArray(int32_t& count) const;
00173
00174 #ifdef U_USE_COLLATION_KEY_DEPRECATES
00175
00182 uint8_t* toByteArray(int32_t& count) const;
00183 #endif
00184
00185 #ifndef U_HIDE_DEPRECATED_API
00186
00195 Collator::EComparisonResult compareTo(const CollationKey& target) const;
00196 #endif
00197
00208 UCollationResult compareTo(const CollationKey& target, UErrorCode &status) const;
00209
00230 int32_t hashCode(void) const;
00231
00236 virtual UClassID getDynamicClassID() const;
00237
00242 static UClassID U_EXPORT2 getStaticClassID();
00243
00244 private:
00250 uint8_t *reallocate(int32_t newCapacity, int32_t length);
00254 void setLength(int32_t newLength);
00255
00256 uint8_t *getBytes() {
00257 return (fFlagAndLength >= 0) ? fUnion.fStackBuffer : fUnion.fFields.fBytes;
00258 }
00259 const uint8_t *getBytes() const {
00260 return (fFlagAndLength >= 0) ? fUnion.fStackBuffer : fUnion.fFields.fBytes;
00261 }
00262 int32_t getCapacity() const {
00263 return (fFlagAndLength >= 0) ? (int32_t)sizeof(fUnion) : fUnion.fFields.fCapacity;
00264 }
00265 int32_t getLength() const { return fFlagAndLength & 0x7fffffff; }
00266
00271 CollationKey& setToBogus(void);
00276 CollationKey& reset(void);
00277
00281 friend class RuleBasedCollator;
00282 friend class CollationKeyByteSink;
00283
00284
00285
00286
00287
00288
00289
00295 int32_t fFlagAndLength;
00300 mutable int32_t fHashCode;
00305 union StackBufferOrFields {
00307 uint8_t fStackBuffer[32];
00308 struct {
00309 uint8_t *fBytes;
00310 int32_t fCapacity;
00311 } fFields;
00312 } fUnion;
00313 };
00314
00315 inline UBool
00316 CollationKey::operator!=(const CollationKey& other) const
00317 {
00318 return !(*this == other);
00319 }
00320
00321 inline UBool
00322 CollationKey::isBogus() const
00323 {
00324 return fHashCode == 2;
00325 }
00326
00327 inline const uint8_t*
00328 CollationKey::getByteArray(int32_t &count) const
00329 {
00330 count = getLength();
00331 return getBytes();
00332 }
00333
00334 U_NAMESPACE_END
00335
00336 #endif
00337
00338 #endif