From 3e8c1b4e04f0ede7f29d9f47f567bc732d74130a Mon Sep 17 00:00:00 2001 From: Jonathan Sweemer Date: Tue, 10 Oct 2023 21:47:13 +0900 Subject: [PATCH] Deprecate Currency::format --- ql/currency.cpp | 39 ++++++++++++++++++++++++++++++++++++++- ql/currency.hpp | 40 ++++++++++++++++++++++++++++++++++++++++ ql/money.cpp | 2 ++ ql/money.hpp | 4 ++++ test-suite/currency.cpp | 2 +- 5 files changed, 85 insertions(+), 2 deletions(-) diff --git a/ql/currency.cpp b/ql/currency.cpp index 2ca5b72463d..5c268c9c224 100644 --- a/ql/currency.cpp +++ b/ql/currency.cpp @@ -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 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, @@ -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& minorUnitCodes) + : data_(ext::make_shared(name, + code, + numericCode, + symbol, + fractionSymbol, + fractionsPerUnit, + rounding, + triangulationCurrency, + minorUnitCodes)) {} + Currency::Currency(const std::string& name, const std::string& code, Integer numericCode, @@ -64,5 +99,7 @@ namespace QuantLib { formatString, triangulationCurrency, minorUnitCodes)) {} -} + QL_DEPRECATED_ENABLE_WARNING + +} diff --git a/ql/currency.hpp b/ql/currency.hpp index 2d9296bca21..b1d65b2e6d8 100644 --- a/ql/currency.hpp +++ b/ql/currency.hpp @@ -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& minorUnitCodes = {}); + /*! \deprecated Use the constructor without formatString. + Deprecated in version 1.32. + */ + QL_DEPRECATED Currency(const std::string& name, const std::string& code, Integer numericCode, @@ -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.32. + */ + [[deprecated("Copy the formatting into your project if you need it.")]] std::string format() const; //@} //! \name Other information @@ -93,6 +110,8 @@ namespace QuantLib { void checkNonEmpty() const; }; + QL_DEPRECATED_DISABLE_WARNING + struct Currency::Data { std::string name, code; Integer numeric; @@ -100,9 +119,24 @@ namespace QuantLib { Integer fractionsPerUnit; Rounding rounding; Currency triangulated; + QL_DEPRECATED std::string formatString; std::set minorUnitCodes; + /*! \deprecated Use the constructor without formatString. + Deprecated in version 1.32. + */ + 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 minorUnitCodes = {}); + Data(std::string name, std::string code, Integer numericCode, @@ -115,6 +149,8 @@ namespace QuantLib { std::set minorUnitCodes = {}); }; + QL_DEPRECATED_ENABLE_WARNING + /*! \relates Currency */ bool operator==(const Currency&, const Currency&); @@ -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_; } diff --git a/ql/money.cpp b/ql/money.cpp index f0f45656bbf..32de7a9d6b4 100644 --- a/ql/money.cpp +++ b/ql/money.cpp @@ -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()); @@ -214,6 +215,7 @@ namespace QuantLib { % m.currency().symbol(); } + QL_DEPRECATED_ENABLE_WARNING const Money::ConversionType & Money::Settings::conversionType() const { diff --git a/ql/money.hpp b/ql/money.hpp index 66533030f0a..f101f5c3f0c 100644 --- a/ql/money.hpp +++ b/ql/money.hpp @@ -159,6 +159,10 @@ namespace QuantLib { // formatting /*! \relates Money */ + /*! \deprecated Copy the formatting into your project if you need it. + Deprecated in version 1.32. + */ + [[deprecated("Copy the formatting into your project if you need it.")]] std::ostream& operator<<(std::ostream&, const Money&); diff --git a/test-suite/currency.cpp b/test-suite/currency.cpp index 7c0d6889b27..1908597275f 100644 --- a/test-suite/currency.cpp +++ b/test-suite/currency.cpp @@ -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.");