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

- File List
- Globals

# choicfmt.h

Go to the documentation of this file.

    00001 /*
    00002 ********************************************************************************
    00003 *   Copyright (C) 1997-2010, 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
    00443
    00444     using NumberFormat::format;
    00445
    00457     virtual UnicodeString& format(double number,
    00458                                   UnicodeString& appendTo,
    00459                                   FieldPosition& pos) const;
    00471     virtual UnicodeString& format(int32_t number,
    00472                                   UnicodeString& appendTo,
    00473                                   FieldPosition& pos) const;
    00474
    00486     virtual UnicodeString& format(int64_t number,
    00487                                   UnicodeString& appendTo,
    00488                                   FieldPosition& pos) const;
    00489
    00504     virtual UnicodeString& format(const Formattable* objs,
    00505                                   int32_t cnt,
    00506                                   UnicodeString& appendTo,
    00507                                   FieldPosition& pos,
    00508                                   UErrorCode& success) const;
    00523     virtual UnicodeString& format(const Formattable& obj,
    00524                                   UnicodeString& appendTo,
    00525                                   FieldPosition& pos,
    00526                                   UErrorCode& status) const;
    00527
    00539     UnicodeString& format(const Formattable& obj,
    00540                           UnicodeString& appendTo,
    00541                           UErrorCode& status) const;
    00542
    00554     UnicodeString& format(  double number,
    00555                             UnicodeString& appendTo) const;
    00556
    00568     UnicodeString& format(  int32_t number,
    00569                             UnicodeString& appendTo) const;
    00570
    00589     virtual void parse(const UnicodeString& text,
    00590                        Formattable& result,
    00591                        ParsePosition& parsePosition) const;
    00592
    00609     virtual void parse(const UnicodeString& text,
    00610                        Formattable& result,
    00611                        UErrorCode& status) const;
    00612
    00613
    00614 public:
    00626     virtual UClassID getDynamicClassID(void) const;
    00627
    00639     static UClassID U_EXPORT2 getStaticClassID(void);
    00640
    00641 private:
    00642     // static cache management (thread-safe)
    00643   //  static NumberFormat* getNumberFormat(UErrorCode &status); // call this function to 'check out' a numberformat from the cache.
    00644   //  static void          releaseNumberFormat(NumberFormat *adopt); // call this function to 'return' the number format to the cache.
    00645
    00652     static double stod(const UnicodeString& string);
    00653
    00661     static UnicodeString& dtos(double value, UnicodeString& string);
    00662
    00663     ChoiceFormat(); // default constructor not implemented
    00664
    00676     ChoiceFormat(const UnicodeString& newPattern,
    00677                  UParseError& parseError,
    00678                  UErrorCode& status);
    00679
    00680     friend class MessageFormat;
    00718     double*         fChoiceLimits;
    00719     UBool*          fClosures;
    00720     UnicodeString*  fChoiceFormats;
    00721     int32_t         fCount;
    00722 };
    00723
    00724 inline UnicodeString&
    00725 ChoiceFormat::format(const Formattable& obj,
    00726                      UnicodeString& appendTo,
    00727                      UErrorCode& status) const {
    00728     // Don't use Format:: - use immediate base class only,
    00729     // in case immediate base modifies behavior later.
    00730     return NumberFormat::format(obj, appendTo, status);
    00731 }
    00732
    00733 inline UnicodeString&
    00734 ChoiceFormat::format(double number,
    00735                      UnicodeString& appendTo) const {
    00736     return NumberFormat::format(number, appendTo);
    00737 }
    00738
    00739 inline UnicodeString&
    00740 ChoiceFormat::format(int32_t number,
    00741                      UnicodeString& appendTo) const {
    00742     return NumberFormat::format(number, appendTo);
    00743 }
    00744 U_NAMESPACE_END
    00745
    00746 #endif /* #if !UCONFIG_NO_FORMATTING */
    00747
    00748 #endif // _CHOICFMT
    00749 //eof

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines