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
22U_NAMESPACE_BEGIN namespace number {
23namespace impl {
24
25struct 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 char nsName[9];
36
37 // Note: This struct has no direct ownership of the following pointers.
38 const DecimalFormatSymbols* symbols;
39 const Modifier* modOuter;
40 const Modifier* modMiddle;
41 const Modifier* modInner;
42
43 // The following "helper" fields may optionally be used during the MicroPropsGenerator.
44 // They live here to retain memory.
45 struct {
46 ScientificModifier scientificModifier;
47 EmptyModifier emptyWeakModifier{false};
48 EmptyModifier emptyStrongModifier{true};
49 MultiplierFormatHandler multiplier;
50 } helpers;
51
52
53 MicroProps() = default;
54
55 MicroProps(const MicroProps& other) = default;
56
57 MicroProps& operator=(const MicroProps& other) = default;
58
59 void processQuantity(DecimalQuantity&, MicroProps& micros, UErrorCode& status) const U_OVERRIDE {
60 (void) status;
61 if (this == &micros) {
62 // Unsafe path: no need to perform a copy.
63 U_ASSERT(!exhausted);
64 micros.exhausted = true;
65 U_ASSERT(exhausted);
66 } else {
67 // Safe path: copy self into the output micros.
68 micros = *this;
69 }
70 }
71
72 private:
73 // Internal fields:
74 bool exhausted = false;
75};
76
77} // namespace impl
78} // namespace number
79U_NAMESPACE_END
80
81#endif // __NUMBER_MICROPROPS_H__
82
83#endif /* #if !UCONFIG_NO_FORMATTING */
84