Home | History | Annotate | Download | only in i18n
      1 /*
      2 ********************************************************************************
      3 *   Copyright (C) 2005-2007, International Business Machines
      4 *   Corporation and others.  All Rights Reserved.
      5 ********************************************************************************
      6 *
      7 * File WINNMFMT.H
      8 *
      9 ********************************************************************************
     10 */
     11 
     12 #ifndef __WINNMFMT
     13 #define __WINNMFMT
     14 
     15 #include "unicode/utypes.h"
     16 
     17 #ifdef U_WINDOWS
     18 
     19 #include "unicode/format.h"
     20 #include "unicode/datefmt.h"
     21 #include "unicode/calendar.h"
     22 #include "unicode/ustring.h"
     23 #include "unicode/locid.h"
     24 
     25 #if !UCONFIG_NO_FORMATTING
     26 
     27 /**
     28  * \file
     29  * \brief C++ API: Format numbers using Windows API.
     30  */
     31 
     32 U_NAMESPACE_BEGIN
     33 
     34 union FormatInfo;
     35 
     36 class Win32NumberFormat : public NumberFormat
     37 {
     38 public:
     39     Win32NumberFormat(const Locale &locale, UBool currency, UErrorCode &status);
     40 
     41     Win32NumberFormat(const Win32NumberFormat &other);
     42 
     43     virtual ~Win32NumberFormat();
     44 
     45     virtual Format *clone(void) const;
     46 
     47     Win32NumberFormat &operator=(const Win32NumberFormat &other);
     48 
     49     /**
     50      * Format a double number. Concrete subclasses must implement
     51      * these pure virtual methods.
     52      *
     53      * @param number    The value to be formatted.
     54      * @param appendTo  Output parameter to receive result.
     55      *                  Result is appended to existing contents.
     56      * @param pos       On input: an alignment field, if desired.
     57      *                  On output: the offsets of the alignment field.
     58      * @return          Reference to 'appendTo' parameter.
     59      * @draft ICU 3.6
     60      */
     61     virtual UnicodeString& format(double number,
     62                                   UnicodeString& appendTo,
     63                                   FieldPosition& pos) const;
     64     /**
     65      * Format a long number. Concrete subclasses must implement
     66      * these pure virtual methods.
     67      *
     68      * @param number    The value to be formatted.
     69      * @param appendTo  Output parameter to receive result.
     70      *                  Result is appended to existing contents.
     71      * @param pos       On input: an alignment field, if desired.
     72      *                  On output: the offsets of the alignment field.
     73      * @return          Reference to 'appendTo' parameter.
     74      * @draft ICU 3.6
     75     */
     76     virtual UnicodeString& format(int32_t number,
     77                                   UnicodeString& appendTo,
     78                                   FieldPosition& pos) const;
     79 
     80     /**
     81      * Format an int64 number.
     82      *
     83      * @param number    The value to be formatted.
     84      * @param appendTo  Output parameter to receive result.
     85      *                  Result is appended to existing contents.
     86      * @param pos       On input: an alignment field, if desired.
     87      *                  On output: the offsets of the alignment field.
     88      * @return          Reference to 'appendTo' parameter.
     89      * @draft ICU 3.6
     90     */
     91     virtual UnicodeString& format(int64_t number,
     92                                   UnicodeString& appendTo,
     93                                   FieldPosition& pos) const;
     94 
     95 // Use the default behavior for the following.
     96 //    virtual UnicodeString &format(double number, UnicodeString &appendTo) const;
     97 //    virtual UnicodeString &format(int32_t number, UnicodeString &appendTo) const;
     98 //    virtual UnicodeString &format(int64_t number, UnicodeString &appendTo) const;
     99 
    100     virtual void parse(const UnicodeString& text, Formattable& result, ParsePosition& parsePosition) const;
    101 
    102     /**
    103      * Sets the maximum number of digits allowed in the fraction portion of a
    104      * number. maximumFractionDigits must be >= minimumFractionDigits.  If the
    105      * new value for maximumFractionDigits is less than the current value
    106      * of minimumFractionDigits, then minimumFractionDigits will also be set to
    107      * the new value.
    108      * @param newValue    the new value to be set.
    109      * @see getMaximumFractionDigits
    110      * @draft ICU 3.6
    111      */
    112     virtual void setMaximumFractionDigits(int32_t newValue);
    113 
    114     /**
    115      * Sets the minimum number of digits allowed in the fraction portion of a
    116      * number. minimumFractionDigits must be <= maximumFractionDigits.   If the
    117      * new value for minimumFractionDigits exceeds the current value
    118      * of maximumFractionDigits, then maximumIntegerDigits will also be set to
    119      * the new value
    120      * @param newValue    the new value to be set.
    121      * @see getMinimumFractionDigits
    122      * @draft ICU 3.6
    123      */
    124     virtual void setMinimumFractionDigits(int32_t newValue);
    125 
    126     /**
    127      * Return the class ID for this class. This is useful only for comparing to
    128      * a return value from getDynamicClassID(). For example:
    129      * <pre>
    130      * .   Base* polymorphic_pointer = createPolymorphicObject();
    131      * .   if (polymorphic_pointer->getDynamicClassID() ==
    132      * .       erived::getStaticClassID()) ...
    133      * </pre>
    134      * @return          The class ID for all objects of this class.
    135      * @stable ICU 2.0
    136      */
    137     U_I18N_API static UClassID U_EXPORT2 getStaticClassID(void);
    138 
    139     /**
    140      * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
    141      * method is to implement a simple version of RTTI, since not all C++
    142      * compilers support genuine RTTI. Polymorphic operator==() and clone()
    143      * methods call this method.
    144      *
    145      * @return          The class ID for this object. All objects of a
    146      *                  given class have the same class ID.  Objects of
    147      *                  other classes have different class IDs.
    148      * @stable ICU 2.0
    149      */
    150     virtual UClassID getDynamicClassID(void) const;
    151 
    152 private:
    153     UnicodeString &format(int32_t numDigits, UnicodeString &appendTo, wchar_t *format, ...) const;
    154 
    155     UBool fCurrency;
    156     int32_t fLCID;
    157     FormatInfo *fFormatInfo;
    158     UBool fFractionDigitsSet;
    159 
    160 };
    161 
    162 U_NAMESPACE_END
    163 
    164 #endif /* #if !UCONFIG_NO_FORMATTING */
    165 
    166 #endif // #ifdef U_WINDOWS
    167 
    168 #endif // __WINNMFMT
    169