Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Search  

choicfmt.h

Go to the documentation of this file.
00001 /*
00002 ********************************************************************************
00003 *   Copyright (C) 1997-2001, 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 
00245 class U_I18N_API ChoiceFormat: public NumberFormat {
00246 public:
00256     ChoiceFormat(const UnicodeString& newPattern,
00257                  UErrorCode& status);
00258 
00259 
00270     ChoiceFormat(const double* limits,
00271                  const UnicodeString* formats,
00272                  int32_t count );
00273 
00291     ChoiceFormat(const double* limits,
00292                  const UBool* closures,
00293                  const UnicodeString* formats,
00294                  int32_t count);
00295 
00302     ChoiceFormat(const ChoiceFormat&);
00303 
00310     const ChoiceFormat& operator=(const ChoiceFormat&);
00311 
00316     virtual ~ChoiceFormat();
00317 
00325     virtual Format* clone(void) const;
00326 
00335     virtual UBool operator==(const Format& other) const;
00336 
00345     virtual void applyPattern(const UnicodeString& pattern,
00346                               UErrorCode& status);
00347 
00358     virtual void applyPattern(const UnicodeString& pattern,
00359                              UParseError& parseError,
00360                              UErrorCode& status);
00369     virtual UnicodeString& toPattern(UnicodeString &pattern) const;
00370 
00384     virtual void adoptChoices(double* limitsToAdopt,
00385                               UnicodeString* formatsToAdopt,
00386                               int32_t count );  
00387 
00398     virtual void adoptChoices(double* limitsToAdopt,
00399                               UBool* closuresToAdopt,
00400                               UnicodeString* formatsToAdopt,
00401                               int32_t count);
00402     
00415     virtual void setChoices(const double* limitsToCopy,
00416                             const UnicodeString* formatsToCopy,
00417                             int32_t count );    
00418 
00428     virtual void setChoices(const double* limits,
00429                             const UBool* closures,
00430                             const UnicodeString* formats,
00431                             int32_t count);
00432 
00440     virtual const double* getLimits(int32_t& count) const;
00441     
00450     virtual const UBool* getClosures(int32_t& count) const;
00451 
00459     virtual const UnicodeString* getFormats(int32_t& count) const;
00460 
00472     virtual UnicodeString& format(double number,
00473                                   UnicodeString& appendTo,
00474                                   FieldPosition& pos) const;
00486     virtual UnicodeString& format(int32_t number,
00487                                   UnicodeString& appendTo,
00488                                   FieldPosition& pos) const;
00503     virtual UnicodeString& format(const Formattable* objs,
00504                                   int32_t cnt,
00505                                   UnicodeString& appendTo,
00506                                   FieldPosition& pos,
00507                                   UErrorCode& success) const;
00522     virtual UnicodeString& format(const Formattable& obj,
00523                                   UnicodeString& appendTo,
00524                                   FieldPosition& pos, 
00525                                   UErrorCode& status) const;
00526 
00538     UnicodeString& format(const Formattable& obj,
00539                           UnicodeString& appendTo,
00540                           UErrorCode& status) const;
00541 
00553     UnicodeString& format(  double number,
00554                             UnicodeString& appendTo) const;
00555 
00567     UnicodeString& format(  int32_t number,
00568                             UnicodeString& appendTo) const;
00569 
00588     virtual void parse(const UnicodeString& text,
00589                        Formattable& result,
00590                        ParsePosition& parsePosition) const;
00591     
00608     virtual void parse(const UnicodeString& text,
00609                        Formattable& result,
00610                        UErrorCode& status) const;
00611     
00612     
00613 public:
00625     virtual UClassID getDynamicClassID(void) const;
00626 
00638     static UClassID getStaticClassID(void) { return (UClassID)&fgClassID; }
00639 
00640 #ifdef ICU_NEXTDOUBLE_USE_DEPRECATES
00641 
00649     static double nextDouble(double d, UBool positive);
00650 
00658     static double nextDouble(double d );
00659 
00666     static double previousDouble(double d );
00667 #endif /* ICU_NEXTDOUBLE_USE_DEPRECATES */
00668 
00669 private:
00670     // static cache management (thread-safe)
00671   //  static NumberFormat* getNumberFormat(UErrorCode &status); // call this function to 'check out' a numberformat from the cache.
00672   //  static void          releaseNumberFormat(NumberFormat *adopt); // call this function to 'return' the number format to the cache.
00673     
00680     static double stod(const UnicodeString& string);
00681 
00689     static UnicodeString& dtos(double value, UnicodeString& string);
00690 
00691     //static UMTX fgMutex;
00692     //static NumberFormat* fgNumberFormat;
00693     static const char fgClassID;
00694 
00695     static const UChar fgPositiveInfinity[];
00696     static const UChar fgNegativeInfinity[];
00708     ChoiceFormat(const UnicodeString& newPattern,
00709                  UParseError& parseError,
00710                  UErrorCode& status);
00711 
00712     friend class MessageFormat;
00750     double*         fChoiceLimits;
00751     UBool*          fClosures;
00752     UnicodeString*  fChoiceFormats;
00753     int32_t         fCount;
00754 };
00755  
00756 inline UClassID 
00757 ChoiceFormat::getDynamicClassID() const
00758 { 
00759     return ChoiceFormat::getStaticClassID(); 
00760 }
00761 
00762 #ifdef ICU_NEXTDOUBLE_USE_DEPRECATES
00763 inline double ChoiceFormat::nextDouble( double d )
00764 {
00765     return ChoiceFormat::nextDouble( d, TRUE );
00766 }
00767     
00768 inline double ChoiceFormat::previousDouble( double d )
00769 {
00770     return ChoiceFormat::nextDouble( d, FALSE );
00771 }
00772 #endif /* ICU_NEXTDOUBLE_USE_DEPRECATES */
00773 
00774 inline UnicodeString&
00775 ChoiceFormat::format(const Formattable& obj,
00776                      UnicodeString& appendTo,
00777                      UErrorCode& status) const {
00778     // Don't use Format:: - use immediate base class only,
00779     // in case immediate base modifies behavior later.
00780     return NumberFormat::format(obj, appendTo, status);
00781 }
00782 
00783 inline UnicodeString&
00784 ChoiceFormat::format(double number,
00785                      UnicodeString& appendTo) const {
00786     return NumberFormat::format(number, appendTo);
00787 }
00788 
00789 inline UnicodeString&
00790 ChoiceFormat::format(int32_t number,
00791                      UnicodeString& appendTo) const {
00792     return NumberFormat::format(number, appendTo);
00793 }
00794 U_NAMESPACE_END
00795 
00796 #endif /* #if !UCONFIG_NO_FORMATTING */
00797 
00798 #endif // _CHOICFMT
00799 //eof

Generated on Wed Dec 18 16:49:29 2002 for ICU 2.4 by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001