~ubuntu-branches/ubuntu/jaunty/texlive-bin/jaunty-security

« back to all changes in this revision

Viewing changes to build/source/libs/icu-xetex/i18n/unicode/numfmt.h

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Preining
  • Date: 2008-06-26 23:14:59 UTC
  • mfrom: (2.1.30 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080626231459-y02rjsrgtafu83yr
Tags: 2007.dfsg.2-3
add missing source roadmap.fig of roadmap.eps in fontinst documentation
(Closes: #482915) (urgency medium due to RC bug)
(new patch add-missing-fontinst-source)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
* Copyright (C) {1997-2005}, International Business Machines Corporation and others. All Rights Reserved.
 
3
********************************************************************************
 
4
*
 
5
* File NUMFMT.H
 
6
*
 
7
* Modification History:
 
8
*
 
9
*   Date        Name        Description
 
10
*   02/19/97    aliu        Converted from java.
 
11
*   03/18/97    clhuang     Updated per C++ implementation.
 
12
*   04/17/97    aliu        Changed DigitCount to int per code review.
 
13
*    07/20/98    stephen        JDK 1.2 sync up. Added scientific support.
 
14
*                            Changed naming conventions to match C++ guidelines
 
15
*                            Derecated Java style constants (eg, INTEGER_FIELD)
 
16
********************************************************************************
 
17
*/
 
18
 
 
19
#ifndef NUMFMT_H
 
20
#define NUMFMT_H
 
21
 
 
22
 
 
23
#include "unicode/utypes.h"
 
24
 
 
25
/**
 
26
 * \file 
 
27
 * \brief C++ API: Abstract base class for all number formats.
 
28
 */
 
29
 
 
30
#if !UCONFIG_NO_FORMATTING
 
31
 
 
32
#include "unicode/unistr.h"
 
33
#include "unicode/format.h"
 
34
#include "unicode/unum.h" // UNumberFormatStyle
 
35
#include "unicode/locid.h"
 
36
 
 
37
U_NAMESPACE_BEGIN
 
38
 
 
39
#if !UCONFIG_NO_SERVICE
 
40
class NumberFormatFactory;
 
41
class StringEnumeration;
 
42
 
 
43
/**
 
44
 * @internal
 
45
 */
 
46
typedef const void* URegistryKey;
 
47
#endif
 
48
 
 
49
/**
 
50
 *
 
51
 * Abstract base class for all number formats.  Provides interface for
 
52
 * formatting and parsing a number.  Also provides methods for
 
53
 * determining which locales have number formats, and what their names
 
54
 * are.
 
55
 * <P>
 
56
 * NumberFormat helps you to format and parse numbers for any locale.
 
57
 * Your code can be completely independent of the locale conventions
 
58
 * for decimal points, thousands-separators, or even the particular
 
59
 * decimal digits used, or whether the number format is even decimal.
 
60
 * <P>
 
61
 * To format a number for the current Locale, use one of the static
 
62
 * factory methods:
 
63
 * <pre>
 
64
 * \code
 
65
 *    double myNumber = 7.0;
 
66
 *    UnicodeString myString;
 
67
 *    UErrorCode success = U_ZERO_ERROR;
 
68
 *    NumberFormat* nf = NumberFormat::createInstance(success)
 
69
 *    nf->format(myNumber, myString);
 
70
 *    cout << " Example 1: " << myString << endl;
 
71
 * \endcode
 
72
 * </pre>
 
73
 * If you are formatting multiple numbers, it is more efficient to get
 
74
 * the format and use it multiple times so that the system doesn't
 
75
 * have to fetch the information about the local language and country
 
76
 * conventions multiple times.
 
77
 * <pre>
 
78
 * \code
 
79
 *     UnicodeString myString;
 
80
 *     UErrorCode success = U_ZERO_ERROR;
 
81
 *     nf = NumberFormat::createInstance( success );
 
82
 *     int32_t a[] = { 123, 3333, -1234567 };
 
83
 *     const int32_t a_len = sizeof(a) / sizeof(a[0]);
 
84
 *     myString.remove();
 
85
 *     for (int32_t i = 0; i < a_len; i++) {
 
86
 *         nf->format(a[i], myString);
 
87
 *         myString += " ; ";
 
88
 *     }
 
89
 *     cout << " Example 2: " << myString << endl;
 
90
 * \endcode
 
91
 * </pre>
 
92
 * To format a number for a different Locale, specify it in the
 
93
 * call to createInstance().
 
94
 * <pre>
 
95
 * \code
 
96
 *     nf = NumberFormat::createInstance( Locale::FRENCH, success );
 
97
 * \endcode
 
98
 * </pre>
 
99
 * You can use a NumberFormat to parse also.
 
100
 * <pre>
 
101
 * \code
 
102
 *    UErrorCode success;
 
103
 *    Formattable result(-999);  // initialized with error code
 
104
 *    nf->parse(myString, result, success);
 
105
 * \endcode
 
106
 * </pre>
 
107
 * Use createInstance to get the normal number format for that country.
 
108
 * There are other static factory methods available.  Use getCurrency
 
109
 * to get the currency number format for that country.  Use getPercent
 
110
 * to get a format for displaying percentages. With this format, a
 
111
 * fraction from 0.53 is displayed as 53%.
 
112
 * <P>
 
113
 * You can also control the display of numbers with such methods as
 
114
 * getMinimumFractionDigits.  If you want even more control over the
 
115
 * format or parsing, or want to give your users more control, you can
 
116
 * try casting the NumberFormat you get from the factory methods to a
 
117
 * DecimalNumberFormat. This will work for the vast majority of
 
118
 * countries; just remember to put it in a try block in case you
 
119
 * encounter an unusual one.
 
120
 * <P>
 
121
 * You can also use forms of the parse and format methods with
 
122
 * ParsePosition and FieldPosition to allow you to:
 
123
 * <ul type=round>
 
124
 *   <li>(a) progressively parse through pieces of a string.
 
125
 *   <li>(b) align the decimal point and other areas.
 
126
 * </ul>
 
127
 * For example, you can align numbers in two ways.
 
128
 * <P>
 
129
 * If you are using a monospaced font with spacing for alignment, you
 
130
 * can pass the FieldPosition in your format call, with field =
 
131
 * INTEGER_FIELD. On output, getEndIndex will be set to the offset
 
132
 * between the last character of the integer and the decimal. Add
 
133
 * (desiredSpaceCount - getEndIndex) spaces at the front of the
 
134
 * string.
 
135
 * <P>
 
136
 * If you are using proportional fonts, instead of padding with
 
137
 * spaces, measure the width of the string in pixels from the start to
 
138
 * getEndIndex.  Then move the pen by (desiredPixelWidth -
 
139
 * widthToAlignmentPoint) before drawing the text.  It also works
 
140
 * where there is no decimal, but possibly additional characters at
 
141
 * the end, e.g. with parentheses in negative numbers: "(12)" for -12.
 
142
 * <p>
 
143
 * <em>User subclasses are not supported.</em> While clients may write
 
144
 * subclasses, such code will not necessarily work and will not be
 
145
 * guaranteed to work stably from release to release.
 
146
 *
 
147
 * @stable ICU 2.0
 
148
 */
 
149
class U_I18N_API NumberFormat : public Format {
 
150
public:
 
151
 
 
152
    /**
 
153
     * Alignment Field constants used to construct a FieldPosition object.
 
154
     * Signifies that the position of the integer part or fraction part of
 
155
     * a formatted number should be returned.
 
156
     *
 
157
     * @see FieldPosition
 
158
     * @stable ICU 2.0
 
159
     */
 
160
    enum EAlignmentFields {
 
161
        kIntegerField,
 
162
        kFractionField,
 
163
 
 
164
 
 
165
    /**
 
166
     * These constants are provided for backwards compatibility only.
 
167
     * Please use the C++ style constants defined above.
 
168
     * @stable ICU 2.0
 
169
     */
 
170
        INTEGER_FIELD        = kIntegerField,
 
171
        FRACTION_FIELD        = kFractionField
 
172
    };
 
173
 
 
174
    /**
 
175
     * Destructor.
 
176
     * @stable ICU 2.0
 
177
     */
 
178
    virtual ~NumberFormat();
 
179
 
 
180
    /**
 
181
     * Return true if the given Format objects are semantically equal.
 
182
     * Objects of different subclasses are considered unequal.
 
183
     * @return    true if the given Format objects are semantically equal.
 
184
     * @stable ICU 2.0
 
185
     */
 
186
    virtual UBool operator==(const Format& other) const;
 
187
 
 
188
    /**
 
189
     * Format an object to produce a string.  This method handles
 
190
     * Formattable objects with numeric types. If the Formattable
 
191
     * object type is not a numeric type, then it returns a failing
 
192
     * UErrorCode.
 
193
     *
 
194
     * @param obj       The object to format.
 
195
     * @param appendTo  Output parameter to receive result.
 
196
     *                  Result is appended to existing contents.
 
197
     * @param pos       On input: an alignment field, if desired.
 
198
     *                  On output: the offsets of the alignment field.
 
199
     * @param status    Output param filled with success/failure status.
 
200
     * @return          Reference to 'appendTo' parameter.
 
201
     * @stable ICU 2.0
 
202
     */
 
203
    virtual UnicodeString& format(const Formattable& obj,
 
204
                                  UnicodeString& appendTo,
 
205
                                  FieldPosition& pos,
 
206
                                  UErrorCode& status) const;
 
207
 
 
208
    /**
 
209
     * Parse a string to produce an object.  This methods handles
 
210
     * parsing of numeric strings into Formattable objects with numeric
 
211
     * types.
 
212
     * <P>
 
213
     * Before calling, set parse_pos.index to the offset you want to
 
214
     * start parsing at in the source. After calling, parse_pos.index
 
215
     * indicates the position after the successfully parsed text.  If
 
216
     * an error occurs, parse_pos.index is unchanged.
 
217
     * <P>
 
218
     * When parsing, leading whitespace is discarded (with successful
 
219
     * parse), while trailing whitespace is left as is.
 
220
     * <P>
 
221
     * See Format::parseObject() for more.
 
222
     *
 
223
     * @param source    The string to be parsed into an object.
 
224
     * @param result    Formattable to be set to the parse result.
 
225
     *                  If parse fails, return contents are undefined.
 
226
     * @param parse_pos The position to start parsing at. Upon return
 
227
     *                  this param is set to the position after the
 
228
     *                  last character successfully parsed. If the
 
229
     *                  source is not parsed successfully, this param
 
230
     *                  will remain unchanged.
 
231
     * @return          A newly created Formattable* object, or NULL
 
232
     *                  on failure.  The caller owns this and should
 
233
     *                  delete it when done.
 
234
     * @stable ICU 2.0
 
235
     */
 
236
    virtual void parseObject(const UnicodeString& source,
 
237
                             Formattable& result,
 
238
                             ParsePosition& parse_pos) const;
 
239
 
 
240
    /**
 
241
     * Format a double number. These methods call the NumberFormat
 
242
     * pure virtual format() methods with the default FieldPosition.
 
243
     *
 
244
     * @param number    The value to be formatted.
 
245
     * @param appendTo  Output parameter to receive result.
 
246
     *                  Result is appended to existing contents.
 
247
     * @return          Reference to 'appendTo' parameter.
 
248
     * @stable ICU 2.0
 
249
     */
 
250
    UnicodeString& format(  double number,
 
251
                            UnicodeString& appendTo) const;
 
252
 
 
253
    /**
 
254
     * Format a long number. These methods call the NumberFormat
 
255
     * pure virtual format() methods with the default FieldPosition.
 
256
     *
 
257
     * @param number    The value to be formatted.
 
258
     * @param appendTo  Output parameter to receive result.
 
259
     *                  Result is appended to existing contents.
 
260
     * @return          Reference to 'appendTo' parameter.
 
261
     * @stable ICU 2.0
 
262
     */
 
263
    UnicodeString& format(  int32_t number,
 
264
                            UnicodeString& appendTo) const;
 
265
 
 
266
    /**
 
267
     * Format an int64 number. These methods call the NumberFormat
 
268
     * pure virtual format() methods with the default FieldPosition.
 
269
     *
 
270
     * @param number    The value to be formatted.
 
271
     * @param appendTo  Output parameter to receive result.
 
272
     *                  Result is appended to existing contents.
 
273
     * @return          Reference to 'appendTo' parameter.
 
274
     * @stable ICU 2.8
 
275
     */
 
276
    UnicodeString& format(  int64_t number,
 
277
                            UnicodeString& appendTo) const;
 
278
 
 
279
    /**
 
280
     * Format a double number. Concrete subclasses must implement
 
281
     * these pure virtual methods.
 
282
     *
 
283
     * @param number    The value to be formatted.
 
284
     * @param appendTo  Output parameter to receive result.
 
285
     *                  Result is appended to existing contents.
 
286
     * @param pos       On input: an alignment field, if desired.
 
287
     *                  On output: the offsets of the alignment field.
 
288
     * @return          Reference to 'appendTo' parameter.
 
289
     * @stable ICU 2.0
 
290
     */
 
291
    virtual UnicodeString& format(double number,
 
292
                                  UnicodeString& appendTo,
 
293
                                  FieldPosition& pos) const = 0;
 
294
    /**
 
295
     * Format a long number. Concrete subclasses must implement
 
296
     * these pure virtual methods.
 
297
     *
 
298
     * @param number    The value to be formatted.
 
299
     * @param appendTo  Output parameter to receive result.
 
300
     *                  Result is appended to existing contents.
 
301
     * @param pos       On input: an alignment field, if desired.
 
302
     *                  On output: the offsets of the alignment field.
 
303
     * @return          Reference to 'appendTo' parameter.
 
304
     * @stable ICU 2.0
 
305
    */
 
306
    virtual UnicodeString& format(int32_t number,
 
307
                                  UnicodeString& appendTo,
 
308
                                  FieldPosition& pos) const = 0;
 
309
 
 
310
    /**
 
311
     * Format an int64 number. (Not abstract to retain compatibility
 
312
     * with earlier releases, however subclasses should override this
 
313
     * method as it just delegates to format(int32_t number...);
 
314
     *
 
315
     * @param number    The value to be formatted.
 
316
     * @param appendTo  Output parameter to receive result.
 
317
     *                  Result is appended to existing contents.
 
318
     * @param pos       On input: an alignment field, if desired.
 
319
     *                  On output: the offsets of the alignment field.
 
320
     * @return          Reference to 'appendTo' parameter.
 
321
     * @stable ICU 2.8
 
322
    */
 
323
    virtual UnicodeString& format(int64_t number,
 
324
                                  UnicodeString& appendTo,
 
325
                                  FieldPosition& pos) const;
 
326
    /**
 
327
     * Redeclared Format method.
 
328
     * @param obj       The object to be formatted.
 
329
     * @param appendTo  Output parameter to receive result.
 
330
     *                  Result is appended to existing contents.
 
331
     * @param status    Output parameter set to a failure error code
 
332
     *                  when a failure occurs.
 
333
     * @return          Reference to 'appendTo' parameter.
 
334
     * @stable ICU 2.0
 
335
     */
 
336
    UnicodeString& format(const Formattable& obj,
 
337
                          UnicodeString& appendTo,
 
338
                          UErrorCode& status) const;
 
339
 
 
340
   /**
 
341
    * Return a long if possible (e.g. within range LONG_MAX,
 
342
    * LONG_MAX], and with no decimals), otherwise a double.  If
 
343
    * IntegerOnly is set, will stop at a decimal point (or equivalent;
 
344
    * e.g. for rational numbers "1 2/3", will stop after the 1).
 
345
    * <P>
 
346
    * If no object can be parsed, index is unchanged, and NULL is
 
347
    * returned.
 
348
    * <P>
 
349
    * This is a pure virtual which concrete subclasses must implement.
 
350
    *
 
351
    * @param text           The text to be parsed.
 
352
    * @param result         Formattable to be set to the parse result.
 
353
    *                       If parse fails, return contents are undefined.
 
354
    * @param parsePosition  The position to start parsing at on input.
 
355
    *                       On output, moved to after the last successfully
 
356
    *                       parse character. On parse failure, does not change.
 
357
    * @return               A Formattable object of numeric type.  The caller
 
358
    *                       owns this an must delete it.  NULL on failure.
 
359
    * @stable ICU 2.0
 
360
    */
 
361
    virtual void parse(const UnicodeString& text,
 
362
                       Formattable& result,
 
363
                       ParsePosition& parsePosition) const = 0;
 
364
 
 
365
    /**
 
366
     * Parse a string as a numeric value, and return a Formattable
 
367
     * numeric object. This method parses integers only if IntegerOnly
 
368
     * is set.
 
369
     *
 
370
     * @param text          The text to be parsed.
 
371
     * @param result        Formattable to be set to the parse result.
 
372
     *                      If parse fails, return contents are undefined.
 
373
     * @param status        Output parameter set to a failure error code
 
374
     *                      when a failure occurs.
 
375
     * @return              A Formattable object of numeric type.  The caller
 
376
     *                      owns this an must delete it.  NULL on failure.
 
377
     * @see                 NumberFormat::isParseIntegerOnly
 
378
     * @stable ICU 2.0
 
379
     */
 
380
    virtual void parse( const UnicodeString& text,
 
381
                        Formattable& result,
 
382
                        UErrorCode& status) const;
 
383
 
 
384
    /**
 
385
     * Parses text from the given string as a currency amount.  Unlike
 
386
     * the parse() method, this method will attempt to parse a generic
 
387
     * currency name, searching for a match of this object's locale's
 
388
     * currency display names, or for a 3-letter ISO currency code.
 
389
     * This method will fail if this format is not a currency format,
 
390
     * that is, if it does not contain the currency pattern symbol
 
391
     * (U+00A4) in its prefix or suffix.
 
392
     *
 
393
     * @param text the string to parse
 
394
     * @param result output parameter to receive result. This will have
 
395
     * its currency set to the parsed ISO currency code.
 
396
     * @param pos input-output position; on input, the position within
 
397
     * text to match; must have 0 <= pos.getIndex() < text.length();
 
398
     * on output, the position after the last matched character. If
 
399
     * the parse fails, the position in unchanged upon output.
 
400
     * @return a reference to result
 
401
     * @internal
 
402
     */
 
403
    virtual Formattable& parseCurrency(const UnicodeString& text,
 
404
                                       Formattable& result,
 
405
                                       ParsePosition& pos) const;
 
406
 
 
407
    /**
 
408
     * Return true if this format will parse numbers as integers
 
409
     * only.  For example in the English locale, with ParseIntegerOnly
 
410
     * true, the string "1234." would be parsed as the integer value
 
411
     * 1234 and parsing would stop at the "." character.  Of course,
 
412
     * the exact format accepted by the parse operation is locale
 
413
     * dependant and determined by sub-classes of NumberFormat.
 
414
     * @return    true if this format will parse numbers as integers
 
415
     *            only.
 
416
     * @stable ICU 2.0
 
417
     */
 
418
    UBool isParseIntegerOnly(void) const;
 
419
 
 
420
    /**
 
421
     * Sets whether or not numbers should be parsed as integers only.
 
422
     * @param value    set True, this format will parse numbers as integers
 
423
     *                 only.
 
424
     * @see isParseIntegerOnly
 
425
     * @stable ICU 2.0
 
426
     */
 
427
    virtual void setParseIntegerOnly(UBool value);
 
428
 
 
429
    /**
 
430
     * Returns the default number format for the current default
 
431
     * locale.  The default format is one of the styles provided by
 
432
     * the other factory methods: getNumberInstance,
 
433
     * getCurrencyInstance or getPercentInstance.  Exactly which one
 
434
     * is locale dependant.
 
435
     * @stable ICU 2.0
 
436
     */
 
437
    static NumberFormat* U_EXPORT2 createInstance(UErrorCode&);
 
438
 
 
439
    /**
 
440
     * Returns the default number format for the specified locale.
 
441
     * The default format is one of the styles provided by the other
 
442
     * factory methods: getNumberInstance, getCurrencyInstance or
 
443
     * getPercentInstance.  Exactly which one is locale dependant.
 
444
     * @param inLocale    the given locale.
 
445
     * @stable ICU 2.0
 
446
     */
 
447
    static NumberFormat* U_EXPORT2 createInstance(const Locale& inLocale,
 
448
                                        UErrorCode&);
 
449
 
 
450
    /**
 
451
     * Returns a currency format for the current default locale.
 
452
     * @stable ICU 2.0
 
453
     */
 
454
    static NumberFormat* U_EXPORT2 createCurrencyInstance(UErrorCode&);
 
455
 
 
456
    /**
 
457
     * Returns a currency format for the specified locale.
 
458
     * @param inLocale    the given locale.
 
459
     * @stable ICU 2.0
 
460
     */
 
461
    static NumberFormat* U_EXPORT2 createCurrencyInstance(const Locale& inLocale,
 
462
                                                UErrorCode&);
 
463
 
 
464
    /**
 
465
     * Returns a percentage format for the current default locale.
 
466
     * @stable ICU 2.0
 
467
     */
 
468
    static NumberFormat* U_EXPORT2 createPercentInstance(UErrorCode&);
 
469
 
 
470
    /**
 
471
     * Returns a percentage format for the specified locale.
 
472
     * @param inLocale    the given locale.
 
473
     * @stable ICU 2.0
 
474
     */
 
475
    static NumberFormat* U_EXPORT2 createPercentInstance(const Locale& inLocale,
 
476
                                               UErrorCode&);
 
477
 
 
478
    /**
 
479
     * Returns a scientific format for the current default locale.
 
480
     * @stable ICU 2.0
 
481
     */
 
482
    static NumberFormat* U_EXPORT2 createScientificInstance(UErrorCode&);
 
483
 
 
484
    /**
 
485
     * Returns a scientific format for the specified locale.
 
486
     * @param inLocale    the given locale.
 
487
     * @stable ICU 2.0
 
488
     */
 
489
    static NumberFormat* U_EXPORT2 createScientificInstance(const Locale& inLocale,
 
490
                                                UErrorCode&);
 
491
 
 
492
    /**
 
493
     * Get the set of Locales for which NumberFormats are installed.
 
494
     * @param count    Output param to receive the size of the locales
 
495
     * @stable ICU 2.0
 
496
     */
 
497
    static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
 
498
 
 
499
#if !UCONFIG_NO_SERVICE
 
500
    /**
 
501
     * Register a new NumberFormatFactory.  The factory will be adopted.
 
502
     * @param toAdopt the NumberFormatFactory instance to be adopted
 
503
     * @param status the in/out status code, no special meanings are assigned
 
504
     * @return a registry key that can be used to unregister this factory
 
505
     * @stable ICU 2.6
 
506
     */
 
507
    static URegistryKey U_EXPORT2 registerFactory(NumberFormatFactory* toAdopt, UErrorCode& status);
 
508
 
 
509
    /**
 
510
     * Unregister a previously-registered NumberFormatFactory using the key returned from the
 
511
     * register call.  Key becomes invalid after a successful call and should not be used again.
 
512
     * The NumberFormatFactory corresponding to the key will be deleted.
 
513
     * @param key the registry key returned by a previous call to registerFactory
 
514
     * @param status the in/out status code, no special meanings are assigned
 
515
     * @return TRUE if the factory for the key was successfully unregistered
 
516
     * @stable ICU 2.6
 
517
     */
 
518
    static UBool U_EXPORT2 unregister(URegistryKey key, UErrorCode& status);
 
519
 
 
520
    /**
 
521
     * Return a StringEnumeration over the locales available at the time of the call,
 
522
     * including registered locales.
 
523
     * @return a StringEnumeration over the locales available at the time of the call
 
524
     * @stable ICU 2.6
 
525
     */
 
526
    static StringEnumeration* U_EXPORT2 getAvailableLocales(void);
 
527
#endif /* UCONFIG_NO_SERVICE */
 
528
 
 
529
    /**
 
530
     * Returns true if grouping is used in this format. For example,
 
531
     * in the English locale, with grouping on, the number 1234567
 
532
     * might be formatted as "1,234,567". The grouping separator as
 
533
     * well as the size of each group is locale dependant and is
 
534
     * determined by sub-classes of NumberFormat.
 
535
     * @see setGroupingUsed
 
536
     * @stable ICU 2.0
 
537
     */
 
538
    UBool isGroupingUsed(void) const;
 
539
 
 
540
    /**
 
541
     * Set whether or not grouping will be used in this format.
 
542
     * @param newValue    True, grouping will be used in this format.
 
543
     * @see getGroupingUsed
 
544
     * @stable ICU 2.0
 
545
     */
 
546
    virtual void setGroupingUsed(UBool newValue);
 
547
 
 
548
    /**
 
549
     * Returns the maximum number of digits allowed in the integer portion of a
 
550
     * number.
 
551
     * @return     the maximum number of digits allowed in the integer portion of a
 
552
     *             number.
 
553
     * @see setMaximumIntegerDigits
 
554
     * @stable ICU 2.0
 
555
     */
 
556
    int32_t getMaximumIntegerDigits(void) const;
 
557
 
 
558
    /**
 
559
     * Sets the maximum number of digits allowed in the integer portion of a
 
560
     * number. maximumIntegerDigits must be >= minimumIntegerDigits.  If the
 
561
     * new value for maximumIntegerDigits is less than the current value
 
562
     * of minimumIntegerDigits, then minimumIntegerDigits will also be set to
 
563
     * the new value.
 
564
     *
 
565
     * @param newValue    the new value for the maximum number of digits
 
566
     *                    allowed in the integer portion of a number.
 
567
     * @see getMaximumIntegerDigits
 
568
     * @stable ICU 2.0
 
569
     */
 
570
    virtual void setMaximumIntegerDigits(int32_t newValue);
 
571
 
 
572
    /**
 
573
     * Returns the minimum number of digits allowed in the integer portion of a
 
574
     * number.
 
575
     * @return    the minimum number of digits allowed in the integer portion of a
 
576
     *            number.
 
577
     * @see setMinimumIntegerDigits
 
578
     * @stable ICU 2.0
 
579
     */
 
580
    int32_t getMinimumIntegerDigits(void) const;
 
581
 
 
582
    /**
 
583
     * Sets the minimum number of digits allowed in the integer portion of a
 
584
     * number. minimumIntegerDigits must be &lt;= maximumIntegerDigits.  If the
 
585
     * new value for minimumIntegerDigits exceeds the current value
 
586
     * of maximumIntegerDigits, then maximumIntegerDigits will also be set to
 
587
     * the new value.
 
588
     * @param newValue    the new value to be set.
 
589
     * @see getMinimumIntegerDigits
 
590
     * @stable ICU 2.0
 
591
     */
 
592
    virtual void setMinimumIntegerDigits(int32_t newValue);
 
593
 
 
594
    /**
 
595
     * Returns the maximum number of digits allowed in the fraction portion of a
 
596
     * number.
 
597
     * @return    the maximum number of digits allowed in the fraction portion of a
 
598
     *            number.
 
599
     * @see setMaximumFractionDigits
 
600
     * @stable ICU 2.0
 
601
     */
 
602
    int32_t getMaximumFractionDigits(void) const;
 
603
 
 
604
    /**
 
605
     * Sets the maximum number of digits allowed in the fraction portion of a
 
606
     * number. maximumFractionDigits must be >= minimumFractionDigits.  If the
 
607
     * new value for maximumFractionDigits is less than the current value
 
608
     * of minimumFractionDigits, then minimumFractionDigits will also be set to
 
609
     * the new value.
 
610
     * @param newValue    the new value to be set.
 
611
     * @see getMaximumFractionDigits
 
612
     * @stable ICU 2.0
 
613
     */
 
614
    virtual void setMaximumFractionDigits(int32_t newValue);
 
615
 
 
616
    /**
 
617
     * Returns the minimum number of digits allowed in the fraction portion of a
 
618
     * number.
 
619
     * @return    the minimum number of digits allowed in the fraction portion of a
 
620
     *            number.
 
621
     * @see setMinimumFractionDigits
 
622
     * @stable ICU 2.0
 
623
     */
 
624
    int32_t getMinimumFractionDigits(void) const;
 
625
 
 
626
    /**
 
627
     * Sets the minimum number of digits allowed in the fraction portion of a
 
628
     * number. minimumFractionDigits must be &lt;= maximumFractionDigits.   If the
 
629
     * new value for minimumFractionDigits exceeds the current value
 
630
     * of maximumFractionDigits, then maximumIntegerDigits will also be set to
 
631
     * the new value
 
632
     * @param newValue    the new value to be set.
 
633
     * @see getMinimumFractionDigits
 
634
     * @stable ICU 2.0
 
635
     */
 
636
    virtual void setMinimumFractionDigits(int32_t newValue);
 
637
 
 
638
    /**
 
639
     * Sets the currency used to display currency
 
640
     * amounts.  This takes effect immediately, if this format is a
 
641
     * currency format.  If this format is not a currency format, then
 
642
     * the currency is used if and when this object becomes a
 
643
     * currency format.
 
644
     * @param theCurrency a 3-letter ISO code indicating new currency
 
645
     * to use.  It need not be null-terminated.  May be the empty
 
646
     * string or NULL to indicate no currency.
 
647
     * @param ec input-output error code
 
648
     * @draft ICU 3.0
 
649
     */
 
650
    virtual void setCurrency(const UChar* theCurrency, UErrorCode& ec);
 
651
 
 
652
    /**
 
653
     * Gets the currency used to display currency
 
654
     * amounts.  This may be an empty string for some subclasses.
 
655
     * @return a 3-letter null-terminated ISO code indicating
 
656
     * the currency in use, or a pointer to the empty string.
 
657
     * @stable ICU 2.6
 
658
     */
 
659
    const UChar* getCurrency() const;
 
660
 
 
661
public:
 
662
 
 
663
    /**
 
664
     * Return the class ID for this class.  This is useful for
 
665
     * comparing to a return value from getDynamicClassID(). Note that,
 
666
     * because NumberFormat is an abstract base class, no fully constructed object
 
667
     * will have the class ID returned by NumberFormat::getStaticClassID().
 
668
     * @return The class ID for all objects of this class.
 
669
     * @stable ICU 2.0
 
670
     */
 
671
    static UClassID U_EXPORT2 getStaticClassID(void);
 
672
 
 
673
    /**
 
674
     * Returns a unique class ID POLYMORPHICALLY.  Pure virtual override.
 
675
     * This method is to implement a simple version of RTTI, since not all
 
676
     * C++ compilers support genuine RTTI.  Polymorphic operator==() and
 
677
     * clone() methods call this method.
 
678
     * <P>
 
679
     * @return The class ID for this object. All objects of a
 
680
     * given class have the same class ID.  Objects of
 
681
     * other classes have different class IDs.
 
682
     * @stable ICU 2.0
 
683
     */
 
684
    virtual UClassID getDynamicClassID(void) const = 0;
 
685
 
 
686
protected:
 
687
 
 
688
    /**
 
689
     * Default constructor for subclass use only.
 
690
     * @stable ICU 2.0
 
691
     */
 
692
    NumberFormat();
 
693
 
 
694
    /**
 
695
     * Copy constructor.
 
696
     * @stable ICU 2.0
 
697
     */
 
698
    NumberFormat(const NumberFormat&);
 
699
 
 
700
    /**
 
701
     * Assignment operator.
 
702
     * @stable ICU 2.0
 
703
     */
 
704
    NumberFormat& operator=(const NumberFormat&);
 
705
 
 
706
    /**
 
707
     * Returns the currency in effect for this formatter.  Subclasses
 
708
     * should override this method as needed.  Unlike getCurrency(),
 
709
     * this method should never return "".
 
710
     * @result output parameter for null-terminated result, which must
 
711
     * have a capacity of at least 4
 
712
     * @internal
 
713
     */
 
714
    virtual void getEffectiveCurrency(UChar* result, UErrorCode& ec) const;
 
715
 
 
716
private:
 
717
 
 
718
    enum EStyles {
 
719
        kNumberStyle,
 
720
        kCurrencyStyle,
 
721
        kPercentStyle,
 
722
        kScientificStyle,
 
723
        kStyleCount // ALWAYS LAST ENUM: number of styles
 
724
    };
 
725
 
 
726
    /**
 
727
     * Creates the specified decimal format style of the desired locale.
 
728
     * Hook for service registration, uses makeInstance directly if no services
 
729
     * registered.
 
730
     * @param desiredLocale    the given locale.
 
731
     * @param choice           the given style.
 
732
     * @param success          Output param filled with success/failure status.
 
733
     * @return                 A new NumberFormat instance.
 
734
     */
 
735
    static NumberFormat* U_EXPORT2 createInstance(const Locale& desiredLocale, EStyles choice, UErrorCode& success);
 
736
 
 
737
    /**
 
738
     * Creates the specified decimal format style of the desired locale.
 
739
     * @param desiredLocale    the given locale.
 
740
     * @param choice           the given style.
 
741
     * @param success          Output param filled with success/failure status.
 
742
     * @return                 A new NumberFormat instance.
 
743
     */
 
744
    static NumberFormat* makeInstance(const Locale& desiredLocale, EStyles choice, UErrorCode& success);
 
745
 
 
746
    UBool      fGroupingUsed;
 
747
    int32_t     fMaxIntegerDigits;
 
748
    int32_t     fMinIntegerDigits;
 
749
    int32_t     fMaxFractionDigits;
 
750
    int32_t     fMinFractionDigits;
 
751
    UBool      fParseIntegerOnly;
 
752
 
 
753
    // ISO currency code
 
754
    UChar      fCurrency[4];
 
755
 
 
756
    friend class ICUNumberFormatFactory; // access to makeInstance, EStyles
 
757
    friend class ICUNumberFormatService;
 
758
};
 
759
 
 
760
#if !UCONFIG_NO_SERVICE
 
761
/**
 
762
 * A NumberFormatFactory is used to register new number formats.  The factory
 
763
 * should be able to create any of the predefined formats for each locale it
 
764
 * supports.  When registered, the locales it supports extend or override the
 
765
 * locale already supported by ICU.
 
766
 *
 
767
 * @stable ICU 2.6
 
768
 */
 
769
class U_I18N_API NumberFormatFactory : public UObject {
 
770
public:
 
771
 
 
772
    /**
 
773
     * Destructor
 
774
     * @draft ICU 3.0
 
775
     */
 
776
    virtual ~NumberFormatFactory();
 
777
 
 
778
    /**
 
779
     * Return true if this factory will be visible.  Default is true.
 
780
     * If not visible, the locales supported by this factory will not
 
781
     * be listed by getAvailableLocales.
 
782
     * @stable ICU 2.6
 
783
     */
 
784
    virtual UBool visible(void) const = 0;
 
785
 
 
786
    /**
 
787
     * Return the locale names directly supported by this factory.  The number of names
 
788
     * is returned in count;
 
789
     * @stable ICU 2.6
 
790
     */
 
791
    virtual const UnicodeString * getSupportedIDs(int32_t &count, UErrorCode& status) const = 0;
 
792
 
 
793
    /**
 
794
     * Return a number format of the appropriate type.  If the locale
 
795
     * is not supported, return null.  If the locale is supported, but
 
796
     * the type is not provided by this service, return null.  Otherwise
 
797
     * return an appropriate instance of NumberFormat.
 
798
     * @stable ICU 2.6
 
799
     */
 
800
    virtual NumberFormat* createFormat(const Locale& loc, UNumberFormatStyle formatType) = 0;
 
801
};
 
802
 
 
803
/**
 
804
 * A NumberFormatFactory that supports a single locale.  It can be visible or invisible.
 
805
 * @draft ICU 3.0
 
806
 */
 
807
class U_I18N_API SimpleNumberFormatFactory : public NumberFormatFactory {
 
808
protected:
 
809
    /**
 
810
     * True if the locale supported by this factory is visible.
 
811
     * @stable ICU 2.6
 
812
     */
 
813
    const UBool _visible;
 
814
 
 
815
    /**
 
816
     * The locale supported by this factory, as a UnicodeString.
 
817
     * @stable ICU 2.6
 
818
     */
 
819
    UnicodeString _id;
 
820
 
 
821
public:
 
822
    /**
 
823
     * @stable ICU 2.6
 
824
     */
 
825
    SimpleNumberFormatFactory(const Locale& locale, UBool visible = TRUE);
 
826
 
 
827
    /**
 
828
     * @draft ICU 3.0
 
829
     */
 
830
    virtual ~SimpleNumberFormatFactory();
 
831
 
 
832
    /**
 
833
     * @stable ICU 2.6
 
834
     */
 
835
    virtual UBool visible(void) const;
 
836
 
 
837
    /**
 
838
     * @stable ICU 2.6
 
839
     */
 
840
    virtual const UnicodeString * getSupportedIDs(int32_t &count, UErrorCode& status) const;
 
841
};
 
842
#endif /* #if !UCONFIG_NO_SERVICE */
 
843
 
 
844
// -------------------------------------
 
845
 
 
846
inline UBool
 
847
NumberFormat::isParseIntegerOnly() const
 
848
{
 
849
    return fParseIntegerOnly;
 
850
}
 
851
 
 
852
inline UnicodeString&
 
853
NumberFormat::format(const Formattable& obj,
 
854
                     UnicodeString& appendTo,
 
855
                     UErrorCode& status) const {
 
856
    return Format::format(obj, appendTo, status);
 
857
}
 
858
 
 
859
U_NAMESPACE_END
 
860
 
 
861
#endif /* #if !UCONFIG_NO_FORMATTING */
 
862
 
 
863
#endif // _NUMFMT
 
864
//eof