ICU 4.8.1.1  4.8.1.1
 All Data Structures 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-2011, 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 UnicodeString& pattern, UErrorCode& status);
206 
221  PluralFormat(const Locale& locale, const UnicodeString& pattern, UErrorCode& status);
222 
234  PluralFormat(const PluralRules& rules,
235  const UnicodeString& pattern,
236  UErrorCode& status);
237 
252  PluralFormat(const Locale& locale,
253  const PluralRules& rules,
254  const UnicodeString& pattern,
255  UErrorCode& status);
256 
261  PluralFormat(const PluralFormat& other);
262 
267  virtual ~PluralFormat();
268 
281  void applyPattern(const UnicodeString& pattern, UErrorCode& status);
282 
283 
284  using Format::format;
285 
298  UnicodeString format(int32_t number, UErrorCode& status) const;
299 
312  UnicodeString format(double number, UErrorCode& status) const;
313 
330  UnicodeString& format(int32_t number,
331  UnicodeString& appendTo,
332  FieldPosition& pos,
333  UErrorCode& status) const;
334 
351  UnicodeString& format(double number,
352  UnicodeString& appendTo,
353  FieldPosition& pos,
354  UErrorCode& status) const;
355 
368  void setLocale(const Locale& locale, UErrorCode& status);
369 
379  void setNumberFormat(const NumberFormat* format, UErrorCode& status);
380 
387  PluralFormat& operator=(const PluralFormat& other);
388 
396  virtual UBool operator==(const Format& other) const;
397 
405  virtual UBool operator!=(const Format& other) const;
406 
412  virtual Format* clone(void) const;
413 
426  UnicodeString& format(const Formattable& obj,
427  UnicodeString& appendTo,
428  FieldPosition& pos,
429  UErrorCode& status) const;
430 
439  UnicodeString& toPattern(UnicodeString& appendTo);
440 
463  virtual void parseObject(const UnicodeString& source,
464  Formattable& result,
465  ParsePosition& parse_pos) const;
466 
473  static UClassID U_EXPORT2 getStaticClassID(void);
474 
480  virtual UClassID getDynamicClassID() const;
481 
482  private:
483 
487  class U_I18N_API PluralSelector : public UMemory {
488  public:
496  virtual UnicodeString select(double number, UErrorCode& ec) const = 0;
497  };
498 
502  class U_I18N_API PluralSelectorAdapter : public PluralSelector {
503  public:
504  PluralSelectorAdapter() : pluralRules(NULL) {
505  }
506 
507  virtual ~PluralSelectorAdapter();
508 
509  virtual UnicodeString select(double number, UErrorCode& /*ec*/) const;
510 
511  void reset();
512 
513  PluralRules* pluralRules;
514  };
515 
516  Locale locale;
517  MessagePattern msgPattern;
518  NumberFormat* numberFormat;
519  double offset;
520  PluralSelectorAdapter pluralRulesWrapper;
521 
522  PluralFormat(); // default constructor not implemented
523  void init(const PluralRules* rules, UErrorCode& status);
528  void copyObjects(const PluralFormat& other);
529 
540  static int32_t findSubMessage(
541  const MessagePattern& pattern, int32_t partIndex,
542  const PluralSelector& selector, double number, UErrorCode& ec);
543 
544  friend class MessageFormat;
545 };
546 
548 
549 #endif /* #if !UCONFIG_NO_FORMATTING */
550 
551 #endif // _PLURFMT
552 //eof
UBool operator!=(const Format &other) const
Return true if the given Format objects are not semantically equal.
Definition: format.h:119
virtual void parseObject(const UnicodeString &source, Formattable &result, ParsePosition &parse_pos) const =0
Parse a string to produce an object.
UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, UErrorCode &status) const
Formats an object to produce a string.
C++ API: PluralRules object.
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
Definition: utypes.h:521
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:131
Abstract base class for all number formats.
Definition: numfmt.h:165
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition: parsepos.h:47
#define NULL
Define NULL if necessary, to 0 for C++ and to ((void *)0) for C.
Definition: utypes.h:299
virtual UBool operator==(const Format &other) const =0
Return true if the given Format objects are semantically equal.
UMemory is the common ICU base class.
Definition: uobject.h:101
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:188
#define U_EXPORT2
Definition: platform.h:314
virtual Format * clone() const =0
Clone this object polymorphically.
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition: fieldpos.h:106
Parses and represents ICU MessageFormat patterns.
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:132
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:52
void * UClassID
UClassID is used to identify classes without using RTTI, since RTTI is not yet supported by all C++ c...
Definition: utypes.h:385
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:639
Defines rules for mapping non-negative numeric values onto a small set of keywords.
Definition: plurrule.h:126
Base class for all formats.
Definition: format.h:94
Basic definitions for ICU, for both C and C++ APIs.
C++ API: MessagePattern class: Parses and represents ICU MessageFormat patterns.
C++ API: Abstract base class for all number formats.
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:181
virtual UClassID getDynamicClassID() const =0
ICU4C "poor man's RTTI", returns a UClassID for the actual ICU class.
int8_t UBool
The ICU boolean type.
Definition: umachine.h:228
Format & operator=(const Format &)