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 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_TRANSPORT_H
25 #define PXR_BASE_TF_ERROR_TRANSPORT_H
26 
27 /// \file tf/errorTransport.h
28 
29 #include "pxr/pxr.h"
31 #include "pxr/base/arch/hints.h"
32 #include "pxr/base/tf/api.h"
33 
35 
36 /// \class TfErrorTransport
37 ///
38 /// A facility for transporting errors from thread to thread.
39 ///
40 /// Typical use is to create a TfErrorMark in the thread that is the error
41 /// source (e.g. the child thread), then call TfErrorMark::Transport() or
42 /// TfErrorMark::TransportTo() to lift generated errors out into a
43 /// TfErrorTransport object. Later the thread that wants to sink those errors
44 /// (e.g. the parent thread) invokes TfErrorTransport::Post() to post all
45 /// contained errors to its own thread's error list.
47 {
48 public:
50 
51  /// Construct an empty TfErrorTransport.
53 
54  /// Post all contained errors to the current thread's error list, leaving
55  /// this TfErrorTransport empty.
56  void Post() {
57  if (ARCH_UNLIKELY(!IsEmpty()))
58  _PostImpl();
59  }
60 
61  /// Return true if this TfErrorTransport contains no errors, false
62  /// otherwise.
63  bool IsEmpty() const { return _errorList.empty(); }
64 
65  /// Swap this TfErrorTransport's content with \p other. This provides a
66  /// lightweight way to move the contents of one TfErrorTransport to
67  /// another.
68  void swap(TfErrorTransport &other) {
69  _errorList.swap(other._errorList);
70  }
71 
72 private:
73  friend class TfErrorMark;
74 
76  ErrorList::iterator first,
77  ErrorList::iterator last) {
78  _errorList.splice(_errorList.begin(), src, first, last);
79  }
80 
81  TF_API
82  void _PostImpl();
83 
84  ErrorList _errorList;
85 };
86 
87 inline void
89 {
90  l.swap(r);
91 }
92 
94 
95 #endif // PXR_BASE_TF_ERROR_TRANSPORT_H
void swap(ArAssetInfo &lhs, ArAssetInfo &rhs)
Definition: assetInfo.h:60
GLenum src
Definition: glew.h:2410
#define TF_API
Definition: api.h:40
void swap(TfErrorTransport &other)
const GLint * first
Definition: glew.h:1528
GLdouble l
Definition: glew.h:9122
TfErrorTransport()
Construct an empty TfErrorTransport.
#define ARCH_UNLIKELY(x)
Definition: hints.h:47
std::list< TfError > ErrorList
Definition: diagnosticMgr.h:76
TfDiagnosticMgr::ErrorList ErrorList
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1346
GLdouble GLdouble GLdouble r
Definition: glew.h:1406
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
bool IsEmpty() const