numfmt.h

Go to the documentation of this file.
00001 /*
00002 * Copyright (C) {1997-2005}, International Business Machines Corporation and others. All Rights Reserved.
00003 ********************************************************************************
00004 *
00005 * File NUMFMT.H
00006 *
00007 * Modification History:
00008 *
00009 *   Date        Name        Description
00010 *   02/19/97    aliu        Converted from java.
00011 *   03/18/97    clhuang     Updated per C++ implementation.
00012 *   04/17/97    aliu        Changed DigitCount to int per code review.
00013 *    07/20/98    stephen        JDK 1.2 sync up. Added scientific support.
00014 *                            Changed naming conventions to match C++ guidelines
00015 *                            Derecated Java style constants (eg, INTEGER_FIELD)
00016 ********************************************************************************
00017 */
00018 
00019 #ifndef NUMFMT_H
00020 #define NUMFMT_H
00021 
00022 
00023 #include "unicode/utypes.h"
00024 
00030 #if !UCONFIG_NO_FORMATTING
00031 
00032 #include "unicode/unistr.h"
00033 #include "unicode/format.h"
00034 #include "unicode/unum.h" // UNumberFormatStyle
00035 #include "unicode/locid.h"
00036 
00037 U_NAMESPACE_BEGIN
00038 
00039 #if !UCONFIG_NO_SERVICE
00040 class NumberFormatFactory;
00041 class StringEnumeration;
00042 
00046 typedef const void* URegistryKey;
00047 #endif
00048 
00149 class U_I18N_API NumberFormat : public Format {
00150 public:
00151 
00160     enum EAlignmentFields {
00161         kIntegerField,
00162         kFractionField,
00163 
00164 
00170         INTEGER_FIELD        = kIntegerField,
00171         FRACTION_FIELD        = kFractionField
00172     };
00173 
00178     virtual ~NumberFormat();
00179 
00186     virtual UBool operator==(const Format& other) const;
00187 
00203     virtual UnicodeString& format(const Formattable& obj,
00204                                   UnicodeString& appendTo,
00205                                   FieldPosition& pos,
00206                                   UErrorCode& status) const;
00207 
00236     virtual void parseObject(const UnicodeString& source,
00237                              Formattable& result,
00238                              ParsePosition& parse_pos) const;
00239 
00250     UnicodeString& format(  double number,
00251                             UnicodeString& appendTo) const;
00252 
00263     UnicodeString& format(  int32_t number,
00264                             UnicodeString& appendTo) const;
00265 
00276     UnicodeString& format(  int64_t number,
00277                             UnicodeString& appendTo) const;
00278 
00291     virtual UnicodeString& format(double number,
00292                                   UnicodeString& appendTo,
00293                                   FieldPosition& pos) const = 0;
00306     virtual UnicodeString& format(int32_t number,
00307                                   UnicodeString& appendTo,
00308                                   FieldPosition& pos) const = 0;
00309 
00323     virtual UnicodeString& format(int64_t number,
00324                                   UnicodeString& appendTo,
00325                                   FieldPosition& pos) const;
00336     UnicodeString& format(const Formattable& obj,
00337                           UnicodeString& appendTo,
00338                           UErrorCode& status) const;
00339 
00361     virtual void parse(const UnicodeString& text,
00362                        Formattable& result,
00363                        ParsePosition& parsePosition) const = 0;
00364 
00380     virtual void parse( const UnicodeString& text,
00381                         Formattable& result,
00382                         UErrorCode& status) const;
00383 
00403     virtual Formattable& parseCurrency(const UnicodeString& text,
00404                                        Formattable& result,
00405                                        ParsePosition& pos) const;
00406 
00418     UBool isParseIntegerOnly(void) const;
00419 
00427     virtual void setParseIntegerOnly(UBool value);
00428 
00437     static NumberFormat* U_EXPORT2 createInstance(UErrorCode&);
00438 
00447     static NumberFormat* U_EXPORT2 createInstance(const Locale& inLocale,
00448                                         UErrorCode&);
00449 
00454     static NumberFormat* U_EXPORT2 createCurrencyInstance(UErrorCode&);
00455 
00461     static NumberFormat* U_EXPORT2 createCurrencyInstance(const Locale& inLocale,
00462                                                 UErrorCode&);
00463 
00468     static NumberFormat* U_EXPORT2 createPercentInstance(UErrorCode&);
00469 
00475     static NumberFormat* U_EXPORT2 createPercentInstance(const Locale& inLocale,
00476                                                UErrorCode&);
00477 
00482     static NumberFormat* U_EXPORT2 createScientificInstance(UErrorCode&);
00483 
00489     static NumberFormat* U_EXPORT2 createScientificInstance(const Locale& inLocale,
00490                                                 UErrorCode&);
00491 
00497     static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
00498 
00499 #if !UCONFIG_NO_SERVICE
00500 
00507     static URegistryKey U_EXPORT2 registerFactory(NumberFormatFactory* toAdopt, UErrorCode& status);
00508 
00518     static UBool U_EXPORT2 unregister(URegistryKey key, UErrorCode& status);
00519 
00526     static StringEnumeration* U_EXPORT2 getAvailableLocales(void);
00527 #endif /* UCONFIG_NO_SERVICE */
00528 
00538     UBool isGroupingUsed(void) const;
00539 
00546     virtual void setGroupingUsed(UBool newValue);
00547 
00556     int32_t getMaximumIntegerDigits(void) const;
00557 
00570     virtual void setMaximumIntegerDigits(int32_t newValue);
00571 
00580     int32_t getMinimumIntegerDigits(void) const;
00581 
00592     virtual void setMinimumIntegerDigits(int32_t newValue);
00593 
00602     int32_t getMaximumFractionDigits(void) const;
00603 
00614     virtual void setMaximumFractionDigits(int32_t newValue);
00615 
00624     int32_t getMinimumFractionDigits(void) const;
00625 
00636     virtual void setMinimumFractionDigits(int32_t newValue);
00637 
00650     virtual void setCurrency(const UChar* theCurrency, UErrorCode& ec);
00651 
00659     const UChar* getCurrency() const;
00660 
00661 public:
00662 
00671     static UClassID U_EXPORT2 getStaticClassID(void);
00672 
00684     virtual UClassID getDynamicClassID(void) const = 0;
00685 
00686 protected:
00687 
00692     NumberFormat();
00693 
00698     NumberFormat(const NumberFormat&);
00699 
00704     NumberFormat& operator=(const NumberFormat&);
00705 
00714     virtual void getEffectiveCurrency(UChar* result, UErrorCode& ec) const;
00715 
00716 private:
00717 
00718     enum EStyles {
00719         kNumberStyle,
00720         kCurrencyStyle,
00721         kPercentStyle,
00722         kScientificStyle,
00723         kStyleCount // ALWAYS LAST ENUM: number of styles
00724     };
00725 
00735     static NumberFormat* U_EXPORT2 createInstance(const Locale& desiredLocale, EStyles choice, UErrorCode& success);
00736 
00744     static NumberFormat* makeInstance(const Locale& desiredLocale, EStyles choice, UErrorCode& success);
00745 
00746     UBool      fGroupingUsed;
00747     int32_t     fMaxIntegerDigits;
00748     int32_t     fMinIntegerDigits;
00749     int32_t     fMaxFractionDigits;
00750     int32_t     fMinFractionDigits;
00751     UBool      fParseIntegerOnly;
00752 
00753     // ISO currency code
00754     UChar      fCurrency[4];
00755 
00756     friend class ICUNumberFormatFactory; // access to makeInstance, EStyles
00757     friend class ICUNumberFormatService;
00758 };
00759 
00760 #if !UCONFIG_NO_SERVICE
00761 
00769 class U_I18N_API NumberFormatFactory : public UObject {
00770 public:
00771 
00776     virtual ~NumberFormatFactory();
00777 
00784     virtual UBool visible(void) const = 0;
00785 
00791     virtual const UnicodeString * getSupportedIDs(int32_t &count, UErrorCode& status) const = 0;
00792 
00800     virtual NumberFormat* createFormat(const Locale& loc, UNumberFormatStyle formatType) = 0;
00801 };
00802 
00807 class U_I18N_API SimpleNumberFormatFactory : public NumberFormatFactory {
00808 protected:
00813     const UBool _visible;
00814 
00819     UnicodeString _id;
00820 
00821 public:
00825     SimpleNumberFormatFactory(const Locale& locale, UBool visible = TRUE);
00826 
00830     virtual ~SimpleNumberFormatFactory();
00831 
00835     virtual UBool visible(void) const;
00836 
00840     virtual const UnicodeString * getSupportedIDs(int32_t &count, UErrorCode& status) const;
00841 };
00842 #endif /* #if !UCONFIG_NO_SERVICE */
00843 
00844 // -------------------------------------
00845 
00846 inline UBool
00847 NumberFormat::isParseIntegerOnly() const
00848 {
00849     return fParseIntegerOnly;
00850 }
00851 
00852 inline UnicodeString&
00853 NumberFormat::format(const Formattable& obj,
00854                      UnicodeString& appendTo,
00855                      UErrorCode& status) const {
00856     return Format::format(obj, appendTo, status);
00857 }
00858 
00859 U_NAMESPACE_END
00860 
00861 #endif /* #if !UCONFIG_NO_FORMATTING */
00862 
00863 #endif // _NUMFMT
00864 //eof

Generated on Sat Feb 11 18:13:00 2006 for ICU 3.4 by  doxygen 1.4.6