plurfmt.h

Go to the documentation of this file.
00001 /*
00002 *******************************************************************************
00003 * Copyright (C) 2007-2012, International Business Machines Corporation and
00004 * others. All Rights Reserved.
00005 *******************************************************************************
00006 *
00007 
00008 * File PLURFMT.H
00009 *
00010 * Modification History:*
00011 *   Date        Name        Description
00012 *
00013 ********************************************************************************
00014 */
00015 
00016 #ifndef PLURFMT
00017 #define PLURFMT
00018 
00019 #include "unicode/utypes.h"
00020 
00026 #if !UCONFIG_NO_FORMATTING
00027 
00028 #include "unicode/messagepattern.h"
00029 #include "unicode/numfmt.h"
00030 #include "unicode/plurrule.h"
00031 
00032 U_NAMESPACE_BEGIN
00033 
00034 class Hashtable;
00035 
00147 class U_I18N_API PluralFormat : public Format {
00148 public:
00149 
00158     PluralFormat(UErrorCode& status);
00159 
00169     PluralFormat(const Locale& locale, UErrorCode& status);
00170 
00180     PluralFormat(const PluralRules& rules, UErrorCode& status);
00181 
00193     PluralFormat(const Locale& locale, const PluralRules& rules, UErrorCode& status);
00194 
00205     PluralFormat(const Locale& locale, UPluralType type, UErrorCode& status);
00206 
00217     PluralFormat(const UnicodeString& pattern, UErrorCode& status);
00218 
00233     PluralFormat(const Locale& locale, const UnicodeString& pattern, UErrorCode& status);
00234 
00246     PluralFormat(const PluralRules& rules,
00247                  const UnicodeString& pattern,
00248                  UErrorCode& status);
00249 
00264     PluralFormat(const Locale& locale,
00265                  const PluralRules& rules,
00266                  const UnicodeString& pattern,
00267                  UErrorCode& status);
00268 
00282     PluralFormat(const Locale& locale,
00283                  UPluralType type,
00284                  const UnicodeString& pattern,
00285                  UErrorCode& status);
00286 
00291     PluralFormat(const PluralFormat& other);
00292 
00297     virtual ~PluralFormat();
00298 
00311     void applyPattern(const UnicodeString& pattern, UErrorCode& status);
00312 
00313 
00314     using Format::format;
00315 
00328     UnicodeString format(int32_t number, UErrorCode& status) const;
00329 
00342     UnicodeString format(double number, UErrorCode& status) const;
00343 
00360     UnicodeString& format(int32_t number,
00361                           UnicodeString& appendTo,
00362                           FieldPosition& pos,
00363                           UErrorCode& status) const;
00364 
00381     UnicodeString& format(double number,
00382                           UnicodeString& appendTo,
00383                           FieldPosition& pos,
00384                           UErrorCode& status) const;
00385 
00401     void setLocale(const Locale& locale, UErrorCode& status);
00402 
00412     void setNumberFormat(const NumberFormat* format, UErrorCode& status);
00413 
00420     PluralFormat& operator=(const PluralFormat& other);
00421 
00429     virtual UBool operator==(const Format& other) const;
00430 
00438     virtual UBool operator!=(const Format& other) const;
00439 
00445     virtual Format* clone(void) const;
00446 
00459    UnicodeString& format(const Formattable& obj,
00460                          UnicodeString& appendTo,
00461                          FieldPosition& pos,
00462                          UErrorCode& status) const;
00463 
00472    UnicodeString& toPattern(UnicodeString& appendTo);
00473 
00496    virtual void parseObject(const UnicodeString& source,
00497                             Formattable& result,
00498                             ParsePosition& parse_pos) const;
00499 
00506     static UClassID U_EXPORT2 getStaticClassID(void);
00507 
00513      virtual UClassID getDynamicClassID() const;
00514 
00515 #if (defined(__xlC__) && (__xlC__ < 0x0C00)) || (U_PLATFORM == U_PF_OS390) || (U_PLATFORM ==U_PF_OS400)
00516 // Work around a compiler bug on xlC 11.1 on AIX 7.1 that would
00517 // prevent PluralSelectorAdapter from implementing private PluralSelector.
00518 // xlC error message:
00519 // 1540-0300 (S) The "private" member "class icu_49::PluralFormat::PluralSelector" cannot be accessed.
00520 public:
00521 #else
00522 private:
00523 #endif
00524 
00527     class U_I18N_API PluralSelector : public UMemory {
00528       public:
00529         virtual ~PluralSelector();
00537         virtual UnicodeString select(double number, UErrorCode& ec) const = 0;
00538     };
00539 
00543     class U_I18N_API PluralSelectorAdapter : public PluralSelector {
00544       public:
00545         PluralSelectorAdapter() : pluralRules(NULL) {
00546         }
00547 
00548         virtual ~PluralSelectorAdapter();
00549 
00550         virtual UnicodeString select(double number, UErrorCode& /*ec*/) const;
00551 
00552         void reset();
00553 
00554         PluralRules* pluralRules;
00555     };
00556 
00557 #if defined(__xlC__)
00558 // End of xlC bug workaround, keep remaining definitions private.
00559 private:
00560 #endif
00561     Locale  locale;
00562     MessagePattern msgPattern;
00563     NumberFormat*  numberFormat;
00564     double offset;
00565     PluralSelectorAdapter pluralRulesWrapper;
00566 
00567     PluralFormat();   // default constructor not implemented
00568     void init(const PluralRules* rules, UPluralType type, UErrorCode& status);
00573     void copyObjects(const PluralFormat& other);
00574 
00585     static int32_t findSubMessage(
00586          const MessagePattern& pattern, int32_t partIndex,
00587          const PluralSelector& selector, double number, UErrorCode& ec);
00588 
00589     friend class MessageFormat;
00590 };
00591 
00592 U_NAMESPACE_END
00593 
00594 #endif /* #if !UCONFIG_NO_FORMATTING */
00595 
00596 #endif // _PLURFMT
00597 //eof

Generated on 25 Nov 2014 for ICU 50.1.2 by  doxygen 1.4.7