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) Lumiera.org
5  2018, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 */
22 
39 #ifndef LIB_ZOMBIE_CHECK_H
40 #define LIB_ZOMBIE_CHECK_H
41 
42 #include "lib/error.hpp"
43 
44 #include <cstring>
45 #include <string>
46 
47 
48 
49 namespace lib {
50  namespace error = lumiera::error;
51 
52  using std::string;
53 
54 
60  {
61  bool deceased_ = false;
62  char zombieID_[42]{};
63 
64  public:
71  ZombieCheck (string id)
72  {
73  std::strncpy(zombieID_, id.c_str(), 41);
74  }
75 
76  ZombieCheck() = default;
77  ~ZombieCheck()
78  {
79  deceased_ = true;
80  }
81 
82  operator bool() const
83  {
84  return deceased_;
85  }
86 
87  void
88  operator() () const
89  {
90  if (deceased_)
91  throw error::Fatal(buildDiagnosticMessage()
92  ,error::LUMIERA_ERROR_LIFECYCLE);
93  }
94 
95  private:
96  string
97  buildDiagnosticMessage() const
98  {
99  string msg{"Already deceased object called out of order during Application shutdown. "
100  "Lumiera Policy violated: Dependencies must not be used from destructors."};
101  if (zombieID_[0])
102  msg += " Offender = "+string{zombieID_};
103  return msg;
104  }
105  };
106 
107 
108 } // namespace lib
109 #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:199
Automatic lifecycle tracker, to produce an alarm when accessing objects after deletion.
Lumiera error handling (C++ interface).