All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
errorMark.h
Go to the documentation of this file.
1//
2// Copyright 2016 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_BASE_TF_ERROR_MARK_H
8#define PXR_BASE_TF_ERROR_MARK_H
9
11
12#include "pxr/pxr.h"
15#include "pxr/base/tf/api.h"
16
17PXR_NAMESPACE_OPEN_SCOPE
18
48{
49 TfErrorMark(const TfErrorMark&) = delete;
50 TfErrorMark& operator=(const TfErrorMark&) = delete;
51 public:
52
53 typedef TfDiagnosticMgr::ErrorIterator Iterator;
54
59 TF_API TfErrorMark();
60
66 TF_API ~TfErrorMark();
67
71 inline void SetMark() {
72 _mark = TfDiagnosticMgr::GetInstance()._nextSerial;
73 }
74
82 inline bool IsClean() const {
84 return _mark >= mgr._nextSerial || _IsCleanImpl(mgr);
85 }
86
92 inline bool Clear() const {
94 auto b = GetBegin(), e = mgr.GetErrorEnd();
95 if (b != e) {
96 mgr.EraseRange(b, e);
97 return true;
98 }
99 return false;
100 }
101
111 return TfErrorTransport(mgr._errorList.local(),
112 GetBegin(), mgr.GetErrorEnd());
113 }
114
120 inline void TransportTo(TfErrorTransport &dest) const {
121 Transport().swap(dest);
122 }
123
139 Iterator GetBegin(size_t *nErrors = 0) const {
140 return
141 TfDiagnosticMgr::GetInstance()._GetErrorMarkBegin(_mark, nErrors);
142 }
143
148 Iterator GetEnd() const {
150 }
151
153 Iterator begin() const { return GetBegin(); }
154
156 Iterator end() const { return GetEnd(); }
157
158 private:
159 friend class TfDiagnosticMgr;
160
161 // Helper to check if the _mark identifies any errors present on the
162 // thread-local error list.
163 TF_API bool _IsCleanImpl(TfDiagnosticMgr &mgr) const;
164
165 void _ReportErrors(TfDiagnosticMgr &mgr) const;
166
167 size_t _mark;
168};
169
170
186#define TF_HAS_ERRORS(marker, expr) \
187 (marker.SetMark(), (expr), !marker.IsClean())
188
196TF_API
198
199PXR_NAMESPACE_CLOSE_SCOPE
200
201#endif // PXR_BASE_TF_ERROR_MARK_H
Singleton class through which all errors and diagnostics pass.
Definition: diagnosticMgr.h:54
static TF_API This & GetInstance()
Return the singleton instance.
ErrorIterator GetErrorEnd()
Return an iterator to the end of this thread's error list.
TF_API ErrorIterator EraseRange(ErrorIterator first, ErrorIterator last)
Remove all the errors in [first, last) from this thread's error stream.
ErrorList::iterator ErrorIterator
Synonym for standard STL iterator to traverse the error list.
Definition: diagnosticMgr.h:79
Class used to record the end of the error-list.
Definition: errorMark.h:48
Iterator begin() const
Equivalent to GetBegin()
Definition: errorMark.h:153
bool Clear() const
Remove all errors in this mark from the error system.
Definition: errorMark.h:92
TF_API ~TfErrorMark()
Destroy this ErrorMark.
TF_API TfErrorMark()
Default constructor.
Iterator end() const
Equivalent to GetEnd()
Definition: errorMark.h:156
void TransportTo(TfErrorTransport &dest) const
Remove all errors in this mark fom the error system and return them in a TfErrorTransport.
Definition: errorMark.h:120
Iterator GetBegin(size_t *nErrors=0) const
Return an iterator to the first error added to the error list after SetMark().
Definition: errorMark.h:139
TfErrorTransport Transport() const
Remove all errors in this mark fom the error system and return them in a TfErrorTransport.
Definition: errorMark.h:109
Iterator GetEnd() const
Return an iterator past the last error in the error system.
Definition: errorMark.h:148
bool IsClean() const
Return true if no new errors were posted in this thread since the last call to SetMark(),...
Definition: errorMark.h:82
void SetMark()
Record future errors.
Definition: errorMark.h:71
A facility for transporting errors from thread to thread.
void swap(TfErrorTransport &other)
Swap this TfErrorTransport's content with other.
TF_API void TfReportActiveErrorMarks()
Report current TfErrorMark instances and the stack traces that created them to stdout for debugging p...