3 // message archive field names
4 static const char *kArchivedCurrencyCodeName
= "be:currency code";
5 static const char *kArchivedDefaultSymbol
= "be:default symbol";
6 static const char *kArchivedDefaultFractionDigits
7 = "be:default fraction digits";
10 BCurrency::BCurrency(const BCurrency
&other
)
13 fDefaultFractionDigits(B_NO_INIT
)
19 BCurrency::BCurrency(BMessage
*archive
)
22 fDefaultFractionDigits(B_NO_INIT
)
24 if (archive
->FindString(kArchivedCurrencyCodeName
, &fCurrencyCode
)
26 && archive
->FindString(kArchivedDefaultSymbol
, &fDefaultSymbol
)
28 && archive
->FindInt32(kArchivedDefaultFractionDigits
,
29 &fDefaultFractionDigits
) == B_OK
31 // everything went fine
37 BCurrency::BCurrency(const char *currencyCode
)
39 // TODO: load currency from disk
43 BCurrency::~BCurrency()
49 BCurrency::InitCheck() const
51 return (fDefaultFractionDigits
< 0 ? fDefaultFractionDigits
: B_OK
);
56 BCurrency::Archive(BMessage
*archive
, bool deep
) const
58 status_t error
= BArchivable::Archive(archive
, deep
);
60 if (archive
->AddString(kArchivedCurrencyCodeName
, fCurrencyCode
)
62 && archive
->AddString(kArchivedDefaultSymbol
, fDefaultSymbol
)
64 && archive
->AddInt32(kArchivedDefaultFractionDigits
,
65 fDefaultFractionDigits
) == B_OK
) {
66 // everything went fine
76 BCurrency::Instantiate(BMessage
*archive
)
78 if (!validate_instantiation(archive
, "BCurrency"))
80 return new BCurrency(archive
);
85 BCurrency::CurrencyCode() const
87 return (InitCheck() == B_OK
? fCurrencyCode
.String() : NULL
);
92 BCurrency::DefaultSymbol() const
94 return (InitCheck() == B_OK
? fDefaultSymbol
.String() : NULL
);
97 // DefaultFractionDigits
99 BCurrency::DefaultFractionDigits() const
101 return (InitCheck() == B_OK
? fDefaultFractionDigits
: 0);
106 BCurrency::GetSymbol(char *symbol
, size_t maxSize
, BLocale
*locale
)
108 // check initialization and parameters
109 if (InitCheck() != B_OK
)
113 // TODO: get symbol from locale
114 // fall back to the default symbol
115 if ((int32
)maxSize
<= fDefaultSymbol
.Length())
116 return EOVERFLOW
; // OpenBeOS: B_BUFFER_OVERFLOW
117 strcpy(symbol
, fDefaultSymbol
.String());
123 BCurrency::GetSymbol(BString
*symbol
, BLocale
*locale
)
125 // check initialization and parameters
126 if (InitCheck() != B_OK
)
130 // TODO: get symbol from locale
131 // fall back to the default symbol
132 *symbol
= fDefaultSymbol
;
133 if (symbol
->Length() != fDefaultSymbol
.Length())
140 BCurrency::operator=(const BCurrency
&other
)
142 if (other
.InitCheck() == B_OK
) {
143 fCurrencyCode
= other
.fCurrencyCode
;
144 fDefaultSymbol
= other
.fDefaultSymbol
;
145 fDefaultFractionDigits
= other
.fDefaultFractionDigits
;
155 BCurrency::operator==(const BCurrency
&other
) const
157 if (InitCheck() != B_OK
|| other
.InitCheck() != B_OK
)
159 return (fCurrencyCode
== other
.fCurrencyCode
);
164 BCurrency::operator!=(const BCurrency
&other
) const
166 return !(*this == other
);
170 BCurrency::BCurrency()
172 // privatized to make it unaccessible
177 BCurrency::_CheckData() const
179 return (fDefaultFractionDigits
>= 0
180 && fCurrencyCode
.Length() > 0
181 && fDefaultSymbol
.Length() == 0);
186 BCurrency::_Unset(status_t error
)
188 fCurrencyCode
.Truncate(0);
189 fDefaultSymbol
.Truncate(0);
190 fDefaultFractionDigits
= error
;