1 // © 2018 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 #include "unicode/utypes.h"
6 #if !UCONFIG_NO_FORMATTING
7 #ifndef __SOURCE_NUMBER_UTYPES_H__
8 #define __SOURCE_NUMBER_UTYPES_H__
10 #include "unicode/numberformatter.h"
11 #include "number_types.h"
12 #include "number_decimalquantity.h"
13 #include "number_stringbuilder.h"
15 U_NAMESPACE_BEGIN
namespace number
{
20 * Implementation class for UNumberFormatter with a magic number for safety.
22 * Wraps a LocalizedNumberFormatter by value.
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;
30 int32_t fMagic
= kMagic
;
31 LocalizedNumberFormatter fFormatter
;
33 /** Convert from UNumberFormatter -> UNumberFormatterData. */
34 static UNumberFormatterData
* validate(UNumberFormatter
* input
, UErrorCode
& status
);
36 /** Convert from UNumberFormatter -> UNumberFormatterData (const version). */
37 static const UNumberFormatterData
* validate(const UNumberFormatter
* input
, UErrorCode
& status
);
39 /** Convert from UNumberFormatterData -> UNumberFormatter. */
40 UNumberFormatter
* exportForC();
45 * Implementation class for UFormattedNumber with magic number for safety.
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.
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.
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;
59 int32_t fMagic
= kMagic
;
60 DecimalQuantity quantity
;
61 NumberStringBuilder string
;
63 /** Convert from UFormattedNumber -> UFormattedNumberData. */
64 static UFormattedNumberData
* validate(UFormattedNumber
* input
, UErrorCode
& status
);
66 /** Convert from UFormattedNumber -> UFormattedNumberData (const version). */
67 static const UFormattedNumberData
* validate(const UFormattedNumber
* input
, UErrorCode
& status
);
69 /** Convert from UFormattedNumberData -> UFormattedNumber. */
70 UFormattedNumber
* exportForC();
78 #endif //__SOURCE_NUMBER_UTYPES_H__
79 #endif /* #if !UCONFIG_NO_FORMATTING */