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

choicfmt.h

00001 /*
00002 ********************************************************************************
00003 *   Copyright (C) 1997-2003, 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 #include "unicode/utypes.h"
00026 
00027 #if !UCONFIG_NO_FORMATTING
00028 
00029 #include "unicode/unistr.h"
00030 #include "unicode/numfmt.h"
00031 #include "unicode/fieldpos.h"
00032 #include "unicode/format.h"
00033 
00034 U_NAMESPACE_BEGIN
00035 
00036 class MessageFormat;
00037 
00250 class U_I18N_API ChoiceFormat: public NumberFormat {
00251 public:
00261     ChoiceFormat(const UnicodeString& pattern,
00262                  UErrorCode& status);
00263 
00264 
00275     ChoiceFormat(const double* limits,
00276                  const UnicodeString* formats,
00277                  int32_t count );
00278 
00296     ChoiceFormat(const double* limits,
00297                  const UBool* closures,
00298                  const UnicodeString* formats,
00299                  int32_t count);
00300 
00307     ChoiceFormat(const ChoiceFormat& that);
00308 
00315     const ChoiceFormat& operator=(const ChoiceFormat& that);
00316 
00321     virtual ~ChoiceFormat();
00322 
00330     virtual Format* clone(void) const;
00331 
00340     virtual UBool operator==(const Format& other) const;
00341 
00350     virtual void applyPattern(const UnicodeString& pattern,
00351                               UErrorCode& status);
00352 
00363     virtual void applyPattern(const UnicodeString& pattern,
00364                              UParseError& parseError,
00365                              UErrorCode& status);
00374     virtual UnicodeString& toPattern(UnicodeString &pattern) const;
00375 
00376 #ifdef U_USE_CHOICE_FORMAT_DEPRECATES
00377 
00390     virtual void adoptChoices(double* limitsToAdopt,
00391                               UnicodeString* formatsToAdopt,
00392                               int32_t count );  
00393 
00404     virtual void adoptChoices(double* limitsToAdopt,
00405                               UBool* closuresToAdopt,
00406                               UnicodeString* formatsToAdopt,
00407                               int32_t count);
00408 #endif
00409 
00422     virtual void setChoices(const double* limitsToCopy,
00423                             const UnicodeString* formatsToCopy,
00424                             int32_t count );    
00425 
00435     virtual void setChoices(const double* limits,
00436                             const UBool* closures,
00437                             const UnicodeString* formats,
00438                             int32_t count);
00439 
00447     virtual const double* getLimits(int32_t& count) const;
00448     
00457     virtual const UBool* getClosures(int32_t& count) const;
00458 
00466     virtual const UnicodeString* getFormats(int32_t& count) const;
00467 
00479     virtual UnicodeString& format(double number,
00480                                   UnicodeString& appendTo,
00481                                   FieldPosition& pos) const;
00493     virtual UnicodeString& format(int32_t number,
00494                                   UnicodeString& appendTo,
00495                                   FieldPosition& pos) const;
00496 
00508     virtual UnicodeString& format(int64_t number,
00509                                   UnicodeString& appendTo,
00510                                   FieldPosition& pos) const;
00511 
00526     virtual UnicodeString& format(const Formattable* objs,
00527                                   int32_t cnt,
00528                                   UnicodeString& appendTo,
00529                                   FieldPosition& pos,
00530                                   UErrorCode& success) const;
00545     virtual UnicodeString& format(const Formattable& obj,
00546                                   UnicodeString& appendTo,
00547                                   FieldPosition& pos, 
00548                                   UErrorCode& status) const;
00549 
00561     UnicodeString& format(const Formattable& obj,
00562                           UnicodeString& appendTo,
00563                           UErrorCode& status) const;
00564 
00576     UnicodeString& format(  double number,
00577                             UnicodeString& appendTo) const;
00578 
00590     UnicodeString& format(  int32_t number,
00591                             UnicodeString& appendTo) const;
00592 
00611     virtual void parse(const UnicodeString& text,
00612                        Formattable& result,
00613                        ParsePosition& parsePosition) const;
00614     
00631     virtual void parse(const UnicodeString& text,
00632                        Formattable& result,
00633                        UErrorCode& status) const;
00634     
00635     
00636 public:
00648     virtual UClassID getDynamicClassID(void) const;
00649 
00661     static UClassID getStaticClassID(void);
00662 
00663 private:
00664     // static cache management (thread-safe)
00665   //  static NumberFormat* getNumberFormat(UErrorCode &status); // call this function to 'check out' a numberformat from the cache.
00666   //  static void          releaseNumberFormat(NumberFormat *adopt); // call this function to 'return' the number format to the cache.
00667     
00674     static double stod(const UnicodeString& string);
00675 
00683     static UnicodeString& dtos(double value, UnicodeString& string);
00684 
00685     ChoiceFormat(); // default constructor not implemented
00686 
00698     ChoiceFormat(const UnicodeString& newPattern,
00699                  UParseError& parseError,
00700                  UErrorCode& status);
00701 
00702     friend class MessageFormat;
00740     double*         fChoiceLimits;
00741     UBool*          fClosures;
00742     UnicodeString*  fChoiceFormats;
00743     int32_t         fCount;
00744 };
00745  
00746 inline UnicodeString&
00747 ChoiceFormat::format(const Formattable& obj,
00748                      UnicodeString& appendTo,
00749                      UErrorCode& status) const {
00750     // Don't use Format:: - use immediate base class only,
00751     // in case immediate base modifies behavior later.
00752     return NumberFormat::format(obj, appendTo, status);
00753 }
00754 
00755 inline UnicodeString&
00756 ChoiceFormat::format(double number,
00757                      UnicodeString& appendTo) const {
00758     return NumberFormat::format(number, appendTo);
00759 }
00760 
00761 inline UnicodeString&
00762 ChoiceFormat::format(int32_t number,
00763                      UnicodeString& appendTo) const {
00764     return NumberFormat::format(number, appendTo);
00765 }
00766 U_NAMESPACE_END
00767 
00768 #endif /* #if !UCONFIG_NO_FORMATTING */
00769 
00770 #endif // _CHOICFMT
00771 //eof

Generated on Tue Oct 26 18:11:08 2004 for ICU 2.8 by  doxygen 1.3.9.1