1 #include <NumberFormatParameters.h>
4 static const bool kDefaultUseGrouping
= false;
5 static const number_format_sign_policy kDefaultSignPolicy
6 = B_USE_NEGATIVE_SIGN_ONLY
;
7 static const number_format_base kDefaultBase
= B_DEFAULT_BASE
;
8 static const bool kDefaultUseBasePrefix
= false;
9 static const size_t kDefaultMinimalIntegerDigits
= 1;
10 static const bool kDefaultUseZeroPadding
= false;
14 USE_GROUPING_SET
= 0x01,
15 SIGN_POLICY_SET
= 0x02,
17 USE_BASE_PREFIX_SET
= 0x08,
18 MINIMAL_INTEGER_DIGITS_SET
= 0x10,
19 USE_ZERO_PADDING_SET
= 0x20,
23 BNumberFormatParameters::BNumberFormatParameters(
24 const BNumberFormatParameters
*parent
)
25 : BFormatParameters(parent
),
32 BNumberFormatParameters::BNumberFormatParameters(
33 const BNumberFormatParameters
&other
)
34 : BFormatParameters(other
),
35 fParent(other
.fParent
),
36 fUseGrouping(other
.fUseGrouping
),
37 fSignPolicy(other
.fSignPolicy
),
39 fUseBasePrefix(other
.fUseBasePrefix
),
40 fMinimalIntegerDigits(other
.fMinimalIntegerDigits
),
46 BNumberFormatParameters::~BNumberFormatParameters()
52 BNumberFormatParameters::SetUseGrouping(bool useGrouping
)
54 fUseGrouping
= useGrouping
;
55 fFlags
|= USE_GROUPING_SET
;
60 BNumberFormatParameters::UseGrouping() const
62 if (fFlags
& USE_GROUPING_SET
)
65 return fParent
->UseGrouping();
66 return kDefaultUseGrouping
;
71 BNumberFormatParameters::SetSignPolicy(number_format_sign_policy policy
)
74 fFlags
|= SIGN_POLICY_SET
;
78 number_format_sign_policy
79 BNumberFormatParameters::SignPolicy() const
81 if (fFlags
& SIGN_POLICY_SET
)
84 return fParent
->SignPolicy();
85 return kDefaultSignPolicy
;
90 BNumberFormatParameters::SetBase(number_format_base base
)
98 BNumberFormatParameters::Base() const
100 if (fFlags
& BASE_SET
)
103 return fParent
->Base();
109 BNumberFormatParameters::SetUseBasePrefix(bool useBasePrefix
)
111 fUseBasePrefix
= useBasePrefix
;
112 fFlags
|= USE_BASE_PREFIX_SET
;
117 BNumberFormatParameters::UseBasePrefix() const
119 if (fFlags
& USE_BASE_PREFIX_SET
)
120 return fUseBasePrefix
;
122 return fParent
->UseBasePrefix();
123 return kDefaultUseBasePrefix
;
126 // SetMinimalIntegerDigits
128 BNumberFormatParameters::SetMinimalIntegerDigits(size_t minIntegerDigits
)
130 fMinimalIntegerDigits
= minIntegerDigits
;
131 fFlags
|= MINIMAL_INTEGER_DIGITS_SET
;
134 // MinimalIntegerDigits
136 BNumberFormatParameters::MinimalIntegerDigits() const
138 if (fFlags
& MINIMAL_INTEGER_DIGITS_SET
)
139 return fMinimalIntegerDigits
;
141 return fParent
->MinimalIntegerDigits();
142 return kDefaultMinimalIntegerDigits
;
147 BNumberFormatParameters::SetUseZeroPadding(bool useZeroPadding
)
149 fUseZeroPadding
= useZeroPadding
;
150 fFlags
|= USE_ZERO_PADDING_SET
;
155 BNumberFormatParameters::UseZeroPadding() const
157 if (fFlags
& USE_ZERO_PADDING_SET
)
158 return fUseZeroPadding
;
160 return fParent
->UseZeroPadding();
161 return kDefaultUseZeroPadding
;
164 // SetParentNumberParameters
166 BNumberFormatParameters::SetParentNumberParameters(
167 const BNumberFormatParameters
*parent
)
170 SetParentParameters(parent
);
173 // ParentNumberParameters
174 const BNumberFormatParameters
*
175 BNumberFormatParameters::ParentNumberParameters() const
181 BNumberFormatParameters
&
182 BNumberFormatParameters::operator=(const BNumberFormatParameters
&other
)
184 BFormatParameters::operator=(other
);
185 fParent
= other
.fParent
;
186 fUseGrouping
= other
.fUseGrouping
;
187 fSignPolicy
= other
.fSignPolicy
;
189 fUseBasePrefix
= other
.fUseBasePrefix
;
190 fMinimalIntegerDigits
= other
.fMinimalIntegerDigits
;
191 fFlags
= other
.fFlags
;
192 fUseZeroPadding
= other
.fUseZeroPadding
;