Debian Codegraph @

intl/icu/source/i18n/collationtailoring.h

raw
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 *******************************************************************************
5 * Copyright (C) 2013-2014, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 *******************************************************************************
8 * collationtailoring.h
9 *
10 * created on: 2013mar12
11 * created by: Markus W. Scherer
12 */
13
14 #ifndef __COLLATIONTAILORING_H__
15 #define __COLLATIONTAILORING_H__
16
17 #include "unicode/utypes.h"
18
19 #if !UCONFIG_NO_COLLATION
20
21 #include "unicode/locid.h"
22 #include "unicode/unistr.h"
23 #include "unicode/uversion.h"
24 #include "collationsettings.h"
25 #include "uhash.h"
26 #include "umutex.h"
27 #include "unifiedcache.h"
28
29
30 struct UDataMemory;
31 struct UResourceBundle;
32 struct UTrie2;
33
34 U_NAMESPACE_BEGIN
35
36 struct CollationData;
37
38 class UnicodeSet;
39
40 /**
41 * Collation tailoring data & settings.
42 * This is a container of values for a collation tailoring
43 * built from rules or deserialized from binary data.
44 *
45 * It is logically immutable: Do not modify its values.
46 * The fields are public for convenience.
47 *
48 * It is shared, reference-counted, and auto-deleted; see SharedObject.
49 */
50 struct U_I18N_API CollationTailoring : public SharedObject {
51 CollationTailoring(const CollationSettings *baseSettings);
52 virtual ~CollationTailoring();
53
54 /**
55 * Returns true if the constructor could not initialize properly.
56 */
57 UBool isBogus() { return settings == nullptr; }
58
59 UBool ensureOwnedData(UErrorCode &errorCode);
60
61 static void makeBaseVersion(const UVersionInfo ucaVersion, UVersionInfo version);
62 void setVersion(const UVersionInfo baseVersion, const UVersionInfo rulesVersion);
63 int32_t getUCAVersion() const;
64
65 // data for sorting etc.
66 const CollationData *data; // == base data or ownedData
67 const CollationSettings *settings; // reference-counted
68 UnicodeString rules;
69 // The locale is bogus when built from rules or constructed from a binary blob.
70 // It can then be set by the service registration code which is thread-safe.
71 mutable Locale actualLocale;
72 // UCA version u.v.w & rules version r.s.t.q:
73 // version[0]: builder version (runtime version is mixed in at runtime)
74 // version[1]: bits 7..3=u, bits 2..0=v
75 // version[2]: bits 7..6=w, bits 5..0=r
76 // version[3]= (s<<5)+(s>>3)+t+(q<<4)+(q>>4)
77 UVersionInfo version;
78
79 // owned objects
80 CollationData *ownedData;
81 UObject *builder;
82 UDataMemory *memory;
83 UResourceBundle *bundle;
84 UTrie2 *trie;
85 UnicodeSet *unsafeBackwardSet;
86 mutable UHashtable *maxExpansions;
87 mutable UInitOnce maxExpansionsInitOnce;
88
89 private:
90 /**
91 * No copy constructor: A CollationTailoring cannot be copied.
92 * It is immutable, and the data trie cannot be copied either.
93 */
94 CollationTailoring(const CollationTailoring &other) = delete;
95 };
96
97 struct U_I18N_API CollationCacheEntry : public SharedObject {
98 CollationCacheEntry(const Locale &loc, const CollationTailoring *t)
99 : validLocale(loc), tailoring(t) {
100 if(t != nullptr) {
101 t->addRef();
102 }
103 }
104 ~CollationCacheEntry();
105
106 Locale validLocale;
107 const CollationTailoring *tailoring;
108 };
109
110 template<> U_I18N_API
111 const CollationCacheEntry *
112 LocaleCacheKey<CollationCacheEntry>::createObject(const void *creationContext,
113 UErrorCode &errorCode) const;
114 U_NAMESPACE_END
115
116 #endif // !UCONFIG_NO_COLLATION
117 #endif // __COLLATIONTAILORING_H__