ICU 56.1: sortkey.h Source File

ICU 56.1 56.1

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

- File List
- Globals

sortkey.h
Go to the documentation of this file.
1 /*
2 *****************************************************************************
3 * Copyright (C) 1996-2014, International Business Machines Corporation and others.
4 * All Rights Reserved.
5 *****************************************************************************
6 *
7 * File sortkey.h
8 *
9 * Created by: Helena Shih
10 *
11 * Modification History:
12 *
13 * Date Name Description
14 *
15 * 6/20/97 helena Java class name change.
16 * 8/18/97 helena Added internal API documentation.
17 * 6/26/98 erm Changed to use byte arrays and memcmp.
18 *****************************************************************************
19 */
20
21 #ifndef SORTKEY_H
22 #define SORTKEY_H
23
24 #include "unicode/utypes.h"
25
31 #if !UCONFIG_NO_COLLATION
32
33 #include "unicode/uobject.h"
34 #include "unicode/unistr.h"
35 #include "unicode/coll.h"
36
37 U_NAMESPACE_BEGIN
38
39 /* forward declaration */
40 class RuleBasedCollator;
41 class CollationKeyByteSink;
42
97 class U_I18N_API CollationKey : public UObject {
98 public:
106 CollationKey();
107
108
115 CollationKey(const uint8_t* values,
116 int32_t count);
117
123 CollationKey(const CollationKey& other);
124
129 virtual ~CollationKey();
130
136 const CollationKey& operator=(const CollationKey& other);
137
144 UBool operator==(const CollationKey& source) const;
145
152 UBool operator!=(const CollationKey& source) const;
153
154
161 UBool isBogus(void) const;
162
172 const uint8_t* getByteArray(int32_t& count) const;
173
174 #ifdef U_USE_COLLATION_KEY_DEPRECATES
175
182 uint8_t* toByteArray(int32_t& count) const;
183 #endif
184
185 #ifndef U_HIDE_DEPRECATED_API
186
195 Collator::EComparisonResult compareTo(const CollationKey& target) const;
196 #endif /* U_HIDE_DEPRECATED_API */
197
208 UCollationResult compareTo(const CollationKey& target, UErrorCode &status) const;
209
230 int32_t hashCode(void) const;
231
236 virtual UClassID getDynamicClassID() const;
237
242 static UClassID U_EXPORT2 getStaticClassID();
243
244 private:
250 uint8_t *reallocate(int32_t newCapacity, int32_t length);
254 void setLength(int32_t newLength);
255
256 uint8_t *getBytes() {
257 return (fFlagAndLength >= 0) ? fUnion.fStackBuffer : fUnion.fFields.fBytes;
258 }
259 const uint8_t *getBytes() const {
260 return (fFlagAndLength >= 0) ? fUnion.fStackBuffer : fUnion.fFields.fBytes;
261 }
262 int32_t getCapacity() const {
263 return (fFlagAndLength >= 0) ? (int32_t)sizeof(fUnion) : fUnion.fFields.fCapacity;
264 }
265 int32_t getLength() const { return fFlagAndLength & 0x7fffffff; }
266
271 CollationKey& setToBogus(void);
276 CollationKey& reset(void);
277
281 friend class RuleBasedCollator;
282 friend class CollationKeyByteSink;
283
284 // Class fields. sizeof(CollationKey) is intended to be 48 bytes
285 // on a machine with 64-bit pointers.
286 // We use a union to maximize the size of the internal buffer,
287 // similar to UnicodeString but not as tight and complex.
288
289 // (implicit) *vtable;
295 int32_t fFlagAndLength;
300 mutable int32_t fHashCode;
305 union StackBufferOrFields {
307 uint8_t fStackBuffer[32];
308 struct {
309 uint8_t *fBytes;
310 int32_t fCapacity;
311 } fFields;
312 } fUnion;
313 };
314
315 inline UBool
316 CollationKey::operator!=(const CollationKey& other) const
317 {
318 return !(*this == other);
319 }
320
321 inline UBool
322 CollationKey::isBogus() const
323 {
324 return fHashCode == 2; // kBogusHashCode
325 }
326
327 inline const uint8_t*
328 CollationKey::getByteArray(int32_t &count) const
329 {
330 count = getLength();
331 return getBytes();
332 }
333
334 U_NAMESPACE_END
335
336 #endif /* #if !UCONFIG_NO_COLLATION */
337
338 #endif
icu::UObject::getDynamicClassID
virtual UClassID getDynamicClassID() const
ICU4C "poor man'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:71
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's RTTI.
Definition: uobject.h:91
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:358
U_NAMESPACE_BEGIN
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:129
icu::RuleBasedCollator
The RuleBasedCollator class provides the implementation of Collator, using data-driven tables...
Definition: tblcoll.h:111
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:212
icu::CollationKey
Collation keys are generated by the Collator class.
Definition: sortkey.h:97
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:130
UErrorCode
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:476
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
icu::UObject
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:221
UBool
int8_t UBool
The ICU boolean type.
Definition: umachine.h:234