|
||||
File indexing completed on 2025-01-18 10:13:07
0001 // © 2016 and later: Unicode, Inc. and others. 0002 // License & terms of use: http://www.unicode.org/copyright.html 0003 /* 0004 ******************************************************************************* 0005 * Copyright (C) 2014-2016, International Business Machines Corporation and others. 0006 * All Rights Reserved. 0007 ******************************************************************************* 0008 */ 0009 0010 #ifndef REGION_H 0011 #define REGION_H 0012 0013 /** 0014 * \file 0015 * \brief C++ API: Region classes (territory containment) 0016 */ 0017 0018 #include "unicode/utypes.h" 0019 0020 #if U_SHOW_CPLUSPLUS_API 0021 0022 #if !UCONFIG_NO_FORMATTING 0023 0024 #include "unicode/uregion.h" 0025 #include "unicode/uobject.h" 0026 #include "unicode/uniset.h" 0027 #include "unicode/unistr.h" 0028 #include "unicode/strenum.h" 0029 0030 U_NAMESPACE_BEGIN 0031 0032 /** 0033 * <code>Region</code> is the class representing a Unicode Region Code, also known as a 0034 * Unicode Region Subtag, which is defined based upon the BCP 47 standard. We often think of 0035 * "regions" as "countries" when defining the characteristics of a locale. Region codes There are different 0036 * types of region codes that are important to distinguish. 0037 * <p> 0038 * Macroregion - A code for a "macro geographical (continental) region, geographical sub-region, or 0039 * selected economic and other grouping" as defined in 0040 * UN M.49 (http://unstats.un.org/unsd/methods/m49/m49regin.htm). 0041 * These are typically 3-digit codes, but contain some 2-letter codes, such as the LDML code QO 0042 * added for Outlying Oceania. Not all UNM.49 codes are defined in LDML, but most of them are. 0043 * Macroregions are represented in ICU by one of three region types: WORLD ( region code 001 ), 0044 * CONTINENTS ( regions contained directly by WORLD ), and SUBCONTINENTS ( things contained directly 0045 * by a continent ). 0046 * <p> 0047 * TERRITORY - A Region that is not a Macroregion. These are typically codes for countries, but also 0048 * include areas that are not separate countries, such as the code "AQ" for Antarctica or the code 0049 * "HK" for Hong Kong (SAR China). Overseas dependencies of countries may or may not have separate 0050 * codes. The codes are typically 2-letter codes aligned with the ISO 3166 standard, but BCP47 allows 0051 * for the use of 3-digit codes in the future. 0052 * <p> 0053 * UNKNOWN - The code ZZ is defined by Unicode LDML for use to indicate that the Region is unknown, 0054 * or that the value supplied as a region was invalid. 0055 * <p> 0056 * DEPRECATED - Region codes that have been defined in the past but are no longer in modern usage, 0057 * usually due to a country splitting into multiple territories or changing its name. 0058 * <p> 0059 * GROUPING - A widely understood grouping of territories that has a well defined membership such 0060 * that a region code has been assigned for it. Some of these are UNM.49 codes that do't fall into 0061 * the world/continent/sub-continent hierarchy, while others are just well known groupings that have 0062 * their own region code. Region "EU" (European Union) is one such region code that is a grouping. 0063 * Groupings will never be returned by the getContainingRegion() API, since a different type of region 0064 * ( WORLD, CONTINENT, or SUBCONTINENT ) will always be the containing region instead. 0065 * 0066 * The Region class is not intended for public subclassing. 0067 * 0068 * @author John Emmons 0069 * @stable ICU 51 0070 */ 0071 0072 class U_I18N_API Region : public UObject { 0073 public: 0074 /** 0075 * Destructor. 0076 * @stable ICU 51 0077 */ 0078 virtual ~Region(); 0079 0080 /** 0081 * Returns true if the two regions are equal. 0082 * @stable ICU 51 0083 */ 0084 bool operator==(const Region &that) const; 0085 0086 /** 0087 * Returns true if the two regions are NOT equal; that is, if operator ==() returns false. 0088 * @stable ICU 51 0089 */ 0090 bool operator!=(const Region &that) const; 0091 0092 /** 0093 * Returns a pointer to a Region using the given region code. The region code can be either 2-letter ISO code, 0094 * 3-letter ISO code, UNM.49 numeric code, or other valid Unicode Region Code as defined by the LDML specification. 0095 * The identifier will be canonicalized internally using the supplemental metadata as defined in the CLDR. 0096 * If the region code is nullptr or not recognized, the appropriate error code will be set ( U_ILLEGAL_ARGUMENT_ERROR ) 0097 * @stable ICU 51 0098 */ 0099 static const Region* U_EXPORT2 getInstance(const char *region_code, UErrorCode &status); 0100 0101 /** 0102 * Returns a pointer to a Region using the given numeric region code. If the numeric region code is not recognized, 0103 * the appropriate error code will be set ( U_ILLEGAL_ARGUMENT_ERROR ). 0104 * @stable ICU 51 0105 */ 0106 static const Region* U_EXPORT2 getInstance (int32_t code, UErrorCode &status); 0107 0108 /** 0109 * Returns an enumeration over the IDs of all known regions that match the given type. 0110 * @stable ICU 55 0111 */ 0112 static StringEnumeration* U_EXPORT2 getAvailable(URegionType type, UErrorCode &status); 0113 0114 /** 0115 * Returns a pointer to the region that contains this region. Returns nullptr if this region is code "001" (World) 0116 * or "ZZ" (Unknown region). For example, calling this method with region "IT" (Italy) returns the 0117 * region "039" (Southern Europe). 0118 * @stable ICU 51 0119 */ 0120 const Region* getContainingRegion() const; 0121 0122 /** 0123 * Return a pointer to the region that geographically contains this region and matches the given type, 0124 * moving multiple steps up the containment chain if necessary. Returns nullptr if no containing region can be found 0125 * that matches the given type. Note: The URegionTypes = "URGN_GROUPING", "URGN_DEPRECATED", or "URGN_UNKNOWN" 0126 * are not appropriate for use in this API. nullptr will be returned in this case. For example, calling this method 0127 * with region "IT" (Italy) for type "URGN_CONTINENT" returns the region "150" ( Europe ). 0128 * @stable ICU 51 0129 */ 0130 const Region* getContainingRegion(URegionType type) const; 0131 0132 /** 0133 * Return an enumeration over the IDs of all the regions that are immediate children of this region in the 0134 * region hierarchy. These returned regions could be either macro regions, territories, or a mixture of the two, 0135 * depending on the containment data as defined in CLDR. This API may return nullptr if this region doesn't have 0136 * any sub-regions. For example, calling this method with region "150" (Europe) returns an enumeration containing 0137 * the various sub regions of Europe - "039" (Southern Europe) - "151" (Eastern Europe) - "154" (Northern Europe) 0138 * and "155" (Western Europe). 0139 * @stable ICU 55 0140 */ 0141 StringEnumeration* getContainedRegions(UErrorCode &status) const; 0142 0143 /** 0144 * Returns an enumeration over the IDs of all the regions that are children of this region anywhere in the region 0145 * hierarchy and match the given type. This API may return an empty enumeration if this region doesn't have any 0146 * sub-regions that match the given type. For example, calling this method with region "150" (Europe) and type 0147 * "URGN_TERRITORY" returns a set containing all the territories in Europe ( "FR" (France) - "IT" (Italy) - "DE" (Germany) etc. ) 0148 * @stable ICU 55 0149 */ 0150 StringEnumeration* getContainedRegions( URegionType type, UErrorCode &status ) const; 0151 0152 /** 0153 * Returns true if this region contains the supplied other region anywhere in the region hierarchy. 0154 * @stable ICU 51 0155 */ 0156 UBool contains(const Region &other) const; 0157 0158 /** 0159 * For deprecated regions, return an enumeration over the IDs of the regions that are the preferred replacement 0160 * regions for this region. Returns null for a non-deprecated region. For example, calling this method with region 0161 * "SU" (Soviet Union) would return a list of the regions containing "RU" (Russia), "AM" (Armenia), "AZ" (Azerbaijan), etc... 0162 * @stable ICU 55 0163 */ 0164 StringEnumeration* getPreferredValues(UErrorCode &status) const; 0165 0166 /** 0167 * Return this region's canonical region code. 0168 * @stable ICU 51 0169 */ 0170 const char* getRegionCode() const; 0171 0172 /** 0173 * Return this region's numeric code. 0174 * Returns a negative value if the given region does not have a numeric code assigned to it. 0175 * @stable ICU 51 0176 */ 0177 int32_t getNumericCode() const; 0178 0179 /** 0180 * Returns the region type of this region. 0181 * @stable ICU 51 0182 */ 0183 URegionType getType() const; 0184 0185 #ifndef U_HIDE_INTERNAL_API 0186 /** 0187 * Cleans up statically allocated memory. 0188 * @internal 0189 */ 0190 static void cleanupRegionData(); 0191 #endif /* U_HIDE_INTERNAL_API */ 0192 0193 private: 0194 char id[4]; 0195 UnicodeString idStr; 0196 int32_t code; 0197 URegionType fType; 0198 Region *containingRegion; 0199 UVector *containedRegions; 0200 UVector *preferredValues; 0201 0202 /** 0203 * Default Constructor. Internal - use factory methods only. 0204 */ 0205 Region(); 0206 0207 0208 /* 0209 * Initializes the region data from the ICU resource bundles. The region data 0210 * contains the basic relationships such as which regions are known, what the numeric 0211 * codes are, any known aliases, and the territory containment data. 0212 * 0213 * If the region data has already loaded, then this method simply returns without doing 0214 * anything meaningful. 0215 */ 0216 0217 static void U_CALLCONV loadRegionData(UErrorCode &status); 0218 0219 }; 0220 0221 U_NAMESPACE_END 0222 0223 #endif /* #if !UCONFIG_NO_FORMATTING */ 0224 0225 #endif /* U_SHOW_CPLUSPLUS_API */ 0226 0227 #endif // REGION_H 0228 0229 //eof
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |