| Flutter Impeller |

validation.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef FLUTTER_IMPELLER_BASE_VALIDATION_H_
6 #define FLUTTER_IMPELLER_BASE_VALIDATION_H_
7
8 #include <functional>
9 #include <sstream>
10
11 namespace impeller {
12
13 class ValidationLog {
14 public:
15 ValidationLog(const char* file, int line);
16
17 ~ValidationLog();
18
19 std::ostream& GetStream();
20
21 private:
22 const char* file_ = nullptr;
23 int line_ = 0;
24 std::ostringstream stream_;
25
26 ValidationLog(const ValidationLog&) = delete;
27
28 ValidationLog(ValidationLog&&) = delete;
29
30 ValidationLog& operator=(const ValidationLog&) = delete;
31
32 ValidationLog& operator=(ValidationLog&&) = delete;
33 };
34
35 void ImpellerValidationBreak(const char* message, const char* file, int line);
36
37 void ImpellerValidationErrorsSetFatal(bool fatal);
38
39 bool ImpellerValidationErrorsAreFatal();
40
41 using ValidationFailureCallback =
42 std::function<bool(const char* message, const char* file, int line)>;
43
44 //------------------------------------------------------------------------------
45 /// @brief Sets a callback that callers (usually tests) can set to
46 /// intercept validation failures.
47 ///
48 /// Returning true from the callback indicates that Impeller can
49 /// continue and avoid any default behavior on tripping validation
50 /// (which could include process termination).
51 ///
52 /// @param[in] callback The callback
53 ///
54 void ImpellerValidationErrorsSetCallback(ValidationFailureCallback callback);
55
56 struct ScopedValidationDisable {
57 ScopedValidationDisable();
58
59 ~ScopedValidationDisable();
60
61 ScopedValidationDisable(const ScopedValidationDisable&) = delete;
62
63 ScopedValidationDisable& operator=(const ScopedValidationDisable&) = delete;
64 };
65
66 struct ScopedValidationFatal {
67 ScopedValidationFatal();
68
69 ~ScopedValidationFatal();
70
71 ScopedValidationFatal(const ScopedValidationFatal&) = delete;
72
73 ScopedValidationFatal& operator=(const ScopedValidationFatal&) = delete;
74 };
75
76 } // namespace impeller
77
78 //------------------------------------------------------------------------------
79 /// Get a stream to the log Impeller uses for all validation errors. The
80 /// behavior of these logs is as follows:
81 ///
82 /// * Validation error are completely ignored in the Flutter release
83 /// runtime-mode.
84 /// * In non-release runtime-modes, validation logs are redirected to the
85 /// Flutter `INFO` log. These logs typically show up when verbose logging is
86 /// enabled.
87 /// * If `ImpellerValidationErrorsSetFatal` is set to `true`, validation logs
88 /// are fatal. The runtime-mode restriction still applies. This usually
89 /// happens in test environments.
90 ///
91 #define VALIDATION_LOG ::impeller::ValidationLog{__FILE__, __LINE__}.GetStream()
92
93 #endif // FLUTTER_IMPELLER_BASE_VALIDATION_H_
impeller::ScopedValidationFatal::ScopedValidationFatal
ScopedValidationFatal()
Definition: validation.cc:33
impeller::ScopedValidationDisable::~ScopedValidationDisable
~ScopedValidationDisable()
Definition: validation.cc:29
impeller::ScopedValidationFatal::~ScopedValidationFatal
~ScopedValidationFatal()
Definition: validation.cc:37
impeller::ValidationLog::~ValidationLog
~ValidationLog()
Definition: validation.cc:44
impeller::ScopedValidationFatal::operator=
ScopedValidationFatal & operator=(const ScopedValidationFatal &)=delete
impeller::ValidationFailureCallback
std::function< bool(const char *message, const char *file, int line)> ValidationFailureCallback
Definition: validation.h:42
impeller::ScopedValidationDisable::ScopedValidationDisable
ScopedValidationDisable()
Definition: validation.cc:25
impeller::ValidationLog
Definition: validation.h:13
impeller::ImpellerValidationErrorsSetFatal
void ImpellerValidationErrorsSetFatal(bool fatal)
Definition: validation.cc:17
impeller::ImpellerValidationErrorsAreFatal
bool ImpellerValidationErrorsAreFatal()
Definition: validation.cc:71
impeller::ScopedValidationFatal
Definition: validation.h:66
impeller::ValidationLog::ValidationLog
ValidationLog(const char *file, int line)
Definition: validation.cc:41
impeller::ImpellerValidationBreak
void ImpellerValidationBreak(const char *message, const char *file, int line)
Definition: validation.cc:54
impeller::ValidationLog::GetStream
std::ostream & GetStream()
Definition: validation.cc:50
impeller::ScopedValidationDisable::operator=
ScopedValidationDisable & operator=(const ScopedValidationDisable &)=delete
impeller::ScopedValidationDisable
Definition: validation.h:56
impeller
Definition: allocation.cc:12
impeller::ImpellerValidationErrorsSetCallback
void ImpellerValidationErrorsSetCallback(ValidationFailureCallback callback)
Sets a callback that callers (usually tests) can set to intercept validation failures.
Definition: validation.cc:21