sl@0: /* sl@0: ********************************************************************** sl@0: * Copyright (c) 2004, International Business Machines sl@0: * Corporation and others. All Rights Reserved. sl@0: ********************************************************************** sl@0: * Author: Alan Liu sl@0: * Created: January 16 2004 sl@0: * Since: ICU 2.8 sl@0: ********************************************************************** sl@0: */ sl@0: #ifndef LOCBASED_H sl@0: #define LOCBASED_H sl@0: sl@0: #include "unicode/locid.h" sl@0: #include "unicode/uobject.h" sl@0: sl@0: /** sl@0: * Macro to declare a locale LocaleBased wrapper object for the given sl@0: * object, which must have two members named `validLocale' and sl@0: * `actualLocale'. sl@0: */ sl@0: #define U_LOCALE_BASED(varname, objname) \ sl@0: LocaleBased varname((objname).validLocale, (objname).actualLocale); sl@0: sl@0: U_NAMESPACE_BEGIN sl@0: sl@0: /** sl@0: * A utility class that unifies the implementation of getLocale() by sl@0: * various ICU services. This class is likely to be removed in the sl@0: * ICU 3.0 time frame in favor of an integrated approach with the sl@0: * services framework. sl@0: * @since ICU 2.8 sl@0: */ sl@0: class U_COMMON_API LocaleBased : public UMemory { sl@0: sl@0: public: sl@0: sl@0: /** sl@0: * Construct a LocaleBased wrapper around the two pointers. These sl@0: * will be aliased for the lifetime of this object. sl@0: */ sl@0: inline LocaleBased(char* validAlias, char* actualAlias); sl@0: sl@0: /** sl@0: * Construct a LocaleBased wrapper around the two const pointers. sl@0: * These will be aliased for the lifetime of this object. sl@0: */ sl@0: inline LocaleBased(const char* validAlias, const char* actualAlias); sl@0: sl@0: /** sl@0: * Return locale meta-data for the service object wrapped by this sl@0: * object. Either the valid or the actual locale may be sl@0: * retrieved. sl@0: * @param type either ULOC_VALID_LOCALE or ULOC_ACTUAL_LOCALE sl@0: * @param status input-output error code sl@0: * @return the indicated locale sl@0: */ sl@0: Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const; sl@0: sl@0: /** sl@0: * Return the locale ID for the service object wrapped by this sl@0: * object. Either the valid or the actual locale may be sl@0: * retrieved. sl@0: * @param type either ULOC_VALID_LOCALE or ULOC_ACTUAL_LOCALE sl@0: * @param status input-output error code sl@0: * @return the indicated locale ID sl@0: */ sl@0: const char* getLocaleID(ULocDataLocaleType type, UErrorCode& status) const; sl@0: sl@0: /** sl@0: * Set the locale meta-data for the service object wrapped by this sl@0: * object. If either parameter is zero, it is ignored. sl@0: * @param valid the ID of the valid locale sl@0: * @param actual the ID of the actual locale sl@0: */ sl@0: void setLocaleIDs(const char* valid, const char* actual); sl@0: sl@0: private: sl@0: sl@0: char* valid; sl@0: sl@0: char* actual; sl@0: }; sl@0: sl@0: inline LocaleBased::LocaleBased(char* validAlias, char* actualAlias) : sl@0: valid(validAlias), actual(actualAlias) { sl@0: } sl@0: sl@0: inline LocaleBased::LocaleBased(const char* validAlias, sl@0: const char* actualAlias) : sl@0: // ugh: cast away const sl@0: valid((char*)validAlias), actual((char*)actualAlias) { sl@0: } sl@0: sl@0: U_NAMESPACE_END sl@0: sl@0: #endif