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