errorMark.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PXR_BASE_TF_ERROR_MARK_H
25 #define PXR_BASE_TF_ERROR_MARK_H
26 
28 
29 #include "pxr/pxr.h"
32 #include "pxr/base/tf/api.h"
33 
34 #include <boost/noncopyable.hpp>
35 
36 PXR_NAMESPACE_OPEN_SCOPE
37 
66 class TfErrorMark : boost::noncopyable
67 {
68  public:
69 
70  typedef TfDiagnosticMgr::ErrorIterator Iterator;
71 
76  TF_API TfErrorMark();
77 
83  TF_API ~TfErrorMark();
84 
88  inline void SetMark() {
89  _mark = TfDiagnosticMgr::GetInstance()._nextSerial;
90  }
91 
99  inline bool IsClean() const {
101  return _mark >= mgr._nextSerial || _IsCleanImpl(mgr);
102  }
103 
109  inline bool Clear() const {
111  auto b = GetBegin(), e = mgr.GetErrorEnd();
112  if (b != e) {
113  mgr.EraseRange(b, e);
114  return true;
115  }
116  return false;
117  }
118 
126  inline TfErrorTransport Transport() const {
128  return TfErrorTransport(mgr._errorList.local(),
129  GetBegin(), mgr.GetErrorEnd());
130  }
131 
137  inline void TransportTo(TfErrorTransport &dest) const {
138  Transport().swap(dest);
139  }
140 
156  Iterator GetBegin(size_t *nErrors = 0) const {
157  return
158  TfDiagnosticMgr::GetInstance()._GetErrorMarkBegin(_mark, nErrors);
159  }
160 
165  Iterator GetEnd() const {
167  }
168 
170  Iterator begin() const { return GetBegin(); }
171 
173  Iterator end() const { return GetEnd(); }
174 
175  private:
176  friend class TfDiagnosticMgr;
177 
178  // Helper to check if the _mark identifies any errors present on the
179  // thread-local error list.
180  TF_API bool _IsCleanImpl(TfDiagnosticMgr &mgr) const;
181 
182  void _ReportErrors(TfDiagnosticMgr &mgr) const;
183 
184  size_t _mark;
185 };
186 
187 
203 #define TF_HAS_ERRORS(marker, expr) \
204  (marker.SetMark(), (expr), !marker.IsClean())
205 
213 TF_API
215 
216 PXR_NAMESPACE_CLOSE_SCOPE
217 
218 #endif // PXR_BASE_TF_ERROR_MARK_H
TF_API ~TfErrorMark()
Destroy this ErrorMark.
Singleton class through which all errors and diagnostics pass.
Definition: diagnosticMgr.h:71
Iterator GetEnd() const
Return an iterator past the last error in the error system.
Definition: errorMark.h:165
void TransportTo(TfErrorTransport &dest) const
Remove all errors in this mark fom the error system and return them in a TfErrorTransport.
Definition: errorMark.h:137
TF_API void TfReportActiveErrorMarks()
Report current TfErrorMark instances and the stack traces that created them to stdout for debugging p...
ErrorIterator GetErrorEnd()
Return an iterator to the end of this thread's error list.
static TF_API This & GetInstance()
Return the singleton instance.
Iterator begin() const
Equivalent to GetBegin()
Definition: errorMark.h:170
Iterator GetBegin(size_t *nErrors=0) const
Return an iterator to the first error added to the error list after SetMark().
Definition: errorMark.h:156
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:66
TF_API TfErrorMark()
Default constructor.
void swap(TfErrorTransport &other)
Swap this TfErrorTransport's content with other.
TfErrorTransport Transport() const
Remove all errors in this mark fom the error system and return them in a TfErrorTransport.
Definition: errorMark.h:126
bool Clear() const
Remove all errors in this mark from the error system.
Definition: errorMark.h:109
Iterator end() const
Equivalent to GetEnd()
Definition: errorMark.h:173
bool IsClean() const
Return true if no new errors were posted in this thread since the last call to SetMark(),...
Definition: errorMark.h:99
ErrorList::iterator ErrorIterator
Synonym for standard STL iterator to traverse the error list.
Definition: diagnosticMgr.h:96
void SetMark()
Record future errors.
Definition: errorMark.h:88
A facility for transporting errors from thread to thread.