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) 2014-2016, International Business Machines Corporation and others. 6*0e209d39SAndroid Build Coastguard Worker * All Rights Reserved. 7*0e209d39SAndroid Build Coastguard Worker ******************************************************************************* 8*0e209d39SAndroid Build Coastguard Worker */ 9*0e209d39SAndroid Build Coastguard Worker 10*0e209d39SAndroid Build Coastguard Worker #ifndef REGION_H 11*0e209d39SAndroid Build Coastguard Worker #define REGION_H 12*0e209d39SAndroid Build Coastguard Worker 13*0e209d39SAndroid Build Coastguard Worker /** 14*0e209d39SAndroid Build Coastguard Worker * \file 15*0e209d39SAndroid Build Coastguard Worker * \brief C++ API: Region classes (territory containment) 16*0e209d39SAndroid Build Coastguard Worker */ 17*0e209d39SAndroid Build Coastguard Worker 18*0e209d39SAndroid Build Coastguard Worker #include "unicode/utypes.h" 19*0e209d39SAndroid Build Coastguard Worker 20*0e209d39SAndroid Build Coastguard Worker #if U_SHOW_CPLUSPLUS_API 21*0e209d39SAndroid Build Coastguard Worker 22*0e209d39SAndroid Build Coastguard Worker #if !UCONFIG_NO_FORMATTING 23*0e209d39SAndroid Build Coastguard Worker 24*0e209d39SAndroid Build Coastguard Worker #include "unicode/uregion.h" 25*0e209d39SAndroid Build Coastguard Worker #include "unicode/uobject.h" 26*0e209d39SAndroid Build Coastguard Worker #include "unicode/uniset.h" 27*0e209d39SAndroid Build Coastguard Worker #include "unicode/unistr.h" 28*0e209d39SAndroid Build Coastguard Worker #include "unicode/strenum.h" 29*0e209d39SAndroid Build Coastguard Worker 30*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_BEGIN 31*0e209d39SAndroid Build Coastguard Worker 32*0e209d39SAndroid Build Coastguard Worker /** 33*0e209d39SAndroid Build Coastguard Worker * <code>Region</code> is the class representing a Unicode Region Code, also known as a 34*0e209d39SAndroid Build Coastguard Worker * Unicode Region Subtag, which is defined based upon the BCP 47 standard. We often think of 35*0e209d39SAndroid Build Coastguard Worker * "regions" as "countries" when defining the characteristics of a locale. Region codes There are different 36*0e209d39SAndroid Build Coastguard Worker * types of region codes that are important to distinguish. 37*0e209d39SAndroid Build Coastguard Worker * <p> 38*0e209d39SAndroid Build Coastguard Worker * Macroregion - A code for a "macro geographical (continental) region, geographical sub-region, or 39*0e209d39SAndroid Build Coastguard Worker * selected economic and other grouping" as defined in 40*0e209d39SAndroid Build Coastguard Worker * UN M.49 (http://unstats.un.org/unsd/methods/m49/m49regin.htm). 41*0e209d39SAndroid Build Coastguard Worker * These are typically 3-digit codes, but contain some 2-letter codes, such as the LDML code QO 42*0e209d39SAndroid Build Coastguard Worker * added for Outlying Oceania. Not all UNM.49 codes are defined in LDML, but most of them are. 43*0e209d39SAndroid Build Coastguard Worker * Macroregions are represented in ICU by one of three region types: WORLD ( region code 001 ), 44*0e209d39SAndroid Build Coastguard Worker * CONTINENTS ( regions contained directly by WORLD ), and SUBCONTINENTS ( things contained directly 45*0e209d39SAndroid Build Coastguard Worker * by a continent ). 46*0e209d39SAndroid Build Coastguard Worker * <p> 47*0e209d39SAndroid Build Coastguard Worker * TERRITORY - A Region that is not a Macroregion. These are typically codes for countries, but also 48*0e209d39SAndroid Build Coastguard Worker * include areas that are not separate countries, such as the code "AQ" for Antarctica or the code 49*0e209d39SAndroid Build Coastguard Worker * "HK" for Hong Kong (SAR China). Overseas dependencies of countries may or may not have separate 50*0e209d39SAndroid Build Coastguard Worker * codes. The codes are typically 2-letter codes aligned with the ISO 3166 standard, but BCP47 allows 51*0e209d39SAndroid Build Coastguard Worker * for the use of 3-digit codes in the future. 52*0e209d39SAndroid Build Coastguard Worker * <p> 53*0e209d39SAndroid Build Coastguard Worker * UNKNOWN - The code ZZ is defined by Unicode LDML for use to indicate that the Region is unknown, 54*0e209d39SAndroid Build Coastguard Worker * or that the value supplied as a region was invalid. 55*0e209d39SAndroid Build Coastguard Worker * <p> 56*0e209d39SAndroid Build Coastguard Worker * DEPRECATED - Region codes that have been defined in the past but are no longer in modern usage, 57*0e209d39SAndroid Build Coastguard Worker * usually due to a country splitting into multiple territories or changing its name. 58*0e209d39SAndroid Build Coastguard Worker * <p> 59*0e209d39SAndroid Build Coastguard Worker * GROUPING - A widely understood grouping of territories that has a well defined membership such 60*0e209d39SAndroid Build Coastguard Worker * that a region code has been assigned for it. Some of these are UNM.49 codes that do't fall into 61*0e209d39SAndroid Build Coastguard Worker * the world/continent/sub-continent hierarchy, while others are just well known groupings that have 62*0e209d39SAndroid Build Coastguard Worker * their own region code. Region "EU" (European Union) is one such region code that is a grouping. 63*0e209d39SAndroid Build Coastguard Worker * Groupings will never be returned by the getContainingRegion() API, since a different type of region 64*0e209d39SAndroid Build Coastguard Worker * ( WORLD, CONTINENT, or SUBCONTINENT ) will always be the containing region instead. 65*0e209d39SAndroid Build Coastguard Worker * 66*0e209d39SAndroid Build Coastguard Worker * The Region class is not intended for public subclassing. 67*0e209d39SAndroid Build Coastguard Worker * 68*0e209d39SAndroid Build Coastguard Worker * @author John Emmons 69*0e209d39SAndroid Build Coastguard Worker * @stable ICU 51 70*0e209d39SAndroid Build Coastguard Worker */ 71*0e209d39SAndroid Build Coastguard Worker 72*0e209d39SAndroid Build Coastguard Worker class U_I18N_API Region : public UObject { 73*0e209d39SAndroid Build Coastguard Worker public: 74*0e209d39SAndroid Build Coastguard Worker /** 75*0e209d39SAndroid Build Coastguard Worker * Destructor. 76*0e209d39SAndroid Build Coastguard Worker * @stable ICU 51 77*0e209d39SAndroid Build Coastguard Worker */ 78*0e209d39SAndroid Build Coastguard Worker virtual ~Region(); 79*0e209d39SAndroid Build Coastguard Worker 80*0e209d39SAndroid Build Coastguard Worker /** 81*0e209d39SAndroid Build Coastguard Worker * Returns true if the two regions are equal. 82*0e209d39SAndroid Build Coastguard Worker * @stable ICU 51 83*0e209d39SAndroid Build Coastguard Worker */ 84*0e209d39SAndroid Build Coastguard Worker bool operator==(const Region &that) const; 85*0e209d39SAndroid Build Coastguard Worker 86*0e209d39SAndroid Build Coastguard Worker /** 87*0e209d39SAndroid Build Coastguard Worker * Returns true if the two regions are NOT equal; that is, if operator ==() returns false. 88*0e209d39SAndroid Build Coastguard Worker * @stable ICU 51 89*0e209d39SAndroid Build Coastguard Worker */ 90*0e209d39SAndroid Build Coastguard Worker bool operator!=(const Region &that) const; 91*0e209d39SAndroid Build Coastguard Worker 92*0e209d39SAndroid Build Coastguard Worker /** 93*0e209d39SAndroid Build Coastguard Worker * Returns a pointer to a Region using the given region code. The region code can be either 2-letter ISO code, 94*0e209d39SAndroid Build Coastguard Worker * 3-letter ISO code, UNM.49 numeric code, or other valid Unicode Region Code as defined by the LDML specification. 95*0e209d39SAndroid Build Coastguard Worker * The identifier will be canonicalized internally using the supplemental metadata as defined in the CLDR. 96*0e209d39SAndroid Build Coastguard Worker * If the region code is nullptr or not recognized, the appropriate error code will be set ( U_ILLEGAL_ARGUMENT_ERROR ) 97*0e209d39SAndroid Build Coastguard Worker * @stable ICU 51 98*0e209d39SAndroid Build Coastguard Worker */ 99*0e209d39SAndroid Build Coastguard Worker static const Region* U_EXPORT2 getInstance(const char *region_code, UErrorCode &status); 100*0e209d39SAndroid Build Coastguard Worker 101*0e209d39SAndroid Build Coastguard Worker /** 102*0e209d39SAndroid Build Coastguard Worker * Returns a pointer to a Region using the given numeric region code. If the numeric region code is not recognized, 103*0e209d39SAndroid Build Coastguard Worker * the appropriate error code will be set ( U_ILLEGAL_ARGUMENT_ERROR ). 104*0e209d39SAndroid Build Coastguard Worker * @stable ICU 51 105*0e209d39SAndroid Build Coastguard Worker */ 106*0e209d39SAndroid Build Coastguard Worker static const Region* U_EXPORT2 getInstance (int32_t code, UErrorCode &status); 107*0e209d39SAndroid Build Coastguard Worker 108*0e209d39SAndroid Build Coastguard Worker /** 109*0e209d39SAndroid Build Coastguard Worker * Returns an enumeration over the IDs of all known regions that match the given type. 110*0e209d39SAndroid Build Coastguard Worker * @stable ICU 55 111*0e209d39SAndroid Build Coastguard Worker */ 112*0e209d39SAndroid Build Coastguard Worker static StringEnumeration* U_EXPORT2 getAvailable(URegionType type, UErrorCode &status); 113*0e209d39SAndroid Build Coastguard Worker 114*0e209d39SAndroid Build Coastguard Worker /** 115*0e209d39SAndroid Build Coastguard Worker * Returns a pointer to the region that contains this region. Returns nullptr if this region is code "001" (World) 116*0e209d39SAndroid Build Coastguard Worker * or "ZZ" (Unknown region). For example, calling this method with region "IT" (Italy) returns the 117*0e209d39SAndroid Build Coastguard Worker * region "039" (Southern Europe). 118*0e209d39SAndroid Build Coastguard Worker * @stable ICU 51 119*0e209d39SAndroid Build Coastguard Worker */ 120*0e209d39SAndroid Build Coastguard Worker const Region* getContainingRegion() const; 121*0e209d39SAndroid Build Coastguard Worker 122*0e209d39SAndroid Build Coastguard Worker /** 123*0e209d39SAndroid Build Coastguard Worker * Return a pointer to the region that geographically contains this region and matches the given type, 124*0e209d39SAndroid Build Coastguard Worker * moving multiple steps up the containment chain if necessary. Returns nullptr if no containing region can be found 125*0e209d39SAndroid Build Coastguard Worker * that matches the given type. Note: The URegionTypes = "URGN_GROUPING", "URGN_DEPRECATED", or "URGN_UNKNOWN" 126*0e209d39SAndroid Build Coastguard Worker * are not appropriate for use in this API. nullptr will be returned in this case. For example, calling this method 127*0e209d39SAndroid Build Coastguard Worker * with region "IT" (Italy) for type "URGN_CONTINENT" returns the region "150" ( Europe ). 128*0e209d39SAndroid Build Coastguard Worker * @stable ICU 51 129*0e209d39SAndroid Build Coastguard Worker */ 130*0e209d39SAndroid Build Coastguard Worker const Region* getContainingRegion(URegionType type) const; 131*0e209d39SAndroid Build Coastguard Worker 132*0e209d39SAndroid Build Coastguard Worker /** 133*0e209d39SAndroid Build Coastguard Worker * Return an enumeration over the IDs of all the regions that are immediate children of this region in the 134*0e209d39SAndroid Build Coastguard Worker * region hierarchy. These returned regions could be either macro regions, territories, or a mixture of the two, 135*0e209d39SAndroid Build Coastguard Worker * depending on the containment data as defined in CLDR. This API may return nullptr if this region doesn't have 136*0e209d39SAndroid Build Coastguard Worker * any sub-regions. For example, calling this method with region "150" (Europe) returns an enumeration containing 137*0e209d39SAndroid Build Coastguard Worker * the various sub regions of Europe - "039" (Southern Europe) - "151" (Eastern Europe) - "154" (Northern Europe) 138*0e209d39SAndroid Build Coastguard Worker * and "155" (Western Europe). 139*0e209d39SAndroid Build Coastguard Worker * @stable ICU 55 140*0e209d39SAndroid Build Coastguard Worker */ 141*0e209d39SAndroid Build Coastguard Worker StringEnumeration* getContainedRegions(UErrorCode &status) const; 142*0e209d39SAndroid Build Coastguard Worker 143*0e209d39SAndroid Build Coastguard Worker /** 144*0e209d39SAndroid Build Coastguard Worker * Returns an enumeration over the IDs of all the regions that are children of this region anywhere in the region 145*0e209d39SAndroid Build Coastguard Worker * hierarchy and match the given type. This API may return an empty enumeration if this region doesn't have any 146*0e209d39SAndroid Build Coastguard Worker * sub-regions that match the given type. For example, calling this method with region "150" (Europe) and type 147*0e209d39SAndroid Build Coastguard Worker * "URGN_TERRITORY" returns a set containing all the territories in Europe ( "FR" (France) - "IT" (Italy) - "DE" (Germany) etc. ) 148*0e209d39SAndroid Build Coastguard Worker * @stable ICU 55 149*0e209d39SAndroid Build Coastguard Worker */ 150*0e209d39SAndroid Build Coastguard Worker StringEnumeration* getContainedRegions( URegionType type, UErrorCode &status ) const; 151*0e209d39SAndroid Build Coastguard Worker 152*0e209d39SAndroid Build Coastguard Worker /** 153*0e209d39SAndroid Build Coastguard Worker * Returns true if this region contains the supplied other region anywhere in the region hierarchy. 154*0e209d39SAndroid Build Coastguard Worker * @stable ICU 51 155*0e209d39SAndroid Build Coastguard Worker */ 156*0e209d39SAndroid Build Coastguard Worker UBool contains(const Region &other) const; 157*0e209d39SAndroid Build Coastguard Worker 158*0e209d39SAndroid Build Coastguard Worker /** 159*0e209d39SAndroid Build Coastguard Worker * For deprecated regions, return an enumeration over the IDs of the regions that are the preferred replacement 160*0e209d39SAndroid Build Coastguard Worker * regions for this region. Returns null for a non-deprecated region. For example, calling this method with region 161*0e209d39SAndroid Build Coastguard Worker * "SU" (Soviet Union) would return a list of the regions containing "RU" (Russia), "AM" (Armenia), "AZ" (Azerbaijan), etc... 162*0e209d39SAndroid Build Coastguard Worker * @stable ICU 55 163*0e209d39SAndroid Build Coastguard Worker */ 164*0e209d39SAndroid Build Coastguard Worker StringEnumeration* getPreferredValues(UErrorCode &status) const; 165*0e209d39SAndroid Build Coastguard Worker 166*0e209d39SAndroid Build Coastguard Worker /** 167*0e209d39SAndroid Build Coastguard Worker * Return this region's canonical region code. 168*0e209d39SAndroid Build Coastguard Worker * @stable ICU 51 169*0e209d39SAndroid Build Coastguard Worker */ 170*0e209d39SAndroid Build Coastguard Worker const char* getRegionCode() const; 171*0e209d39SAndroid Build Coastguard Worker 172*0e209d39SAndroid Build Coastguard Worker /** 173*0e209d39SAndroid Build Coastguard Worker * Return this region's numeric code. 174*0e209d39SAndroid Build Coastguard Worker * Returns a negative value if the given region does not have a numeric code assigned to it. 175*0e209d39SAndroid Build Coastguard Worker * @stable ICU 51 176*0e209d39SAndroid Build Coastguard Worker */ 177*0e209d39SAndroid Build Coastguard Worker int32_t getNumericCode() const; 178*0e209d39SAndroid Build Coastguard Worker 179*0e209d39SAndroid Build Coastguard Worker /** 180*0e209d39SAndroid Build Coastguard Worker * Returns the region type of this region. 181*0e209d39SAndroid Build Coastguard Worker * @stable ICU 51 182*0e209d39SAndroid Build Coastguard Worker */ 183*0e209d39SAndroid Build Coastguard Worker URegionType getType() const; 184*0e209d39SAndroid Build Coastguard Worker 185*0e209d39SAndroid Build Coastguard Worker #ifndef U_HIDE_INTERNAL_API 186*0e209d39SAndroid Build Coastguard Worker /** 187*0e209d39SAndroid Build Coastguard Worker * Cleans up statically allocated memory. 188*0e209d39SAndroid Build Coastguard Worker * @internal 189*0e209d39SAndroid Build Coastguard Worker */ 190*0e209d39SAndroid Build Coastguard Worker static void cleanupRegionData(); 191*0e209d39SAndroid Build Coastguard Worker #endif /* U_HIDE_INTERNAL_API */ 192*0e209d39SAndroid Build Coastguard Worker 193*0e209d39SAndroid Build Coastguard Worker private: 194*0e209d39SAndroid Build Coastguard Worker char id[4]; 195*0e209d39SAndroid Build Coastguard Worker UnicodeString idStr; 196*0e209d39SAndroid Build Coastguard Worker int32_t code; 197*0e209d39SAndroid Build Coastguard Worker URegionType fType; 198*0e209d39SAndroid Build Coastguard Worker Region *containingRegion; 199*0e209d39SAndroid Build Coastguard Worker UVector *containedRegions; 200*0e209d39SAndroid Build Coastguard Worker UVector *preferredValues; 201*0e209d39SAndroid Build Coastguard Worker 202*0e209d39SAndroid Build Coastguard Worker /** 203*0e209d39SAndroid Build Coastguard Worker * Default Constructor. Internal - use factory methods only. 204*0e209d39SAndroid Build Coastguard Worker */ 205*0e209d39SAndroid Build Coastguard Worker Region(); 206*0e209d39SAndroid Build Coastguard Worker 207*0e209d39SAndroid Build Coastguard Worker 208*0e209d39SAndroid Build Coastguard Worker /* 209*0e209d39SAndroid Build Coastguard Worker * Initializes the region data from the ICU resource bundles. The region data 210*0e209d39SAndroid Build Coastguard Worker * contains the basic relationships such as which regions are known, what the numeric 211*0e209d39SAndroid Build Coastguard Worker * codes are, any known aliases, and the territory containment data. 212*0e209d39SAndroid Build Coastguard Worker * 213*0e209d39SAndroid Build Coastguard Worker * If the region data has already loaded, then this method simply returns without doing 214*0e209d39SAndroid Build Coastguard Worker * anything meaningful. 215*0e209d39SAndroid Build Coastguard Worker */ 216*0e209d39SAndroid Build Coastguard Worker 217*0e209d39SAndroid Build Coastguard Worker static void U_CALLCONV loadRegionData(UErrorCode &status); 218*0e209d39SAndroid Build Coastguard Worker 219*0e209d39SAndroid Build Coastguard Worker }; 220*0e209d39SAndroid Build Coastguard Worker 221*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_END 222*0e209d39SAndroid Build Coastguard Worker 223*0e209d39SAndroid Build Coastguard Worker #endif /* #if !UCONFIG_NO_FORMATTING */ 224*0e209d39SAndroid Build Coastguard Worker 225*0e209d39SAndroid Build Coastguard Worker #endif /* U_SHOW_CPLUSPLUS_API */ 226*0e209d39SAndroid Build Coastguard Worker 227*0e209d39SAndroid Build Coastguard Worker #endif // REGION_H 228*0e209d39SAndroid Build Coastguard Worker 229*0e209d39SAndroid Build Coastguard Worker //eof 230