• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
28 struct UDataMemory;
29 struct UResourceBundle;
30 struct UTrie2;
31 
32 U_NAMESPACE_BEGIN
33 
34 struct CollationData;
35 
36 class UnicodeSet;
37 
38 /**
39  * Collation tailoring data & settings.
40  * This is a container of values for a collation tailoring
41  * built from rules or deserialized from binary data.
42  *
43  * It is logically immutable: Do not modify its values.
44  * The fields are public for convenience.
45  *
46  * It is shared, reference-counted, and auto-deleted; see SharedObject.
47  */
48 struct U_I18N_API CollationTailoring : public SharedObject {
49     CollationTailoring(const CollationSettings *baseSettings);
50     virtual ~CollationTailoring();
51 
52     /**
53      * Returns TRUE if the constructor could not initialize properly.
54      */
isBogusCollationTailoring55     UBool isBogus() { return settings == NULL; }
56 
57     UBool ensureOwnedData(UErrorCode &errorCode);
58 
59     static void makeBaseVersion(const UVersionInfo ucaVersion, UVersionInfo version);
60     void setVersion(const UVersionInfo baseVersion, const UVersionInfo rulesVersion);
61     int32_t getUCAVersion() const;
62 
63     // data for sorting etc.
64     const CollationData *data;  // == base data or ownedData
65     const CollationSettings *settings;  // reference-counted
66     UnicodeString rules;
67     // The locale is bogus when built from rules or constructed from a binary blob.
68     // It can then be set by the service registration code which is thread-safe.
69     mutable Locale actualLocale;
70     // UCA version u.v.w & rules version r.s.t.q:
71     // version[0]: builder version (runtime version is mixed in at runtime)
72     // version[1]: bits 7..3=u, bits 2..0=v
73     // version[2]: bits 7..6=w, bits 5..0=r
74     // version[3]= (s<<5)+(s>>3)+t+(q<<4)+(q>>4)
75     UVersionInfo version;
76 
77     // owned objects
78     CollationData *ownedData;
79     UObject *builder;
80     UDataMemory *memory;
81     UResourceBundle *bundle;
82     UTrie2 *trie;
83     UnicodeSet *unsafeBackwardSet;
84     mutable UHashtable *maxExpansions;
85     mutable UInitOnce maxExpansionsInitOnce;
86 
87 private:
88     /**
89      * No copy constructor: A CollationTailoring cannot be copied.
90      * It is immutable, and the data trie cannot be copied either.
91      */
92     CollationTailoring(const CollationTailoring &other);
93 };
94 
95 struct CollationCacheEntry : public SharedObject {
CollationCacheEntryCollationCacheEntry96     CollationCacheEntry(const Locale &loc, const CollationTailoring *t)
97             : validLocale(loc), tailoring(t) {
98         if(t != NULL) {
99             t->addRef();
100         }
101     }
102     ~CollationCacheEntry();
103 
104     Locale validLocale;
105     const CollationTailoring *tailoring;
106 };
107 
108 U_NAMESPACE_END
109 
110 #endif  // !UCONFIG_NO_COLLATION
111 #endif  // __COLLATIONTAILORING_H__
112