7#ifndef PXR_BASE_TF_DIAGNOSTIC_CONTAINER_H
8#define PXR_BASE_TF_DIAGNOSTIC_CONTAINER_H
13#include "pxr/base/tf/api.h"
15#include "pxr/base/tf/status.h"
17#include "pxr/base/tf/warning.h"
25PXR_NAMESPACE_OPEN_SCOPE
33class Tf_DiagnosticContainer
47 explicit Iterator(Tf_DiagnosticContainer
const &container,
49 : _container(container) {
51 while (skip-- > 0 && _orderIndex < _container._order.size()) {
52 switch (_container._order[_orderIndex++]) {
53 case
'E': ++_errorIndex; break;
54 case
'W': ++_warningIndex; break;
55 case
'S': ++_statusIndex; break;
63 using RetT =
typename _IterNextReturnType<Fn>::Type;
65 while (_orderIndex < _container._order.size()) {
66 char c = _container._order[_orderIndex++];
70 fn, _container._errors[_errorIndex++])) {
76 fn, _container._warnings[_warningIndex++])) {
82 fn, _container._statuses[_statusIndex++])) {
92 Tf_DiagnosticContainer
const &_container;
93 size_t _orderIndex = 0;
94 size_t _errorIndex = 0;
95 size_t _warningIndex = 0;
96 size_t _statusIndex = 0;
100 bool IsEmpty()
const {
return _order.empty(); }
103 size_t size()
const {
return _order.size(); }
106 std::vector<TfError>
const&
GetErrors()
const {
return _errors; }
109 std::vector<TfWarning>
const& GetWarnings()
const {
return _warnings; }
112 std::vector<TfStatus>
const& GetStatuses()
const {
return _statuses; }
116 void Append(
TfError const &e) {
117 _errors.push_back(e);
118 _order.push_back(
'E');
122 _warnings.push_back(w);
123 _order.push_back(
'W');
127 _statuses.push_back(s);
128 _order.push_back(
'S');
143 Iterator GetIterator(
size_t skip = 0)
const {
144 return Iterator(*
this, skip);
154 template <
class Fn,
class Arg,
bool Invocable>
155 struct _SafeInvokeResult {
159 template <
class Fn,
class Arg>
160 struct _SafeInvokeResult<Fn, Arg, true> {
161 using type = std::invoke_result_t<Fn, Arg>;
165 struct _IterNextReturnType {
166 static constexpr bool _ErrInvocable =
167 std::is_invocable_v<Fn, TfError const &>;
168 static constexpr bool _WarnInvocable =
169 std::is_invocable_v<Fn, TfWarning const &>;
170 static constexpr bool _StatInvocable =
171 std::is_invocable_v<Fn, TfStatus const &>;
173 static_assert(_ErrInvocable || _WarnInvocable || _StatInvocable,
174 "Callable must be invocable with at least one of "
175 "TfError, TfWarning, or TfStatus");
177 using _ErrResult =
typename _SafeInvokeResult<
178 Fn,
TfError const &, _ErrInvocable>::type;
179 using _WarnResult =
typename _SafeInvokeResult<
180 Fn,
TfWarning const &, _WarnInvocable>::type;
181 using _StatResult =
typename _SafeInvokeResult<
182 Fn,
TfStatus const &, _StatInvocable>::type;
184 using Type = std::conditional_t<
185 _ErrInvocable, _ErrResult,
187 _WarnInvocable, _WarnResult, _StatResult>>;
189 static_assert(!_ErrInvocable || !_WarnInvocable ||
190 std::is_same_v<_ErrResult, _WarnResult>,
191 "Callable must return the same type for all "
192 "invocable diagnostic types");
193 static_assert(!_ErrInvocable || !_StatInvocable ||
194 std::is_same_v<_ErrResult, _StatResult>,
195 "Callable must return the same type for all "
196 "invocable diagnostic types");
197 static_assert(!_WarnInvocable || !_StatInvocable ||
198 std::is_same_v<_WarnResult, _StatResult>,
199 "Callable must return the same type for all "
200 "invocable diagnostic types");
203 std::vector<TfError> _errors;
204 std::vector<TfWarning> _warnings;
205 std::vector<TfStatus> _statuses;
209PXR_NAMESPACE_CLOSE_SCOPE
Provide facilities for error handling in script.
Represents an object that contains error information.
Represents an object that contains information about a status message.
Represents an object that contains information about a warning.
constexpr auto TfNotInvoked()
Return the result type of TfTryInvoke<Ret> in the case where the function was not invoked – false if ...
auto TfTryInvoke(Fn &&fn, Args &&...args)
Invoke fn with args if fn is invocable with those arguments and return a result that indicates both w...
SDF_API const std::vector< std::string > & GetErrors() const
Returns a list of errors encountered when parsing this expression.