]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Lazily initialize JobIdentifier's global variables
authorDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Sun, 18 Nov 2018 11:32:25 +0000 (12:32 +0100)
committerDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Sun, 18 Nov 2018 11:32:25 +0000 (12:32 +0100)
include/deal.II/base/job_identifier.h
source/base/job_identifier.cc
source/base/logstream.cc
tests/base/base_name.cc

index 7763c5e110878a396b1ee4d6f89760af68f7a6d3..82ed5496fca2247dab7e7d79ec30605f87ba8ecc 100644 (file)
@@ -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
index ef0f1c2ccff088c450f2aa3abf1029afe33f7c7c..885fa8651151fdfd616dce9f36d449f6ce87245b 100644 (file)
 DEAL_II_NAMESPACE_OPEN
 
 
-JobIdentifier dealjobid;
+const JobIdentifier &
+JobIdentifier::get_dealjobid()
+{
+  static JobIdentifier dealjobid;
+  return dealjobid;
+}
+
 
 
 JobIdentifier::JobIdentifier()
index 556bb5a1256bdd07f3715b342fadd60f1c78fc81..4ed0dfb64a605c7e2c82156bf1902c312f154aeb 100644 (file)
@@ -223,7 +223,7 @@ LogStream::attach(std::ostream &                o,
   file = &o;
   o.setf(flags);
   if (print_job_id)
-    o << dealjobid();
+    o << JobIdentifier::get_dealjobid()();
 }
 
 
index d747f604e12e3d1314250a1a094f7f402350be01..95ed29d11c85a6f08c58ca4d4987d8538c526bcc 100644 (file)
@@ -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;
 }

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.