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 
00026 #include "unicode/utypes.h"
00027 #include "unicode/unistr.h"
00028 #include "unicode/numfmt.h"
00029 #include "unicode/fieldpos.h"
00030 #include "unicode/format.h"
00031 
00032 U_NAMESPACE_BEGIN
00033 
00034 class MessageFormat;
00035 
00243 class U_I18N_API ChoiceFormat: public NumberFormat {
00244 public:
00254     ChoiceFormat(const UnicodeString& newPattern,
00255                  UErrorCode& status);
00256 
00257 
00268     ChoiceFormat(const double* limits,
00269                  const UnicodeString* formats,
00270                  int32_t count );
00271 
00288     ChoiceFormat(const double* limits,
00289                  const UBool* closures,
00290                  const UnicodeString* formats,
00291                  int32_t count);
00292 
00299     ChoiceFormat(const ChoiceFormat&);
00300 
00307     const ChoiceFormat& operator=(const ChoiceFormat&);
00308 
00313     virtual ~ChoiceFormat();
00314 
00322     virtual Format* clone(void) const;
00323 
00332     virtual UBool operator==(const Format& other) const;
00333 
00342     virtual void applyPattern(const UnicodeString& pattern,
00343                               UErrorCode& status);
00344 
00355     virtual void applyPattern(const UnicodeString& pattern,
00356                              UParseError& parseError,
00357                              UErrorCode& status);
00365     virtual UnicodeString& toPattern(UnicodeString &pattern) const;
00366 
00380     virtual void adoptChoices(double* limitsToAdopt,
00381                               UnicodeString* formatsToAdopt,
00382                               int32_t count );  
00383 
00394     virtual void adoptChoices(double* limitsToAdopt,
00395                               UBool* closuresToAdopt,
00396                               UnicodeString* formatsToAdopt,
00397                               int32_t count);
00398     
00411     virtual void setChoices(const double* limitsToCopy,
00412                             const UnicodeString* formatsToCopy,
00413                             int32_t count );    
00414 
00423     virtual void setChoices(const double* limits,
00424                             const UBool* closures,
00425                             const UnicodeString* formats,
00426                             int32_t count);
00427 
00435     virtual const double* getLimits(int32_t& count) const;
00436     
00444     virtual const UBool* getClosures(int32_t& count) const;
00445 
00453     virtual const UnicodeString* getFormats(int32_t& count) const;
00454 
00466     virtual UnicodeString& format(double number,
00467                                   UnicodeString& toAppendTo,
00468                                   FieldPosition& pos) const;
00480     virtual UnicodeString& format(int32_t number,
00481                                   UnicodeString& toAppendTo,
00482                                   FieldPosition& pos) const;
00497     virtual UnicodeString& format(const Formattable* objs,
00498                                   int32_t cnt,
00499                                   UnicodeString& toAppendTo,
00500                                   FieldPosition& pos,
00501                                   UErrorCode& success) const;
00516     virtual UnicodeString& format(const Formattable& obj,
00517                                   UnicodeString& toAppendTo,
00518                                   FieldPosition& pos, 
00519                                   UErrorCode& status) const;
00520 
00531     UnicodeString& format(const Formattable& obj,
00532                           UnicodeString& result,
00533                           UErrorCode& status) const;
00534 
00545     UnicodeString& format(  double number,
00546                             UnicodeString& output) const;
00547 
00558     UnicodeString& format(  int32_t number,
00559                             UnicodeString& output) const;
00560 
00579     virtual void parse(const UnicodeString& text,
00580                        Formattable& result,
00581                        ParsePosition& parsePosition) const;
00582     
00599     virtual void parse(const UnicodeString& text,
00600                        Formattable& result,
00601                        UErrorCode& status) const;
00602     
00603     
00604 public:
00616     virtual UClassID getDynamicClassID(void) const;
00617 
00629     static UClassID getStaticClassID(void) { return (UClassID)&fgClassID; }
00630 
00639     static double nextDouble(double d, UBool positive);
00640 
00648     static double nextDouble(double d );
00649 
00656     static double previousDouble(double d );
00657 
00658 private:
00659     // static cache management (thread-safe)
00660   //  static NumberFormat* getNumberFormat(UErrorCode &status); // call this function to 'check out' a numberformat from the cache.
00661   //  static void          releaseNumberFormat(NumberFormat *adopt); // call this function to 'return' the number format to the cache.
00662     
00669     static double stod(const UnicodeString& string);
00670 
00678     static UnicodeString& dtos(double value, UnicodeString& string);
00679 
00680     //static UMTX fgMutex;
00681     //static NumberFormat* fgNumberFormat;
00682     static const char fgClassID;
00683 
00684     static const UChar fgPositiveInfinity[];
00685     static const UChar fgNegativeInfinity[];
00697     ChoiceFormat(const UnicodeString& newPattern,
00698                  UParseError& parseError,
00699                  UErrorCode& status);
00700 
00701     friend class MessageFormat;
00739     double*         fChoiceLimits;
00740     UBool*          fClosures;
00741     UnicodeString*  fChoiceFormats;
00742     int32_t         fCount;
00743 };
00744  
00745 inline UClassID 
00746 ChoiceFormat::getDynamicClassID() const
00747 { 
00748     return ChoiceFormat::getStaticClassID(); 
00749 }
00750 
00751 inline double ChoiceFormat::nextDouble( double d )
00752 {
00753     return ChoiceFormat::nextDouble( d, TRUE );
00754 }
00755     
00756 inline double ChoiceFormat::previousDouble( double d )
00757 {
00758     return ChoiceFormat::nextDouble( d, FALSE );
00759 }
00760 
00761 inline UnicodeString&
00762 ChoiceFormat::format(const Formattable& obj,
00763                      UnicodeString& result,
00764                      UErrorCode& status) const {
00765     // Don't use Format:: - use immediate base class only,
00766     // in case immediate base modifies behavior later.
00767     return NumberFormat::format(obj, result, status);
00768 }
00769 
00770 inline UnicodeString&
00771 ChoiceFormat::format(double number,
00772                      UnicodeString& output) const {
00773     return NumberFormat::format(number, output);
00774 }
00775 
00776 inline UnicodeString&
00777 ChoiceFormat::format(int32_t number,
00778                      UnicodeString& output) const {
00779     return NumberFormat::format(number, output);
00780 }
00781 U_NAMESPACE_END
00782 
00783 #endif // _CHOICFMT
00784 //eof

Generated on Thu Aug 15 14:13:23 2002 for ICU 2.2 by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001