1 #include <FloatFormatParameters.h>
4 static const size_t kDefaultMinimalFractionDigits
= 0;
5 static const size_t kDefaultMaximalFractionDigits
= 6;
6 static const bool kDefaultUseUpperCase
= false;
7 static const float_format_type kDefaultFloatFormatType
= B_AUTO_FLOAT_FORMAT
;
8 static const bool kDefaultAlwaysUseFractionSeparator
= false;
9 static const bool kDefaultKeepTrailingFractionZeros
= false;
14 MINIMAL_FRACTION_DIGITS_SET
= 0x01,
15 MAXIMAL_FRACTION_DIGITS_SET
= 0x02,
16 USE_UPPER_CASE_SET
= 0x04,
17 FLOAT_FORMAT_TYPE_SET
= 0x08,
18 ALWAYS_USE_FRACTION_SEPARATOR_SET
= 0x10,
19 KEEP_TRAILING_FRACTION_ZEROS_SET
= 0x20,
23 BFloatFormatParameters::BFloatFormatParameters(
24 const BFloatFormatParameters
*parent
)
25 : BNumberFormatParameters(parent
),
32 BFloatFormatParameters::BFloatFormatParameters(
33 const BFloatFormatParameters
&other
)
34 : BNumberFormatParameters(other
),
35 fParent(other
.fParent
),
36 fMinimalFractionDigits(other
.fMinimalFractionDigits
),
37 fMaximalFractionDigits(other
.fMaximalFractionDigits
),
38 fUseUpperCase(other
.fUseUpperCase
),
39 fFloatFormatType(other
.fFloatFormatType
),
40 fAlwaysUseFractionSeparator(other
.fAlwaysUseFractionSeparator
),
41 fKeepTrailingFractionZeros(other
.fKeepTrailingFractionZeros
),
47 BFloatFormatParameters::~BFloatFormatParameters()
51 // SetMinimalFractionDigits
53 BFloatFormatParameters::SetMinimalFractionDigits(size_t minFractionDigits
)
55 fMinimalFractionDigits
= minFractionDigits
;
56 fFlags
|= MINIMAL_FRACTION_DIGITS_SET
;
59 // MinimalFractionDigits
61 BFloatFormatParameters::MinimalFractionDigits() const
63 if (fFlags
& MINIMAL_FRACTION_DIGITS_SET
)
64 return fMinimalFractionDigits
;
66 return fParent
->MinimalFractionDigits();
67 return kDefaultMinimalFractionDigits
;
70 // SetMaximalFractionDigits
72 BFloatFormatParameters::SetMaximalFractionDigits(size_t maxFractionDigits
)
74 fMaximalFractionDigits
= maxFractionDigits
;
75 fFlags
|= MAXIMAL_FRACTION_DIGITS_SET
;
78 // MaximalFractionDigits
80 BFloatFormatParameters::MaximalFractionDigits() const
82 if (fFlags
& MAXIMAL_FRACTION_DIGITS_SET
)
83 return fMaximalFractionDigits
;
85 return fParent
->MaximalFractionDigits();
86 return kDefaultMaximalFractionDigits
;
91 BFloatFormatParameters::SetUseUpperCase(bool useCapitals
)
93 fUseUpperCase
= useCapitals
;
94 fFlags
|= USE_UPPER_CASE_SET
;
99 BFloatFormatParameters::UseUpperCase() const
101 if (fFlags
& USE_UPPER_CASE_SET
)
102 return fUseUpperCase
;
104 return fParent
->UseUpperCase();
105 return kDefaultUseUpperCase
;
108 // SetFloatFormatType
110 BFloatFormatParameters::SetFloatFormatType(float_format_type type
)
112 fFloatFormatType
= type
;
113 fFlags
|= FLOAT_FORMAT_TYPE_SET
;
118 BFloatFormatParameters::FloatFormatType() const
120 if (fFlags
& FLOAT_FORMAT_TYPE_SET
)
121 return fFloatFormatType
;
123 return fParent
->FloatFormatType();
124 return kDefaultFloatFormatType
;
127 // SetAlwaysUseFractionSeparator
129 BFloatFormatParameters::SetAlwaysUseFractionSeparator(
130 bool alwaysUseFractionSeparator
)
132 fAlwaysUseFractionSeparator
= alwaysUseFractionSeparator
;
133 fFlags
|= ALWAYS_USE_FRACTION_SEPARATOR_SET
;
136 // AlwaysUseFractionSeparator
138 BFloatFormatParameters::AlwaysUseFractionSeparator() const
140 if (fFlags
& ALWAYS_USE_FRACTION_SEPARATOR_SET
)
141 return fAlwaysUseFractionSeparator
;
143 return fParent
->AlwaysUseFractionSeparator();
144 return kDefaultAlwaysUseFractionSeparator
;
147 // SetKeepTrailingFractionZeros
149 BFloatFormatParameters::SetKeepTrailingFractionZeros(
150 bool keepTrailingFractionZeros
)
152 fKeepTrailingFractionZeros
= keepTrailingFractionZeros
;
153 fFlags
|= KEEP_TRAILING_FRACTION_ZEROS_SET
;
156 // KeepTrailingFractionZeros
158 BFloatFormatParameters::KeepTrailingFractionZeros() const
160 if (fFlags
& KEEP_TRAILING_FRACTION_ZEROS_SET
)
161 return fKeepTrailingFractionZeros
;
163 return fParent
->KeepTrailingFractionZeros();
164 return kDefaultKeepTrailingFractionZeros
;
167 // SetParentFloatParameters
169 BFloatFormatParameters::SetParentFloatParameters(
170 const BFloatFormatParameters
*parent
)
173 SetParentNumberParameters(parent
);
176 // ParentFloatParameters
177 const BFloatFormatParameters
*
178 BFloatFormatParameters::ParentFloatParameters() const
184 BFloatFormatParameters
&
185 BFloatFormatParameters::operator=(const BFloatFormatParameters
&other
)
187 BNumberFormatParameters::operator=(other
);
188 fParent
= other
.fParent
;
189 fMinimalFractionDigits
= other
.fMinimalFractionDigits
;
190 fMaximalFractionDigits
= other
.fMaximalFractionDigits
;
191 fUseUpperCase
= other
.fUseUpperCase
;
192 fFloatFormatType
= other
.fFloatFormatType
;
193 fAlwaysUseFractionSeparator
= other
.fAlwaysUseFractionSeparator
;
194 fKeepTrailingFractionZeros
= other
.fKeepTrailingFractionZeros
;
195 fFlags
= other
.fFlags
;