Main Page   Class Hierarchy   Compound List   File List   Header Files   Sources   Compound Members   File Members  

choicfmt.h

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 
00121 class U_I18N_API ChoiceFormat: public NumberFormat {
00122 public:
00132     ChoiceFormat(const UnicodeString& newPattern,
00133                  UErrorCode& status);
00134 
00135 
00146     ChoiceFormat(const double* limits,
00147                  const UnicodeString* formats,
00148                  int32_t count );
00149 
00154     ChoiceFormat(const ChoiceFormat&);
00155 
00160     const ChoiceFormat& operator=(const ChoiceFormat&);
00161 
00166     virtual ~ChoiceFormat();
00167 
00173     virtual Format* clone(void) const;
00174 
00180     virtual UBool operator==(const Format& other) const;
00181 
00190     virtual void applyPattern(const UnicodeString& pattern,
00191                               UErrorCode& status);
00192 
00197     virtual UnicodeString& toPattern(UnicodeString &pattern) const;
00198 
00212     virtual void adoptChoices(double* limitsToAdopt,
00213                               UnicodeString* formatsToAdopt,
00214                               int32_t count );  
00215 
00228     virtual void setChoices(const double* limitsToCopy,
00229                             const UnicodeString* formatsToCopy,
00230                             int32_t count );    
00236     virtual const double* getLimits(int32_t& count) const;
00237 
00243     virtual const UnicodeString* getFormats(int32_t& count) const;
00244 
00256     virtual UnicodeString& format(double number,
00257                                   UnicodeString& toAppendTo,
00258                                   FieldPosition& pos) const;
00264     virtual UnicodeString& format(int32_t number,
00265                                   UnicodeString& toAppendTo,
00266                                   FieldPosition& pos) const;
00272     virtual UnicodeString& format(const Formattable* objs,
00273                                   int32_t cnt,
00274                                   UnicodeString& toAppendTo,
00275                                   FieldPosition& pos,
00276                                   UErrorCode& success) const;
00282     virtual UnicodeString& format(const Formattable& obj,
00283                                   UnicodeString& toAppendTo,
00284                                   FieldPosition& pos, 
00285                                   UErrorCode& status) const;
00286 
00291     UnicodeString& format(const Formattable& obj,
00292                           UnicodeString& result,
00293                           UErrorCode& status) const;
00294 
00299     UnicodeString& format(  double number,
00300                             UnicodeString& output) const;
00301 
00306     UnicodeString& format(  int32_t number,
00307                             UnicodeString& output) const;
00308 
00329     virtual void parse(const UnicodeString& text,
00330                        Formattable& result,
00331                        ParsePosition& parsePosition) const;
00332     virtual void parse(const UnicodeString& text,
00333                        Formattable& result,
00334                        UErrorCode& status) const;
00335     
00336     
00337 public:
00349     virtual UClassID getDynamicClassID(void) const;
00350 
00362     static UClassID getStaticClassID(void) { return (UClassID)&fgClassID; }
00363 
00364     /*
00365      * Finds the least double greater than d (if positive == true),
00366      * or the greatest double less than d (if positive == false).
00367      * If NaN, returns same value.
00368      * <P>
00369      * Does not affect floating-point flags,
00370      * @stable
00371      */
00372     static double nextDouble(double d, UBool positive);
00373 
00381     static double nextDouble(double d );
00382 
00389     static double previousDouble(double d );
00390 
00391 private:
00392     // static cache management (thread-safe)
00393     static NumberFormat* getNumberFormat(UErrorCode &status); // call this function to 'check out' a numberformat from the cache.
00394     static void          releaseNumberFormat(NumberFormat *adopt); // call this function to 'return' the number format to the cache.
00395     
00403     static double stod(const UnicodeString& string, UErrorCode& status);
00404 
00413     static UnicodeString& dtos(double value, UnicodeString& string, UErrorCode& status);
00414 
00415     static NumberFormat* fgNumberFormat;
00416     static char fgClassID;
00417 
00418     double*         fChoiceLimits;
00419     UnicodeString*  fChoiceFormats;
00420     int32_t         fCount;
00421 };
00422  
00423 inline UClassID 
00424 ChoiceFormat::getDynamicClassID() const
00425 { 
00426     return ChoiceFormat::getStaticClassID(); 
00427 }
00428 
00429 inline double ChoiceFormat::nextDouble( double d )
00430 {
00431     return ChoiceFormat::nextDouble( d, TRUE );
00432 }
00433     
00434 inline double ChoiceFormat::previousDouble( double d )
00435 {
00436     return ChoiceFormat::nextDouble( d, FALSE );
00437 }
00438 
00439 inline UnicodeString&
00440 ChoiceFormat::format(const Formattable& obj,
00441                      UnicodeString& result,
00442                      UErrorCode& status) const {
00443     // Don't use Format:: - use immediate base class only,
00444     // in case immediate base modifies behavior later.
00445     return NumberFormat::format(obj, result, status);
00446 }
00447 
00448 inline UnicodeString&
00449 ChoiceFormat::format(double number,
00450                      UnicodeString& output) const {
00451     return NumberFormat::format(number, output);
00452 }
00453 
00454 inline UnicodeString&
00455 ChoiceFormat::format(int32_t number,
00456                      UnicodeString& output) const {
00457     return NumberFormat::format(number, output);
00458 }
00459 
00460 #endif // _CHOICFMT
00461 //eof

Generated at Mon Jun 5 12:53:02 2000 for ICU1.5 by doxygen 1.0.0 written by Dimitri van Heesch, © 1997-1999