Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields   Globals  

choicfmt.h

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 
00297     ChoiceFormat(const ChoiceFormat&);
00298 
00303     const ChoiceFormat& operator=(const ChoiceFormat&);
00304 
00309     virtual ~ChoiceFormat();
00310 
00316     virtual Format* clone(void) const;
00317 
00323     virtual UBool operator==(const Format& other) const;
00324 
00333     virtual void applyPattern(const UnicodeString& pattern,
00334                               UErrorCode& status);
00335 
00346     virtual void applyPattern(const UnicodeString& pattern,
00347                              UParseError& parseError,
00348                              UErrorCode& status);
00353     virtual UnicodeString& toPattern(UnicodeString &pattern) const;
00354 
00368     virtual void adoptChoices(double* limitsToAdopt,
00369                               UnicodeString* formatsToAdopt,
00370                               int32_t count );  
00371 
00381     virtual void adoptChoices(double* limitsToAdopt,
00382                               UBool* closuresToAdopt,
00383                               UnicodeString* formatsToAdopt,
00384                               int32_t count);
00385     
00398     virtual void setChoices(const double* limitsToCopy,
00399                             const UnicodeString* formatsToCopy,
00400                             int32_t count );    
00401 
00410     virtual void setChoices(const double* limits,
00411                             const UBool* closures,
00412                             const UnicodeString* formats,
00413                             int32_t count);
00414 
00420     virtual const double* getLimits(int32_t& count) const;
00421     
00427     virtual const UBool* getClosures(int32_t& count) const;
00428 
00434     virtual const UnicodeString* getFormats(int32_t& count) const;
00435 
00447     virtual UnicodeString& format(double number,
00448                                   UnicodeString& toAppendTo,
00449                                   FieldPosition& pos) const;
00455     virtual UnicodeString& format(int32_t number,
00456                                   UnicodeString& toAppendTo,
00457                                   FieldPosition& pos) const;
00463     virtual UnicodeString& format(const Formattable* objs,
00464                                   int32_t cnt,
00465                                   UnicodeString& toAppendTo,
00466                                   FieldPosition& pos,
00467                                   UErrorCode& success) const;
00473     virtual UnicodeString& format(const Formattable& obj,
00474                                   UnicodeString& toAppendTo,
00475                                   FieldPosition& pos, 
00476                                   UErrorCode& status) const;
00477 
00482     UnicodeString& format(const Formattable& obj,
00483                           UnicodeString& result,
00484                           UErrorCode& status) const;
00485 
00490     UnicodeString& format(  double number,
00491                             UnicodeString& output) const;
00492 
00497     UnicodeString& format(  int32_t number,
00498                             UnicodeString& output) const;
00499 
00520     virtual void parse(const UnicodeString& text,
00521                        Formattable& result,
00522                        ParsePosition& parsePosition) const;
00523     virtual void parse(const UnicodeString& text,
00524                        Formattable& result,
00525                        UErrorCode& status) const;
00526     
00527     
00528 public:
00540     virtual UClassID getDynamicClassID(void) const;
00541 
00553     static UClassID getStaticClassID(void) { return (UClassID)&fgClassID; }
00554 
00555     /*
00556      * Finds the least double greater than d (if positive == true),
00557      * or the greatest double less than d (if positive == false).
00558      * If NaN, returns same value.
00559      * <P>
00560      * Does not affect floating-point flags,
00561      * @deprecated This will be removed after 2002-Jun-30. Use closures API instead.
00562      */
00563     static double nextDouble(double d, UBool positive);
00564 
00572     static double nextDouble(double d );
00573 
00580     static double previousDouble(double d );
00581 
00582 private:
00583     // static cache management (thread-safe)
00584   //  static NumberFormat* getNumberFormat(UErrorCode &status); // call this function to 'check out' a numberformat from the cache.
00585   //  static void          releaseNumberFormat(NumberFormat *adopt); // call this function to 'return' the number format to the cache.
00586     
00594     static double stod(const UnicodeString& string);
00595 
00604     static UnicodeString& dtos(double value, UnicodeString& string);
00605 
00606     //static UMTX fgMutex;
00607     //static NumberFormat* fgNumberFormat;
00608     static const char fgClassID;
00609 
00610     static const UChar fgPositiveInfinity[];
00611     static const UChar fgNegativeInfinity[];
00621     ChoiceFormat(const UnicodeString& newPattern,
00622                  UParseError& parseError,
00623                  UErrorCode& status);
00624 
00625     friend class MessageFormat;
00663     double*         fChoiceLimits;
00664     UBool*          fClosures;
00665     UnicodeString*  fChoiceFormats;
00666     int32_t         fCount;
00667 };
00668  
00669 inline UClassID 
00670 ChoiceFormat::getDynamicClassID() const
00671 { 
00672     return ChoiceFormat::getStaticClassID(); 
00673 }
00674 
00675 inline double ChoiceFormat::nextDouble( double d )
00676 {
00677     return ChoiceFormat::nextDouble( d, TRUE );
00678 }
00679     
00680 inline double ChoiceFormat::previousDouble( double d )
00681 {
00682     return ChoiceFormat::nextDouble( d, FALSE );
00683 }
00684 
00685 inline UnicodeString&
00686 ChoiceFormat::format(const Formattable& obj,
00687                      UnicodeString& result,
00688                      UErrorCode& status) const {
00689     // Don't use Format:: - use immediate base class only,
00690     // in case immediate base modifies behavior later.
00691     return NumberFormat::format(obj, result, status);
00692 }
00693 
00694 inline UnicodeString&
00695 ChoiceFormat::format(double number,
00696                      UnicodeString& output) const {
00697     return NumberFormat::format(number, output);
00698 }
00699 
00700 inline UnicodeString&
00701 ChoiceFormat::format(int32_t number,
00702                      UnicodeString& output) const {
00703     return NumberFormat::format(number, output);
00704 }
00705 U_NAMESPACE_END
00706 
00707 #endif // _CHOICFMT
00708 //eof

Generated on Sun Mar 10 02:53:58 2002 for ICU 2.0 by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002