1/*
2********************************************************************************
3*   Copyright (C) 2005-2013, 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#if U_PLATFORM_USES_ONLY_WIN32_API
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
32U_NAMESPACE_BEGIN
33
34union FormatInfo;
35
36class Win32NumberFormat : public NumberFormat
37{
38public:
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     */
60    virtual UnicodeString& format(double number,
61                                  UnicodeString& appendTo,
62                                  FieldPosition& pos) const;
63    /**
64     * Format a long number. Concrete subclasses must implement
65     * these pure virtual methods.
66     *
67     * @param number    The value to be formatted.
68     * @param appendTo  Output parameter to receive result.
69     *                  Result is appended to existing contents.
70     * @param pos       On input: an alignment field, if desired.
71     *                  On output: the offsets of the alignment field.
72     * @return          Reference to 'appendTo' parameter.
73    */
74    virtual UnicodeString& format(int32_t number,
75                                  UnicodeString& appendTo,
76                                  FieldPosition& pos) const;
77
78    /**
79     * Format an int64 number.
80     *
81     * @param number    The value to be formatted.
82     * @param appendTo  Output parameter to receive result.
83     *                  Result is appended to existing contents.
84     * @param pos       On input: an alignment field, if desired.
85     *                  On output: the offsets of the alignment field.
86     * @return          Reference to 'appendTo' parameter.
87    */
88    virtual UnicodeString& format(int64_t number,
89                                  UnicodeString& appendTo,
90                                  FieldPosition& pos) const;
91
92// Use the default behavior for the following.
93//    virtual UnicodeString &format(double number, UnicodeString &appendTo) const;
94//    virtual UnicodeString &format(int32_t number, UnicodeString &appendTo) const;
95//    virtual UnicodeString &format(int64_t number, UnicodeString &appendTo) const;
96
97    virtual void parse(const UnicodeString& text, Formattable& result, ParsePosition& parsePosition) const;
98
99    /**
100     * Sets the maximum number of digits allowed in the fraction portion of a
101     * number. maximumFractionDigits must be >= minimumFractionDigits.  If the
102     * new value for maximumFractionDigits is less than the current value
103     * of minimumFractionDigits, then minimumFractionDigits will also be set to
104     * the new value.
105     * @param newValue    the new value to be set.
106     * @see getMaximumFractionDigits
107     */
108    virtual void setMaximumFractionDigits(int32_t newValue);
109
110    /**
111     * Sets the minimum number of digits allowed in the fraction portion of a
112     * number. minimumFractionDigits must be <= maximumFractionDigits.   If the
113     * new value for minimumFractionDigits exceeds the current value
114     * of maximumFractionDigits, then maximumIntegerDigits will also be set to
115     * the new value
116     * @param newValue    the new value to be set.
117     * @see getMinimumFractionDigits
118     */
119    virtual void setMinimumFractionDigits(int32_t newValue);
120
121    /**
122     * Return the class ID for this class. This is useful only for comparing to
123     * a return value from getDynamicClassID(). For example:
124     * <pre>
125     * .   Base* polymorphic_pointer = createPolymorphicObject();
126     * .   if (polymorphic_pointer->getDynamicClassID() ==
127     * .       erived::getStaticClassID()) ...
128     * </pre>
129     * @return          The class ID for all objects of this class.
130     */
131    U_I18N_API static UClassID U_EXPORT2 getStaticClassID(void);
132
133    /**
134     * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
135     * method is to implement a simple version of RTTI, since not all C++
136     * compilers support genuine RTTI. Polymorphic operator==() and clone()
137     * methods call this method.
138     *
139     * @return          The class ID for this object. All objects of a
140     *                  given class have the same class ID.  Objects of
141     *                  other classes have different class IDs.
142     */
143    virtual UClassID getDynamicClassID(void) const;
144
145private:
146    UnicodeString &format(int32_t numDigits, UnicodeString &appendTo, const wchar_t *format, ...) const;
147
148    UBool fCurrency;
149    Locale fLocale;
150    int32_t fLCID;
151    FormatInfo *fFormatInfo;
152    UBool fFractionDigitsSet;
153
154};
155
156U_NAMESPACE_END
157
158#endif /* #if !UCONFIG_NO_FORMATTING */
159
160#endif // U_PLATFORM_USES_ONLY_WIN32_API
161
162#endif // __WINNMFMT
163