ICU 51.2  51.2
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 * 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 
195 #ifndef U_HIDE_DRAFT_API
196 
206  PluralFormat(const Locale& locale, UPluralType type, UErrorCode& status);
207 #endif /* U_HIDE_DRAFT_API */
208 
219  PluralFormat(const UnicodeString& pattern, UErrorCode& status);
220 
235  PluralFormat(const Locale& locale, const UnicodeString& pattern, UErrorCode& status);
236 
248  PluralFormat(const PluralRules& rules,
249  const UnicodeString& pattern,
250  UErrorCode& status);
251 
266  PluralFormat(const Locale& locale,
267  const PluralRules& rules,
268  const UnicodeString& pattern,
269  UErrorCode& status);
270 
271 #ifndef U_HIDE_DRAFT_API
272 
285  PluralFormat(const Locale& locale,
286  UPluralType type,
287  const UnicodeString& pattern,
288  UErrorCode& status);
289 #endif /* U_HIDE_DRAFT_API */
290 
295  PluralFormat(const PluralFormat& other);
296 
301  virtual ~PluralFormat();
302 
315  void applyPattern(const UnicodeString& pattern, UErrorCode& status);
316 
317 
318  using Format::format;
319 
332  UnicodeString format(int32_t number, UErrorCode& status) const;
333 
346  UnicodeString format(double number, UErrorCode& status) const;
347 
364  UnicodeString& format(int32_t number,
365  UnicodeString& appendTo,
366  FieldPosition& pos,
367  UErrorCode& status) const;
368 
385  UnicodeString& format(double number,
386  UnicodeString& appendTo,
387  FieldPosition& pos,
388  UErrorCode& status) const;
389 
390 #ifndef U_HIDE_DEPRECATED_API
391 
406  void setLocale(const Locale& locale, UErrorCode& status);
407 #endif /* U_HIDE_DEPRECATED_API */
408 
418  void setNumberFormat(const NumberFormat* format, UErrorCode& status);
419 
426  PluralFormat& operator=(const PluralFormat& other);
427 
435  virtual UBool operator==(const Format& other) const;
436 
444  virtual UBool operator!=(const Format& other) const;
445 
451  virtual Format* clone(void) const;
452 
465  UnicodeString& format(const Formattable& obj,
466  UnicodeString& appendTo,
467  FieldPosition& pos,
468  UErrorCode& status) const;
469 
478  UnicodeString& toPattern(UnicodeString& appendTo);
479 
502  virtual void parseObject(const UnicodeString& source,
503  Formattable& result,
504  ParsePosition& parse_pos) const;
505 
512  static UClassID U_EXPORT2 getStaticClassID(void);
513 
519  virtual UClassID getDynamicClassID() const;
520 
521 #if (defined(__xlC__) && (__xlC__ < 0x0C00)) || (U_PLATFORM == U_PF_OS390) || (U_PLATFORM ==U_PF_OS400)
522 // Work around a compiler bug on xlC 11.1 on AIX 7.1 that would
523 // prevent PluralSelectorAdapter from implementing private PluralSelector.
524 // xlC error message:
525 // 1540-0300 (S) The "private" member "class icu_49::PluralFormat::PluralSelector" cannot be accessed.
526 public:
527 #else
528 private:
529 #endif
530 
534  public:
535  virtual ~PluralSelector();
543  virtual UnicodeString select(double number, UErrorCode& ec) const = 0;
544  };
545 
550  public:
551  PluralSelectorAdapter() : pluralRules(NULL) {
552  }
553 
554  virtual ~PluralSelectorAdapter();
555 
556  virtual UnicodeString select(double number, UErrorCode& /*ec*/) const;
557 
558  void reset();
559 
560  PluralRules* pluralRules;
561  };
562 
563 #if defined(__xlC__)
564 // End of xlC bug workaround, keep remaining definitions private.
565 private:
566 #endif
567  Locale locale;
568  MessagePattern msgPattern;
569  NumberFormat* numberFormat;
570  double offset;
571  PluralSelectorAdapter pluralRulesWrapper;
572 
573  PluralFormat(); // default constructor not implemented
574  void init(const PluralRules* rules, UPluralType type, UErrorCode& status);
579  void copyObjects(const PluralFormat& other);
580 
591  static int32_t findSubMessage(
592  const MessagePattern& pattern, int32_t partIndex,
593  const PluralSelector& selector, double number, UErrorCode& ec);
594 
595  friend class MessageFormat;
596 };
597 
599 
600 #endif /* #if !UCONFIG_NO_FORMATTING */
601 
602 #endif // _PLURFMT
603 //eof