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