intl/icu/source/i18n/unicode/region.h

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

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

mercurial