BPicture: Fix archive constructor.
[haiku.git] / src / kits / locale / FloatFormatParameters.cpp
blob28919018a30b97e6c892df3da900f1d9b27454ab
1 #include <FloatFormatParameters.h>
3 // defaults
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;
12 // flags
13 enum {
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,
22 // constructor
23 BFloatFormatParameters::BFloatFormatParameters(
24 const BFloatFormatParameters *parent)
25 : BNumberFormatParameters(parent),
26 fParent(parent),
27 fFlags(0)
31 // copy constructor
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),
42 fFlags(other.fFlags)
46 // destructor
47 BFloatFormatParameters::~BFloatFormatParameters()
51 // SetMinimalFractionDigits
52 void
53 BFloatFormatParameters::SetMinimalFractionDigits(size_t minFractionDigits)
55 fMinimalFractionDigits = minFractionDigits;
56 fFlags |= MINIMAL_FRACTION_DIGITS_SET;
59 // MinimalFractionDigits
60 size_t
61 BFloatFormatParameters::MinimalFractionDigits() const
63 if (fFlags & MINIMAL_FRACTION_DIGITS_SET)
64 return fMinimalFractionDigits;
65 if (fParent)
66 return fParent->MinimalFractionDigits();
67 return kDefaultMinimalFractionDigits;
70 // SetMaximalFractionDigits
71 void
72 BFloatFormatParameters::SetMaximalFractionDigits(size_t maxFractionDigits)
74 fMaximalFractionDigits = maxFractionDigits;
75 fFlags |= MAXIMAL_FRACTION_DIGITS_SET;
78 // MaximalFractionDigits
79 size_t
80 BFloatFormatParameters::MaximalFractionDigits() const
82 if (fFlags & MAXIMAL_FRACTION_DIGITS_SET)
83 return fMaximalFractionDigits;
84 if (fParent)
85 return fParent->MaximalFractionDigits();
86 return kDefaultMaximalFractionDigits;
89 // SetUseUpperCase
90 void
91 BFloatFormatParameters::SetUseUpperCase(bool useCapitals)
93 fUseUpperCase = useCapitals;
94 fFlags |= USE_UPPER_CASE_SET;
97 // UseUpperCase
98 bool
99 BFloatFormatParameters::UseUpperCase() const
101 if (fFlags & USE_UPPER_CASE_SET)
102 return fUseUpperCase;
103 if (fParent)
104 return fParent->UseUpperCase();
105 return kDefaultUseUpperCase;
108 // SetFloatFormatType
109 void
110 BFloatFormatParameters::SetFloatFormatType(float_format_type type)
112 fFloatFormatType = type;
113 fFlags |= FLOAT_FORMAT_TYPE_SET;
116 // FloatFormatType
117 float_format_type
118 BFloatFormatParameters::FloatFormatType() const
120 if (fFlags & FLOAT_FORMAT_TYPE_SET)
121 return fFloatFormatType;
122 if (fParent)
123 return fParent->FloatFormatType();
124 return kDefaultFloatFormatType;
127 // SetAlwaysUseFractionSeparator
128 void
129 BFloatFormatParameters::SetAlwaysUseFractionSeparator(
130 bool alwaysUseFractionSeparator)
132 fAlwaysUseFractionSeparator = alwaysUseFractionSeparator;
133 fFlags |= ALWAYS_USE_FRACTION_SEPARATOR_SET;
136 // AlwaysUseFractionSeparator
137 bool
138 BFloatFormatParameters::AlwaysUseFractionSeparator() const
140 if (fFlags & ALWAYS_USE_FRACTION_SEPARATOR_SET)
141 return fAlwaysUseFractionSeparator;
142 if (fParent)
143 return fParent->AlwaysUseFractionSeparator();
144 return kDefaultAlwaysUseFractionSeparator;
147 // SetKeepTrailingFractionZeros
148 void
149 BFloatFormatParameters::SetKeepTrailingFractionZeros(
150 bool keepTrailingFractionZeros)
152 fKeepTrailingFractionZeros = keepTrailingFractionZeros;
153 fFlags |= KEEP_TRAILING_FRACTION_ZEROS_SET;
156 // KeepTrailingFractionZeros
157 bool
158 BFloatFormatParameters::KeepTrailingFractionZeros() const
160 if (fFlags & KEEP_TRAILING_FRACTION_ZEROS_SET)
161 return fKeepTrailingFractionZeros;
162 if (fParent)
163 return fParent->KeepTrailingFractionZeros();
164 return kDefaultKeepTrailingFractionZeros;
167 // SetParentFloatParameters
168 void
169 BFloatFormatParameters::SetParentFloatParameters(
170 const BFloatFormatParameters *parent)
172 fParent = parent;
173 SetParentNumberParameters(parent);
176 // ParentFloatParameters
177 const BFloatFormatParameters *
178 BFloatFormatParameters::ParentFloatParameters() const
180 return fParent;
183 // =
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;
196 return *this;