ICU 49.1.1  49.1.1
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 UnicodeString& pattern, UErrorCode& status);
00206 
00221     PluralFormat(const Locale& locale, const UnicodeString& pattern, UErrorCode& status);
00222 
00234     PluralFormat(const PluralRules& rules,
00235                  const UnicodeString& pattern,
00236                  UErrorCode& status);
00237 
00252     PluralFormat(const Locale& locale,
00253                  const PluralRules& rules,
00254                  const UnicodeString& pattern,
00255                  UErrorCode& status);
00256 
00261     PluralFormat(const PluralFormat& other);
00262 
00267     virtual ~PluralFormat();
00268 
00281     void applyPattern(const UnicodeString& pattern, UErrorCode& status);
00282 
00283 
00284     using Format::format;
00285 
00298     UnicodeString format(int32_t number, UErrorCode& status) const;
00299 
00312     UnicodeString format(double number, UErrorCode& status) const;
00313 
00330     UnicodeString& format(int32_t number,
00331                           UnicodeString& appendTo,
00332                           FieldPosition& pos,
00333                           UErrorCode& status) const;
00334 
00351     UnicodeString& format(double number,
00352                           UnicodeString& appendTo,
00353                           FieldPosition& pos,
00354                           UErrorCode& status) const;
00355 
00368     void setLocale(const Locale& locale, UErrorCode& status);
00369 
00379     void setNumberFormat(const NumberFormat* format, UErrorCode& status);
00380 
00387     PluralFormat& operator=(const PluralFormat& other);
00388 
00396     virtual UBool operator==(const Format& other) const;
00397 
00405     virtual UBool operator!=(const Format& other) const;
00406 
00412     virtual Format* clone(void) const;
00413 
00426    UnicodeString& format(const Formattable& obj,
00427                          UnicodeString& appendTo,
00428                          FieldPosition& pos,
00429                          UErrorCode& status) const;
00430 
00439    UnicodeString& toPattern(UnicodeString& appendTo);
00440 
00463    virtual void parseObject(const UnicodeString& source,
00464                             Formattable& result,
00465                             ParsePosition& parse_pos) const;
00466 
00473     static UClassID U_EXPORT2 getStaticClassID(void);
00474 
00480      virtual UClassID getDynamicClassID() const;
00481 
00482 #if defined(__xlC__) || (U_PLATFORM == U_PF_OS390) || (U_PLATFORM ==U_PF_OS400) 
00483 // Work around a compiler bug on xlC 11.1 on AIX 7.1 that would
00484 // prevent PluralSelectorAdapter from implementing private PluralSelector.
00485 // xlC error message:
00486 // 1540-0300 (S) The "private" member "class icu_49::PluralFormat::PluralSelector" cannot be accessed.
00487 public:
00488 #else
00489 private:
00490 #endif
00491 
00494     class U_I18N_API PluralSelector : public UMemory {
00495       public:
00496         virtual ~PluralSelector();
00504         virtual UnicodeString select(double number, UErrorCode& ec) const = 0;
00505     };
00506 
00510     class U_I18N_API PluralSelectorAdapter : public PluralSelector {
00511       public:
00512         PluralSelectorAdapter() : pluralRules(NULL) {
00513         }
00514 
00515         virtual ~PluralSelectorAdapter();
00516 
00517         virtual UnicodeString select(double number, UErrorCode& /*ec*/) const;
00518 
00519         void reset();
00520 
00521         PluralRules* pluralRules;
00522     };
00523 
00524 #if defined(__xlC__)
00525 // End of xlC bug workaround, keep remaining definitions private.
00526 private:
00527 #endif
00528     Locale  locale;
00529     MessagePattern msgPattern;
00530     NumberFormat*  numberFormat;
00531     double offset;
00532     PluralSelectorAdapter pluralRulesWrapper;
00533 
00534     PluralFormat();   // default constructor not implemented
00535     void init(const PluralRules* rules, UErrorCode& status);
00540     void copyObjects(const PluralFormat& other);
00541 
00552     static int32_t findSubMessage(
00553          const MessagePattern& pattern, int32_t partIndex,
00554          const PluralSelector& selector, double number, UErrorCode& ec);
00555 
00556     friend class MessageFormat;
00557 };
00558 
00559 U_NAMESPACE_END
00560 
00561 #endif /* #if !UCONFIG_NO_FORMATTING */
00562 
00563 #endif // _PLURFMT
00564 //eof