numfmt.h

Go to the documentation of this file.
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 class NumberFormatFactory; 00035 class StringEnumeration; 00036 00040 typedef const void* URegistryKey; 00041 00141 class U_I18N_API NumberFormat : public Format { 00142 public: 00143 00152 enum EAlignmentFields { 00153 kIntegerField, 00154 kFractionField, 00155 00156 00162 INTEGER_FIELD = kIntegerField, 00163 FRACTION_FIELD = kFractionField 00164 }; 00165 00170 virtual ~NumberFormat(); 00171 00178 virtual UBool operator==(const Format& other) const; 00179 00195 virtual UnicodeString& format(const Formattable& obj, 00196 UnicodeString& appendTo, 00197 FieldPosition& pos, 00198 UErrorCode& status) const; 00199 00228 virtual void parseObject(const UnicodeString& source, 00229 Formattable& result, 00230 ParsePosition& parse_pos) const; 00231 00242 UnicodeString& format( double number, 00243 UnicodeString& appendTo) const; 00244 00255 UnicodeString& format( int32_t number, 00256 UnicodeString& appendTo) const; 00257 00268 UnicodeString& format( int64_t number, 00269 UnicodeString& appendTo) const; 00270 00283 virtual UnicodeString& format(double number, 00284 UnicodeString& appendTo, 00285 FieldPosition& pos) const = 0; 00298 virtual UnicodeString& format(int32_t number, 00299 UnicodeString& appendTo, 00300 FieldPosition& pos) const = 0; 00301 00315 virtual UnicodeString& format(int64_t number, 00316 UnicodeString& appendTo, 00317 FieldPosition& pos) const; 00328 UnicodeString& format(const Formattable& obj, 00329 UnicodeString& appendTo, 00330 UErrorCode& status) const; 00331 00353 virtual void parse(const UnicodeString& text, 00354 Formattable& result, 00355 ParsePosition& parsePosition) const = 0; 00356 00372 virtual void parse( const UnicodeString& text, 00373 Formattable& result, 00374 UErrorCode& status) const; 00375 00395 virtual Formattable& parseCurrency(const UnicodeString& text, 00396 Formattable& result, 00397 ParsePosition& pos) const; 00398 00410 UBool isParseIntegerOnly(void) const; 00411 00419 virtual void setParseIntegerOnly(UBool value); 00420 00429 static NumberFormat* createInstance(UErrorCode&); 00430 00439 static NumberFormat* createInstance(const Locale& inLocale, 00440 UErrorCode&); 00441 00446 static NumberFormat* createCurrencyInstance(UErrorCode&); 00447 00453 static NumberFormat* createCurrencyInstance(const Locale& inLocale, 00454 UErrorCode&); 00455 00460 static NumberFormat* createPercentInstance(UErrorCode&); 00461 00467 static NumberFormat* createPercentInstance(const Locale& inLocale, 00468 UErrorCode&); 00469 00474 static NumberFormat* createScientificInstance(UErrorCode&); 00475 00481 static NumberFormat* createScientificInstance(const Locale& inLocale, 00482 UErrorCode&); 00483 00489 static const Locale* getAvailableLocales(int32_t& count); 00490 00498 static URegistryKey registerFactory(NumberFormatFactory* toAdopt, UErrorCode& status); 00499 00509 static UBool unregister(URegistryKey key, UErrorCode& status); 00510 00517 static StringEnumeration* getAvailableLocales(void); 00518 00528 UBool isGroupingUsed(void) const; 00529 00536 virtual void setGroupingUsed(UBool newValue); 00537 00546 int32_t getMaximumIntegerDigits(void) const; 00547 00560 virtual void setMaximumIntegerDigits(int32_t newValue); 00561 00570 int32_t getMinimumIntegerDigits(void) const; 00571 00582 virtual void setMinimumIntegerDigits(int32_t newValue); 00583 00592 int32_t getMaximumFractionDigits(void) const; 00593 00604 virtual void setMaximumFractionDigits(int32_t newValue); 00605 00614 int32_t getMinimumFractionDigits(void) const; 00615 00626 virtual void setMinimumFractionDigits(int32_t newValue); 00627 00640 virtual void setCurrency(const UChar* theCurrency, UErrorCode& ec); 00641 00649 const UChar* getCurrency() const; 00650 00651 public: 00652 00661 static UClassID getStaticClassID(void); 00662 00674 virtual UClassID getDynamicClassID(void) const = 0; 00675 00676 protected: 00677 00682 NumberFormat(); 00683 00688 NumberFormat(const NumberFormat&); 00689 00694 NumberFormat& operator=(const NumberFormat&); 00695 00704 virtual void getEffectiveCurrency(UChar* result, UErrorCode& ec) const; 00705 00706 private: 00707 static const int32_t fgMaxIntegerDigits; 00708 static const int32_t fgMinIntegerDigits; 00709 00710 private: 00711 00712 enum EStyles { 00713 kNumberStyle, 00714 kCurrencyStyle, 00715 kPercentStyle, 00716 kScientificStyle, 00717 kStyleCount // ALWAYS LAST ENUM: number of styles 00718 }; 00719 00729 static NumberFormat* createInstance(const Locale& desiredLocale, EStyles choice, UErrorCode& success); 00730 00738 static NumberFormat* makeInstance(const Locale& desiredLocale, EStyles choice, UErrorCode& success); 00739 static const int32_t fgNumberPatternsCount; 00740 static const UChar* const fgLastResortNumberPatterns[]; 00741 00742 UBool fGroupingUsed; 00743 int32_t fMaxIntegerDigits; 00744 int32_t fMinIntegerDigits; 00745 int32_t fMaxFractionDigits; 00746 int32_t fMinFractionDigits; 00747 UBool fParseIntegerOnly; 00748 00749 // ISO currency code 00750 UChar fCurrency[4]; 00751 00752 friend class ICUNumberFormatFactory; // access to makeInstance, EStyles 00753 friend class ICUNumberFormatService; 00754 }; 00755 00764 class U_I18N_API NumberFormatFactory : public UObject { 00765 public: 00766 00771 virtual ~NumberFormatFactory(); 00772 00779 virtual UBool visible(void) const = 0; 00780 00786 virtual const UnicodeString * getSupportedIDs(int32_t &count, UErrorCode& status) const = 0; 00787 00795 virtual NumberFormat* createFormat(const Locale& loc, UNumberFormatStyle formatType) = 0; 00796 }; 00797 00802 class U_I18N_API SimpleNumberFormatFactory : public NumberFormatFactory { 00803 protected: 00808 const UBool _visible; 00809 00814 UnicodeString _id; 00815 00816 public: 00820 SimpleNumberFormatFactory(const Locale& locale, UBool visible = TRUE) 00821 : _visible(visible) 00822 , _id(locale.getName()) 00823 { 00824 } 00825 00829 virtual ~SimpleNumberFormatFactory(); 00830 00834 virtual UBool visible(void) const; 00835 00839 virtual const UnicodeString * getSupportedIDs(int32_t &count, UErrorCode& status) const; 00840 }; 00841 00842 00843 // ------------------------------------- 00844 00845 inline UBool 00846 NumberFormat::isParseIntegerOnly() const 00847 { 00848 return fParseIntegerOnly; 00849 } 00850 00851 inline UnicodeString& 00852 NumberFormat::format(const Formattable& obj, 00853 UnicodeString& appendTo, 00854 UErrorCode& status) const { 00855 return Format::format(obj, appendTo, status); 00856 } 00857 00858 U_NAMESPACE_END 00859 00860 #endif /* #if !UCONFIG_NO_FORMATTING */ 00861 00862 #endif // _NUMFMT 00863 //eof

Generated on Fri Jun 18 12:35:58 2004 for ICU by doxygen 1.3.7