Implement Params singleton in modern C++ way

This commit is contained in:
Luis Díaz Más 2022-02-20 09:22:55 +01:00
parent a357596a2e
commit 4163236e72
2 changed files with 2 additions and 17 deletions

View File

@ -181,7 +181,6 @@ int main(int argc, char* const argv[])
} }
taskFactory.cleanup(); taskFactory.cleanup();
Params::cleanup();
Exiv2::XmpParser::terminate(); Exiv2::XmpParser::terminate();
} }
} catch (const std::exception& exc) { } catch (const std::exception& exc) {
@ -195,7 +194,6 @@ int main(int argc, char* const argv[])
// ***************************************************************************** // *****************************************************************************
// class Params // class Params
Params* Params::instance_ = nullptr;
const Params::YodAdjust Params::emptyYodAdjust_[] = { const Params::YodAdjust Params::emptyYodAdjust_[] = {
{ false, "-Y", 0 }, { 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() Params& Params::instance()
{ {
if (nullptr == instance_) { static Params instance_;
instance_ = new Params; return instance_;
}
return *instance_;
}
void Params::cleanup()
{
delete instance_;
instance_ = nullptr;
} }
void Params::version(bool verbose, std::ostream& os) void Params::version(bool verbose, std::ostream& os)

View File

@ -148,9 +148,6 @@ public:
//! Prevent copy-construction: not implemented. //! Prevent copy-construction: not implemented.
Params(const Params& rhs) = delete; Params(const Params& rhs) = delete;
//! Destructor
static void cleanup();
//! Enumerates print modes //! Enumerates print modes
enum PrintMode { enum PrintMode {
pmSummary, pmSummary,
@ -244,8 +241,6 @@ public:
Exiv2::DataBuf stdinBuf; //!< DataBuf with the binary bytes from stdin Exiv2::DataBuf stdinBuf; //!< DataBuf with the binary bytes from stdin
private: private:
//! Pointer to the global Params object.
static Params* instance_;
//! Initializer for year, month and day adjustment info. //! Initializer for year, month and day adjustment info.
static const YodAdjust emptyYodAdjust_[]; static const YodAdjust emptyYodAdjust_[];