ICU 50.1.2  50.1.2
plurfmt.h
Go to the documentation of this file.
1 /*
2 *******************************************************************************
3 * Copyright (C) 2007-2012, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 *******************************************************************************
6 *
7 
8 * File PLURFMT.H
9 *
10 * Modification History:*
11 * Date Name Description
12 *
13 ********************************************************************************
14 */
15 
16 #ifndef PLURFMT
17 #define PLURFMT
18 
19 #include "unicode/utypes.h"
20 
26 #if !UCONFIG_NO_FORMATTING
27 
28 #include "unicode/messagepattern.h"
29 #include "unicode/numfmt.h"
30 #include "unicode/plurrule.h"
31 
33 
34 class Hashtable;
35 
148 public:
149 
158  PluralFormat(UErrorCode& status);
159 
169  PluralFormat(const Locale& locale, UErrorCode& status);
170 
180  PluralFormat(const PluralRules& rules, UErrorCode& status);
181 
193  PluralFormat(const Locale& locale, const PluralRules& rules, UErrorCode& status);
194 
205  PluralFormat(const Locale& locale, UPluralType type, UErrorCode& status);
206 
217  PluralFormat(const UnicodeString& pattern, UErrorCode& status);
218 
233  PluralFormat(const Locale& locale, const UnicodeString& pattern, UErrorCode& status);
234 
246  PluralFormat(const PluralRules& rules,
247  const UnicodeString& pattern,
248  UErrorCode& status);
249 
264  PluralFormat(const Locale& locale,
265  const PluralRules& rules,
266  const UnicodeString& pattern,
267  UErrorCode& status);
268 
282  PluralFormat(const Locale& locale,
283  UPluralType type,
284  const UnicodeString& pattern,
285  UErrorCode& status);
286 
291  PluralFormat(const PluralFormat& other);
292 
297  virtual ~PluralFormat();
298 
311  void applyPattern(const UnicodeString& pattern, UErrorCode& status);
312 
313 
314  using Format::format;
315 
328  UnicodeString format(int32_t number, UErrorCode& status) const;
329 
342  UnicodeString format(double number, UErrorCode& status) const;
343 
360  UnicodeString& format(int32_t number,
361  UnicodeString& appendTo,
362  FieldPosition& pos,
363  UErrorCode& status) const;
364 
381  UnicodeString& format(double number,
382  UnicodeString& appendTo,
383  FieldPosition& pos,
384  UErrorCode& status) const;
385 
401  void setLocale(const Locale& locale, UErrorCode& status);
402 
412  void setNumberFormat(const NumberFormat* format, UErrorCode& status);
413 
420  PluralFormat& operator=(const PluralFormat& other);
421 
429  virtual UBool operator==(const Format& other) const;
430 
438  virtual UBool operator!=(const Format& other) const;
439 
445  virtual Format* clone(void) const;
446 
459  UnicodeString& format(const Formattable& obj,
460  UnicodeString& appendTo,
461  FieldPosition& pos,
462  UErrorCode& status) const;
463 
472  UnicodeString& toPattern(UnicodeString& appendTo);
473 
496  virtual void parseObject(const UnicodeString& source,
497  Formattable& result,
498  ParsePosition& parse_pos) const;
499 
506  static UClassID U_EXPORT2 getStaticClassID(void);
507 
513  virtual UClassID getDynamicClassID() const;
514 
515 #if (defined(__xlC__) && (__xlC__ < 0x0C00)) || (U_PLATFORM == U_PF_OS390) || (U_PLATFORM ==U_PF_OS400)
516 // Work around a compiler bug on xlC 11.1 on AIX 7.1 that would
517 // prevent PluralSelectorAdapter from implementing private PluralSelector.
518 // xlC error message:
519 // 1540-0300 (S) The "private" member "class icu_49::PluralFormat::PluralSelector" cannot be accessed.
520 public:
521 #else
522 private:
523 #endif
524 
528  public:
529  virtual ~PluralSelector();
537  virtual UnicodeString select(double number, UErrorCode& ec) const = 0;
538  };
539 
544  public:
545  PluralSelectorAdapter() : pluralRules(NULL) {
546  }
547 
548  virtual ~PluralSelectorAdapter();
549 
550  virtual UnicodeString select(double number, UErrorCode& /*ec*/) const;
551 
552  void reset();
553 
554  PluralRules* pluralRules;
555  };
556 
557 #if defined(__xlC__)
558 // End of xlC bug workaround, keep remaining definitions private.
559 private:
560 #endif
561  Locale locale;
562  MessagePattern msgPattern;
563  NumberFormat* numberFormat;
564  double offset;
565  PluralSelectorAdapter pluralRulesWrapper;
566 
567  PluralFormat(); // default constructor not implemented
568  void init(const PluralRules* rules, UPluralType type, UErrorCode& status);
573  void copyObjects(const PluralFormat& other);
574 
585  static int32_t findSubMessage(
586  const MessagePattern& pattern, int32_t partIndex,
587  const PluralSelector& selector, double number, UErrorCode& ec);
588 
589  friend class MessageFormat;
590 };
591 
593 
594 #endif /* #if !UCONFIG_NO_FORMATTING */
595 
596 #endif // _PLURFMT
597 //eof
Base class for all formats.
Definition: format.h:94
void copyObjects(const PluralFormat &other)
Copies dynamically allocated values (pointer fields).
Abstract base class for all number formats.
Definition: numfmt.h:166
virtual UClassID getDynamicClassID() const =0
ICU4C &quot;poor man&#39;s RTTI&quot;, returns a UClassID for the actual ICU class.
static int32_t findSubMessage(const MessagePattern &pattern, int32_t partIndex, const PluralSelector &selector, double number, UErrorCode &ec)
Finds the PluralFormat sub-message for the given number, or the &quot;other&quot; sub-message.
void * UClassID
UClassID is used to identify classes without using the compiler&#39;s RTTI.
Definition: uobject.h:96
virtual Format * clone() const =0
Clone this object polymorphically.
C++ API: PluralRules object.
Defines rules for mapping non-negative numeric values onto a small set of keywords.
Definition: plurrule.h:127
Parses and represents ICU MessageFormat patterns.
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
Definition: utypes.h:358
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:129
#define NULL
Define NULL if necessary, to 0 for C++ and to ((void *)0) for C.
Definition: utypes.h:186
UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, UErrorCode &status) const
Formats an object to produce a string.
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:130
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:476
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition: fieldpos.h:106
UPluralType
Type of plurals and PluralRules.
Definition: upluralrules.h:44
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition: parsepos.h:47
virtual UBool operator==(const Format &other) const =0
Return true if the given Format objects are semantically equal.
virtual void parseObject(const UnicodeString &source, Formattable &result, ParsePosition &parse_pos) const =0
Parse a string to produce an object.
Basic definitions for ICU, for both C and C++ APIs.
Format & operator=(const Format &)
UBool operator!=(const Format &other) const
Return true if the given Format objects are not semantically equal.
Definition: format.h:119
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:246
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:62
C++ API: MessagePattern class: Parses and represents ICU MessageFormat patterns.
C++ API: Abstract base class for all number formats.
UMemory is the common ICU base class.
Definition: uobject.h:115
int8_t UBool
The ICU boolean type.
Definition: umachine.h:200
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:182