jpayne@69: // © 2016 and later: Unicode, Inc. and others.
jpayne@69: // License & terms of use: http://www.unicode.org/copyright.html
jpayne@69: /*
jpayne@69: *******************************************************************************
jpayne@69: * Copyright (C) 2014-2016, International Business Machines Corporation and others.
jpayne@69: * All Rights Reserved.
jpayne@69: *******************************************************************************
jpayne@69: */
jpayne@69:
jpayne@69: #ifndef REGION_H
jpayne@69: #define REGION_H
jpayne@69:
jpayne@69: /**
jpayne@69: * \file
jpayne@69: * \brief C++ API: Region classes (territory containment)
jpayne@69: */
jpayne@69:
jpayne@69: #include "unicode/utypes.h"
jpayne@69:
jpayne@69: #if U_SHOW_CPLUSPLUS_API
jpayne@69:
jpayne@69: #if !UCONFIG_NO_FORMATTING
jpayne@69:
jpayne@69: #include "unicode/uregion.h"
jpayne@69: #include "unicode/uobject.h"
jpayne@69: #include "unicode/uniset.h"
jpayne@69: #include "unicode/unistr.h"
jpayne@69: #include "unicode/strenum.h"
jpayne@69:
jpayne@69: U_NAMESPACE_BEGIN
jpayne@69:
jpayne@69: /**
jpayne@69: * Region
is the class representing a Unicode Region Code, also known as a
jpayne@69: * Unicode Region Subtag, which is defined based upon the BCP 47 standard. We often think of
jpayne@69: * "regions" as "countries" when defining the characteristics of a locale. Region codes There are different
jpayne@69: * types of region codes that are important to distinguish.
jpayne@69: *
jpayne@69: * Macroregion - A code for a "macro geographical (continental) region, geographical sub-region, or jpayne@69: * selected economic and other grouping" as defined in jpayne@69: * UN M.49 (http://unstats.un.org/unsd/methods/m49/m49regin.htm). jpayne@69: * These are typically 3-digit codes, but contain some 2-letter codes, such as the LDML code QO jpayne@69: * added for Outlying Oceania. Not all UNM.49 codes are defined in LDML, but most of them are. jpayne@69: * Macroregions are represented in ICU by one of three region types: WORLD ( region code 001 ), jpayne@69: * CONTINENTS ( regions contained directly by WORLD ), and SUBCONTINENTS ( things contained directly jpayne@69: * by a continent ). jpayne@69: *
jpayne@69: * TERRITORY - A Region that is not a Macroregion. These are typically codes for countries, but also jpayne@69: * include areas that are not separate countries, such as the code "AQ" for Antarctica or the code jpayne@69: * "HK" for Hong Kong (SAR China). Overseas dependencies of countries may or may not have separate jpayne@69: * codes. The codes are typically 2-letter codes aligned with the ISO 3166 standard, but BCP47 allows jpayne@69: * for the use of 3-digit codes in the future. jpayne@69: *
jpayne@69: * UNKNOWN - The code ZZ is defined by Unicode LDML for use to indicate that the Region is unknown, jpayne@69: * or that the value supplied as a region was invalid. jpayne@69: *
jpayne@69: * DEPRECATED - Region codes that have been defined in the past but are no longer in modern usage, jpayne@69: * usually due to a country splitting into multiple territories or changing its name. jpayne@69: *
jpayne@69: * GROUPING - A widely understood grouping of territories that has a well defined membership such jpayne@69: * that a region code has been assigned for it. Some of these are UNM.49 codes that do't fall into jpayne@69: * the world/continent/sub-continent hierarchy, while others are just well known groupings that have jpayne@69: * their own region code. Region "EU" (European Union) is one such region code that is a grouping. jpayne@69: * Groupings will never be returned by the getContainingRegion() API, since a different type of region jpayne@69: * ( WORLD, CONTINENT, or SUBCONTINENT ) will always be the containing region instead. jpayne@69: * jpayne@69: * The Region class is not intended for public subclassing. jpayne@69: * jpayne@69: * @author John Emmons jpayne@69: * @stable ICU 51 jpayne@69: */ jpayne@69: jpayne@69: class U_I18N_API Region : public UObject { jpayne@69: public: jpayne@69: /** jpayne@69: * Destructor. jpayne@69: * @stable ICU 51 jpayne@69: */ jpayne@69: virtual ~Region(); jpayne@69: jpayne@69: /** jpayne@69: * Returns true if the two regions are equal. jpayne@69: * @stable ICU 51 jpayne@69: */ jpayne@69: UBool operator==(const Region &that) const; jpayne@69: jpayne@69: /** jpayne@69: * Returns true if the two regions are NOT equal; that is, if operator ==() returns false. jpayne@69: * @stable ICU 51 jpayne@69: */ jpayne@69: UBool operator!=(const Region &that) const; jpayne@69: jpayne@69: /** jpayne@69: * Returns a pointer to a Region using the given region code. The region code can be either 2-letter ISO code, jpayne@69: * 3-letter ISO code, UNM.49 numeric code, or other valid Unicode Region Code as defined by the LDML specification. jpayne@69: * The identifier will be canonicalized internally using the supplemental metadata as defined in the CLDR. jpayne@69: * If the region code is NULL or not recognized, the appropriate error code will be set ( U_ILLEGAL_ARGUMENT_ERROR ) jpayne@69: * @stable ICU 51 jpayne@69: */ jpayne@69: static const Region* U_EXPORT2 getInstance(const char *region_code, UErrorCode &status); jpayne@69: jpayne@69: /** jpayne@69: * Returns a pointer to a Region using the given numeric region code. If the numeric region code is not recognized, jpayne@69: * the appropriate error code will be set ( U_ILLEGAL_ARGUMENT_ERROR ). jpayne@69: * @stable ICU 51 jpayne@69: */ jpayne@69: static const Region* U_EXPORT2 getInstance (int32_t code, UErrorCode &status); jpayne@69: jpayne@69: /** jpayne@69: * Returns an enumeration over the IDs of all known regions that match the given type. jpayne@69: * @stable ICU 55 jpayne@69: */ jpayne@69: static StringEnumeration* U_EXPORT2 getAvailable(URegionType type, UErrorCode &status); jpayne@69: jpayne@69: /** jpayne@69: * Returns a pointer to the region that contains this region. Returns NULL if this region is code "001" (World) jpayne@69: * or "ZZ" (Unknown region). For example, calling this method with region "IT" (Italy) returns the jpayne@69: * region "039" (Southern Europe). jpayne@69: * @stable ICU 51 jpayne@69: */ jpayne@69: const Region* getContainingRegion() const; jpayne@69: jpayne@69: /** jpayne@69: * Return a pointer to the region that geographically contains this region and matches the given type, jpayne@69: * moving multiple steps up the containment chain if necessary. Returns NULL if no containing region can be found jpayne@69: * that matches the given type. Note: The URegionTypes = "URGN_GROUPING", "URGN_DEPRECATED", or "URGN_UNKNOWN" jpayne@69: * are not appropriate for use in this API. NULL will be returned in this case. For example, calling this method jpayne@69: * with region "IT" (Italy) for type "URGN_CONTINENT" returns the region "150" ( Europe ). jpayne@69: * @stable ICU 51 jpayne@69: */ jpayne@69: const Region* getContainingRegion(URegionType type) const; jpayne@69: jpayne@69: /** jpayne@69: * Return an enumeration over the IDs of all the regions that are immediate children of this region in the jpayne@69: * region hierarchy. These returned regions could be either macro regions, territories, or a mixture of the two, jpayne@69: * depending on the containment data as defined in CLDR. This API may return NULL if this region doesn't have jpayne@69: * any sub-regions. For example, calling this method with region "150" (Europe) returns an enumeration containing jpayne@69: * the various sub regions of Europe - "039" (Southern Europe) - "151" (Eastern Europe) - "154" (Northern Europe) jpayne@69: * and "155" (Western Europe). jpayne@69: * @stable ICU 55 jpayne@69: */ jpayne@69: StringEnumeration* getContainedRegions(UErrorCode &status) const; jpayne@69: jpayne@69: /** jpayne@69: * Returns an enumeration over the IDs of all the regions that are children of this region anywhere in the region jpayne@69: * hierarchy and match the given type. This API may return an empty enumeration if this region doesn't have any jpayne@69: * sub-regions that match the given type. For example, calling this method with region "150" (Europe) and type jpayne@69: * "URGN_TERRITORY" returns a set containing all the territories in Europe ( "FR" (France) - "IT" (Italy) - "DE" (Germany) etc. ) jpayne@69: * @stable ICU 55 jpayne@69: */ jpayne@69: StringEnumeration* getContainedRegions( URegionType type, UErrorCode &status ) const; jpayne@69: jpayne@69: /** jpayne@69: * Returns true if this region contains the supplied other region anywhere in the region hierarchy. jpayne@69: * @stable ICU 51 jpayne@69: */ jpayne@69: UBool contains(const Region &other) const; jpayne@69: jpayne@69: /** jpayne@69: * For deprecated regions, return an enumeration over the IDs of the regions that are the preferred replacement jpayne@69: * regions for this region. Returns null for a non-deprecated region. For example, calling this method with region jpayne@69: * "SU" (Soviet Union) would return a list of the regions containing "RU" (Russia), "AM" (Armenia), "AZ" (Azerbaijan), etc... jpayne@69: * @stable ICU 55 jpayne@69: */ jpayne@69: StringEnumeration* getPreferredValues(UErrorCode &status) const; jpayne@69: jpayne@69: /** jpayne@69: * Return this region's canonical region code. jpayne@69: * @stable ICU 51 jpayne@69: */ jpayne@69: const char* getRegionCode() const; jpayne@69: jpayne@69: /** jpayne@69: * Return this region's numeric code. jpayne@69: * Returns a negative value if the given region does not have a numeric code assigned to it. jpayne@69: * @stable ICU 51 jpayne@69: */ jpayne@69: int32_t getNumericCode() const; jpayne@69: jpayne@69: /** jpayne@69: * Returns the region type of this region. jpayne@69: * @stable ICU 51 jpayne@69: */ jpayne@69: URegionType getType() const; jpayne@69: jpayne@69: #ifndef U_HIDE_INTERNAL_API jpayne@69: /** jpayne@69: * Cleans up statically allocated memory. jpayne@69: * @internal jpayne@69: */ jpayne@69: static void cleanupRegionData(); jpayne@69: #endif /* U_HIDE_INTERNAL_API */ jpayne@69: jpayne@69: private: jpayne@69: char id[4]; jpayne@69: UnicodeString idStr; jpayne@69: int32_t code; jpayne@69: URegionType fType; jpayne@69: Region *containingRegion; jpayne@69: UVector *containedRegions; jpayne@69: UVector *preferredValues; jpayne@69: jpayne@69: /** jpayne@69: * Default Constructor. Internal - use factory methods only. jpayne@69: */ jpayne@69: Region(); jpayne@69: jpayne@69: jpayne@69: /* jpayne@69: * Initializes the region data from the ICU resource bundles. The region data jpayne@69: * contains the basic relationships such as which regions are known, what the numeric jpayne@69: * codes are, any known aliases, and the territory containment data. jpayne@69: * jpayne@69: * If the region data has already loaded, then this method simply returns without doing jpayne@69: * anything meaningful. jpayne@69: */ jpayne@69: jpayne@69: static void U_CALLCONV loadRegionData(UErrorCode &status); jpayne@69: jpayne@69: }; jpayne@69: jpayne@69: U_NAMESPACE_END jpayne@69: jpayne@69: #endif /* #if !UCONFIG_NO_FORMATTING */ jpayne@69: jpayne@69: #endif /* U_SHOW_CPLUSPLUS_API */ jpayne@69: jpayne@69: #endif // REGION_H jpayne@69: jpayne@69: //eof