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

choicfmt.h

Go to the documentation of this file.
00001 /*
00002 ********************************************************************************
00003 *   Copyright (C) 1997-1999, 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 
00133 class U_I18N_API ChoiceFormat: public NumberFormat {
00134 public:
00144     ChoiceFormat(const UnicodeString& newPattern,
00145                  UErrorCode& status);
00146 
00147 
00158     ChoiceFormat(const double* limits,
00159                  const UnicodeString* formats,
00160                  int32_t count );
00161 
00166     ChoiceFormat(const ChoiceFormat&);
00167 
00172     const ChoiceFormat& operator=(const ChoiceFormat&);
00173 
00178     virtual ~ChoiceFormat();
00179 
00185     virtual Format* clone(void) const;
00186 
00192     virtual UBool operator==(const Format& other) const;
00193 
00202     virtual void applyPattern(const UnicodeString& pattern,
00203                               UErrorCode& status);
00204 
00209     virtual UnicodeString& toPattern(UnicodeString &pattern) const;
00210 
00224     virtual void adoptChoices(double* limitsToAdopt,
00225                               UnicodeString* formatsToAdopt,
00226                               int32_t count );  
00227 
00240     virtual void setChoices(const double* limitsToCopy,
00241                             const UnicodeString* formatsToCopy,
00242                             int32_t count );    
00248     virtual const double* getLimits(int32_t& count) const;
00249 
00255     virtual const UnicodeString* getFormats(int32_t& count) const;
00256 
00268     virtual UnicodeString& format(double number,
00269                                   UnicodeString& toAppendTo,
00270                                   FieldPosition& pos) const;
00276     virtual UnicodeString& format(int32_t number,
00277                                   UnicodeString& toAppendTo,
00278                                   FieldPosition& pos) const;
00284     virtual UnicodeString& format(const Formattable* objs,
00285                                   int32_t cnt,
00286                                   UnicodeString& toAppendTo,
00287                                   FieldPosition& pos,
00288                                   UErrorCode& success) const;
00294     virtual UnicodeString& format(const Formattable& obj,
00295                                   UnicodeString& toAppendTo,
00296                                   FieldPosition& pos, 
00297                                   UErrorCode& status) const;
00298 
00303     UnicodeString& format(const Formattable& obj,
00304                           UnicodeString& result,
00305                           UErrorCode& status) const;
00306 
00311     UnicodeString& format(  double number,
00312                             UnicodeString& output) const;
00313 
00318     UnicodeString& format(  int32_t number,
00319                             UnicodeString& output) const;
00320 
00341     virtual void parse(const UnicodeString& text,
00342                        Formattable& result,
00343                        ParsePosition& parsePosition) const;
00344     virtual void parse(const UnicodeString& text,
00345                        Formattable& result,
00346                        UErrorCode& status) const;
00347     
00348     
00349 public:
00361     virtual UClassID getDynamicClassID(void) const;
00362 
00374     static UClassID getStaticClassID(void) { return (UClassID)&fgClassID; }
00375 
00376     /*
00377      * Finds the least double greater than d (if positive == true),
00378      * or the greatest double less than d (if positive == false).
00379      * If NaN, returns same value.
00380      * <P>
00381      * Does not affect floating-point flags,
00382      * @stable
00383      */
00384     static double nextDouble(double d, UBool positive);
00385 
00393     static double nextDouble(double d );
00394 
00401     static double previousDouble(double d );
00402 
00403 private:
00404     // static cache management (thread-safe)
00405     static NumberFormat* getNumberFormat(UErrorCode &status); // call this function to 'check out' a numberformat from the cache.
00406     static void          releaseNumberFormat(NumberFormat *adopt); // call this function to 'return' the number format to the cache.
00407     
00415     static double stod(const UnicodeString& string, UErrorCode& status);
00416 
00425     static UnicodeString& dtos(double value, UnicodeString& string, UErrorCode& status);
00426 
00427     static NumberFormat* fgNumberFormat;
00428     static char fgClassID;
00429 
00430     double*         fChoiceLimits;
00431     UnicodeString*  fChoiceFormats;
00432     int32_t         fCount;
00433 };
00434  
00435 inline UClassID 
00436 ChoiceFormat::getDynamicClassID() const
00437 { 
00438     return ChoiceFormat::getStaticClassID(); 
00439 }
00440 
00441 inline double ChoiceFormat::nextDouble( double d )
00442 {
00443     return ChoiceFormat::nextDouble( d, TRUE );
00444 }
00445     
00446 inline double ChoiceFormat::previousDouble( double d )
00447 {
00448     return ChoiceFormat::nextDouble( d, FALSE );
00449 }
00450 
00451 inline UnicodeString&
00452 ChoiceFormat::format(const Formattable& obj,
00453                      UnicodeString& result,
00454                      UErrorCode& status) const {
00455     // Don't use Format:: - use immediate base class only,
00456     // in case immediate base modifies behavior later.
00457     return NumberFormat::format(obj, result, status);
00458 }
00459 
00460 inline UnicodeString&
00461 ChoiceFormat::format(double number,
00462                      UnicodeString& output) const {
00463     return NumberFormat::format(number, output);
00464 }
00465 
00466 inline UnicodeString&
00467 ChoiceFormat::format(int32_t number,
00468                      UnicodeString& output) const {
00469     return NumberFormat::format(number, output);
00470 }
00471 
00472 #endif // _CHOICFMT
00473 //eof

Generated at Fri Dec 15 12:12:31 2000 for ICU 1.7 by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000