collationtailoring.h 3.3 KB

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