choicfmt.h

Go to the documentation of this file.
00001 /*
00002 ********************************************************************************
00003 *   Copyright (C) 1997-2008, 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 
00032 #if !UCONFIG_NO_FORMATTING
00033 
00034 #include "unicode/unistr.h"
00035 #include "unicode/numfmt.h"
00036 #include "unicode/fieldpos.h"
00037 #include "unicode/format.h"
00038 
00039 U_NAMESPACE_BEGIN
00040 
00041 class MessageFormat;
00042 
00259 class U_I18N_API ChoiceFormat: public NumberFormat {
00260 public:
00270     ChoiceFormat(const UnicodeString& pattern,
00271                  UErrorCode& status);
00272 
00273 
00284     ChoiceFormat(const double* limits,
00285                  const UnicodeString* formats,
00286                  int32_t count );
00287 
00305     ChoiceFormat(const double* limits,
00306                  const UBool* closures,
00307                  const UnicodeString* formats,
00308                  int32_t count);
00309 
00316     ChoiceFormat(const ChoiceFormat& that);
00317 
00324     const ChoiceFormat& operator=(const ChoiceFormat& that);
00325 
00330     virtual ~ChoiceFormat();
00331 
00339     virtual Format* clone(void) const;
00340 
00349     virtual UBool operator==(const Format& other) const;
00350 
00359     virtual void applyPattern(const UnicodeString& pattern,
00360                               UErrorCode& status);
00361 
00372     virtual void applyPattern(const UnicodeString& pattern,
00373                              UParseError& parseError,
00374                              UErrorCode& status);
00383     virtual UnicodeString& toPattern(UnicodeString &pattern) const;
00384 
00397     virtual void setChoices(const double* limitsToCopy,
00398                             const UnicodeString* formatsToCopy,
00399                             int32_t count );    
00400 
00410     virtual void setChoices(const double* limits,
00411                             const UBool* closures,
00412                             const UnicodeString* formats,
00413                             int32_t count);
00414 
00422     virtual const double* getLimits(int32_t& count) const;
00423     
00432     virtual const UBool* getClosures(int32_t& count) const;
00433 
00441     virtual const UnicodeString* getFormats(int32_t& count) const;
00442 
00454     virtual UnicodeString& format(double number,
00455                                   UnicodeString& appendTo,
00456                                   FieldPosition& pos) const;
00468     virtual UnicodeString& format(int32_t number,
00469                                   UnicodeString& appendTo,
00470                                   FieldPosition& pos) const;
00471 
00483     virtual UnicodeString& format(int64_t number,
00484                                   UnicodeString& appendTo,
00485                                   FieldPosition& pos) const;
00486 
00501     virtual UnicodeString& format(const Formattable* objs,
00502                                   int32_t cnt,
00503                                   UnicodeString& appendTo,
00504                                   FieldPosition& pos,
00505                                   UErrorCode& success) const;
00520     virtual UnicodeString& format(const Formattable& obj,
00521                                   UnicodeString& appendTo,
00522                                   FieldPosition& pos, 
00523                                   UErrorCode& status) const;
00524 
00536     UnicodeString& format(const Formattable& obj,
00537                           UnicodeString& appendTo,
00538                           UErrorCode& status) const;
00539 
00551     UnicodeString& format(  double number,
00552                             UnicodeString& appendTo) const;
00553 
00565     UnicodeString& format(  int32_t number,
00566                             UnicodeString& appendTo) const;
00567 
00586     virtual void parse(const UnicodeString& text,
00587                        Formattable& result,
00588                        ParsePosition& parsePosition) const;
00589     
00606     virtual void parse(const UnicodeString& text,
00607                        Formattable& result,
00608                        UErrorCode& status) const;
00609     
00610     
00611 public:
00623     virtual UClassID getDynamicClassID(void) const;
00624 
00636     static UClassID U_EXPORT2 getStaticClassID(void);
00637 
00638 private:
00639     // static cache management (thread-safe)
00640   //  static NumberFormat* getNumberFormat(UErrorCode &status); // call this function to 'check out' a numberformat from the cache.
00641   //  static void          releaseNumberFormat(NumberFormat *adopt); // call this function to 'return' the number format to the cache.
00642     
00649     static double stod(const UnicodeString& string);
00650 
00658     static UnicodeString& dtos(double value, UnicodeString& string);
00659 
00660     ChoiceFormat(); // default constructor not implemented
00661 
00673     ChoiceFormat(const UnicodeString& newPattern,
00674                  UParseError& parseError,
00675                  UErrorCode& status);
00676 
00677     friend class MessageFormat;
00715     double*         fChoiceLimits;
00716     UBool*          fClosures;
00717     UnicodeString*  fChoiceFormats;
00718     int32_t         fCount;
00719 };
00720  
00721 inline UnicodeString&
00722 ChoiceFormat::format(const Formattable& obj,
00723                      UnicodeString& appendTo,
00724                      UErrorCode& status) const {
00725     // Don't use Format:: - use immediate base class only,
00726     // in case immediate base modifies behavior later.
00727     return NumberFormat::format(obj, appendTo, status);
00728 }
00729 
00730 inline UnicodeString&
00731 ChoiceFormat::format(double number,
00732                      UnicodeString& appendTo) const {
00733     return NumberFormat::format(number, appendTo);
00734 }
00735 
00736 inline UnicodeString&
00737 ChoiceFormat::format(int32_t number,
00738                      UnicodeString& appendTo) const {
00739     return NumberFormat::format(number, appendTo);
00740 }
00741 U_NAMESPACE_END
00742 
00743 #endif /* #if !UCONFIG_NO_FORMATTING */
00744 
00745 #endif // _CHOICFMT
00746 //eof

Generated on Sun Aug 22 15:43:57 2010 for ICU 4.0.1 by  doxygen 1.3.9.1