Skip to content

Commit

Permalink
Deprecate Currency::format
Browse files Browse the repository at this point in the history
  • Loading branch information
sweemer committed Oct 22, 2023
1 parent 6441d1b commit 5abfbf8
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 2 deletions.
39 changes: 38 additions & 1 deletion ql/currency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@ namespace QuantLib {
return out << "null currency";
}

QL_DEPRECATED_DISABLE_WARNING

Currency::Data::Data(std::string name,
std::string code,
Integer numericCode,
std::string symbol,
std::string fractionSymbol,
Integer fractionsPerUnit,
const Rounding& rounding,
Currency triangulationCurrency,
std::set<std::string> minorUnitCodes)
: name(std::move(name)), code(std::move(code)), numeric(numericCode), symbol(std::move(symbol)),
fractionSymbol(std::move(fractionSymbol)), fractionsPerUnit(fractionsPerUnit),
rounding(rounding), triangulated(std::move(triangulationCurrency)),
minorUnitCodes(std::move(minorUnitCodes)) {}

Currency::Data::Data(std::string name,
std::string code,
Integer numericCode,
Expand All @@ -44,6 +60,25 @@ namespace QuantLib {
rounding(rounding), triangulated(std::move(triangulationCurrency)),
formatString(std::move(formatString)), minorUnitCodes(std::move(minorUnitCodes)) {}

Currency::Currency(const std::string& name,
const std::string& code,
Integer numericCode,
const std::string& symbol,
const std::string& fractionSymbol,
Integer fractionsPerUnit,
const Rounding& rounding,
const Currency& triangulationCurrency,
const std::set<std::string>& minorUnitCodes)
: data_(ext::make_shared<Currency::Data>(name,
code,
numericCode,
symbol,
fractionSymbol,
fractionsPerUnit,
rounding,
triangulationCurrency,
minorUnitCodes)) {}

Currency::Currency(const std::string& name,
const std::string& code,
Integer numericCode,
Expand All @@ -64,5 +99,7 @@ namespace QuantLib {
formatString,
triangulationCurrency,
minorUnitCodes)) {}
}

QL_DEPRECATED_ENABLE_WARNING

}
40 changes: 40 additions & 0 deletions ql/currency.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ namespace QuantLib {
used.
*/
Currency() = default;
Currency(const std::string& name,
const std::string& code,
Integer numericCode,
const std::string& symbol,
const std::string& fractionSymbol,
Integer fractionsPerUnit,
const Rounding& rounding,
const Currency& triangulationCurrency = Currency(),
const std::set<std::string>& minorUnitCodes = {});
/*! \deprecated Use the constructor without formatString.
Deprecated in version 1.33.
*/
QL_DEPRECATED
Currency(const std::string& name,
const std::string& code,
Integer numericCode,
Expand Down Expand Up @@ -75,6 +88,10 @@ namespace QuantLib {
/*! The format will be fed three positional parameters,
namely, value, code, and symbol, in this order.
*/
/*! \deprecated Copy the formatting into your project if you need it.
Deprecated in version 1.33.
*/
[[deprecated("Copy the formatting into your project if you need it.")]]
std::string format() const;
//@}
//! \name Other information
Expand All @@ -93,16 +110,33 @@ namespace QuantLib {
void checkNonEmpty() const;
};

QL_DEPRECATED_DISABLE_WARNING

struct Currency::Data {
std::string name, code;
Integer numeric;
std::string symbol, fractionSymbol;
Integer fractionsPerUnit;
Rounding rounding;
Currency triangulated;
QL_DEPRECATED
std::string formatString;
std::set<std::string> minorUnitCodes;

/*! \deprecated Use the constructor without formatString.
Deprecated in version 1.33.
*/
QL_DEPRECATED
Data(std::string name,
std::string code,
Integer numericCode,
std::string symbol,
std::string fractionSymbol,
Integer fractionsPerUnit,
const Rounding& rounding,
Currency triangulationCurrency = Currency(),
std::set<std::string> minorUnitCodes = {});

Data(std::string name,
std::string code,
Integer numericCode,
Expand All @@ -115,6 +149,8 @@ namespace QuantLib {
std::set<std::string> minorUnitCodes = {});
};

QL_DEPRECATED_ENABLE_WARNING

/*! \relates Currency */
bool operator==(const Currency&,
const Currency&);
Expand Down Expand Up @@ -169,11 +205,15 @@ namespace QuantLib {
return data_->rounding;
}

QL_DEPRECATED_DISABLE_WARNING

inline std::string Currency::format() const {
checkNonEmpty();
return data_->formatString;
}

QL_DEPRECATED_ENABLE_WARNING

inline bool Currency::empty() const {
return !data_;
}
Expand Down
2 changes: 2 additions & 0 deletions ql/money.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ namespace QuantLib {
}
}

QL_DEPRECATED_DISABLE_WARNING

std::ostream& operator<<(std::ostream& out, const Money& m) {
boost::format fmt(m.currency().format());
Expand All @@ -214,6 +215,7 @@ namespace QuantLib {
% m.currency().symbol();
}

QL_DEPRECATED_ENABLE_WARNING

const Money::ConversionType & Money::Settings::conversionType() const
{
Expand Down
4 changes: 4 additions & 0 deletions ql/money.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ namespace QuantLib {
// formatting

/*! \relates Money */
/*! \deprecated Copy the formatting into your project if you need it.
Deprecated in version 1.33.
*/
[[deprecated("Copy the formatting into your project if you need it.")]]
std::ostream& operator<<(std::ostream&, const Money&);


Expand Down
2 changes: 1 addition & 1 deletion test-suite/currency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void CurrencyTest::testBespokeConstructor() {
std::string code("CCY");
std::string symbol("#");

Currency customCcy(name, code, 100, symbol, "", 100, Rounding(), "");
Currency customCcy(name, code, 100, symbol, "", 100, Rounding());

if (customCcy.empty())
BOOST_ERROR("Failed to create bespoke currency.");
Expand Down

0 comments on commit 5abfbf8

Please sign in to comment.