Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
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
40namespace 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;
69 {
70 deceased_ = true;
71 }
72
73 operator bool() const
74 {
75 return deceased_;
76 }
77
78 void
80 {
81 if (deceased_)
83 ,error::LUMIERA_ERROR_LIFECYCLE);
84 }
85
86 private:
87 string
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*/
Automatic lifecycle tracker, to produce an alarm when accessing objects after deletion.
ZombieCheck()=default
ZombieCheck(string id)
install a zombie check, tagged with the given id.
string buildDiagnosticMessage() const
void operator()() const
Lumiera error handling (C++ interface).
Implementation namespace for support and library code.
LumieraError< LERR_(FATAL), Logic > Fatal
Definition error.hpp:208