BPicture: Fix archive constructor.
[haiku.git] / src / kits / locale / NumberFormatParameters.cpp
blob53a91bb3b193ae2e490c1af419c10bf085f25481
1 #include <NumberFormatParameters.h>
3 // defaults
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;
12 // flags
13 enum {
14 USE_GROUPING_SET = 0x01,
15 SIGN_POLICY_SET = 0x02,
16 BASE_SET = 0x04,
17 USE_BASE_PREFIX_SET = 0x08,
18 MINIMAL_INTEGER_DIGITS_SET = 0x10,
19 USE_ZERO_PADDING_SET = 0x20,
22 // constructor
23 BNumberFormatParameters::BNumberFormatParameters(
24 const BNumberFormatParameters *parent)
25 : BFormatParameters(parent),
26 fParent(parent),
27 fFlags(0)
31 // copy constructor
32 BNumberFormatParameters::BNumberFormatParameters(
33 const BNumberFormatParameters &other)
34 : BFormatParameters(other),
35 fParent(other.fParent),
36 fUseGrouping(other.fUseGrouping),
37 fSignPolicy(other.fSignPolicy),
38 fBase(other.fBase),
39 fUseBasePrefix(other.fUseBasePrefix),
40 fMinimalIntegerDigits(other.fMinimalIntegerDigits),
41 fFlags(other.fFlags)
45 // destructor
46 BNumberFormatParameters::~BNumberFormatParameters()
50 // SetUseGrouping
51 void
52 BNumberFormatParameters::SetUseGrouping(bool useGrouping)
54 fUseGrouping = useGrouping;
55 fFlags |= USE_GROUPING_SET;
58 // UseGrouping
59 bool
60 BNumberFormatParameters::UseGrouping() const
62 if (fFlags & USE_GROUPING_SET)
63 return fUseGrouping;
64 if (fParent)
65 return fParent->UseGrouping();
66 return kDefaultUseGrouping;
69 // SetSignPolicy
70 void
71 BNumberFormatParameters::SetSignPolicy(number_format_sign_policy policy)
73 fSignPolicy = policy;
74 fFlags |= SIGN_POLICY_SET;
77 // SignPolicy
78 number_format_sign_policy
79 BNumberFormatParameters::SignPolicy() const
81 if (fFlags & SIGN_POLICY_SET)
82 return fSignPolicy;
83 if (fParent)
84 return fParent->SignPolicy();
85 return kDefaultSignPolicy;
88 // SetBase
89 void
90 BNumberFormatParameters::SetBase(number_format_base base)
92 fBase = base;
93 fFlags |= BASE_SET;
96 // Base
97 number_format_base
98 BNumberFormatParameters::Base() const
100 if (fFlags & BASE_SET)
101 return fBase;
102 if (fParent)
103 return fParent->Base();
104 return kDefaultBase;
107 // SetUseBasePrefix
108 void
109 BNumberFormatParameters::SetUseBasePrefix(bool useBasePrefix)
111 fUseBasePrefix = useBasePrefix;
112 fFlags |= USE_BASE_PREFIX_SET;
115 // UseBasePrefix
116 bool
117 BNumberFormatParameters::UseBasePrefix() const
119 if (fFlags & USE_BASE_PREFIX_SET)
120 return fUseBasePrefix;
121 if (fParent)
122 return fParent->UseBasePrefix();
123 return kDefaultUseBasePrefix;
126 // SetMinimalIntegerDigits
127 void
128 BNumberFormatParameters::SetMinimalIntegerDigits(size_t minIntegerDigits)
130 fMinimalIntegerDigits = minIntegerDigits;
131 fFlags |= MINIMAL_INTEGER_DIGITS_SET;
134 // MinimalIntegerDigits
135 size_t
136 BNumberFormatParameters::MinimalIntegerDigits() const
138 if (fFlags & MINIMAL_INTEGER_DIGITS_SET)
139 return fMinimalIntegerDigits;
140 if (fParent)
141 return fParent->MinimalIntegerDigits();
142 return kDefaultMinimalIntegerDigits;
145 // SetUseZeroPadding
146 void
147 BNumberFormatParameters::SetUseZeroPadding(bool useZeroPadding)
149 fUseZeroPadding = useZeroPadding;
150 fFlags |= USE_ZERO_PADDING_SET;
153 // UseZeroPadding
154 bool
155 BNumberFormatParameters::UseZeroPadding() const
157 if (fFlags & USE_ZERO_PADDING_SET)
158 return fUseZeroPadding;
159 if (fParent)
160 return fParent->UseZeroPadding();
161 return kDefaultUseZeroPadding;
164 // SetParentNumberParameters
165 void
166 BNumberFormatParameters::SetParentNumberParameters(
167 const BNumberFormatParameters *parent)
169 fParent = parent;
170 SetParentParameters(parent);
173 // ParentNumberParameters
174 const BNumberFormatParameters *
175 BNumberFormatParameters::ParentNumberParameters() const
177 return fParent;
180 // =
181 BNumberFormatParameters &
182 BNumberFormatParameters::operator=(const BNumberFormatParameters &other)
184 BFormatParameters::operator=(other);
185 fParent = other.fParent;
186 fUseGrouping = other.fUseGrouping;
187 fSignPolicy = other.fSignPolicy;
188 fBase = other.fBase;
189 fUseBasePrefix = other.fUseBasePrefix;
190 fMinimalIntegerDigits = other.fMinimalIntegerDigits;
191 fFlags = other.fFlags;
192 fUseZeroPadding = other.fUseZeroPadding;
193 return *this;