ICU 4.2.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
numfmt.h
Go to the documentation of this file.
1 /*
2 ********************************************************************************
3 * Copyright (C) 1997-2009, International Business Machines Corporation and others.
4 * All Rights Reserved.
5 ********************************************************************************
6 *
7 * File NUMFMT.H
8 *
9 * Modification History:
10 *
11 * Date Name Description
12 * 02/19/97 aliu Converted from java.
13 * 03/18/97 clhuang Updated per C++ implementation.
14 * 04/17/97 aliu Changed DigitCount to int per code review.
15 * 07/20/98 stephen JDK 1.2 sync up. Added scientific support.
16 * Changed naming conventions to match C++ guidelines
17 * Derecated Java style constants (eg, INTEGER_FIELD)
18 ********************************************************************************
19 */
20 
21 #ifndef NUMFMT_H
22 #define NUMFMT_H
23 
24 
25 #include "unicode/utypes.h"
26 
32 #if !UCONFIG_NO_FORMATTING
33 
34 #include "unicode/unistr.h"
35 #include "unicode/format.h"
36 #include "unicode/unum.h" // UNumberFormatStyle
37 #include "unicode/locid.h"
38 
40 
41 #if !UCONFIG_NO_SERVICE
43 class StringEnumeration;
44 #endif
45 
163 public:
164 
178  enum EStyles {
179  kNumberStyle,
180  kCurrencyStyle,
181  kPercentStyle,
182  kScientificStyle,
183  kIsoCurrencyStyle,
184  kPluralCurrencyStyle,
185  kStyleCount // ALWAYS LAST ENUM: number of styles
186  };
187 
197  kIntegerField,
198  kFractionField,
199 
200 
206  INTEGER_FIELD = kIntegerField,
207  FRACTION_FIELD = kFractionField
208  };
209 
214  virtual ~NumberFormat();
215 
222  virtual UBool operator==(const Format& other) const;
223 
239  virtual UnicodeString& format(const Formattable& obj,
240  UnicodeString& appendTo,
241  FieldPosition& pos,
242  UErrorCode& status) const;
243 
272  virtual void parseObject(const UnicodeString& source,
273  Formattable& result,
274  ParsePosition& parse_pos) const;
275 
286  UnicodeString& format( double number,
287  UnicodeString& appendTo) const;
288 
299  UnicodeString& format( int32_t number,
300  UnicodeString& appendTo) const;
301 
312  UnicodeString& format( int64_t number,
313  UnicodeString& appendTo) const;
314 
327  virtual UnicodeString& format(double number,
328  UnicodeString& appendTo,
329  FieldPosition& pos) const = 0;
342  virtual UnicodeString& format(int32_t number,
343  UnicodeString& appendTo,
344  FieldPosition& pos) const = 0;
345 
359  virtual UnicodeString& format(int64_t number,
360  UnicodeString& appendTo,
361  FieldPosition& pos) const;
372  UnicodeString& format(const Formattable& obj,
373  UnicodeString& appendTo,
374  UErrorCode& status) const;
375 
397  virtual void parse(const UnicodeString& text,
398  Formattable& result,
399  ParsePosition& parsePosition) const = 0;
400 
416  virtual void parse( const UnicodeString& text,
417  Formattable& result,
418  UErrorCode& status) const;
419 
439  virtual Formattable& parseCurrency(const UnicodeString& text,
440  Formattable& result,
441  ParsePosition& pos) const;
442 
454  UBool isParseIntegerOnly(void) const;
455 
463  virtual void setParseIntegerOnly(UBool value);
464 
473  static NumberFormat* U_EXPORT2 createInstance(UErrorCode&);
474 
483  static NumberFormat* U_EXPORT2 createInstance(const Locale& inLocale,
484  UErrorCode&);
485 
494  static NumberFormat* U_EXPORT2 createInstance(const Locale& desiredLocale, EStyles choice, UErrorCode& success);
495 
496 
501  static NumberFormat* U_EXPORT2 createCurrencyInstance(UErrorCode&);
502 
508  static NumberFormat* U_EXPORT2 createCurrencyInstance(const Locale& inLocale,
509  UErrorCode&);
510 
515  static NumberFormat* U_EXPORT2 createPercentInstance(UErrorCode&);
516 
522  static NumberFormat* U_EXPORT2 createPercentInstance(const Locale& inLocale,
523  UErrorCode&);
524 
529  static NumberFormat* U_EXPORT2 createScientificInstance(UErrorCode&);
530 
536  static NumberFormat* U_EXPORT2 createScientificInstance(const Locale& inLocale,
537  UErrorCode&);
538 
544  static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
545 
546 #if !UCONFIG_NO_SERVICE
547 
554  static URegistryKey U_EXPORT2 registerFactory(NumberFormatFactory* toAdopt, UErrorCode& status);
555 
565  static UBool U_EXPORT2 unregister(URegistryKey key, UErrorCode& status);
566 
573  static StringEnumeration* U_EXPORT2 getAvailableLocales(void);
574 #endif /* UCONFIG_NO_SERVICE */
575 
585  UBool isGroupingUsed(void) const;
586 
593  virtual void setGroupingUsed(UBool newValue);
594 
603  int32_t getMaximumIntegerDigits(void) const;
604 
617  virtual void setMaximumIntegerDigits(int32_t newValue);
618 
627  int32_t getMinimumIntegerDigits(void) const;
628 
639  virtual void setMinimumIntegerDigits(int32_t newValue);
640 
649  int32_t getMaximumFractionDigits(void) const;
650 
661  virtual void setMaximumFractionDigits(int32_t newValue);
662 
671  int32_t getMinimumFractionDigits(void) const;
672 
683  virtual void setMinimumFractionDigits(int32_t newValue);
684 
697  virtual void setCurrency(const UChar* theCurrency, UErrorCode& ec);
698 
706  const UChar* getCurrency() const;
707 
708 public:
709 
718  static UClassID U_EXPORT2 getStaticClassID(void);
719 
731  virtual UClassID getDynamicClassID(void) const = 0;
732 
733 protected:
734 
739  NumberFormat();
740 
745  NumberFormat(const NumberFormat&);
746 
752 
761  virtual void getEffectiveCurrency(UChar* result, UErrorCode& ec) const;
762 
763 private:
764 
772  static NumberFormat* makeInstance(const Locale& desiredLocale, EStyles choice, UErrorCode& success);
773 
774  UBool fGroupingUsed;
775  int32_t fMaxIntegerDigits;
776  int32_t fMinIntegerDigits;
777  int32_t fMaxFractionDigits;
778  int32_t fMinFractionDigits;
779  UBool fParseIntegerOnly;
780 
781  // ISO currency code
782  UChar fCurrency[4];
783 
784  friend class ICUNumberFormatFactory; // access to makeInstance, EStyles
785  friend class ICUNumberFormatService;
786 };
787 
788 #if !UCONFIG_NO_SERVICE
789 
798 public:
799 
804  virtual ~NumberFormatFactory();
805 
812  virtual UBool visible(void) const = 0;
813 
819  virtual const UnicodeString * getSupportedIDs(int32_t &count, UErrorCode& status) const = 0;
820 
828  virtual NumberFormat* createFormat(const Locale& loc, UNumberFormatStyle formatType) = 0;
829 };
830 
836 protected:
842 
848 
849 public:
853  SimpleNumberFormatFactory(const Locale& locale, UBool visible = TRUE);
854 
858  virtual ~SimpleNumberFormatFactory();
859 
863  virtual UBool visible(void) const;
864 
868  virtual const UnicodeString * getSupportedIDs(int32_t &count, UErrorCode& status) const;
869 };
870 #endif /* #if !UCONFIG_NO_SERVICE */
871 
872 // -------------------------------------
873 
874 inline UBool
876 {
877  return fParseIntegerOnly;
878 }
879 
880 inline UnicodeString&
882  UnicodeString& appendTo,
883  UErrorCode& status) const {
884  return Format::format(obj, appendTo, status);
885 }
886 
888 
889 #endif /* #if !UCONFIG_NO_FORMATTING */
890 
891 #endif // _NUMFMT
892 //eof
virtual UClassID getDynamicClassID() const =0
Returns a unique class ID POLYMORPHICALLY.
const UBool _visible
True if the locale supported by this factory is visible.
Definition: numfmt.h:841
virtual void parseObject(const UnicodeString &source, Formattable &result, ParsePosition &parse_pos) const =0
Parse a string to produce an object.
C++ API: Unicode String.
UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, UErrorCode &status) const
Formats an object to produce a string.
C++ API: Base class for all formats.
virtual const UnicodeString * getSupportedIDs(int32_t &count, UErrorCode &status) const =0
Return the locale names directly supported by this factory.
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
Definition: utypes.h:475
#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
UNumberFormatStyle
The possible number format styles.
Definition: unum.h:134
UBool isParseIntegerOnly(void) const
Return true if this format will parse numbers as integers only.
Definition: numfmt.h:875
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition: parsepos.h:47
A NumberFormatFactory is used to register new number formats.
Definition: numfmt.h:797
EStyles
Constants for various number format styles.
Definition: numfmt.h:178
virtual UBool operator==(const Format &other) const =0
Return true if the given Format objects are semantically equal.
#define TRUE
The TRUE value of a UBool.
Definition: umachine.h:212
A NumberFormatFactory that supports a single locale.
Definition: numfmt.h:835
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
UnicodeString _id
The locale supported by this factory, as a UnicodeString.
Definition: numfmt.h:847
virtual UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const
Format an object to produce a string.
const void * URegistryKey
Opaque type returned by registerInstance, registerFactory and unregister for service registration...
Definition: umisc.h:55
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition: fieldpos.h:106
uint16_t UChar
Define UChar to be wchar_t if that is 16 bits wide; always assumed to be unsigned.
Definition: umachine.h:299
#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
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:212
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
Base class for 'pure' C++ implementations of uenum api.
Definition: strenum.h:55
EAlignmentFields
Alignment Field constants used to construct a FieldPosition object.
Definition: numfmt.h:196
C++ API: Locale ID object.
signed long long int64_t
Define 64 bit limits.
Definition: pwin32.h:152
Base class for all formats.
Definition: format.h:93
Basic definitions for ICU, for both C and C++ APIs.
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:181
virtual UBool visible(void) const =0
Return true if this factory will be visible.
signed int int32_t
Define 64 bit limits.
Definition: pwin32.h:143
int8_t UBool
The ICU boolean type.
Definition: umachine.h:208
C API: NumberFormat.
Format & operator=(const Format &)