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 
14  public:
15  ValidationLog(const char* file, int line);
16 
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 
40 
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 ///
55 
58 
60 
62 
64 };
65 
68 
70 
72 
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_
ValidationLog(const char *file, int line)
Definition: validation.cc:41
std::ostream & GetStream()
Definition: validation.cc:50
std::function< bool(const char *message, const char *file, int line)> ValidationFailureCallback
Definition: validation.h:42
void ImpellerValidationBreak(const char *message, const char *file, int line)
Definition: validation.cc:54
void ImpellerValidationErrorsSetCallback(ValidationFailureCallback callback)
Sets a callback that callers (usually tests) can set to intercept validation failures.
Definition: validation.cc:21
bool ImpellerValidationErrorsAreFatal()
Definition: validation.cc:71
void ImpellerValidationErrorsSetFatal(bool fatal)
Definition: validation.cc:17
ScopedValidationDisable(const ScopedValidationDisable &)=delete
ScopedValidationDisable & operator=(const ScopedValidationDisable &)=delete
ScopedValidationFatal & operator=(const ScopedValidationFatal &)=delete
ScopedValidationFatal(const ScopedValidationFatal &)=delete