choicfmt.h

Go to the documentation of this file.
00001 /* 00002 ******************************************************************************** 00003 * Copyright (C) 1997-2004, International Business Machines 00004 * Corporation and others. All Rights Reserved. 00005 ******************************************************************************** 00006 * 00007 * File CHOICFMT.H 00008 * 00009 * Modification History: 00010 * 00011 * Date Name Description 00012 * 02/19/97 aliu Converted from java. 00013 * 03/20/97 helena Finished first cut of implementation and got rid 00014 * of nextDouble/previousDouble and replaced with 00015 * boolean array. 00016 * 4/10/97 aliu Clean up. Modified to work on AIX. 00017 * 8/6/97 nos Removed overloaded constructor, member var 'buffer'. 00018 * 07/22/98 stephen Removed operator!= (implemented in Format) 00019 ******************************************************************************** 00020 */ 00021 00022 #ifndef CHOICFMT_H 00023 #define CHOICFMT_H 00024 00025 #include "unicode/utypes.h" 00026 00027 #if !UCONFIG_NO_FORMATTING 00028 00029 #include "unicode/unistr.h" 00030 #include "unicode/numfmt.h" 00031 #include "unicode/fieldpos.h" 00032 #include "unicode/format.h" 00033 00034 U_NAMESPACE_BEGIN 00035 00036 class MessageFormat; 00037 00254 class U_I18N_API ChoiceFormat: public NumberFormat { 00255 public: 00265 ChoiceFormat(const UnicodeString& pattern, 00266 UErrorCode& status); 00267 00268 00279 ChoiceFormat(const double* limits, 00280 const UnicodeString* formats, 00281 int32_t count ); 00282 00300 ChoiceFormat(const double* limits, 00301 const UBool* closures, 00302 const UnicodeString* formats, 00303 int32_t count); 00304 00311 ChoiceFormat(const ChoiceFormat& that); 00312 00319 const ChoiceFormat& operator=(const ChoiceFormat& that); 00320 00325 virtual ~ChoiceFormat(); 00326 00334 virtual Format* clone(void) const; 00335 00344 virtual UBool operator==(const Format& other) const; 00345 00354 virtual void applyPattern(const UnicodeString& pattern, 00355 UErrorCode& status); 00356 00367 virtual void applyPattern(const UnicodeString& pattern, 00368 UParseError& parseError, 00369 UErrorCode& status); 00378 virtual UnicodeString& toPattern(UnicodeString &pattern) const; 00379 00380 #ifdef U_USE_CHOICE_FORMAT_DEPRECATES 00381 00394 virtual void adoptChoices(double* limitsToAdopt, 00395 UnicodeString* formatsToAdopt, 00396 int32_t count ); 00397 00408 virtual void adoptChoices(double* limitsToAdopt, 00409 UBool* closuresToAdopt, 00410 UnicodeString* formatsToAdopt, 00411 int32_t count); 00412 #endif 00413 00426 virtual void setChoices(const double* limitsToCopy, 00427 const UnicodeString* formatsToCopy, 00428 int32_t count ); 00429 00439 virtual void setChoices(const double* limits, 00440 const UBool* closures, 00441 const UnicodeString* formats, 00442 int32_t count); 00443 00451 virtual const double* getLimits(int32_t& count) const; 00452 00461 virtual const UBool* getClosures(int32_t& count) const; 00462 00470 virtual const UnicodeString* getFormats(int32_t& count) const; 00471 00483 virtual UnicodeString& format(double number, 00484 UnicodeString& appendTo, 00485 FieldPosition& pos) const; 00497 virtual UnicodeString& format(int32_t number, 00498 UnicodeString& appendTo, 00499 FieldPosition& pos) const; 00500 00512 virtual UnicodeString& format(int64_t number, 00513 UnicodeString& appendTo, 00514 FieldPosition& pos) const; 00515 00530 virtual UnicodeString& format(const Formattable* objs, 00531 int32_t cnt, 00532 UnicodeString& appendTo, 00533 FieldPosition& pos, 00534 UErrorCode& success) const; 00549 virtual UnicodeString& format(const Formattable& obj, 00550 UnicodeString& appendTo, 00551 FieldPosition& pos, 00552 UErrorCode& status) const; 00553 00565 UnicodeString& format(const Formattable& obj, 00566 UnicodeString& appendTo, 00567 UErrorCode& status) const; 00568 00580 UnicodeString& format( double number, 00581 UnicodeString& appendTo) const; 00582 00594 UnicodeString& format( int32_t number, 00595 UnicodeString& appendTo) const; 00596 00615 virtual void parse(const UnicodeString& text, 00616 Formattable& result, 00617 ParsePosition& parsePosition) const; 00618 00635 virtual void parse(const UnicodeString& text, 00636 Formattable& result, 00637 UErrorCode& status) const; 00638 00639 00640 public: 00652 virtual UClassID getDynamicClassID(void) const; 00653 00665 static UClassID getStaticClassID(void); 00666 00667 private: 00668 // static cache management (thread-safe) 00669 // static NumberFormat* getNumberFormat(UErrorCode &status); // call this function to 'check out' a numberformat from the cache. 00670 // static void releaseNumberFormat(NumberFormat *adopt); // call this function to 'return' the number format to the cache. 00671 00678 static double stod(const UnicodeString& string); 00679 00687 static UnicodeString& dtos(double value, UnicodeString& string); 00688 00689 ChoiceFormat(); // default constructor not implemented 00690 00702 ChoiceFormat(const UnicodeString& newPattern, 00703 UParseError& parseError, 00704 UErrorCode& status); 00705 00706 friend class MessageFormat; 00744 double* fChoiceLimits; 00745 UBool* fClosures; 00746 UnicodeString* fChoiceFormats; 00747 int32_t fCount; 00748 }; 00749 00750 inline UnicodeString& 00751 ChoiceFormat::format(const Formattable& obj, 00752 UnicodeString& appendTo, 00753 UErrorCode& status) const { 00754 // Don't use Format:: - use immediate base class only, 00755 // in case immediate base modifies behavior later. 00756 return NumberFormat::format(obj, appendTo, status); 00757 } 00758 00759 inline UnicodeString& 00760 ChoiceFormat::format(double number, 00761 UnicodeString& appendTo) const { 00762 return NumberFormat::format(number, appendTo); 00763 } 00764 00765 inline UnicodeString& 00766 ChoiceFormat::format(int32_t number, 00767 UnicodeString& appendTo) const { 00768 return NumberFormat::format(number, appendTo); 00769 } 00770 U_NAMESPACE_END 00771 00772 #endif /* #if !UCONFIG_NO_FORMATTING */ 00773 00774 #endif // _CHOICFMT 00775 //eof

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