Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

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 
00382     virtual void adoptChoices(double* limitsToAdopt,
00383                               UBool* closuresToAdopt,
00384                               UnicodeString* formatsToAdopt,
00385                               int32_t count);
00386     
00399     virtual void setChoices(const double* limitsToCopy,
00400                             const UnicodeString* formatsToCopy,
00401                             int32_t count );    
00402 
00411     virtual void setChoices(const double* limits,
00412                             const UBool* closures,
00413                             const UnicodeString* formats,
00414                             int32_t count);
00415 
00421     virtual const double* getLimits(int32_t& count) const;
00422     
00428     virtual const UBool* getClosures(int32_t& count) const;
00429 
00435     virtual const UnicodeString* getFormats(int32_t& count) const;
00436 
00448     virtual UnicodeString& format(double number,
00449                                   UnicodeString& toAppendTo,
00450                                   FieldPosition& pos) const;
00456     virtual UnicodeString& format(int32_t number,
00457                                   UnicodeString& toAppendTo,
00458                                   FieldPosition& pos) const;
00464     virtual UnicodeString& format(const Formattable* objs,
00465                                   int32_t cnt,
00466                                   UnicodeString& toAppendTo,
00467                                   FieldPosition& pos,
00468                                   UErrorCode& success) const;
00474     virtual UnicodeString& format(const Formattable& obj,
00475                                   UnicodeString& toAppendTo,
00476                                   FieldPosition& pos, 
00477                                   UErrorCode& status) const;
00478 
00483     UnicodeString& format(const Formattable& obj,
00484                           UnicodeString& result,
00485                           UErrorCode& status) const;
00486 
00491     UnicodeString& format(  double number,
00492                             UnicodeString& output) const;
00493 
00498     UnicodeString& format(  int32_t number,
00499                             UnicodeString& output) const;
00500 
00521     virtual void parse(const UnicodeString& text,
00522                        Formattable& result,
00523                        ParsePosition& parsePosition) const;
00524     virtual void parse(const UnicodeString& text,
00525                        Formattable& result,
00526                        UErrorCode& status) const;
00527     
00528     
00529 public:
00541     virtual UClassID getDynamicClassID(void) const;
00542 
00554     static UClassID getStaticClassID(void) { return (UClassID)&fgClassID; }
00555 
00556     /*
00557      * Finds the least double greater than d (if positive == true),
00558      * or the greatest double less than d (if positive == false).
00559      * If NaN, returns same value.
00560      * <P>
00561      * Does not affect floating-point flags,
00562      * @deprecated This will be removed after 2002-Jun-30. Use closures API instead.
00563      */
00564     static double nextDouble(double d, UBool positive);
00565 
00573     static double nextDouble(double d );
00574 
00581     static double previousDouble(double d );
00582 
00583 private:
00584     // static cache management (thread-safe)
00585   //  static NumberFormat* getNumberFormat(UErrorCode &status); // call this function to 'check out' a numberformat from the cache.
00586   //  static void          releaseNumberFormat(NumberFormat *adopt); // call this function to 'return' the number format to the cache.
00587     
00595     static double stod(const UnicodeString& string);
00596 
00605     static UnicodeString& dtos(double value, UnicodeString& string);
00606 
00607     //static UMTX fgMutex;
00608     //static NumberFormat* fgNumberFormat;
00609     static const char fgClassID;
00610 
00611     static const UChar fgPositiveInfinity[];
00612     static const UChar fgNegativeInfinity[];
00622     ChoiceFormat(const UnicodeString& newPattern,
00623                  UParseError& parseError,
00624                  UErrorCode& status);
00625 
00626     friend class MessageFormat;
00664     double*         fChoiceLimits;
00665     UBool*          fClosures;
00666     UnicodeString*  fChoiceFormats;
00667     int32_t         fCount;
00668 };
00669  
00670 inline UClassID 
00671 ChoiceFormat::getDynamicClassID() const
00672 { 
00673     return ChoiceFormat::getStaticClassID(); 
00674 }
00675 
00676 inline double ChoiceFormat::nextDouble( double d )
00677 {
00678     return ChoiceFormat::nextDouble( d, TRUE );
00679 }
00680     
00681 inline double ChoiceFormat::previousDouble( double d )
00682 {
00683     return ChoiceFormat::nextDouble( d, FALSE );
00684 }
00685 
00686 inline UnicodeString&
00687 ChoiceFormat::format(const Formattable& obj,
00688                      UnicodeString& result,
00689                      UErrorCode& status) const {
00690     // Don't use Format:: - use immediate base class only,
00691     // in case immediate base modifies behavior later.
00692     return NumberFormat::format(obj, result, status);
00693 }
00694 
00695 inline UnicodeString&
00696 ChoiceFormat::format(double number,
00697                      UnicodeString& output) const {
00698     return NumberFormat::format(number, output);
00699 }
00700 
00701 inline UnicodeString&
00702 ChoiceFormat::format(int32_t number,
00703                      UnicodeString& output) const {
00704     return NumberFormat::format(number, output);
00705 }
00706 U_NAMESPACE_END
00707 
00708 #endif // _CHOICFMT
00709 //eof

Generated on Mon Jul 25 21:50:48 2005 for ICU 2.1 by  doxygen 1.4.3-20050530