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 00260 UnicodeString& format( int64_t number, 00261 UnicodeString& appendTo) const; 00262 00275 virtual UnicodeString& format(double number, 00276 UnicodeString& appendTo, 00277 FieldPosition& pos) const = 0; 00290 virtual UnicodeString& format(int32_t number, 00291 UnicodeString& appendTo, 00292 FieldPosition& pos) const = 0; 00293 00307 virtual UnicodeString& format(int64_t number, 00308 UnicodeString& appendTo, 00309 FieldPosition& pos) const; 00320 UnicodeString& format(const Formattable& obj, 00321 UnicodeString& appendTo, 00322 UErrorCode& status) const; 00323 00345 virtual void parse(const UnicodeString& text, 00346 Formattable& result, 00347 ParsePosition& parsePosition) const = 0; 00348 00364 virtual void parse( const UnicodeString& text, 00365 Formattable& result, 00366 UErrorCode& status) const; 00367 00379 UBool isParseIntegerOnly(void) const; 00380 00388 virtual void setParseIntegerOnly(UBool value); 00389 00398 static NumberFormat* createInstance(UErrorCode&); 00399 00408 static NumberFormat* createInstance(const Locale& inLocale, 00409 UErrorCode&); 00410 00415 static NumberFormat* createCurrencyInstance(UErrorCode&); 00416 00422 static NumberFormat* createCurrencyInstance(const Locale& inLocale, 00423 UErrorCode&); 00424 00429 static NumberFormat* createPercentInstance(UErrorCode&); 00430 00436 static NumberFormat* createPercentInstance(const Locale& inLocale, 00437 UErrorCode&); 00438 00443 static NumberFormat* createScientificInstance(UErrorCode&); 00444 00450 static NumberFormat* createScientificInstance(const Locale& inLocale, 00451 UErrorCode&); 00452 00458 static const Locale* getAvailableLocales(int32_t& count); 00459 00467 static URegistryKey registerFactory(NumberFormatFactory* toAdopt, UErrorCode& status); 00468 00478 static UBool unregister(URegistryKey key, UErrorCode& status); 00479 00486 static StringEnumeration* getAvailableLocales(void); 00487 00497 UBool isGroupingUsed(void) const; 00498 00505 virtual void setGroupingUsed(UBool newValue); 00506 00515 int32_t getMaximumIntegerDigits(void) const; 00516 00529 virtual void setMaximumIntegerDigits(int32_t newValue); 00530 00539 int32_t getMinimumIntegerDigits(void) const; 00540 00551 virtual void setMinimumIntegerDigits(int32_t newValue); 00552 00561 int32_t getMaximumFractionDigits(void) const; 00562 00573 virtual void setMaximumFractionDigits(int32_t newValue); 00574 00583 int32_t getMinimumFractionDigits(void) const; 00584 00595 virtual void setMinimumFractionDigits(int32_t newValue); 00596 00608 virtual void setCurrency(const UChar* theCurrency); 00609 00617 const UChar* getCurrency() const; 00618 00619 public: 00620 00632 virtual UClassID getDynamicClassID(void) const = 0; 00633 00634 protected: 00635 00640 NumberFormat(); 00641 00646 NumberFormat(const NumberFormat&); 00647 00652 NumberFormat& operator=(const NumberFormat&); 00653 00654 private: 00655 static const int32_t fgMaxIntegerDigits; 00656 static const int32_t fgMinIntegerDigits; 00657 00658 private: 00659 00660 enum EStyles { 00661 kNumberStyle, 00662 kCurrencyStyle, 00663 kPercentStyle, 00664 kScientificStyle, 00665 kStyleCount // ALWAYS LAST ENUM: number of styles 00666 }; 00667 00677 static NumberFormat* createInstance(const Locale& desiredLocale, EStyles choice, UErrorCode& success); 00678 00686 static NumberFormat* makeInstance(const Locale& desiredLocale, EStyles choice, UErrorCode& success); 00687 static const int32_t fgNumberPatternsCount; 00688 static const UChar* const fgLastResortNumberPatterns[]; 00689 00690 UBool fGroupingUsed; 00691 int32_t fMaxIntegerDigits; 00692 int32_t fMinIntegerDigits; 00693 int32_t fMaxFractionDigits; 00694 int32_t fMinFractionDigits; 00695 UBool fParseIntegerOnly; 00696 00697 // ISO currency code 00698 UChar currency[4]; 00699 00700 friend class ICUNumberFormatFactory; // access to makeInstance, EStyles 00701 friend class ICUNumberFormatService; 00702 }; 00703 00712 class U_I18N_API NumberFormatFactory : public UObject { 00713 public: 00714 00721 virtual UBool visible(void) const = 0; 00722 00728 virtual const UnicodeString * getSupportedIDs(int32_t &count, UErrorCode& status) const = 0; 00729 00737 virtual NumberFormat* createFormat(const Locale& loc, UNumberFormatStyle formatType) = 0; 00738 }; 00739 00744 class U_I18N_API SimpleNumberFormatFactory : public NumberFormatFactory { 00745 protected: 00750 const UBool _visible; 00751 00756 UnicodeString _id; 00757 00758 public: 00762 SimpleNumberFormatFactory(const Locale& locale, UBool visible = TRUE) 00763 : _visible(visible) 00764 , _id(locale.getName()) 00765 { 00766 } 00767 00771 virtual UBool visible(void) const { 00772 return _visible; 00773 } 00774 00778 virtual const UnicodeString * getSupportedIDs(int32_t &count, UErrorCode& status) const 00779 { 00780 if (U_SUCCESS(status)) { 00781 count = 1; 00782 return &_id; 00783 } 00784 count = 0; 00785 return NULL; 00786 } 00787 }; 00788 00789 00790 // ------------------------------------- 00791 00792 inline UBool 00793 NumberFormat::isParseIntegerOnly() const 00794 { 00795 return fParseIntegerOnly; 00796 } 00797 00798 inline UnicodeString& 00799 NumberFormat::format(const Formattable& obj, 00800 UnicodeString& appendTo, 00801 UErrorCode& status) const { 00802 return Format::format(obj, appendTo, status); 00803 } 00804 00805 U_NAMESPACE_END 00806 00807 #endif /* #if !UCONFIG_NO_FORMATTING */ 00808 00809 #endif // _NUMFMT 00810 //eof

Generated on Wed Jul 28 09:15:54 2004 for ICU 2.8 by doxygen 1.3.7