HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
errorTransport.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_TRANSPORT_H
8 #define PXR_BASE_TF_ERROR_TRANSPORT_H
9 
10 /// \file tf/errorTransport.h
11 
12 #include "pxr/pxr.h"
14 #include "pxr/base/arch/hints.h"
15 #include "pxr/base/tf/api.h"
16 
18 
19 /// \class TfErrorTransport
20 ///
21 /// A facility for transporting errors from thread to thread.
22 ///
23 /// Typical use is to create a TfErrorMark in the thread that is the error
24 /// source (e.g. the child thread), then call TfErrorMark::Transport() or
25 /// TfErrorMark::TransportTo() to lift generated errors out into a
26 /// TfErrorTransport object. Later the thread that wants to sink those errors
27 /// (e.g. the parent thread) invokes TfErrorTransport::Post() to post all
28 /// contained errors to its own thread's error list.
30 {
31 public:
33 
34  /// Construct an empty TfErrorTransport.
36 
37  /// Post all contained errors to the current thread's error list, leaving
38  /// this TfErrorTransport empty.
39  void Post() {
40  if (ARCH_UNLIKELY(!IsEmpty()))
41  _PostImpl();
42  }
43 
44  /// Return true if this TfErrorTransport contains no errors, false
45  /// otherwise.
46  bool IsEmpty() const { return _errorList.empty(); }
47 
48  /// Swap this TfErrorTransport's content with \p other. This provides a
49  /// lightweight way to move the contents of one TfErrorTransport to
50  /// another.
51  void swap(TfErrorTransport &other) {
52  _errorList.swap(other._errorList);
53  }
54 
55 private:
56  friend class TfErrorMark;
57 
59  ErrorList::iterator first,
60  ErrorList::iterator last) {
61  _errorList.splice(_errorList.begin(), src, first, last);
62  }
63 
64  TF_API
65  void _PostImpl();
66 
67  ErrorList _errorList;
68 };
69 
70 inline void
72 {
73  l.swap(r);
74 }
75 
77 
78 #endif // PXR_BASE_TF_ERROR_TRANSPORT_H
void swap(ArAssetInfo &lhs, ArAssetInfo &rhs)
Definition: assetInfo.h:57
GLint first
Definition: glcorearb.h:405
#define TF_API
Definition: api.h:23
void swap(TfErrorTransport &other)
TfErrorTransport()
Construct an empty TfErrorTransport.
#define ARCH_UNLIKELY(x)
Definition: hints.h:30
std::list< TfError > ErrorList
Definition: diagnosticMgr.h:59
TfDiagnosticMgr::ErrorList ErrorList
__hostdev__ uint64_t last(uint32_t i) const
Definition: NanoVDB.h:5976
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
GLboolean r
Definition: glcorearb.h:1222
bool IsEmpty() const
GLenum src
Definition: glcorearb.h:1793