Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
diagnostic-context.hpp
Go to the documentation of this file.
1/*
2 DIAGNOSTIC-CONTEXT.hpp - thread local stack for explicitly collecting diagnostic context info
3
4 Copyright (C)
5 2010, 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
28#ifndef LIB_DIAGNOSTIC_CONTEXT_H
29#define LIB_DIAGNOSTIC_CONTEXT_H
30
31
32#include "lib/error.hpp"
33#include "lib/nocopy.hpp"
34
35
36
37namespace lib {
38
39
40
41
50 template<typename VAL>
53 {
54 using ValSequence = std::vector<VAL>;
55
56 const VAL value_;
58
61 static DiagnosticContext* &
63 {
64 thread_local DiagnosticContext* accessPoint;
65 return accessPoint;
66 }
67
68
69 public:
70 DiagnosticContext(VAL const& value_to_log = VAL())
71 : value_{value_to_log}
72 , prev_{current()}
73 {
74 current() = this;
75 }
76
78 {
79 ASSERT (this == current());
80 current() = prev_;
81 }
82
83
84 operator VAL const&()
85 {
86 return value_;
87 }
88
90 static DiagnosticContext&
92 {
93 DiagnosticContext* innermost = current();
94 if (!innermost)
95 throw lumiera::error::Logic ("Accessing Diagnostic context out of order; "
96 "an instance should have been created within "
97 "an enclosing scope");
98 return *innermost;
99 }
100
101
109 static ValSequence
111 {
112 ValSequence loggedValues;
113 DiagnosticContext* next = current();
114 while (next)
115 {
116 loggedValues.push_back (*next);
117 next = next->prev_;
118 }
119 return loggedValues;
120 }
121 };
122
123
124
125
126
127} // namespace lib
128#endif
Diagnostic data frame to collect specific information concerning a scope.
static DiagnosticContext & access()
accessing the innermost diagnostic context created
DiagnosticContext *const prev_
std::vector< VAL > ValSequence
static DiagnosticContext *& current()
embedded thread local pointer to the innermost context encountered
DiagnosticContext(VAL const &value_to_log=VAL())
static ValSequence extractStack()
snapshot of the current stack of diagnostic frames
Any copy and copy construction prohibited.
Definition nocopy.hpp:38
Lumiera error handling (C++ interface).
Implementation namespace for support and library code.
LumieraError< LERR_(LOGIC)> Logic
Definition error.hpp:207
Mix-Ins to allow or prohibit various degrees of copying and cloning.