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;
00510     virtual UnicodeString& format(const Formattable* objs,
00511                                   int32_t cnt,
00512                                   UnicodeString& appendTo,
00513                                   FieldPosition& pos,
00514                                   UErrorCode& success) const;
00529     virtual UnicodeString& format(const Formattable& obj,
00530                                   UnicodeString& appendTo,
00531                                   FieldPosition& pos, 
00532                                   UErrorCode& status) const;
00533 
00545     UnicodeString& format(const Formattable& obj,
00546                           UnicodeString& appendTo,
00547                           UErrorCode& status) const;
00548 
00560     UnicodeString& format(  double number,
00561                             UnicodeString& appendTo) const;
00562 
00574     UnicodeString& format(  int32_t number,
00575                             UnicodeString& appendTo) const;
00576 
00595     virtual void parse(const UnicodeString& text,
00596                        Formattable& result,
00597                        ParsePosition& parsePosition) const;
00598     
00615     virtual void parse(const UnicodeString& text,
00616                        Formattable& result,
00617                        UErrorCode& status) const;
00618     
00619     
00620 public:
00632     virtual UClassID getDynamicClassID(void) const;
00633 
00645     static inline UClassID getStaticClassID(void);
00646 
00647 private:
00648     // static cache management (thread-safe)
00649   //  static NumberFormat* getNumberFormat(UErrorCode &status); // call this function to 'check out' a numberformat from the cache.
00650   //  static void          releaseNumberFormat(NumberFormat *adopt); // call this function to 'return' the number format to the cache.
00651     
00658     static double stod(const UnicodeString& string);
00659 
00667     static UnicodeString& dtos(double value, UnicodeString& string);
00668 
00669     //static UMTX fgMutex;
00670     //static NumberFormat* fgNumberFormat;
00671     static const char fgClassID;
00672 
00673     static const UChar fgPositiveInfinity[];
00674     static const UChar fgNegativeInfinity[];
00675 
00676     ChoiceFormat(); // default constructor not implemented
00677 
00689     ChoiceFormat(const UnicodeString& newPattern,
00690                  UParseError& parseError,
00691                  UErrorCode& status);
00692 
00693     friend class MessageFormat;
00731     double*         fChoiceLimits;
00732     UBool*          fClosures;
00733     UnicodeString*  fChoiceFormats;
00734     int32_t         fCount;
00735 };
00736  
00737 inline UClassID
00738 ChoiceFormat::getStaticClassID(void)
00739 {
00740     return (UClassID)&fgClassID;
00741 }
00742 
00743 inline UClassID 
00744 ChoiceFormat::getDynamicClassID() const
00745 { 
00746     return ChoiceFormat::getStaticClassID(); 
00747 }
00748 
00749 inline UnicodeString&
00750 ChoiceFormat::format(const Formattable& obj,
00751                      UnicodeString& appendTo,
00752                      UErrorCode& status) const {
00753     // Don't use Format:: - use immediate base class only,
00754     // in case immediate base modifies behavior later.
00755     return NumberFormat::format(obj, appendTo, status);
00756 }
00757 
00758 inline UnicodeString&
00759 ChoiceFormat::format(double number,
00760                      UnicodeString& appendTo) const {
00761     return NumberFormat::format(number, appendTo);
00762 }
00763 
00764 inline UnicodeString&
00765 ChoiceFormat::format(int32_t number,
00766                      UnicodeString& appendTo) const {
00767     return NumberFormat::format(number, appendTo);
00768 }
00769 U_NAMESPACE_END
00770 
00771 #endif /* #if !UCONFIG_NO_FORMATTING */
00772 
00773 #endif // _CHOICFMT
00774 //eof

Generated on Wed Sep 3 17:47:08 2003 for ICU 2.6 by doxygen 1.3.2