From f1ef97d1b62641a847dd1ebdd6c5ce6a983ed799 Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Sun, 18 Nov 2018 12:32:25 +0100 Subject: [PATCH] Lazily initialize JobIdentifier's global variables --- include/deal.II/base/job_identifier.h | 14 ++++++-------- source/base/job_identifier.cc | 8 +++++++- source/base/logstream.cc | 2 +- tests/base/base_name.cc | 7 ++++--- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/include/deal.II/base/job_identifier.h b/include/deal.II/base/job_identifier.h index 7763c5e110..82ed5496fc 100644 --- a/include/deal.II/base/job_identifier.h +++ b/include/deal.II/base/job_identifier.h @@ -66,6 +66,12 @@ public: const std::string operator()() const; + /** + * Function to identify the presently running program. + */ + static const JobIdentifier & + get_dealjobid(); + private: /** * String holding the identifier of the presently running program. @@ -73,14 +79,6 @@ private: std::string id; }; - -/*----------------------------- Inline functions ----------------------------*/ - - -/** - * Global object to identify the presently running program. - */ -extern JobIdentifier dealjobid; DEAL_II_NAMESPACE_CLOSE #endif diff --git a/source/base/job_identifier.cc b/source/base/job_identifier.cc index ef0f1c2ccf..885fa86511 100644 --- a/source/base/job_identifier.cc +++ b/source/base/job_identifier.cc @@ -24,7 +24,13 @@ DEAL_II_NAMESPACE_OPEN -JobIdentifier dealjobid; +const JobIdentifier & +JobIdentifier::get_dealjobid() +{ + static JobIdentifier dealjobid; + return dealjobid; +} + JobIdentifier::JobIdentifier() diff --git a/source/base/logstream.cc b/source/base/logstream.cc index 556bb5a125..4ed0dfb64a 100644 --- a/source/base/logstream.cc +++ b/source/base/logstream.cc @@ -223,7 +223,7 @@ LogStream::attach(std::ostream & o, file = &o; o.setf(flags); if (print_job_id) - o << dealjobid(); + o << JobIdentifier::get_dealjobid()(); } diff --git a/tests/base/base_name.cc b/tests/base/base_name.cc index d747f604e1..95ed29d11c 100644 --- a/tests/base/base_name.cc +++ b/tests/base/base_name.cc @@ -22,9 +22,10 @@ main() { initlog(); - deallog << dealjobid.base_name("mypath/test.cc") << std::endl; - ; - deallog << dealjobid.base_name("/foo.bar/mypath/test.cc") << std::endl; + deallog << JobIdentifier::get_dealjobid().base_name("mypath/test.cc") + << std::endl; + deallog << JobIdentifier::get_dealjobid().base_name("/foo.bar/mypath/test.cc") + << std::endl; return 0; } -- 2.39.5