locbased.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // © 2016 and later: Unicode, Inc. and others.
  2. // License & terms of use: http://www.unicode.org/copyright.html
  3. /*
  4. **********************************************************************
  5. * Copyright (c) 2004-2014, International Business Machines
  6. * Corporation and others. All Rights Reserved.
  7. **********************************************************************
  8. * Author: Alan Liu
  9. * Created: January 16 2004
  10. * Since: ICU 2.8
  11. **********************************************************************
  12. */
  13. #ifndef LOCBASED_H
  14. #define LOCBASED_H
  15. #include "unicode/locid.h"
  16. #include "unicode/uobject.h"
  17. /**
  18. * Macro to declare a locale LocaleBased wrapper object for the given
  19. * object, which must have two members named `validLocale' and
  20. * `actualLocale' of size ULOC_FULLNAME_CAPACITY
  21. */
  22. #define U_LOCALE_BASED(varname, objname) \
  23. LocaleBased varname((objname).validLocale, (objname).actualLocale)
  24. U_NAMESPACE_BEGIN
  25. /**
  26. * A utility class that unifies the implementation of getLocale() by
  27. * various ICU services. This class is likely to be removed in the
  28. * ICU 3.0 time frame in favor of an integrated approach with the
  29. * services framework.
  30. * @since ICU 2.8
  31. */
  32. class U_COMMON_API LocaleBased : public UMemory {
  33. public:
  34. /**
  35. * Construct a LocaleBased wrapper around the two pointers. These
  36. * will be aliased for the lifetime of this object.
  37. */
  38. inline LocaleBased(char* validAlias, char* actualAlias);
  39. /**
  40. * Construct a LocaleBased wrapper around the two const pointers.
  41. * These will be aliased for the lifetime of this object.
  42. */
  43. inline LocaleBased(const char* validAlias, const char* actualAlias);
  44. /**
  45. * Return locale meta-data for the service object wrapped by this
  46. * object. Either the valid or the actual locale may be
  47. * retrieved.
  48. * @param type either ULOC_VALID_LOCALE or ULOC_ACTUAL_LOCALE
  49. * @param status input-output error code
  50. * @return the indicated locale
  51. */
  52. Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const;
  53. /**
  54. * Return the locale ID for the service object wrapped by this
  55. * object. Either the valid or the actual locale may be
  56. * retrieved.
  57. * @param type either ULOC_VALID_LOCALE or ULOC_ACTUAL_LOCALE
  58. * @param status input-output error code
  59. * @return the indicated locale ID
  60. */
  61. const char* getLocaleID(ULocDataLocaleType type, UErrorCode& status) const;
  62. /**
  63. * Set the locale meta-data for the service object wrapped by this
  64. * object. If either parameter is zero, it is ignored.
  65. * @param valid the ID of the valid locale
  66. * @param actual the ID of the actual locale
  67. */
  68. void setLocaleIDs(const char* valid, const char* actual);
  69. /**
  70. * Set the locale meta-data for the service object wrapped by this
  71. * object.
  72. * @param valid the ID of the valid locale
  73. * @param actual the ID of the actual locale
  74. */
  75. void setLocaleIDs(const Locale& valid, const Locale& actual);
  76. private:
  77. char* valid;
  78. char* actual;
  79. };
  80. inline LocaleBased::LocaleBased(char* validAlias, char* actualAlias) :
  81. valid(validAlias), actual(actualAlias) {
  82. }
  83. inline LocaleBased::LocaleBased(const char* validAlias,
  84. const char* actualAlias) :
  85. // ugh: cast away const
  86. valid((char*)validAlias), actual((char*)actualAlias) {
  87. }
  88. U_NAMESPACE_END
  89. #endif