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

numfmt.h

00001 /*
00002 * Copyright (C) {1997-2003}, 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 class NumberFormatFactory;
00035 class StringEnumeration;
00036 
00037 typedef const void* URegistryKey;
00038 
00133 class U_I18N_API NumberFormat : public Format {
00134 public:
00135 
00144     enum EAlignmentFields {
00145         kIntegerField,
00146         kFractionField,
00147 
00148 
00154         INTEGER_FIELD        = kIntegerField,
00155         FRACTION_FIELD        = kFractionField
00156     };
00157 
00162     virtual ~NumberFormat();
00163 
00170     virtual UBool operator==(const Format& other) const;
00171 
00187     virtual UnicodeString& format(const Formattable& obj,
00188                                   UnicodeString& appendTo,
00189                                   FieldPosition& pos,
00190                                   UErrorCode& status) const;
00191 
00220     virtual void parseObject(const UnicodeString& source,
00221                              Formattable& result,
00222                              ParsePosition& parse_pos) const;
00223 
00234     UnicodeString& format(  double number,
00235                             UnicodeString& appendTo) const;
00236 
00247     UnicodeString& format(  int32_t number,
00248                             UnicodeString& appendTo) const;
00249 
00262     virtual UnicodeString& format(double number,
00263                                   UnicodeString& appendTo,
00264                                   FieldPosition& pos) const = 0;
00277     virtual UnicodeString& format(int32_t number,
00278                                   UnicodeString& appendTo,
00279                                   FieldPosition& pos) const = 0;
00280 
00291     UnicodeString& format(const Formattable& obj,
00292                           UnicodeString& appendTo,
00293                           UErrorCode& status) const;
00294 
00316     virtual void parse(const UnicodeString& text,
00317                        Formattable& result,
00318                        ParsePosition& parsePosition) const = 0;
00319 
00335     virtual void parse( const UnicodeString& text,
00336                         Formattable& result,
00337                         UErrorCode& status) const;
00338 
00350     UBool isParseIntegerOnly(void) const;
00351 
00359     virtual void setParseIntegerOnly(UBool value);
00360 
00369     static NumberFormat* createInstance(UErrorCode&);
00370 
00379     static NumberFormat* createInstance(const Locale& inLocale,
00380                                         UErrorCode&);
00381 
00386     static NumberFormat* createCurrencyInstance(UErrorCode&);
00387 
00393     static NumberFormat* createCurrencyInstance(const Locale& inLocale,
00394                                                 UErrorCode&);
00395 
00400     static NumberFormat* createPercentInstance(UErrorCode&);
00401 
00407     static NumberFormat* createPercentInstance(const Locale& inLocale,
00408                                                UErrorCode&);
00409 
00414     static NumberFormat* createScientificInstance(UErrorCode&);
00415 
00421     static NumberFormat* createScientificInstance(const Locale& inLocale,
00422                                                 UErrorCode&);
00423 
00429     static const Locale* getAvailableLocales(int32_t& count);
00430 
00438     static URegistryKey registerFactory(NumberFormatFactory* toAdopt, UErrorCode& status);
00439 
00449     static UBool unregister(URegistryKey key, UErrorCode& status);
00450 
00457     static StringEnumeration* getAvailableLocales(void);
00458 
00468     UBool isGroupingUsed(void) const;
00469 
00476     virtual void setGroupingUsed(UBool newValue);
00477 
00486     int32_t getMaximumIntegerDigits(void) const;
00487 
00500     virtual void setMaximumIntegerDigits(int32_t newValue);
00501 
00510     int32_t getMinimumIntegerDigits(void) const;
00511 
00522     virtual void setMinimumIntegerDigits(int32_t newValue);
00523 
00532     int32_t getMaximumFractionDigits(void) const;
00533 
00544     virtual void setMaximumFractionDigits(int32_t newValue);
00545 
00554     int32_t getMinimumFractionDigits(void) const;
00555 
00566     virtual void setMinimumFractionDigits(int32_t newValue);
00567 
00579     virtual void setCurrency(const UChar* theCurrency);
00580 
00588     const UChar* getCurrency() const;
00589 
00590 public:
00591 
00603     static inline UClassID getStaticClassID(void);
00604 
00616     virtual UClassID getDynamicClassID(void) const = 0;
00617 
00618 protected:
00619 
00624     NumberFormat();
00625 
00630     NumberFormat(const NumberFormat&);
00631 
00636     NumberFormat& operator=(const NumberFormat&);
00637 
00638 private:
00639     static const int32_t fgMaxIntegerDigits;
00640     static const int32_t fgMinIntegerDigits;
00641 
00642 private:
00643     static const char fgClassID;
00644 
00645     enum EStyles {
00646         kNumberStyle,
00647         kCurrencyStyle,
00648         kPercentStyle,
00649         kScientificStyle,
00650         kStyleCount // ALWAYS LAST ENUM: number of styles
00651     };
00652     
00662     static NumberFormat* createInstance(const Locale& desiredLocale, EStyles choice, UErrorCode& success);
00663 
00671         static NumberFormat* makeInstance(const Locale& desiredLocale, EStyles choice, UErrorCode& success);
00672     static const int32_t    fgNumberPatternsCount;
00673     static const UChar* const fgLastResortNumberPatterns[];
00674 
00675     UBool      fGroupingUsed;
00676     int32_t     fMaxIntegerDigits;
00677     int32_t     fMinIntegerDigits;
00678     int32_t     fMaxFractionDigits;
00679     int32_t     fMinFractionDigits;
00680     UBool      fParseIntegerOnly;
00681 
00682     // ISO currency code
00683     UChar      currency[4];
00684 
00685         friend class ICUNumberFormatFactory; // access to makeInstance, EStyles
00686         friend class ICUNumberFormatService;
00687 };
00688 
00697 class U_I18N_API NumberFormatFactory : public UObject {
00698 public:
00699 
00706     virtual UBool visible(void) const = 0;
00707 
00713     virtual const UnicodeString * const getSupportedIDs(int32_t &count, UErrorCode& status) const = 0;
00714 
00722     virtual NumberFormat* createFormat(const Locale& loc, UNumberFormatStyle formatType) = 0;
00723 };
00724 
00729 class U_I18N_API SimpleNumberFormatFactory : public NumberFormatFactory {
00730 protected:
00735     const UBool _visible;
00736 
00741     UnicodeString _id;
00742 
00743 public:
00747     SimpleNumberFormatFactory(const Locale& locale, UBool visible = TRUE)
00748       : _visible(visible)
00749       , _id(locale.getName())
00750     {
00751     }
00752 
00756     virtual UBool visible(void) const {
00757         return _visible;
00758     }
00759 
00763     virtual const UnicodeString * const getSupportedIDs(int32_t &count, UErrorCode& status) const 
00764       {
00765         if (U_SUCCESS(status)) {
00766           count = 1;
00767           return &_id;
00768         }
00769         count = 0;
00770         return NULL;
00771       }
00772 };
00773 
00774 
00775 // -------------------------------------
00776 
00777 inline UClassID
00778 NumberFormat::getStaticClassID(void)
00779 { return (UClassID)&fgClassID; }
00780 
00781 inline UBool
00782 NumberFormat::isParseIntegerOnly() const
00783 {
00784     return fParseIntegerOnly;
00785 }
00786 
00787 inline UnicodeString&
00788 NumberFormat::format(const Formattable& obj,
00789                      UnicodeString& appendTo,
00790                      UErrorCode& status) const {
00791     return Format::format(obj, appendTo, status);
00792 }
00793 
00794 U_NAMESPACE_END
00795 
00796 #endif /* #if !UCONFIG_NO_FORMATTING */
00797 
00798 #endif // _NUMFMT
00799 //eof

Generated on Wed Sep 3 17:47:09 2003 for ICU 2.6 by doxygen 1.3.2