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