Main Page | Class Hierarchy | Alphabetical List | Data Structures | File List | Data Fields | Globals

numfmt.h

00001 /*
00002 * Copyright (C) {1997-2004}, 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 
00025 #if !UCONFIG_NO_FORMATTING
00026 
00027 #include "unicode/unistr.h"
00028 #include "unicode/format.h"
00029 #include "unicode/unum.h" // UNumberFormatStyle
00030 #include "unicode/locid.h"
00031 
00032 U_NAMESPACE_BEGIN
00033 
00034 #if !UCONFIG_NO_SERVICE
00035 class NumberFormatFactory;
00036 class StringEnumeration;
00037 
00041 typedef const void* URegistryKey;
00042 #endif
00043 
00143 class U_I18N_API NumberFormat : public Format {
00144 public:
00145 
00154     enum EAlignmentFields {
00155         kIntegerField,
00156         kFractionField,
00157 
00158 
00164         INTEGER_FIELD        = kIntegerField,
00165         FRACTION_FIELD        = kFractionField
00166     };
00167 
00172     virtual ~NumberFormat();
00173 
00180     virtual UBool operator==(const Format& other) const;
00181 
00197     virtual UnicodeString& format(const Formattable& obj,
00198                                   UnicodeString& appendTo,
00199                                   FieldPosition& pos,
00200                                   UErrorCode& status) const;
00201 
00230     virtual void parseObject(const UnicodeString& source,
00231                              Formattable& result,
00232                              ParsePosition& parse_pos) const;
00233 
00244     UnicodeString& format(  double number,
00245                             UnicodeString& appendTo) const;
00246 
00257     UnicodeString& format(  int32_t number,
00258                             UnicodeString& appendTo) const;
00259 
00270     UnicodeString& format(  int64_t number,
00271                             UnicodeString& appendTo) const;
00272 
00285     virtual UnicodeString& format(double number,
00286                                   UnicodeString& appendTo,
00287                                   FieldPosition& pos) const = 0;
00300     virtual UnicodeString& format(int32_t number,
00301                                   UnicodeString& appendTo,
00302                                   FieldPosition& pos) const = 0;
00303 
00317     virtual UnicodeString& format(int64_t number,
00318                                   UnicodeString& appendTo,
00319                                   FieldPosition& pos) const;
00330     UnicodeString& format(const Formattable& obj,
00331                           UnicodeString& appendTo,
00332                           UErrorCode& status) const;
00333 
00355     virtual void parse(const UnicodeString& text,
00356                        Formattable& result,
00357                        ParsePosition& parsePosition) const = 0;
00358 
00374     virtual void parse( const UnicodeString& text,
00375                         Formattable& result,
00376                         UErrorCode& status) const;
00377 
00397     virtual Formattable& parseCurrency(const UnicodeString& text,
00398                                        Formattable& result,
00399                                        ParsePosition& pos) const;
00400 
00412     UBool isParseIntegerOnly(void) const;
00413 
00421     virtual void setParseIntegerOnly(UBool value);
00422 
00431     static NumberFormat* U_EXPORT2 createInstance(UErrorCode&);
00432 
00441     static NumberFormat* U_EXPORT2 createInstance(const Locale& inLocale,
00442                                         UErrorCode&);
00443 
00448     static NumberFormat* U_EXPORT2 createCurrencyInstance(UErrorCode&);
00449 
00455     static NumberFormat* U_EXPORT2 createCurrencyInstance(const Locale& inLocale,
00456                                                 UErrorCode&);
00457 
00462     static NumberFormat* U_EXPORT2 createPercentInstance(UErrorCode&);
00463 
00469     static NumberFormat* U_EXPORT2 createPercentInstance(const Locale& inLocale,
00470                                                UErrorCode&);
00471 
00476     static NumberFormat* U_EXPORT2 createScientificInstance(UErrorCode&);
00477 
00483     static NumberFormat* U_EXPORT2 createScientificInstance(const Locale& inLocale,
00484                                                 UErrorCode&);
00485 
00491     static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
00492 
00493 #if !UCONFIG_NO_SERVICE
00494 
00501     static URegistryKey U_EXPORT2 registerFactory(NumberFormatFactory* toAdopt, UErrorCode& status);
00502 
00512     static UBool U_EXPORT2 unregister(URegistryKey key, UErrorCode& status);
00513 
00520     static StringEnumeration* U_EXPORT2 getAvailableLocales(void);
00521 #endif /* UCONFIG_NO_SERVICE */
00522 
00532     UBool isGroupingUsed(void) const;
00533 
00540     virtual void setGroupingUsed(UBool newValue);
00541 
00550     int32_t getMaximumIntegerDigits(void) const;
00551 
00564     virtual void setMaximumIntegerDigits(int32_t newValue);
00565 
00574     int32_t getMinimumIntegerDigits(void) const;
00575 
00586     virtual void setMinimumIntegerDigits(int32_t newValue);
00587 
00596     int32_t getMaximumFractionDigits(void) const;
00597 
00608     virtual void setMaximumFractionDigits(int32_t newValue);
00609 
00618     int32_t getMinimumFractionDigits(void) const;
00619 
00630     virtual void setMinimumFractionDigits(int32_t newValue);
00631 
00644     virtual void setCurrency(const UChar* theCurrency, UErrorCode& ec);
00645 
00653     const UChar* getCurrency() const;
00654 
00655 public:
00656 
00665     static UClassID U_EXPORT2 getStaticClassID(void);
00666 
00678     virtual UClassID getDynamicClassID(void) const = 0;
00679 
00680 protected:
00681 
00686     NumberFormat();
00687 
00692     NumberFormat(const NumberFormat&);
00693 
00698     NumberFormat& operator=(const NumberFormat&);
00699 
00708     virtual void getEffectiveCurrency(UChar* result, UErrorCode& ec) const;
00709 
00710 private:
00711     static const int32_t fgMaxIntegerDigits;
00712     static const int32_t fgMinIntegerDigits;
00713 
00714 private:
00715 
00716     enum EStyles {
00717         kNumberStyle,
00718         kCurrencyStyle,
00719         kPercentStyle,
00720         kScientificStyle,
00721         kStyleCount // ALWAYS LAST ENUM: number of styles
00722     };
00723 
00733     static NumberFormat* U_EXPORT2 createInstance(const Locale& desiredLocale, EStyles choice, UErrorCode& success);
00734 
00742     static NumberFormat* makeInstance(const Locale& desiredLocale, EStyles choice, UErrorCode& success);
00743     static const int32_t    fgNumberPatternsCount;
00744     static const UChar* const fgLastResortNumberPatterns[];
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 Tue Jul 26 00:39:58 2005 for ICU 3.2 by  doxygen 1.3.9.1