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

- Search for |

- File List
- Globals

# numfmt.h

Go to the documentation of this file.

    00001 /*
    00002 ********************************************************************************
    00003 * Copyright (C) 1997-2006, 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
    00146 class U_I18N_API NumberFormat : public Format {
    00147 public:
    00148
    00157     enum EAlignmentFields {
    00158         kIntegerField,
    00159         kFractionField,
    00160
    00161
    00167         INTEGER_FIELD        = kIntegerField,
    00168         FRACTION_FIELD        = kFractionField
    00169     };
    00170
    00175     virtual ~NumberFormat();
    00176
    00183     virtual UBool operator==(const Format& other) const;
    00184
    00200     virtual UnicodeString& format(const Formattable& obj,
    00201                                   UnicodeString& appendTo,
    00202                                   FieldPosition& pos,
    00203                                   UErrorCode& status) const;
    00204
    00233     virtual void parseObject(const UnicodeString& source,
    00234                              Formattable& result,
    00235                              ParsePosition& parse_pos) const;
    00236
    00247     UnicodeString& format(  double number,
    00248                             UnicodeString& appendTo) const;
    00249
    00260     UnicodeString& format(  int32_t number,
    00261                             UnicodeString& appendTo) const;
    00262
    00273     UnicodeString& format(  int64_t number,
    00274                             UnicodeString& appendTo) const;
    00275
    00288     virtual UnicodeString& format(double number,
    00289                                   UnicodeString& appendTo,
    00290                                   FieldPosition& pos) const = 0;
    00303     virtual UnicodeString& format(int32_t number,
    00304                                   UnicodeString& appendTo,
    00305                                   FieldPosition& pos) const = 0;
    00306
    00320     virtual UnicodeString& format(int64_t number,
    00321                                   UnicodeString& appendTo,
    00322                                   FieldPosition& pos) const;
    00333     UnicodeString& format(const Formattable& obj,
    00334                           UnicodeString& appendTo,
    00335                           UErrorCode& status) const;
    00336
    00358     virtual void parse(const UnicodeString& text,
    00359                        Formattable& result,
    00360                        ParsePosition& parsePosition) const = 0;
    00361
    00377     virtual void parse( const UnicodeString& text,
    00378                         Formattable& result,
    00379                         UErrorCode& status) const;
    00380
    00400     virtual Formattable& parseCurrency(const UnicodeString& text,
    00401                                        Formattable& result,
    00402                                        ParsePosition& pos) const;
    00403
    00415     UBool isParseIntegerOnly(void) const;
    00416
    00424     virtual void setParseIntegerOnly(UBool value);
    00425
    00434     static NumberFormat* U_EXPORT2 createInstance(UErrorCode&);
    00435
    00444     static NumberFormat* U_EXPORT2 createInstance(const Locale& inLocale,
    00445                                         UErrorCode&);
    00446
    00451     static NumberFormat* U_EXPORT2 createCurrencyInstance(UErrorCode&);
    00452
    00458     static NumberFormat* U_EXPORT2 createCurrencyInstance(const Locale& inLocale,
    00459                                                 UErrorCode&);
    00460
    00465     static NumberFormat* U_EXPORT2 createPercentInstance(UErrorCode&);
    00466
    00472     static NumberFormat* U_EXPORT2 createPercentInstance(const Locale& inLocale,
    00473                                                UErrorCode&);
    00474
    00479     static NumberFormat* U_EXPORT2 createScientificInstance(UErrorCode&);
    00480
    00486     static NumberFormat* U_EXPORT2 createScientificInstance(const Locale& inLocale,
    00487                                                 UErrorCode&);
    00488
    00494     static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
    00495
    00496 #if !UCONFIG_NO_SERVICE
    00497
    00504     static URegistryKey U_EXPORT2 registerFactory(NumberFormatFactory* toAdopt, UErrorCode& status);
    00505
    00515     static UBool U_EXPORT2 unregister(URegistryKey key, UErrorCode& status);
    00516
    00523     static StringEnumeration* U_EXPORT2 getAvailableLocales(void);
    00524 #endif /* UCONFIG_NO_SERVICE */
    00525
    00535     UBool isGroupingUsed(void) const;
    00536
    00543     virtual void setGroupingUsed(UBool newValue);
    00544
    00553     int32_t getMaximumIntegerDigits(void) const;
    00554
    00567     virtual void setMaximumIntegerDigits(int32_t newValue);
    00568
    00577     int32_t getMinimumIntegerDigits(void) const;
    00578
    00589     virtual void setMinimumIntegerDigits(int32_t newValue);
    00590
    00599     int32_t getMaximumFractionDigits(void) const;
    00600
    00611     virtual void setMaximumFractionDigits(int32_t newValue);
    00612
    00621     int32_t getMinimumFractionDigits(void) const;
    00622
    00633     virtual void setMinimumFractionDigits(int32_t newValue);
    00634
    00647     virtual void setCurrency(const UChar* theCurrency, UErrorCode& ec);
    00648
    00656     const UChar* getCurrency() const;
    00657
    00658 public:
    00659
    00668     static UClassID U_EXPORT2 getStaticClassID(void);
    00669
    00681     virtual UClassID getDynamicClassID(void) const = 0;
    00682
    00683 protected:
    00684
    00689     NumberFormat();
    00690
    00695     NumberFormat(const NumberFormat&);
    00696
    00701     NumberFormat& operator=(const NumberFormat&);
    00702
    00711     virtual void getEffectiveCurrency(UChar* result, UErrorCode& ec) const;
    00712
    00713 private:
    00714
    00715     enum EStyles {
    00716         kNumberStyle,
    00717         kCurrencyStyle,
    00718         kPercentStyle,
    00719         kScientificStyle,
    00720         kStyleCount // ALWAYS LAST ENUM: number of styles
    00721     };
    00722
    00732     static NumberFormat* U_EXPORT2 createInstance(const Locale& desiredLocale, EStyles choice, UErrorCode& success);
    00733
    00741     static NumberFormat* makeInstance(const Locale& desiredLocale, EStyles choice, UErrorCode& success);
    00742
    00743     UBool      fGroupingUsed;
    00744     int32_t     fMaxIntegerDigits;
    00745     int32_t     fMinIntegerDigits;
    00746     int32_t     fMaxFractionDigits;
    00747     int32_t     fMinFractionDigits;
    00748     UBool      fParseIntegerOnly;
    00749
    00750     // ISO currency code
    00751     UChar      fCurrency[4];
    00752
    00753     friend class ICUNumberFormatFactory; // access to makeInstance, EStyles
    00754     friend class ICUNumberFormatService;
    00755 };
    00756
    00757 #if !UCONFIG_NO_SERVICE
    00758
    00766 class U_I18N_API NumberFormatFactory : public UObject {
    00767 public:
    00768
    00773     virtual ~NumberFormatFactory();
    00774
    00781     virtual UBool visible(void) const = 0;
    00782
    00788     virtual const UnicodeString * getSupportedIDs(int32_t &count, UErrorCode& status) const = 0;
    00789
    00797     virtual NumberFormat* createFormat(const Locale& loc, UNumberFormatStyle formatType) = 0;
    00798 };
    00799
    00804 class U_I18N_API SimpleNumberFormatFactory : public NumberFormatFactory {
    00805 protected:
    00810     const UBool _visible;
    00811
    00816     UnicodeString _id;
    00817
    00818 public:
    00822     SimpleNumberFormatFactory(const Locale& locale, UBool visible = TRUE);
    00823
    00827     virtual ~SimpleNumberFormatFactory();
    00828
    00832     virtual UBool visible(void) const;
    00833
    00837     virtual const UnicodeString * getSupportedIDs(int32_t &count, UErrorCode& status) const;
    00838 };
    00839 #endif /* #if !UCONFIG_NO_SERVICE */
    00840
    00841 // -------------------------------------
    00842
    00843 inline UBool
    00844 NumberFormat::isParseIntegerOnly() const
    00845 {
    00846     return fParseIntegerOnly;
    00847 }
    00848
    00849 inline UnicodeString&
    00850 NumberFormat::format(const Formattable& obj,
    00851                      UnicodeString& appendTo,
    00852                      UErrorCode& status) const {
    00853     return Format::format(obj, appendTo, status);
    00854 }
    00855
    00856 U_NAMESPACE_END
    00857
    00858 #endif /* #if !UCONFIG_NO_FORMATTING */
    00859
    00860 #endif // _NUMFMT
    00861 //eof