Loading...
Searching...
No Matches
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
109 TF_API
111
117 inline void TransportTo(TfErrorTransport &dest) const {
118 Transport().swap(dest);
119 }
120
136 Iterator GetBegin(size_t *nErrors = 0) const {
137 return
138 TfDiagnosticMgr::GetInstance()._GetErrorMarkBegin(_mark, nErrors);
139 }
140
145 Iterator GetEnd() const {
147 }
148
150 Iterator begin() const { return GetBegin(); }
151
153 Iterator end() const { return GetEnd(); }
154
155 private:
156 friend class TfDiagnosticMgr;
157
158 // Helper to check if the _mark identifies any errors present on the
159 // thread-local error list.
160 TF_API bool _IsCleanImpl(TfDiagnosticMgr &mgr) const;
161
162 void _ReportErrors(TfDiagnosticMgr &mgr) const;
163
164 size_t _mark;
165 void *_markKey = nullptr;
166};
167
168
184#define TF_HAS_ERRORS(marker, expr) \
185 (marker.SetMark(), (expr), !marker.IsClean())
186
194TF_API
196
197PXR_NAMESPACE_CLOSE_SCOPE
198
199#endif // PXR_BASE_TF_ERROR_MARK_H
Singleton class through which all errors and diagnostics pass.
static TF_API This & GetInstance()
Return the singleton instance.
ErrorIterator GetErrorEnd()
Return an iterator to the end of this thread's error list.
ErrorList::iterator ErrorIterator
Synonym for standard STL iterator to traverse the error list.
TF_API ErrorIterator EraseRange(ErrorIterator first, ErrorIterator last)
Remove all the errors in [first, last) from this thread's error stream.
Class used to record the end of the error-list.
Definition errorMark.h:48
Iterator begin() const
Equivalent to GetBegin()
Definition errorMark.h:150
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:153
void TransportTo(TfErrorTransport &dest) const
Remove all errors in this mark fom the error system and return them in a TfErrorTransport.
Definition errorMark.h:117
Iterator GetBegin(size_t *nErrors=0) const
Return an iterator to the first error added to the error list after SetMark().
Definition errorMark.h:136
TF_API TfErrorTransport Transport() const
Remove all errors in this mark fom the error system and return them in a TfErrorTransport.
Iterator GetEnd() const
Return an iterator past the last error in the error system.
Definition errorMark.h:145
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...