ICU 71.1 71.1

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
41 U_NAMESPACE_BEGIN
42
43 /* forward declaration */
44 class RuleBasedCollator;
45 class CollationKeyByteSink;
46
101 class U_I18N_API CollationKey : public UObject {
102 public:
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
179
186 uint8_t* toByteArray(int32_t& count) const;
187 #endif
188
189 #ifndef U_HIDE_DEPRECATED_API
190
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
248 private:
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
319 inline bool
320 CollationKey::operator!=(const CollationKey& other) const
321 {
322 return !(*this == other);
323 }
324
325 inline UBool
326 CollationKey::isBogus() const
327 {
328 return fHashCode == 2; // kBogusHashCode
329 }
330
331 inline const uint8_t*
332 CollationKey::getByteArray(int32_t &count) const
333 {
334 count = getLength();
335 return getBytes();
336 }
337
338 U_NAMESPACE_END
339
340 #endif /* #if !UCONFIG_NO_COLLATION */
341
342 #endif /* U_SHOW_CPLUSPLUS_API */
343
344 #endif
coll.h
C++ API: Collation Service.
icu::CollationKey
Collation keys are generated by the Collator class.
Definition: sortkey.h:101
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
U_I18N_API
#define U_I18N_API
Definition: utypes.h:301
UBool
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition: umachine.h:269
icu::operator==
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
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
icu::UObject
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:223
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:96
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:415
icu::UObject::getDynamicClassID
virtual UClassID getDynamicClassID() const
ICU4C "poor man's RTTI", returns a UClassID for the actual ICU class.
icu::RuleBasedCollator
The RuleBasedCollator class provides the implementation of Collator, using data-driven tables.
Definition: tblcoll.h:115
icu::operator!=
bool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
Definition: stringpiece.h:335
uobject.h
C++ API: Common ICU base class UObject.
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:220
unistr.h
C++ API: Unicode String.