ICU 53.1  53.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
plurfmt.h
Go to the documentation of this file.
1 /*
2 *******************************************************************************
3 * Copyright (C) 2007-2013, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 *******************************************************************************
6 *
7 
8 * File PLURFMT.H
9 ********************************************************************************
10 */
11 
12 #ifndef PLURFMT
13 #define PLURFMT
14 
15 #include "unicode/utypes.h"
16 
22 #if !UCONFIG_NO_FORMATTING
23 
24 #include "unicode/messagepattern.h"
25 #include "unicode/numfmt.h"
26 #include "unicode/plurrule.h"
27 
29 
30 class Hashtable;
31 
144 public:
145 
154  PluralFormat(UErrorCode& status);
155 
165  PluralFormat(const Locale& locale, UErrorCode& status);
166 
176  PluralFormat(const PluralRules& rules, UErrorCode& status);
177 
194  PluralFormat(const Locale& locale, const PluralRules& rules, UErrorCode& status);
195 
206  PluralFormat(const Locale& locale, UPluralType type, UErrorCode& status);
207 
218  PluralFormat(const UnicodeString& pattern, UErrorCode& status);
219 
234  PluralFormat(const Locale& locale, const UnicodeString& pattern, UErrorCode& status);
235 
247  PluralFormat(const PluralRules& rules,
248  const UnicodeString& pattern,
249  UErrorCode& status);
250 
265  PluralFormat(const Locale& locale,
266  const PluralRules& rules,
267  const UnicodeString& pattern,
268  UErrorCode& status);
269 
283  PluralFormat(const Locale& locale,
284  UPluralType type,
285  const UnicodeString& pattern,
286  UErrorCode& status);
287 
292  PluralFormat(const PluralFormat& other);
293 
298  virtual ~PluralFormat();
299 
312  void applyPattern(const UnicodeString& pattern, UErrorCode& status);
313 
314 
315  using Format::format;
316 
329  UnicodeString format(int32_t number, UErrorCode& status) const;
330 
343  UnicodeString format(double number, UErrorCode& status) const;
344 
361  UnicodeString& format(int32_t number,
362  UnicodeString& appendTo,
363  FieldPosition& pos,
364  UErrorCode& status) const;
365 
382  UnicodeString& format(double number,
383  UnicodeString& appendTo,
384  FieldPosition& pos,
385  UErrorCode& status) const;
386 
387 #ifndef U_HIDE_DEPRECATED_API
388 
403  void setLocale(const Locale& locale, UErrorCode& status);
404 #endif /* U_HIDE_DEPRECATED_API */
405 
415  void setNumberFormat(const NumberFormat* format, UErrorCode& status);
416 
423  PluralFormat& operator=(const PluralFormat& other);
424 
432  virtual UBool operator==(const Format& other) const;
433 
441  virtual UBool operator!=(const Format& other) const;
442 
448  virtual Format* clone(void) const;
449 
464  UnicodeString& format(const Formattable& obj,
465  UnicodeString& appendTo,
466  FieldPosition& pos,
467  UErrorCode& status) const;
468 
477  UnicodeString& toPattern(UnicodeString& appendTo);
478 
501  virtual void parseObject(const UnicodeString& source,
502  Formattable& result,
503  ParsePosition& parse_pos) const;
504 
511  static UClassID U_EXPORT2 getStaticClassID(void);
512 
518  virtual UClassID getDynamicClassID() const;
519 
520 #if (defined(__xlC__) && (__xlC__ < 0x0C00)) || (U_PLATFORM == U_PF_OS390) || (U_PLATFORM ==U_PF_OS400)
521 // Work around a compiler bug on xlC 11.1 on AIX 7.1 that would
522 // prevent PluralSelectorAdapter from implementing private PluralSelector.
523 // xlC error message:
524 // 1540-0300 (S) The "private" member "class icu_49::PluralFormat::PluralSelector" cannot be accessed.
525 public:
526 #else
527 private:
528 #endif
529 
533  public:
534  virtual ~PluralSelector();
544  virtual UnicodeString select(void *context, double number, UErrorCode& ec) const = 0;
545  };
546 
551  public:
552  PluralSelectorAdapter() : pluralRules(NULL) {
553  }
554 
555  virtual ~PluralSelectorAdapter();
556 
557  virtual UnicodeString select(void *context, double number, UErrorCode& /*ec*/) const;
559  void reset();
560 
561  PluralRules* pluralRules;
562  };
563 
564 #if defined(__xlC__)
565 // End of xlC bug workaround, keep remaining definitions private.
566 private:
567 #endif
568  Locale locale;
569  MessagePattern msgPattern;
570  NumberFormat* numberFormat;
571  double offset;
572  PluralSelectorAdapter pluralRulesWrapper;
573 
574  PluralFormat(); // default constructor not implemented
575  void init(const PluralRules* rules, UPluralType type, UErrorCode& status);
580  void copyObjects(const PluralFormat& other);
581 
582  UnicodeString& format(const Formattable& numberObject, double number,
583  UnicodeString& appendTo,
584  FieldPosition& pos,
585  UErrorCode& status) const;
598  static int32_t findSubMessage(
599  const MessagePattern& pattern, int32_t partIndex,
600  const PluralSelector& selector, void *context, double number, UErrorCode& ec);
602  friend class MessageFormat;
603 };
604 
606 
607 #endif /* #if !UCONFIG_NO_FORMATTING */
608 
609 #endif // _PLURFMT
610 //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:172
virtual UClassID getDynamicClassID() const
ICU4C "poor man's RTTI", returns a UClassID for the actual ICU class.
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:91
virtual Format * clone() const =0
Clone this object polymorphically.
UnicodeString format(int32_t number, UErrorCode &status) const
Formats a plural message for a given number.
C++ API: PluralRules object.
Defines rules for mapping non-negative numeric values onto a small set of keywords.
Definition: plurrule.h:191
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
virtual UnicodeString select(void *context, double number, UErrorCode &ec) const =0
Given a number, returns the appropriate PluralFormat keyword.
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
static int32_t findSubMessage(const MessagePattern &pattern, int32_t partIndex, const PluralSelector &selector, void *context, double number, UErrorCode &ec)
Finds the PluralFormat sub-message for the given number, or the "other" sub-message.
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:245
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:66
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:110
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:185