Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate Currency::format #1810

Merged
merged 1 commit into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
11 changes: 1 addition & 10 deletions ql/money.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
#include <ql/currencies/exchangeratemanager.hpp>
#include <ql/math/comparison.hpp>

#include <boost/format.hpp>

namespace QuantLib {

namespace {
Expand Down Expand Up @@ -204,17 +202,10 @@ namespace QuantLib {
}
}


std::ostream& operator<<(std::ostream& out, const Money& m) {
boost::format fmt(m.currency().format());
fmt.exceptions(boost::io::all_error_bits ^
boost::io::too_many_args_bit);
return out << fmt % m.rounded().value()
% m.currency().code()
% m.currency().symbol();
return out << m.rounded().value() << " " << m.currency().code();
}


const Money::ConversionType & Money::Settings::conversionType() const
{
return conversionType_;
Expand Down
2 changes: 1 addition & 1 deletion test-suite/currency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ BOOST_AUTO_TEST_CASE(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