- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- Search for |

- File List
- Globals

# numfmt.h

Go to the documentation of this file.

    00001 /*
    00002 ********************************************************************************
    00003 * Copyright (C) 1997-2009, International Business Machines Corporation and others.
    00004 * All Rights Reserved.
    00005 ********************************************************************************
    00006 *
    00007 * File NUMFMT.H
    00008 *
    00009 * Modification History:
    00010 *
    00011 *   Date        Name        Description
    00012 *   02/19/97    aliu        Converted from java.
    00013 *   03/18/97    clhuang     Updated per C++ implementation.
    00014 *   04/17/97    aliu        Changed DigitCount to int per code review.
    00015 *    07/20/98    stephen        JDK 1.2 sync up. Added scientific support.
    00016 *                            Changed naming conventions to match C++ guidelines
    00017 *                            Derecated Java style constants (eg, INTEGER_FIELD)
    00018 ********************************************************************************
    00019 */
    00020
    00021 #ifndef NUMFMT_H
    00022 #define NUMFMT_H
    00023
    00024
    00025 #include "unicode/utypes.h"
    00026
    00032 #if !UCONFIG_NO_FORMATTING
    00033
    00034 #include "unicode/unistr.h"
    00035 #include "unicode/format.h"
    00036 #include "unicode/unum.h" // UNumberFormatStyle
    00037 #include "unicode/locid.h"
    00038
    00039 U_NAMESPACE_BEGIN
    00040
    00041 #if !UCONFIG_NO_SERVICE
    00042 class NumberFormatFactory;
    00043 class StringEnumeration;
    00044 #endif
    00045
    00162 class U_I18N_API NumberFormat : public Format {
    00163 public:
    00164
    00178     enum EStyles {
    00179         kNumberStyle,
    00180         kCurrencyStyle,
    00181         kPercentStyle,
    00182         kScientificStyle,
    00183         kIsoCurrencyStyle,
    00184         kPluralCurrencyStyle,
    00185         kStyleCount // ALWAYS LAST ENUM: number of styles
    00186     };
    00187
    00196     enum EAlignmentFields {
    00197         kIntegerField,
    00198         kFractionField,
    00199
    00200
    00206         INTEGER_FIELD        = kIntegerField,
    00207         FRACTION_FIELD        = kFractionField
    00208     };
    00209
    00214     virtual ~NumberFormat();
    00215
    00222     virtual UBool operator==(const Format& other) const;
    00223
    00239     virtual UnicodeString& format(const Formattable& obj,
    00240                                   UnicodeString& appendTo,
    00241                                   FieldPosition& pos,
    00242                                   UErrorCode& status) const;
    00243
    00272     virtual void parseObject(const UnicodeString& source,
    00273                              Formattable& result,
    00274                              ParsePosition& parse_pos) const;
    00275
    00286     UnicodeString& format(  double number,
    00287                             UnicodeString& appendTo) const;
    00288
    00299     UnicodeString& format(  int32_t number,
    00300                             UnicodeString& appendTo) const;
    00301
    00312     UnicodeString& format(  int64_t number,
    00313                             UnicodeString& appendTo) const;
    00314
    00327     virtual UnicodeString& format(double number,
    00328                                   UnicodeString& appendTo,
    00329                                   FieldPosition& pos) const = 0;
    00342     virtual UnicodeString& format(int32_t number,
    00343                                   UnicodeString& appendTo,
    00344                                   FieldPosition& pos) const = 0;
    00345
    00359     virtual UnicodeString& format(int64_t number,
    00360                                   UnicodeString& appendTo,
    00361                                   FieldPosition& pos) const;
    00372     UnicodeString& format(const Formattable& obj,
    00373                           UnicodeString& appendTo,
    00374                           UErrorCode& status) const;
    00375
    00397     virtual void parse(const UnicodeString& text,
    00398                        Formattable& result,
    00399                        ParsePosition& parsePosition) const = 0;
    00400
    00416     virtual void parse( const UnicodeString& text,
    00417                         Formattable& result,
    00418                         UErrorCode& status) const;
    00419
    00439     virtual Formattable& parseCurrency(const UnicodeString& text,
    00440                                        Formattable& result,
    00441                                        ParsePosition& pos) const;
    00442
    00454     UBool isParseIntegerOnly(void) const;
    00455
    00463     virtual void setParseIntegerOnly(UBool value);
    00464
    00473     static NumberFormat* U_EXPORT2 createInstance(UErrorCode&);
    00474
    00483     static NumberFormat* U_EXPORT2 createInstance(const Locale& inLocale,
    00484                                         UErrorCode&);
    00485
    00494     static NumberFormat* U_EXPORT2 createInstance(const Locale& desiredLocale, EStyles choice, UErrorCode& success);
    00495
    00496
    00501     static NumberFormat* U_EXPORT2 createCurrencyInstance(UErrorCode&);
    00502
    00508     static NumberFormat* U_EXPORT2 createCurrencyInstance(const Locale& inLocale,
    00509                                                 UErrorCode&);
    00510
    00515     static NumberFormat* U_EXPORT2 createPercentInstance(UErrorCode&);
    00516
    00522     static NumberFormat* U_EXPORT2 createPercentInstance(const Locale& inLocale,
    00523                                                UErrorCode&);
    00524
    00529     static NumberFormat* U_EXPORT2 createScientificInstance(UErrorCode&);
    00530
    00536     static NumberFormat* U_EXPORT2 createScientificInstance(const Locale& inLocale,
    00537                                                 UErrorCode&);
    00538
    00544     static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
    00545
    00546 #if !UCONFIG_NO_SERVICE
    00547
    00554     static URegistryKey U_EXPORT2 registerFactory(NumberFormatFactory* toAdopt, UErrorCode& status);
    00555
    00565     static UBool U_EXPORT2 unregister(URegistryKey key, UErrorCode& status);
    00566
    00573     static StringEnumeration* U_EXPORT2 getAvailableLocales(void);
    00574 #endif /* UCONFIG_NO_SERVICE */
    00575
    00585     UBool isGroupingUsed(void) const;
    00586
    00593     virtual void setGroupingUsed(UBool newValue);
    00594
    00603     int32_t getMaximumIntegerDigits(void) const;
    00604
    00617     virtual void setMaximumIntegerDigits(int32_t newValue);
    00618
    00627     int32_t getMinimumIntegerDigits(void) const;
    00628
    00639     virtual void setMinimumIntegerDigits(int32_t newValue);
    00640
    00649     int32_t getMaximumFractionDigits(void) const;
    00650
    00661     virtual void setMaximumFractionDigits(int32_t newValue);
    00662
    00671     int32_t getMinimumFractionDigits(void) const;
    00672
    00683     virtual void setMinimumFractionDigits(int32_t newValue);
    00684
    00697     virtual void setCurrency(const UChar* theCurrency, UErrorCode& ec);
    00698
    00706     const UChar* getCurrency() const;
    00707
    00708 public:
    00709
    00718     static UClassID U_EXPORT2 getStaticClassID(void);
    00719
    00731     virtual UClassID getDynamicClassID(void) const = 0;
    00732
    00733 protected:
    00734
    00739     NumberFormat();
    00740
    00745     NumberFormat(const NumberFormat&);
    00746
    00751     NumberFormat& operator=(const NumberFormat&);
    00752
    00761     virtual void getEffectiveCurrency(UChar* result, UErrorCode& ec) const;
    00762
    00763 private:
    00764
    00772     static NumberFormat* makeInstance(const Locale& desiredLocale, EStyles choice, UErrorCode& success);
    00773
    00774     UBool      fGroupingUsed;
    00775     int32_t     fMaxIntegerDigits;
    00776     int32_t     fMinIntegerDigits;
    00777     int32_t     fMaxFractionDigits;
    00778     int32_t     fMinFractionDigits;
    00779     UBool      fParseIntegerOnly;
    00780
    00781     // ISO currency code
    00782     UChar      fCurrency[4];
    00783
    00784     friend class ICUNumberFormatFactory; // access to makeInstance, EStyles
    00785     friend class ICUNumberFormatService;
    00786 };
    00787
    00788 #if !UCONFIG_NO_SERVICE
    00789
    00797 class U_I18N_API NumberFormatFactory : public UObject {
    00798 public:
    00799
    00804     virtual ~NumberFormatFactory();
    00805
    00812     virtual UBool visible(void) const = 0;
    00813
    00819     virtual const UnicodeString * getSupportedIDs(int32_t &count, UErrorCode& status) const = 0;
    00820
    00828     virtual NumberFormat* createFormat(const Locale& loc, UNumberFormatStyle formatType) = 0;
    00829 };
    00830
    00835 class U_I18N_API SimpleNumberFormatFactory : public NumberFormatFactory {
    00836 protected:
    00841     const UBool _visible;
    00842
    00847     UnicodeString _id;
    00848
    00849 public:
    00853     SimpleNumberFormatFactory(const Locale& locale, UBool visible = TRUE);
    00854
    00858     virtual ~SimpleNumberFormatFactory();
    00859
    00863     virtual UBool visible(void) const;
    00864
    00868     virtual const UnicodeString * getSupportedIDs(int32_t &count, UErrorCode& status) const;
    00869 };
    00870 #endif /* #if !UCONFIG_NO_SERVICE */
    00871
    00872 // -------------------------------------
    00873
    00874 inline UBool
    00875 NumberFormat::isParseIntegerOnly() const
    00876 {
    00877     return fParseIntegerOnly;
    00878 }
    00879
    00880 inline UnicodeString&
    00881 NumberFormat::format(const Formattable& obj,
    00882                      UnicodeString& appendTo,
    00883                      UErrorCode& status) const {
    00884     return Format::format(obj, appendTo, status);
    00885 }
    00886
    00887 U_NAMESPACE_END
    00888
    00889 #endif /* #if !UCONFIG_NO_FORMATTING */
    00890
    00891 #endif // _NUMFMT
    00892 //eof