]> git.saurik.com Git - apple/icu.git/blob - icuSources/i18n/number_microprops.h
ICU-62109.0.1.tar.gz
[apple/icu.git] / icuSources / i18n / number_microprops.h
1 // © 2017 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 __NUMBER_MICROPROPS_H__
8 #define __NUMBER_MICROPROPS_H__
9
10 // TODO: minimize includes
11 #include "unicode/numberformatter.h"
12 #include "number_types.h"
13 #include "number_decimalquantity.h"
14 #include "number_scientific.h"
15 #include "number_patternstring.h"
16 #include "number_modifiers.h"
17 #include "number_multiplier.h"
18 #include "number_roundingutils.h"
19 #include "decNumber.h"
20 #include "charstr.h"
21
22 U_NAMESPACE_BEGIN namespace number {
23 namespace impl {
24
25 struct MicroProps : public MicroPropsGenerator {
26
27 // NOTE: All of these fields are properly initialized in NumberFormatterImpl.
28 RoundingImpl rounder;
29 Grouper grouping;
30 Padder padding;
31 IntegerWidth integerWidth;
32 UNumberSignDisplay sign;
33 UNumberDecimalSeparatorDisplay decimal;
34 bool useCurrency;
35
36 // Note: This struct has no direct ownership of the following pointers.
37 const DecimalFormatSymbols* symbols;
38 const Modifier* modOuter;
39 const Modifier* modMiddle;
40 const Modifier* modInner;
41
42 // The following "helper" fields may optionally be used during the MicroPropsGenerator.
43 // They live here to retain memory.
44 struct {
45 ScientificModifier scientificModifier;
46 EmptyModifier emptyWeakModifier{false};
47 EmptyModifier emptyStrongModifier{true};
48 MultiplierFormatHandler multiplier;
49 } helpers;
50
51
52 MicroProps() = default;
53
54 MicroProps(const MicroProps& other) = default;
55
56 MicroProps& operator=(const MicroProps& other) = default;
57
58 void processQuantity(DecimalQuantity&, MicroProps& micros, UErrorCode& status) const U_OVERRIDE {
59 (void) status;
60 if (this == &micros) {
61 // Unsafe path: no need to perform a copy.
62 U_ASSERT(!exhausted);
63 micros.exhausted = true;
64 U_ASSERT(exhausted);
65 } else {
66 // Safe path: copy self into the output micros.
67 micros = *this;
68 }
69 }
70
71 private:
72 // Internal fields:
73 bool exhausted = false;
74 };
75
76 } // namespace impl
77 } // namespace number
78 U_NAMESPACE_END
79
80 #endif // __NUMBER_MICROPROPS_H__
81
82 #endif /* #if !UCONFIG_NO_FORMATTING */