- Main Page
- Modules
- Data Structures
- Files
- Related Pages

- Search for |

- File List
- Globals

# choicfmt.h

Go to the documentation of this file.

    00001 /*
    00002 ********************************************************************************
    00003 *   Copyright (C) 1997-2005, 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
    00385 #ifdef U_USE_CHOICE_FORMAT_DEPRECATES
    00386
    00399     virtual void adoptChoices(double* limitsToAdopt,
    00400                               UnicodeString* formatsToAdopt,
    00401                               int32_t count );
    00402
    00413     virtual void adoptChoices(double* limitsToAdopt,
    00414                               UBool* closuresToAdopt,
    00415                               UnicodeString* formatsToAdopt,
    00416                               int32_t count);
    00417 #endif
    00418
    00431     virtual void setChoices(const double* limitsToCopy,
    00432                             const UnicodeString* formatsToCopy,
    00433                             int32_t count );
    00434
    00444     virtual void setChoices(const double* limits,
    00445                             const UBool* closures,
    00446                             const UnicodeString* formats,
    00447                             int32_t count);
    00448
    00456     virtual const double* getLimits(int32_t& count) const;
    00457
    00466     virtual const UBool* getClosures(int32_t& count) const;
    00467
    00475     virtual const UnicodeString* getFormats(int32_t& count) const;
    00476
    00488     virtual UnicodeString& format(double number,
    00489                                   UnicodeString& appendTo,
    00490                                   FieldPosition& pos) const;
    00502     virtual UnicodeString& format(int32_t number,
    00503                                   UnicodeString& appendTo,
    00504                                   FieldPosition& pos) const;
    00505
    00517     virtual UnicodeString& format(int64_t number,
    00518                                   UnicodeString& appendTo,
    00519                                   FieldPosition& pos) const;
    00520
    00535     virtual UnicodeString& format(const Formattable* objs,
    00536                                   int32_t cnt,
    00537                                   UnicodeString& appendTo,
    00538                                   FieldPosition& pos,
    00539                                   UErrorCode& success) const;
    00554     virtual UnicodeString& format(const Formattable& obj,
    00555                                   UnicodeString& appendTo,
    00556                                   FieldPosition& pos,
    00557                                   UErrorCode& status) const;
    00558
    00570     UnicodeString& format(const Formattable& obj,
    00571                           UnicodeString& appendTo,
    00572                           UErrorCode& status) const;
    00573
    00585     UnicodeString& format(  double number,
    00586                             UnicodeString& appendTo) const;
    00587
    00599     UnicodeString& format(  int32_t number,
    00600                             UnicodeString& appendTo) const;
    00601
    00620     virtual void parse(const UnicodeString& text,
    00621                        Formattable& result,
    00622                        ParsePosition& parsePosition) const;
    00623
    00640     virtual void parse(const UnicodeString& text,
    00641                        Formattable& result,
    00642                        UErrorCode& status) const;
    00643
    00644
    00645 public:
    00657     virtual UClassID getDynamicClassID(void) const;
    00658
    00670     static UClassID U_EXPORT2 getStaticClassID(void);
    00671
    00672 private:
    00673     // static cache management (thread-safe)
    00674   //  static NumberFormat* getNumberFormat(UErrorCode &status); // call this function to 'check out' a numberformat from the cache.
    00675   //  static void          releaseNumberFormat(NumberFormat *adopt); // call this function to 'return' the number format to the cache.
    00676
    00683     static double stod(const UnicodeString& string);
    00684
    00692     static UnicodeString& dtos(double value, UnicodeString& string);
    00693
    00694     ChoiceFormat(); // default constructor not implemented
    00695
    00707     ChoiceFormat(const UnicodeString& newPattern,
    00708                  UParseError& parseError,
    00709                  UErrorCode& status);
    00710
    00711     friend class MessageFormat;
    00749     double*         fChoiceLimits;
    00750     UBool*          fClosures;
    00751     UnicodeString*  fChoiceFormats;
    00752     int32_t         fCount;
    00753 };
    00754
    00755 inline UnicodeString&
    00756 ChoiceFormat::format(const Formattable& obj,
    00757                      UnicodeString& appendTo,
    00758                      UErrorCode& status) const {
    00759     // Don't use Format:: - use immediate base class only,
    00760     // in case immediate base modifies behavior later.
    00761     return NumberFormat::format(obj, appendTo, status);
    00762 }
    00763
    00764 inline UnicodeString&
    00765 ChoiceFormat::format(double number,
    00766                      UnicodeString& appendTo) const {
    00767     return NumberFormat::format(number, appendTo);
    00768 }
    00769
    00770 inline UnicodeString&
    00771 ChoiceFormat::format(int32_t number,
    00772                      UnicodeString& appendTo) const {
    00773     return NumberFormat::format(number, appendTo);
    00774 }
    00775 U_NAMESPACE_END
    00776
    00777 #endif /* #if !UCONFIG_NO_FORMATTING */
    00778
    00779 #endif // _CHOICFMT
    00780 //eof