ICU 74.2: i18n/unicode/sortkey.h Source File

ICU 74.2 74.2

sortkey.h
Go to the documentation of this file.
1// © 2016 and later: Unicode, Inc. and others.
2// License & terms of use: http://www.unicode.org/copyright.html
3/*
4 *****************************************************************************
5 * Copyright (C) 1996-2014, International Business Machines Corporation and others.
6 * All Rights Reserved.
7 *****************************************************************************
8 *
9 * File sortkey.h
10 *
11 * Created by: Helena Shih
12 *
13 * Modification History:
14 *
15 * Date Name Description
16 *
17 * 6/20/97 helena Java class name change.
18 * 8/18/97 helena Added internal API documentation.
19 * 6/26/98 erm Changed to use byte arrays and memcmp.
20 *****************************************************************************
21 */
22
23#ifndef SORTKEY_H
24#define SORTKEY_H
25
26#include "unicode/utypes.h"
27
28#if U_SHOW_CPLUSPLUS_API
29
35#if !UCONFIG_NO_COLLATION
36
37#include "unicode/uobject.h"
38#include "unicode/unistr.h"
39#include "unicode/coll.h"
40
41U_NAMESPACE_BEGIN
42
43/* forward declaration */
44class RuleBasedCollator;
45class CollationKeyByteSink;
46
101 class U_I18N_API CollationKey : public UObject {
102public:
110 CollationKey();
111
112
119 CollationKey(const uint8_t* values,
120 int32_t count);
121
127 CollationKey(const CollationKey& other);
128
133 virtual ~CollationKey();
134
140 const CollationKey& operator=(const CollationKey& other);
141
148 bool operator==(const CollationKey& source) const;
149
156 bool operator!=(const CollationKey& source) const;
157
158
165 UBool isBogus(void) const;
166
176 const uint8_t* getByteArray(int32_t& count) const;
177
178#ifdef U_USE_COLLATION_KEY_DEPRECATES
186 uint8_t* toByteArray(int32_t& count) const;
187#endif
188
189#ifndef U_HIDE_DEPRECATED_API
199 Collator::EComparisonResult compareTo(const CollationKey& target) const;
200#endif /* U_HIDE_DEPRECATED_API */
201
212 UCollationResult compareTo(const CollationKey& target, UErrorCode &status) const;
213
234 int32_t hashCode(void) const;
235
240 virtual UClassID getDynamicClassID() const override;
241
246 static UClassID U_EXPORT2 getStaticClassID();
247
248private:
254 uint8_t *reallocate(int32_t newCapacity, int32_t length);
258 void setLength(int32_t newLength);
259
260 uint8_t *getBytes() {
261 return (fFlagAndLength >= 0) ? fUnion.fStackBuffer : fUnion.fFields.fBytes;
262 }
263 const uint8_t *getBytes() const {
264 return (fFlagAndLength >= 0) ? fUnion.fStackBuffer : fUnion.fFields.fBytes;
265 }
266 int32_t getCapacity() const {
267 return (fFlagAndLength >= 0) ? (int32_t)sizeof(fUnion) : fUnion.fFields.fCapacity;
268 }
269 int32_t getLength() const { return fFlagAndLength & 0x7fffffff; }
270
275 CollationKey& setToBogus(void);
280 CollationKey& reset(void);
281
285 friend class RuleBasedCollator;
286 friend class CollationKeyByteSink;
287
288 // Class fields. sizeof(CollationKey) is intended to be 48 bytes
289 // on a machine with 64-bit pointers.
290 // We use a union to maximize the size of the internal buffer,
291 // similar to UnicodeString but not as tight and complex.
292
293 // (implicit) *vtable;
299 int32_t fFlagAndLength;
304 mutable int32_t fHashCode;
309 union StackBufferOrFields {
311 uint8_t fStackBuffer[32];
312 struct {
313 uint8_t *fBytes;
314 int32_t fCapacity;
315 } fFields;
316 } fUnion;
317};
318
319inline bool
320CollationKey::operator!=(const CollationKey& other) const
321{
322 return !(*this == other);
323}
324
325inline UBool
326CollationKey::isBogus() const
327{
328 return fHashCode == 2; // kBogusHashCode
329}
330
331inline const uint8_t*
332CollationKey::getByteArray(int32_t &count) const
333{
334 count = getLength();
335 return getBytes();
336}
337
338U_NAMESPACE_END
339
340#endif /* #if !UCONFIG_NO_COLLATION */
341
342#endif /* U_SHOW_CPLUSPLUS_API */
343
344#endif
icu::CollationKey
Collation keys are generated by the Collator class.
Definition sortkey.h:101
icu::CollationKey::~CollationKey
virtual ~CollationKey()
Sort key destructor.
icu::CollationKey::operator=
const CollationKey & operator=(const CollationKey &other)
Assignment operator.
icu::CollationKey::CollationKey
CollationKey(const CollationKey &other)
Copy constructor.
icu::CollationKey::getDynamicClassID
virtual UClassID getDynamicClassID() const override
ICU "poor man's RTTI", returns a UClassID for the actual class.
icu::CollationKey::compareTo
UCollationResult compareTo(const CollationKey &target, UErrorCode &status) const
Convenience method which does a string(bit-wise) comparison of the two collation keys.
icu::CollationKey::getStaticClassID
static UClassID getStaticClassID()
ICU "poor man's RTTI", returns a UClassID for this class.
icu::CollationKey::CollationKey
CollationKey(const uint8_t *values, int32_t count)
Creates a collation key based on the collation key values.
icu::CollationKey::compareTo
Collator::EComparisonResult compareTo(const CollationKey &target) const
Convenience method which does a string(bit-wise) comparison of the two collation keys.
icu::CollationKey::CollationKey
CollationKey()
This creates an empty collation key based on the null string.
icu::CollationKey::operator==
bool operator==(const CollationKey &source) const
Compare if two collation keys are the same.
icu::CollationKey::hashCode
int32_t hashCode(void) const
Creates an integer that is unique to the collation key.
icu::Collator::EComparisonResult
EComparisonResult
LESS is returned if source string is compared to be less than target string in the compare() method.
Definition coll.h:221
icu::RuleBasedCollator
The RuleBasedCollator class provides the implementation of Collator, using data-driven tables.
Definition tblcoll.h:115
icu::UObject
UObject is the common ICU "boilerplate" class.
Definition uobject.h:223
coll.h
C++ API: Collation Service.
icu::operator!=
bool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
Definition stringpiece.h:335
UCollationResult
UCollationResult
UCOL_LESS is returned if source string is compared to be less than target string in the ucol_strcoll(...
Definition ucol.h:76
UBool
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition umachine.h:247
unistr.h
C++ API: Unicode String.
uobject.h
C++ API: Common ICU base class UObject.
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition uobject.h:96
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition utypes.h:415
U_I18N_API
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition utypes.h:301