From 4163236e72e160c27f3288ba66252a4f3e62080b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20D=C3=ADaz=20M=C3=A1s?= Date: Sun, 20 Feb 2022 09:22:55 +0100 Subject: [PATCH] Implement Params singleton in modern C++ way --- app/exiv2.cpp | 14 ++------------ app/exiv2app.hpp | 5 ----- 2 files changed, 2 insertions(+), 17 deletions(-) diff --git a/app/exiv2.cpp b/app/exiv2.cpp index b45f859a..d5da161b 100644 --- a/app/exiv2.cpp +++ b/app/exiv2.cpp @@ -181,7 +181,6 @@ int main(int argc, char* const argv[]) } taskFactory.cleanup(); - Params::cleanup(); Exiv2::XmpParser::terminate(); } } catch (const std::exception& exc) { @@ -195,7 +194,6 @@ int main(int argc, char* const argv[]) // ***************************************************************************** // class Params -Params* Params::instance_ = nullptr; const Params::YodAdjust Params::emptyYodAdjust_[] = { { false, "-Y", 0 }, @@ -232,16 +230,8 @@ Params::Params() : optstring_(":hVvqfbuktTFa:Y:O:D:r:p:P:d:e:i:c:m:M:l:S:g:K:n:Q Params& Params::instance() { - if (nullptr == instance_) { - instance_ = new Params; - } - return *instance_; -} - -void Params::cleanup() -{ - delete instance_; - instance_ = nullptr; + static Params instance_; + return instance_; } void Params::version(bool verbose, std::ostream& os) diff --git a/app/exiv2app.hpp b/app/exiv2app.hpp index 0b938623..5c04a4bc 100644 --- a/app/exiv2app.hpp +++ b/app/exiv2app.hpp @@ -148,9 +148,6 @@ public: //! Prevent copy-construction: not implemented. Params(const Params& rhs) = delete; - //! Destructor - static void cleanup(); - //! Enumerates print modes enum PrintMode { pmSummary, @@ -244,8 +241,6 @@ public: Exiv2::DataBuf stdinBuf; //!< DataBuf with the binary bytes from stdin private: - //! Pointer to the global Params object. - static Params* instance_; //! Initializer for year, month and day adjustment info. static const YodAdjust emptyYodAdjust_[];