ICU 60.2 60.2

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

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
33 #if !UCONFIG_NO_COLLATION
34
35 #include "unicode/uobject.h"
36 #include "unicode/unistr.h"
37 #include "unicode/coll.h"
38
39 U_NAMESPACE_BEGIN
40
41 /* forward declaration */
42 class RuleBasedCollator;
43 class CollationKeyByteSink;
44
99 class U_I18N_API CollationKey : public UObject {
100 public:
108 CollationKey();
109
110
117 CollationKey(const uint8_t* values,
118 int32_t count);
119
125 CollationKey(const CollationKey& other);
126
131 virtual ~CollationKey();
132
138 const CollationKey& operator=(const CollationKey& other);
139
146 UBool operator==(const CollationKey& source) const;
147
154 UBool operator!=(const CollationKey& source) const;
155
156
163 UBool isBogus(void) const;
164
174 const uint8_t* getByteArray(int32_t& count) const;
175
176 #ifdef U_USE_COLLATION_KEY_DEPRECATES
177
184 uint8_t* toByteArray(int32_t& count) const;
185 #endif
186
187 #ifndef U_HIDE_DEPRECATED_API
188
197 Collator::EComparisonResult compareTo(const CollationKey& target) const;
198 #endif /* U_HIDE_DEPRECATED_API */
199
210 UCollationResult compareTo(const CollationKey& target, UErrorCode &status) const;
211
232 int32_t hashCode(void) const;
233
238 virtual UClassID getDynamicClassID() const;
239
244 static UClassID U_EXPORT2 getStaticClassID();
245
246 private:
252 uint8_t *reallocate(int32_t newCapacity, int32_t length);
256 void setLength(int32_t newLength);
257
258 uint8_t *getBytes() {
259 return (fFlagAndLength >= 0) ? fUnion.fStackBuffer : fUnion.fFields.fBytes;
260 }
261 const uint8_t *getBytes() const {
262 return (fFlagAndLength >= 0) ? fUnion.fStackBuffer : fUnion.fFields.fBytes;
263 }
264 int32_t getCapacity() const {
265 return (fFlagAndLength >= 0) ? (int32_t)sizeof(fUnion) : fUnion.fFields.fCapacity;
266 }
267 int32_t getLength() const { return fFlagAndLength & 0x7fffffff; }
268
273 CollationKey& setToBogus(void);
278 CollationKey& reset(void);
279
283 friend class RuleBasedCollator;
284 friend class CollationKeyByteSink;
285
286 // Class fields. sizeof(CollationKey) is intended to be 48 bytes
287 // on a machine with 64-bit pointers.
288 // We use a union to maximize the size of the internal buffer,
289 // similar to UnicodeString but not as tight and complex.
290
291 // (implicit) *vtable;
297 int32_t fFlagAndLength;
302 mutable int32_t fHashCode;
307 union StackBufferOrFields {
309 uint8_t fStackBuffer[32];
310 struct {
311 uint8_t *fBytes;
312 int32_t fCapacity;
313 } fFields;
314 } fUnion;
315 };
316
317 inline UBool
318 CollationKey::operator!=(const CollationKey& other) const
319 {
320 return !(*this == other);
321 }
322
323 inline UBool
324 CollationKey::isBogus() const
325 {
326 return fHashCode == 2; // kBogusHashCode
327 }
328
329 inline const uint8_t*
330 CollationKey::getByteArray(int32_t &count) const
331 {
332 count = getLength();
333 return getBytes();
334 }
335
336 U_NAMESPACE_END
337
338 #endif /* #if !UCONFIG_NO_COLLATION */
339
340 #endif
icu::UObject::getDynamicClassID
virtual UClassID getDynamicClassID() const
ICU4C "poor man&#39;s RTTI", returns a UClassID for the actual ICU class.
UCollationResult
UCollationResult
UCOL_LESS is returned if source string is compared to be less than target string in the ucol_strcoll(...
Definition: ucol.h:73
unistr.h
C++ API: Unicode String.
icu::operator==
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler&#39;s RTTI.
Definition: uobject.h:93
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:360
U_NAMESPACE_BEGIN
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:131
icu::RuleBasedCollator
The RuleBasedCollator class provides the implementation of Collator, using data-driven tables...
Definition: tblcoll.h:113
coll.h
C++ API: Collation Service.
icu::operator!=
UBool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
Definition: stringpiece.h:218
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:217
icu::CollationKey
Collation keys are generated by the Collator class.
Definition: sortkey.h:99
uobject.h
C++ API: Common ICU base class UObject.
U_NAMESPACE_END
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:132
UErrorCode
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:396
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
icu::UObject
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:223
UBool
int8_t UBool
The ICU boolean type.
Definition: umachine.h:236