ICU 4.2.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-2008, 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/unistr.h"
35 #include "unicode/numfmt.h"
36 #include "unicode/fieldpos.h"
37 #include "unicode/format.h"
38 
40 
41 class MessageFormat;
42 
260 public:
270  ChoiceFormat(const UnicodeString& pattern,
271  UErrorCode& status);
272 
273 
284  ChoiceFormat(const double* limits,
285  const UnicodeString* formats,
286  int32_t count );
287 
305  ChoiceFormat(const double* limits,
306  const UBool* closures,
307  const UnicodeString* formats,
308  int32_t count);
309 
316  ChoiceFormat(const ChoiceFormat& that);
317 
324  const ChoiceFormat& operator=(const ChoiceFormat& that);
325 
330  virtual ~ChoiceFormat();
331 
339  virtual Format* clone(void) const;
340 
349  virtual UBool operator==(const Format& other) const;
350 
359  virtual void applyPattern(const UnicodeString& pattern,
360  UErrorCode& status);
361 
372  virtual void applyPattern(const UnicodeString& pattern,
373  UParseError& parseError,
374  UErrorCode& status);
383  virtual UnicodeString& toPattern(UnicodeString &pattern) const;
384 
397  virtual void setChoices(const double* limitsToCopy,
398  const UnicodeString* formatsToCopy,
399  int32_t count );
400 
410  virtual void setChoices(const double* limits,
411  const UBool* closures,
412  const UnicodeString* formats,
413  int32_t count);
414 
422  virtual const double* getLimits(int32_t& count) const;
423 
432  virtual const UBool* getClosures(int32_t& count) const;
433 
441  virtual const UnicodeString* getFormats(int32_t& count) const;
442 
454  virtual UnicodeString& format(double number,
455  UnicodeString& appendTo,
456  FieldPosition& pos) const;
468  virtual UnicodeString& format(int32_t number,
469  UnicodeString& appendTo,
470  FieldPosition& pos) const;
471 
483  virtual UnicodeString& format(int64_t number,
484  UnicodeString& appendTo,
485  FieldPosition& pos) const;
486 
501  virtual UnicodeString& format(const Formattable* objs,
502  int32_t cnt,
503  UnicodeString& appendTo,
504  FieldPosition& pos,
505  UErrorCode& success) const;
520  virtual UnicodeString& format(const Formattable& obj,
521  UnicodeString& appendTo,
522  FieldPosition& pos,
523  UErrorCode& status) const;
524 
536  UnicodeString& format(const Formattable& obj,
537  UnicodeString& appendTo,
538  UErrorCode& status) const;
539 
551  UnicodeString& format( double number,
552  UnicodeString& appendTo) const;
553 
565  UnicodeString& format( int32_t number,
566  UnicodeString& appendTo) const;
567 
586  virtual void parse(const UnicodeString& text,
587  Formattable& result,
588  ParsePosition& parsePosition) const;
589 
606  virtual void parse(const UnicodeString& text,
607  Formattable& result,
608  UErrorCode& status) const;
609 
610 
611 public:
623  virtual UClassID getDynamicClassID(void) const;
624 
636  static UClassID U_EXPORT2 getStaticClassID(void);
637 
638 private:
639  // static cache management (thread-safe)
640  // static NumberFormat* getNumberFormat(UErrorCode &status); // call this function to 'check out' a numberformat from the cache.
641  // static void releaseNumberFormat(NumberFormat *adopt); // call this function to 'return' the number format to the cache.
642 
649  static double stod(const UnicodeString& string);
650 
658  static UnicodeString& dtos(double value, UnicodeString& string);
659 
660  ChoiceFormat(); // default constructor not implemented
661 
673  ChoiceFormat(const UnicodeString& newPattern,
674  UParseError& parseError,
675  UErrorCode& status);
676 
677  friend class MessageFormat;
715  double* fChoiceLimits;
716  UBool* fClosures;
717  UnicodeString* fChoiceFormats;
718  int32_t fCount;
719 };
720 
721 inline UnicodeString&
723  UnicodeString& appendTo,
724  UErrorCode& status) const {
725  // Don't use Format:: - use immediate base class only,
726  // in case immediate base modifies behavior later.
727  return NumberFormat::format(obj, appendTo, status);
728 }
729 
730 inline UnicodeString&
731 ChoiceFormat::format(double number,
732  UnicodeString& appendTo) const {
733  return NumberFormat::format(number, appendTo);
734 }
735 
736 inline UnicodeString&
738  UnicodeString& appendTo) const {
739  return NumberFormat::format(number, appendTo);
740 }
742 
743 #endif /* #if !UCONFIG_NO_FORMATTING */
744 
745 #endif // _CHOICFMT
746 //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:475
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:183
Abstract base class for all number formats.
Definition: numfmt.h:162
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:187
#define U_EXPORT2
Definition: platform.h:338
ChoiceFormat converts between ranges of numeric values and string names for those ranges...
Definition: choicfmt.h:259
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
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API If the compiler doesn't support namespaces...
Definition: uversion.h:184
virtual UnicodeString & format(double number, UnicodeString &appendTo, FieldPosition &pos) const
Format a double or long number using this object's choices.
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:47
void * UClassID
UClassID is used to identify classes without using RTTI, since RTTI is not yet supported by all C++ c...
Definition: utypes.h:339
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:593
virtual UClassID getDynamicClassID(void) const =0
Returns a unique class ID POLYMORPHICALLY.
signed long long int64_t
Define 64 bit limits.
Definition: pwin32.h:152
A UParseError struct is used to returned detailed information about parsing errors.
Definition: parseerr.h:56
Base class for all formats.
Definition: format.h:93
Basic definitions for ICU, for both C and C++ APIs.
C++ API: Abstract base class for all number formats.
signed int int32_t
Define 64 bit limits.
Definition: pwin32.h:143
A MessageFormat produces concatenated messages in a language-neutral way.
Definition: msgfmt.h:306
int8_t UBool
The ICU boolean type.
Definition: umachine.h:208