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

- File List
- Globals

# numfmt.h

Go to the documentation of this file.

    00001 /*
    00002 ********************************************************************************
    00003 * Copyright (C) 1997-2010, 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 #include "unicode/stringpiece.h"
    00039
    00040 U_NAMESPACE_BEGIN
    00041
    00042 #if !UCONFIG_NO_SERVICE
    00043 class NumberFormatFactory;
    00044 class StringEnumeration;
    00045 #endif
    00046
    00163 class U_I18N_API NumberFormat : public Format {
    00164 public:
    00165
    00179     enum EStyles {
    00180         kNumberStyle,
    00181         kCurrencyStyle,
    00182         kPercentStyle,
    00183         kScientificStyle,
    00184         kIsoCurrencyStyle,
    00185         kPluralCurrencyStyle,
    00186         kStyleCount // ALWAYS LAST ENUM: number of styles
    00187     };
    00188
    00201     enum EAlignmentFields {
    00202         kIntegerField,
    00203         kFractionField,
    00204         kDecimalSeparatorField,
    00205         kExponentSymbolField,
    00206         kExponentSignField,
    00207         kExponentField,
    00208         kGroupingSeparatorField,
    00209         kCurrencyField,
    00210         kPercentField,
    00211         kPermillField,
    00212         kSignField,
    00213
    00219         INTEGER_FIELD        = kIntegerField,
    00220         FRACTION_FIELD        = kFractionField
    00221     };
    00222
    00227     virtual ~NumberFormat();
    00228
    00235     virtual UBool operator==(const Format& other) const;
    00236
    00237
    00238     using Format::format;
    00239
    00255     virtual UnicodeString& format(const Formattable& obj,
    00256                                   UnicodeString& appendTo,
    00257                                   FieldPosition& pos,
    00258                                   UErrorCode& status) const;
    00259
    00276     virtual UnicodeString& format(const Formattable& obj,
    00277                                   UnicodeString& appendTo,
    00278                                   FieldPositionIterator* posIter,
    00279                                   UErrorCode& status) const;
    00280
    00309     virtual void parseObject(const UnicodeString& source,
    00310                              Formattable& result,
    00311                              ParsePosition& parse_pos) const;
    00312
    00323     UnicodeString& format(  double number,
    00324                             UnicodeString& appendTo) const;
    00325
    00336     UnicodeString& format(  int32_t number,
    00337                             UnicodeString& appendTo) const;
    00338
    00349     UnicodeString& format(  int64_t number,
    00350                             UnicodeString& appendTo) const;
    00351
    00364     virtual UnicodeString& format(double number,
    00365                                   UnicodeString& appendTo,
    00366                                   FieldPosition& pos) const = 0;
    00381     virtual UnicodeString& format(double number,
    00382                                   UnicodeString& appendTo,
    00383                                   FieldPositionIterator* posIter,
    00384                                   UErrorCode& status) const;
    00397     virtual UnicodeString& format(int32_t number,
    00398                                   UnicodeString& appendTo,
    00399                                   FieldPosition& pos) const = 0;
    00400
    00415     virtual UnicodeString& format(int32_t number,
    00416                                   UnicodeString& appendTo,
    00417                                   FieldPositionIterator* posIter,
    00418                                   UErrorCode& status) const;
    00432     virtual UnicodeString& format(int64_t number,
    00433                                   UnicodeString& appendTo,
    00434                                   FieldPosition& pos) const;
    00449     virtual UnicodeString& format(int64_t number,
    00450                                   UnicodeString& appendTo,
    00451                                   FieldPositionIterator* posIter,
    00452                                   UErrorCode& status) const;
    00453
    00470     virtual UnicodeString& format(const StringPiece &number,
    00471                                   UnicodeString& appendTo,
    00472                                   FieldPositionIterator* posIter,
    00473                                   UErrorCode& status) const;
    00474 public:
    00492     virtual UnicodeString& format(const DigitList &number,
    00493                                   UnicodeString& appendTo,
    00494                                   FieldPositionIterator* posIter,
    00495                                   UErrorCode& status) const;
    00496
    00514     virtual UnicodeString& format(const DigitList &number,
    00515                                   UnicodeString& appendTo,
    00516                                   FieldPosition& pos,
    00517                                   UErrorCode& status) const;
    00518
    00519 public:
    00520
    00531     UnicodeString& format(const Formattable& obj,
    00532                           UnicodeString& appendTo,
    00533                           UErrorCode& status) const;
    00534
    00556     virtual void parse(const UnicodeString& text,
    00557                        Formattable& result,
    00558                        ParsePosition& parsePosition) const = 0;
    00559
    00575     virtual void parse( const UnicodeString& text,
    00576                         Formattable& result,
    00577                         UErrorCode& status) const;
    00578
    00598     virtual Formattable& parseCurrency(const UnicodeString& text,
    00599                                        Formattable& result,
    00600                                        ParsePosition& pos) const;
    00601
    00613     UBool isParseIntegerOnly(void) const;
    00614
    00622     virtual void setParseIntegerOnly(UBool value);
    00623
    00632     static NumberFormat* U_EXPORT2 createInstance(UErrorCode&);
    00633
    00642     static NumberFormat* U_EXPORT2 createInstance(const Locale& inLocale,
    00643                                         UErrorCode&);
    00644
    00653     static NumberFormat* U_EXPORT2 createInstance(const Locale& desiredLocale, EStyles choice, UErrorCode& success);
    00654
    00655
    00660     static NumberFormat* U_EXPORT2 createCurrencyInstance(UErrorCode&);
    00661
    00667     static NumberFormat* U_EXPORT2 createCurrencyInstance(const Locale& inLocale,
    00668                                                 UErrorCode&);
    00669
    00674     static NumberFormat* U_EXPORT2 createPercentInstance(UErrorCode&);
    00675
    00681     static NumberFormat* U_EXPORT2 createPercentInstance(const Locale& inLocale,
    00682                                                UErrorCode&);
    00683
    00688     static NumberFormat* U_EXPORT2 createScientificInstance(UErrorCode&);
    00689
    00695     static NumberFormat* U_EXPORT2 createScientificInstance(const Locale& inLocale,
    00696                                                 UErrorCode&);
    00697
    00703     static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
    00704
    00705 #if !UCONFIG_NO_SERVICE
    00706
    00713     static URegistryKey U_EXPORT2 registerFactory(NumberFormatFactory* toAdopt, UErrorCode& status);
    00714
    00724     static UBool U_EXPORT2 unregister(URegistryKey key, UErrorCode& status);
    00725
    00732     static StringEnumeration* U_EXPORT2 getAvailableLocales(void);
    00733 #endif /* UCONFIG_NO_SERVICE */
    00734
    00744     UBool isGroupingUsed(void) const;
    00745
    00752     virtual void setGroupingUsed(UBool newValue);
    00753
    00762     int32_t getMaximumIntegerDigits(void) const;
    00763
    00776     virtual void setMaximumIntegerDigits(int32_t newValue);
    00777
    00786     int32_t getMinimumIntegerDigits(void) const;
    00787
    00798     virtual void setMinimumIntegerDigits(int32_t newValue);
    00799
    00808     int32_t getMaximumFractionDigits(void) const;
    00809
    00820     virtual void setMaximumFractionDigits(int32_t newValue);
    00821
    00830     int32_t getMinimumFractionDigits(void) const;
    00831
    00842     virtual void setMinimumFractionDigits(int32_t newValue);
    00843
    00856     virtual void setCurrency(const UChar* theCurrency, UErrorCode& ec);
    00857
    00865     const UChar* getCurrency() const;
    00866
    00867 public:
    00868
    00877     static UClassID U_EXPORT2 getStaticClassID(void);
    00878
    00890     virtual UClassID getDynamicClassID(void) const = 0;
    00891
    00892 protected:
    00893
    00898     NumberFormat();
    00899
    00904     NumberFormat(const NumberFormat&);
    00905
    00910     NumberFormat& operator=(const NumberFormat&);
    00911
    00920     virtual void getEffectiveCurrency(UChar* result, UErrorCode& ec) const;
    00921
    00922 private:
    00923
    00931     static NumberFormat* makeInstance(const Locale& desiredLocale, EStyles choice, UErrorCode& success);
    00932
    00933     UBool      fGroupingUsed;
    00934     int32_t     fMaxIntegerDigits;
    00935     int32_t     fMinIntegerDigits;
    00936     int32_t     fMaxFractionDigits;
    00937     int32_t     fMinFractionDigits;
    00938     UBool      fParseIntegerOnly;
    00939
    00940     // ISO currency code
    00941     UChar      fCurrency[4];
    00942
    00943     friend class ICUNumberFormatFactory; // access to makeInstance, EStyles
    00944     friend class ICUNumberFormatService;
    00945 };
    00946
    00947 #if !UCONFIG_NO_SERVICE
    00948
    00956 class U_I18N_API NumberFormatFactory : public UObject {
    00957 public:
    00958
    00963     virtual ~NumberFormatFactory();
    00964
    00971     virtual UBool visible(void) const = 0;
    00972
    00978     virtual const UnicodeString * getSupportedIDs(int32_t &count, UErrorCode& status) const = 0;
    00979
    00987     virtual NumberFormat* createFormat(const Locale& loc, UNumberFormatStyle formatType) = 0;
    00988 };
    00989
    00994 class U_I18N_API SimpleNumberFormatFactory : public NumberFormatFactory {
    00995 protected:
    01000     const UBool _visible;
    01001
    01006     UnicodeString _id;
    01007
    01008 public:
    01012     SimpleNumberFormatFactory(const Locale& locale, UBool visible = TRUE);
    01013
    01017     virtual ~SimpleNumberFormatFactory();
    01018
    01022     virtual UBool visible(void) const;
    01023
    01027     virtual const UnicodeString * getSupportedIDs(int32_t &count, UErrorCode& status) const;
    01028 };
    01029 #endif /* #if !UCONFIG_NO_SERVICE */
    01030
    01031 // -------------------------------------
    01032
    01033 inline UBool
    01034 NumberFormat::isParseIntegerOnly() const
    01035 {
    01036     return fParseIntegerOnly;
    01037 }
    01038
    01039 inline UnicodeString&
    01040 NumberFormat::format(const Formattable& obj,
    01041                      UnicodeString& appendTo,
    01042                      UErrorCode& status) const {
    01043     return Format::format(obj, appendTo, status);
    01044 }
    01045
    01046 U_NAMESPACE_END
    01047
    01048 #endif /* #if !UCONFIG_NO_FORMATTING */
    01049
    01050 #endif // _NUMFMT
    01051 //eof

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines