intl/icu/source/common/locbased.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/intl/icu/source/common/locbased.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,97 @@
     1.4 +/*
     1.5 +**********************************************************************
     1.6 +* Copyright (c) 2004, International Business Machines
     1.7 +* Corporation and others.  All Rights Reserved.
     1.8 +**********************************************************************
     1.9 +* Author: Alan Liu
    1.10 +* Created: January 16 2004
    1.11 +* Since: ICU 2.8
    1.12 +**********************************************************************
    1.13 +*/
    1.14 +#ifndef LOCBASED_H
    1.15 +#define LOCBASED_H
    1.16 +
    1.17 +#include "unicode/locid.h"
    1.18 +#include "unicode/uobject.h"
    1.19 +
    1.20 +/**
    1.21 + * Macro to declare a locale LocaleBased wrapper object for the given
    1.22 + * object, which must have two members named `validLocale' and
    1.23 + * `actualLocale'.
    1.24 + */
    1.25 +#define U_LOCALE_BASED(varname, objname) \
    1.26 +  LocaleBased varname((objname).validLocale, (objname).actualLocale);
    1.27 +
    1.28 +U_NAMESPACE_BEGIN
    1.29 +
    1.30 +/**
    1.31 + * A utility class that unifies the implementation of getLocale() by
    1.32 + * various ICU services.  This class is likely to be removed in the
    1.33 + * ICU 3.0 time frame in favor of an integrated approach with the
    1.34 + * services framework.
    1.35 + * @since ICU 2.8
    1.36 + */
    1.37 +class U_COMMON_API LocaleBased : public UMemory {
    1.38 +
    1.39 + public:
    1.40 +
    1.41 +    /**
    1.42 +     * Construct a LocaleBased wrapper around the two pointers.  These
    1.43 +     * will be aliased for the lifetime of this object.
    1.44 +     */
    1.45 +    inline LocaleBased(char* validAlias, char* actualAlias);
    1.46 +
    1.47 +    /**
    1.48 +     * Construct a LocaleBased wrapper around the two const pointers.
    1.49 +     * These will be aliased for the lifetime of this object.
    1.50 +     */
    1.51 +    inline LocaleBased(const char* validAlias, const char* actualAlias);
    1.52 +
    1.53 +    /**
    1.54 +     * Return locale meta-data for the service object wrapped by this
    1.55 +     * object.  Either the valid or the actual locale may be
    1.56 +     * retrieved.
    1.57 +     * @param type either ULOC_VALID_LOCALE or ULOC_ACTUAL_LOCALE
    1.58 +     * @param status input-output error code
    1.59 +     * @return the indicated locale
    1.60 +     */
    1.61 +    Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const;
    1.62 +
    1.63 +    /**
    1.64 +     * Return the locale ID for the service object wrapped by this
    1.65 +     * object.  Either the valid or the actual locale may be
    1.66 +     * retrieved.
    1.67 +     * @param type either ULOC_VALID_LOCALE or ULOC_ACTUAL_LOCALE
    1.68 +     * @param status input-output error code
    1.69 +     * @return the indicated locale ID
    1.70 +     */
    1.71 +    const char* getLocaleID(ULocDataLocaleType type, UErrorCode& status) const;
    1.72 +
    1.73 +    /**
    1.74 +     * Set the locale meta-data for the service object wrapped by this
    1.75 +     * object.  If either parameter is zero, it is ignored.
    1.76 +     * @param valid the ID of the valid locale
    1.77 +     * @param actual the ID of the actual locale
    1.78 +     */
    1.79 +    void setLocaleIDs(const char* valid, const char* actual);
    1.80 +
    1.81 + private:
    1.82 +
    1.83 +    char* valid;
    1.84 +    
    1.85 +    char* actual;
    1.86 +};
    1.87 +
    1.88 +inline LocaleBased::LocaleBased(char* validAlias, char* actualAlias) :
    1.89 +    valid(validAlias), actual(actualAlias) {
    1.90 +}
    1.91 +
    1.92 +inline LocaleBased::LocaleBased(const char* validAlias,
    1.93 +                                const char* actualAlias) :
    1.94 +    // ugh: cast away const
    1.95 +    valid((char*)validAlias), actual((char*)actualAlias) {
    1.96 +}
    1.97 +
    1.98 +U_NAMESPACE_END
    1.99 +
   1.100 +#endif

mercurial