ICU 50.2 50.2
sortkey.h
Go to the documentation of this file.
1/*
2 *****************************************************************************
3 * Copyright (C) 1996-2012, 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
30
31#if !UCONFIG_NO_COLLATION
32#ifndef U_HIDE_DEPRECATED_API
33
34#include "unicode/uobject.h"
35#include "unicode/unistr.h"
36#include "unicode/coll.h"
37
39
40/* forward declaration */
42
98public:
107
108
115 CollationKey(const uint8_t* values,
116 int32_t count);
117
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
182 uint8_t* toByteArray(int32_t& count) const;
183#endif
184
195
206 UCollationResult compareTo(const CollationKey& target, UErrorCode &status) const;
207
228 int32_t hashCode(void) const;
229
235
240 static UClassID U_EXPORT2 getStaticClassID();
241
242private:
248 uint8_t *reallocate(int32_t newCapacity, int32_t length);
252 void setLength(int32_t newLength);
253
254 uint8_t *getBytes() {
255 return (fFlagAndLength >= 0) ? fUnion.fStackBuffer : fUnion.fFields.fBytes;
256 }
257 const uint8_t *getBytes() const {
258 return (fFlagAndLength >= 0) ? fUnion.fStackBuffer : fUnion.fFields.fBytes;
259 }
260 int32_t getCapacity() const {
261 return (fFlagAndLength >= 0) ? (int32_t)sizeof(fUnion) : fUnion.fFields.fCapacity;
262 }
263 int32_t getLength() const { return fFlagAndLength & 0x7fffffff; }
264
269 CollationKey& setToBogus(void);
274 CollationKey& reset(void);
275
279 friend class RuleBasedCollator;
280 friend class CollationKeyByteSink;
281
282 // Class fields. sizeof(CollationKey) is intended to be 48 bytes
283 // on a machine with 64-bit pointers.
284 // We use a union to maximize the size of the internal buffer,
285 // similar to UnicodeString but not as tight and complex.
286
287 // (implicit) *vtable;
293 int32_t fFlagAndLength;
298 mutable int32_t fHashCode;
303 union StackBufferOrFields {
305 uint8_t fStackBuffer[32];
306 struct {
307 uint8_t *fBytes;
308 int32_t fCapacity;
309 } fFields;
310 } fUnion;
311};
312
313inline UBool
315{
316 return !(*this == other);
317}
318
319inline UBool
321{
322 return fHashCode == 2; // kBogusHashCode
323}
324
325inline const uint8_t*
326CollationKey::getByteArray(int32_t &count) const
327{
328 count = getLength();
329 return getBytes();
330}
331
333
334#endif /* U_HIDE_DEPRECATED_API */
335#endif /* #if !UCONFIG_NO_COLLATION */
336
337#endif
virtual UClassID getDynamicClassID() const
ICU "poor man's RTTI", returns a UClassID for the actual class.
friend class RuleBasedCollator
Allow private access to RuleBasedCollator.
Definition sortkey.h:279
int32_t hashCode(void) const
Creates an integer that is unique to the collation key.
CollationKey()
This creates an empty collation key based on the null string.
virtual ~CollationKey()
Sort key destructor.
UCollationResult compareTo(const CollationKey &target, UErrorCode &status) const
Convenience method which does a string(bit-wise) comparison of the two collation keys.
CollationKey(const CollationKey &other)
Copy constructor.
Collator::EComparisonResult compareTo(const CollationKey &target) const
Convenience method which does a string(bit-wise) comparison of the two collation keys.
UBool operator==(const CollationKey &source) const
Compare if two collation keys are the same.
static UClassID getStaticClassID()
ICU "poor man's RTTI", returns a UClassID for this class.
const uint8_t * getByteArray(int32_t &count) const
Returns a pointer to the collation key values.
Definition sortkey.h:326
UBool isBogus(void) const
Test to see if the key is in an invalid state.
Definition sortkey.h:320
UBool operator!=(const CollationKey &source) const
Compare if two collation keys are not the same.
Definition sortkey.h:314
const CollationKey & operator=(const CollationKey &other)
Assignment operator.
CollationKey(const uint8_t *values, int32_t count)
Creates a collation key based on the collation key values.
EComparisonResult
LESS is returned if source string is compared to be less than target string in the compare() method.
Definition coll.h:227
The RuleBasedCollator class provides the simple implementation of Collator, using data-driven tables.
Definition tblcoll.h:112
UObject is the common ICU "boilerplate" class.
Definition uobject.h:229
C++ API: Collation Service.
UBool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
UCollationResult
UCOL_LESS is returned if source string is compared to be less than target string in the u_strcoll() m...
Definition ucol.h:77
int8_t UBool
The ICU boolean type.
Definition umachine.h:200
C++ API: Unicode String.
C++ API: Common ICU base class UObject.
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition uobject.h:96
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers,...
Definition utypes.h:476
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition utypes.h:358
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition uversion.h:130
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition uversion.h:129