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