ICU 4.8.1.1  4.8.1.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
choicfmt.h
Go to the documentation of this file.
1 /*
2 ********************************************************************************
3 * Copyright (C) 1997-2011, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 ********************************************************************************
6 *
7 * File CHOICFMT.H
8 *
9 * Modification History:
10 *
11 * Date Name Description
12 * 02/19/97 aliu Converted from java.
13 * 03/20/97 helena Finished first cut of implementation and got rid
14 * of nextDouble/previousDouble and replaced with
15 * boolean array.
16 * 4/10/97 aliu Clean up. Modified to work on AIX.
17 * 8/6/97 nos Removed overloaded constructor, member var 'buffer'.
18 * 07/22/98 stephen Removed operator!= (implemented in Format)
19 ********************************************************************************
20 */
21 
22 #ifndef CHOICFMT_H
23 #define CHOICFMT_H
24 
25 #include "unicode/utypes.h"
26 
32 #if !UCONFIG_NO_FORMATTING
33 
34 #include "unicode/fieldpos.h"
35 #include "unicode/format.h"
36 #include "unicode/messagepattern.h"
37 #include "unicode/numfmt.h"
38 #include "unicode/unistr.h"
39 
41 
42 class MessageFormat;
43 
169 public:
178  ChoiceFormat(const UnicodeString& pattern,
179  UErrorCode& status);
180 
181 
194  ChoiceFormat(const double* limits,
195  const UnicodeString* formats,
196  int32_t count );
197 
212  ChoiceFormat(const double* limits,
213  const UBool* closures,
214  const UnicodeString* formats,
215  int32_t count);
216 
223  ChoiceFormat(const ChoiceFormat& that);
224 
231  const ChoiceFormat& operator=(const ChoiceFormat& that);
232 
237  virtual ~ChoiceFormat();
238 
246  virtual Format* clone(void) const;
247 
256  virtual UBool operator==(const Format& other) const;
257 
266  virtual void applyPattern(const UnicodeString& pattern,
267  UErrorCode& status);
268 
279  virtual void applyPattern(const UnicodeString& pattern,
280  UParseError& parseError,
281  UErrorCode& status);
290  virtual UnicodeString& toPattern(UnicodeString &pattern) const;
291 
305  virtual void setChoices(const double* limitsToCopy,
306  const UnicodeString* formatsToCopy,
307  int32_t count );
308 
319  virtual void setChoices(const double* limits,
320  const UBool* closures,
321  const UnicodeString* formats,
322  int32_t count);
323 
332  virtual const double* getLimits(int32_t& count) const;
333 
342  virtual const UBool* getClosures(int32_t& count) const;
343 
352  virtual const UnicodeString* getFormats(int32_t& count) const;
353 
354 
355  using NumberFormat::format;
356 
368  virtual UnicodeString& format(double number,
369  UnicodeString& appendTo,
370  FieldPosition& pos) const;
382  virtual UnicodeString& format(int32_t number,
383  UnicodeString& appendTo,
384  FieldPosition& pos) const;
385 
397  virtual UnicodeString& format(int64_t number,
398  UnicodeString& appendTo,
399  FieldPosition& pos) const;
400 
415  virtual UnicodeString& format(const Formattable* objs,
416  int32_t cnt,
417  UnicodeString& appendTo,
418  FieldPosition& pos,
419  UErrorCode& success) const;
434  virtual UnicodeString& format(const Formattable& obj,
435  UnicodeString& appendTo,
436  FieldPosition& pos,
437  UErrorCode& status) const;
438 
450  UnicodeString& format(const Formattable& obj,
451  UnicodeString& appendTo,
452  UErrorCode& status) const;
453 
465  UnicodeString& format( double number,
466  UnicodeString& appendTo) const;
467 
479  UnicodeString& format( int32_t number,
480  UnicodeString& appendTo) const;
481 
496  virtual void parse(const UnicodeString& text,
497  Formattable& result,
498  ParsePosition& parsePosition) const;
499 
512  virtual void parse(const UnicodeString& text,
513  Formattable& result,
514  UErrorCode& status) const;
515 
524  virtual UClassID getDynamicClassID(void) const;
525 
537  static UClassID U_EXPORT2 getStaticClassID(void);
538 
539 private:
546  static UnicodeString& dtos(double value, UnicodeString& string);
547 
548  ChoiceFormat(); // default constructor not implemented
549 
561  ChoiceFormat(const UnicodeString& newPattern,
562  UParseError& parseError,
563  UErrorCode& status);
564 
565  friend class MessageFormat;
566 
567  virtual void setChoices(const double* limits,
568  const UBool* closures,
569  const UnicodeString* formats,
570  int32_t count,
571  UErrorCode &errorCode);
572 
580  static int32_t findSubMessage(const MessagePattern &pattern, int32_t partIndex, double number);
581 
582  static double parseArgument(
583  const MessagePattern &pattern, int32_t partIndex,
584  const UnicodeString &source, ParsePosition &pos);
585 
594  static int32_t matchStringUntilLimitPart(
595  const MessagePattern &pattern, int32_t partIndex, int32_t limitPartIndex,
596  const UnicodeString &source, int32_t sourceOffset);
597 
604  UErrorCode constructorErrorCode;
605 
613  MessagePattern msgPattern;
614 
654  // double* fChoiceLimits;
655  // UBool* fClosures;
656  // UnicodeString* fChoiceFormats;
657  // int32_t fCount;
658 };
659 
660 inline UnicodeString&
662  UnicodeString& appendTo,
663  UErrorCode& status) const {
664  // Don't use Format:: - use immediate base class only,
665  // in case immediate base modifies behavior later.
666  return NumberFormat::format(obj, appendTo, status);
667 }
668 
669 inline UnicodeString&
670 ChoiceFormat::format(double number,
671  UnicodeString& appendTo) const {
672  return NumberFormat::format(number, appendTo);
673 }
674 
675 inline UnicodeString&
676 ChoiceFormat::format(int32_t number,
677  UnicodeString& appendTo) const {
678  return NumberFormat::format(number, appendTo);
679 }
681 
682 #endif /* #if !UCONFIG_NO_FORMATTING */
683 
684 #endif // _CHOICFMT
685 //eof
static UClassID getStaticClassID(void)
Return the class ID for this class.
virtual void parse(const UnicodeString &text, Formattable &result, ParsePosition &parsePosition) const =0
Return a long if possible (e.g.
C++ API: Unicode String.
virtual UBool operator==(const Format &other) const
Return true if the given Format objects are semantically equal.
C++ API: Base class for all formats.
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
Definition: utypes.h:521
C++ API: FieldPosition identifies the fields in a formatted output.
#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
NumberFormat & operator=(const NumberFormat &)
Assignment operator.
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition: parsepos.h:47
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
ChoiceFormat converts between ranges of numeric values and strings for those ranges.
Definition: choicfmt.h:168
virtual UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const
Format an object to produce a string.
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
virtual UnicodeString & format(double number, UnicodeString &appendTo, FieldPosition &pos) const
Formats a double number using this object's choices.
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
virtual UClassID getDynamicClassID(void) const =0
Returns a unique class ID POLYMORPHICALLY.
A UParseError struct is used to returned detailed information about parsing errors.
Definition: parseerr.h:56
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.
int8_t UBool
The ICU boolean type.
Definition: umachine.h:228