choicfmt.h

Go to the documentation of this file.
00001 /*
00002 ********************************************************************************
00003 *   Copyright (C) 1997-2011, 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 #ifndef U_HIDE_DEPRECATED_API
00034 
00035 #include "unicode/fieldpos.h"
00036 #include "unicode/format.h"
00037 #include "unicode/messagepattern.h"
00038 #include "unicode/numfmt.h"
00039 #include "unicode/unistr.h"
00040 
00041 U_NAMESPACE_BEGIN
00042 
00043 class MessageFormat;
00044 
00171 class U_I18N_API ChoiceFormat: public NumberFormat {
00172 public:
00181     ChoiceFormat(const UnicodeString& pattern,
00182                  UErrorCode& status);
00183 
00184 
00197     ChoiceFormat(const double* limits,
00198                  const UnicodeString* formats,
00199                  int32_t count );
00200 
00215     ChoiceFormat(const double* limits,
00216                  const UBool* closures,
00217                  const UnicodeString* formats,
00218                  int32_t count);
00219 
00226     ChoiceFormat(const ChoiceFormat& that);
00227 
00234     const ChoiceFormat& operator=(const ChoiceFormat& that);
00235 
00240     virtual ~ChoiceFormat();
00241 
00249     virtual Format* clone(void) const;
00250 
00259     virtual UBool operator==(const Format& other) const;
00260 
00269     virtual void applyPattern(const UnicodeString& pattern,
00270                               UErrorCode& status);
00271 
00282     virtual void applyPattern(const UnicodeString& pattern,
00283                              UParseError& parseError,
00284                              UErrorCode& status);
00293     virtual UnicodeString& toPattern(UnicodeString &pattern) const;
00294 
00308     virtual void setChoices(const double* limitsToCopy,
00309                             const UnicodeString* formatsToCopy,
00310                             int32_t count );
00311 
00322     virtual void setChoices(const double* limits,
00323                             const UBool* closures,
00324                             const UnicodeString* formats,
00325                             int32_t count);
00326 
00335     virtual const double* getLimits(int32_t& count) const;
00336 
00345     virtual const UBool* getClosures(int32_t& count) const;
00346 
00355     virtual const UnicodeString* getFormats(int32_t& count) const;
00356 
00357 
00358     using NumberFormat::format;
00359 
00371     virtual UnicodeString& format(double number,
00372                                   UnicodeString& appendTo,
00373                                   FieldPosition& pos) const;
00385     virtual UnicodeString& format(int32_t number,
00386                                   UnicodeString& appendTo,
00387                                   FieldPosition& pos) const;
00388 
00400     virtual UnicodeString& format(int64_t number,
00401                                   UnicodeString& appendTo,
00402                                   FieldPosition& pos) const;
00403 
00418     virtual UnicodeString& format(const Formattable* objs,
00419                                   int32_t cnt,
00420                                   UnicodeString& appendTo,
00421                                   FieldPosition& pos,
00422                                   UErrorCode& success) const;
00437     virtual UnicodeString& format(const Formattable& obj,
00438                                   UnicodeString& appendTo,
00439                                   FieldPosition& pos,
00440                                   UErrorCode& status) const;
00441 
00453     UnicodeString& format(const Formattable& obj,
00454                           UnicodeString& appendTo,
00455                           UErrorCode& status) const;
00456 
00468     UnicodeString& format(  double number,
00469                             UnicodeString& appendTo) const;
00470 
00482     UnicodeString& format(  int32_t number,
00483                             UnicodeString& appendTo) const;
00484 
00499     virtual void parse(const UnicodeString& text,
00500                        Formattable& result,
00501                        ParsePosition& parsePosition) const;
00502 
00515     virtual void parse(const UnicodeString& text,
00516                        Formattable& result,
00517                        UErrorCode& status) const;
00518 
00527     virtual UClassID getDynamicClassID(void) const;
00528 
00540     static UClassID U_EXPORT2 getStaticClassID(void);
00541 
00542 private:
00549     static UnicodeString& dtos(double value, UnicodeString& string);
00550 
00551     ChoiceFormat(); // default constructor not implemented
00552 
00563     ChoiceFormat(const UnicodeString& newPattern,
00564                  UParseError& parseError,
00565                  UErrorCode& status);
00566 
00567     friend class MessageFormat;
00568 
00569     virtual void setChoices(const double* limits,
00570                             const UBool* closures,
00571                             const UnicodeString* formats,
00572                             int32_t count,
00573                             UErrorCode &errorCode);
00574 
00582     static int32_t findSubMessage(const MessagePattern &pattern, int32_t partIndex, double number);
00583 
00584     static double parseArgument(
00585             const MessagePattern &pattern, int32_t partIndex,
00586             const UnicodeString &source, ParsePosition &pos);
00587 
00596     static int32_t matchStringUntilLimitPart(
00597             const MessagePattern &pattern, int32_t partIndex, int32_t limitPartIndex,
00598             const UnicodeString &source, int32_t sourceOffset);
00599 
00606     UErrorCode constructorErrorCode;
00607 
00615     MessagePattern msgPattern;
00616 
00656     // double*         fChoiceLimits;
00657     // UBool*          fClosures;
00658     // UnicodeString*  fChoiceFormats;
00659     // int32_t         fCount;
00660 };
00661 
00662 inline UnicodeString&
00663 ChoiceFormat::format(const Formattable& obj,
00664                      UnicodeString& appendTo,
00665                      UErrorCode& status) const {
00666     // Don't use Format:: - use immediate base class only,
00667     // in case immediate base modifies behavior later.
00668     return NumberFormat::format(obj, appendTo, status);
00669 }
00670 
00671 inline UnicodeString&
00672 ChoiceFormat::format(double number,
00673                      UnicodeString& appendTo) const {
00674     return NumberFormat::format(number, appendTo);
00675 }
00676 
00677 inline UnicodeString&
00678 ChoiceFormat::format(int32_t number,
00679                      UnicodeString& appendTo) const {
00680     return NumberFormat::format(number, appendTo);
00681 }
00682 U_NAMESPACE_END
00683 
00684 #endif  // U_HIDE_DEPRECATED_API
00685 #endif /* #if !UCONFIG_NO_FORMATTING */
00686 
00687 #endif // CHOICFMT_H
00688 //eof

Generated on 27 Oct 2013 for ICU 50.1.2 by  doxygen 1.4.7