]> git.saurik.com Git - apple/icu.git/blob - icuSources/i18n/number_utypes.h
ICU-62109.0.1.tar.gz
[apple/icu.git] / icuSources / i18n / number_utypes.h
1 // © 2018 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3
4 #include "unicode/utypes.h"
5
6 #if !UCONFIG_NO_FORMATTING
7 #ifndef __SOURCE_NUMBER_UTYPES_H__
8 #define __SOURCE_NUMBER_UTYPES_H__
9
10 #include "unicode/numberformatter.h"
11 #include "number_types.h"
12 #include "number_decimalquantity.h"
13 #include "number_stringbuilder.h"
14
15 U_NAMESPACE_BEGIN namespace number {
16 namespace impl {
17
18
19 /**
20 * Implementation class for UNumberFormatter with a magic number for safety.
21 *
22 * Wraps a LocalizedNumberFormatter by value.
23 */
24 struct UNumberFormatterData : public UMemory {
25 // The magic number to identify incoming objects.
26 // Reads in ASCII as "NFR" (NumberFormatteR with room at the end)
27 static constexpr int32_t kMagic = 0x4E465200;
28
29 // Data members:
30 int32_t fMagic = kMagic;
31 LocalizedNumberFormatter fFormatter;
32
33 /** Convert from UNumberFormatter -> UNumberFormatterData. */
34 static UNumberFormatterData* validate(UNumberFormatter* input, UErrorCode& status);
35
36 /** Convert from UNumberFormatter -> UNumberFormatterData (const version). */
37 static const UNumberFormatterData* validate(const UNumberFormatter* input, UErrorCode& status);
38
39 /** Convert from UNumberFormatterData -> UNumberFormatter. */
40 UNumberFormatter* exportForC();
41 };
42
43
44 /**
45 * Implementation class for UFormattedNumber with magic number for safety.
46 *
47 * This struct is also held internally by the C++ version FormattedNumber since the member types are not
48 * declared in the public header file.
49 *
50 * The DecimalQuantity is not currently being used by FormattedNumber, but at some point it could be used
51 * to add a toDecNumber() or similar method.
52 */
53 struct UFormattedNumberData : public UMemory {
54 // The magic number to identify incoming objects.
55 // Reads in ASCII as "FDN" (FormatteDNumber with room at the end)
56 static constexpr int32_t kMagic = 0x46444E00;
57
58 // Data members:
59 int32_t fMagic = kMagic;
60 DecimalQuantity quantity;
61 NumberStringBuilder string;
62
63 /** Convert from UFormattedNumber -> UFormattedNumberData. */
64 static UFormattedNumberData* validate(UFormattedNumber* input, UErrorCode& status);
65
66 /** Convert from UFormattedNumber -> UFormattedNumberData (const version). */
67 static const UFormattedNumberData* validate(const UFormattedNumber* input, UErrorCode& status);
68
69 /** Convert from UFormattedNumberData -> UFormattedNumber. */
70 UFormattedNumber* exportForC();
71 };
72
73
74 } // namespace impl
75 } // namespace number
76 U_NAMESPACE_END
77
78 #endif //__SOURCE_NUMBER_UTYPES_H__
79 #endif /* #if !UCONFIG_NO_FORMATTING */