Lumiera  0.pre.03
»edit your freedom«
zombie-check.hpp
Go to the documentation of this file.
1 /*
2  ZOMBIE-CHECK.hpp - flatliner self-detection
3 
4  Copyright (C)
5  2018, Hermann Vosseler <Ichthyostega@web.de>
6 
7   **Lumiera** is free software; you can redistribute it and/or modify it
8   under the terms of the GNU General Public License as published by the
9   Free Software Foundation; either version 2 of the License, or (at your
10   option) any later version. See the file COPYING for further details.
11 
12 */
13 
30 #ifndef LIB_ZOMBIE_CHECK_H
31 #define LIB_ZOMBIE_CHECK_H
32 
33 #include "lib/error.hpp"
34 
35 #include <cstring>
36 #include <string>
37 
38 
39 
40 namespace lib {
41  namespace error = lumiera::error;
42 
43  using std::string;
44 
45 
51  {
52  bool deceased_ = false;
53  char zombieID_[42]{};
54 
55  public:
62  ZombieCheck (string id)
63  {
64  std::strncpy(zombieID_, id.c_str(), 41);
65  }
66 
67  ZombieCheck() = default;
68  ~ZombieCheck()
69  {
70  deceased_ = true;
71  }
72 
73  operator bool() const
74  {
75  return deceased_;
76  }
77 
78  void
79  operator() () const
80  {
81  if (deceased_)
82  throw error::Fatal(buildDiagnosticMessage()
83  ,error::LUMIERA_ERROR_LIFECYCLE);
84  }
85 
86  private:
87  string
88  buildDiagnosticMessage() const
89  {
90  string msg{"Already deceased object called out of order during Application shutdown. "
91  "Lumiera Policy violated: Dependencies must not be used from destructors."};
92  if (zombieID_[0])
93  msg += " Offender = "+string{zombieID_};
94  return msg;
95  }
96  };
97 
98 
99 } // namespace lib
100 #endif /*LIB_ZOMBIE_CHECK_H*/
ZombieCheck(string id)
install a zombie check, tagged with the given id.
Implementation namespace for support and library code.
Derived specific exceptions within Lumiera&#39;s exception hierarchy.
Definition: error.hpp:190
Automatic lifecycle tracker, to produce an alarm when accessing objects after deletion.
Lumiera error handling (C++ interface).