ICU 56.1: plurfmt.h Source File

ICU 56.1 56.1

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

plurfmt.h
Go to the documentation of this file.
1 /*
2 *******************************************************************************
3 * Copyright (C) 2007-2014, 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
28 U_NAMESPACE_BEGIN
29
30 class Hashtable;
31 class NFRule;
32
144 class U_I18N_API PluralFormat : public Format {
145 public:
146
155 PluralFormat(UErrorCode& status);
156
166 PluralFormat(const Locale& locale, UErrorCode& status);
167
177 PluralFormat(const PluralRules& rules, UErrorCode& status);
178
195 PluralFormat(const Locale& locale, const PluralRules& rules, UErrorCode& status);
196
207 PluralFormat(const Locale& locale, UPluralType type, UErrorCode& status);
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
284 PluralFormat(const Locale& locale,
285 UPluralType type,
286 const UnicodeString& pattern,
287 UErrorCode& status);
288
293 PluralFormat(const PluralFormat& other);
294
299 virtual ~PluralFormat();
300
313 void applyPattern(const UnicodeString& pattern, UErrorCode& status);
314
315
316 using Format::format;
317
330 UnicodeString format(int32_t number, UErrorCode& status) const;
331
344 UnicodeString format(double number, UErrorCode& status) const;
345
362 UnicodeString& format(int32_t number,
363 UnicodeString& appendTo,
364 FieldPosition& pos,
365 UErrorCode& status) const;
366
383 UnicodeString& format(double number,
384 UnicodeString& appendTo,
385 FieldPosition& pos,
386 UErrorCode& status) const;
387
388 #ifndef U_HIDE_DEPRECATED_API
389
404 void setLocale(const Locale& locale, UErrorCode& status);
405 #endif /* U_HIDE_DEPRECATED_API */
406
416 void setNumberFormat(const NumberFormat* format, UErrorCode& status);
417
424 PluralFormat& operator=(const PluralFormat& other);
425
433 virtual UBool operator==(const Format& other) const;
434
442 virtual UBool operator!=(const Format& other) const;
443
449 virtual Format* clone(void) const;
450
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
533 class U_I18N_API PluralSelector : public UMemory {
534 public:
535 virtual ~PluralSelector();
545 virtual UnicodeString select(void *context, double number, UErrorCode& ec) const = 0;
546 };
547
551 class U_I18N_API PluralSelectorAdapter : public PluralSelector {
552 public:
553 PluralSelectorAdapter() : pluralRules(NULL) {
554 }
555
556 virtual ~PluralSelectorAdapter();
557
558 virtual UnicodeString select(void *context, double number, UErrorCode& /*ec*/) const;
560 void reset();
561
562 PluralRules* pluralRules;
563 };
564
565 #if defined(__xlC__)
566 // End of xlC bug workaround, keep remaining definitions private.
567 private:
568 #endif
569 Locale locale;
570 MessagePattern msgPattern;
571 NumberFormat* numberFormat;
572 double offset;
573 PluralSelectorAdapter pluralRulesWrapper;
574
575 PluralFormat(); // default constructor not implemented
576 void init(const PluralRules* rules, UPluralType type, UErrorCode& status);
581 void copyObjects(const PluralFormat& other);
582
583 UnicodeString& format(const Formattable& numberObject, double number,
584 UnicodeString& appendTo,
585 FieldPosition& pos,
586 UErrorCode& status) const;
599 static int32_t findSubMessage(
600 const MessagePattern& pattern, int32_t partIndex,
601 const PluralSelector& selector, void *context, double number, UErrorCode& ec);
603 void parseType(const UnicodeString& source, const NFRule *rbnfLenientScanner,
604 Formattable& result, FieldPosition& pos) const;
605
606 friend class MessageFormat;
607 friend class NFRule;
608 };
609
610 U_NAMESPACE_END
611
612 #endif /* #if !UCONFIG_NO_FORMATTING */
613
614 #endif // _PLURFMT
615 //eof
icu::Format
Base class for all formats.
Definition: format.h:94
icu::PluralFormat::copyObjects
void copyObjects(const PluralFormat &other)
Copies dynamically allocated values (pointer fields).
icu::NumberFormat
Abstract base class for all number formats.
Definition: numfmt.h:172
icu::UObject::getDynamicClassID
virtual UClassID getDynamicClassID() const
ICU4C "poor man's RTTI", returns a UClassID for the actual ICU class.
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:91
icu::PluralFormat::format
UnicodeString format(int32_t number, UErrorCode &status) const
Formats a plural message for a given number.
plurrule.h
C++ API: PluralRules object.
icu::PluralRules
Defines rules for mapping non-negative numeric values onto a small set of keywords.
Definition: plurrule.h:192
icu::MessagePattern
Parses and represents ICU MessageFormat patterns.
Definition: messagepattern.h:358
U_I18N_API
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
Definition: utypes.h:358
U_NAMESPACE_BEGIN
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:129
NULL
#define NULL
Define NULL if necessary, to 0 for C++ and to ((void *)0) for C.
Definition: utypes.h:186
icu::PluralFormat
Definition: plurfmt.h:144
icu::Format::format
UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, UErrorCode &status) const
Formats an object to produce a string.
icu::PluralFormat::PluralSelector
Definition: plurfmt.h:533
icu::PluralFormat::PluralSelectorAdapter
Definition: plurfmt.h:551
icu::PluralFormat::PluralSelector::select
virtual UnicodeString select(void *context, double number, UErrorCode &ec) const =0
Given a number, returns the appropriate PluralFormat keyword.
icu::MessageFormat
Definition: msgfmt.h:323
U_NAMESPACE_END
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:130
icu::PluralFormat::findSubMessage
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.
icu::Format::parseObject
virtual void parseObject(const UnicodeString &source, Formattable &result, ParsePosition &parse_pos) const =0
Parse a string to produce an object.
icu::Format::operator==
virtual UBool operator==(const Format &other) const =0
Return true if the given Format objects are semantically equal.
UErrorCode
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:476
icu::FieldPosition
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition: fieldpos.h:106
UPluralType
UPluralType
Type of plurals and PluralRules.
Definition: upluralrules.h:44
icu::ParsePosition
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition: parsepos.h:47
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
icu::Format::operator=
Format & operator=(const Format &)
icu::Format::operator!=
UBool operator!=(const Format &other) const
Return true if the given Format objects are not semantically equal.
Definition: format.h:119
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:293
icu::Formattable
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:66
messagepattern.h
C++ API: MessagePattern class: Parses and represents ICU MessageFormat patterns.
numfmt.h
C++ API: Abstract base class for all number formats.
icu::UMemory
UMemory is the common ICU base class.
Definition: uobject.h:110
icu::Format::clone
virtual Format * clone() const =0
Clone this object polymorphically.
UBool
int8_t UBool
The ICU boolean type.
Definition: umachine.h:234
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:185