This document is for a version of USD that is under development. See this page for the current release.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
diagnosticLite.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_DIAGNOSTIC_LITE_H
8#define PXR_BASE_TF_DIAGNOSTIC_LITE_H
9
24
25#include "pxr/pxr.h"
27#include "pxr/base/tf/api.h"
28#include "pxr/base/arch/buildMode.h"
29#include "pxr/base/arch/hints.h"
31
32#include <stddef.h>
33
34PXR_NAMESPACE_OPEN_SCOPE
35
38enum TfDiagnosticType : int {
39 TF_DIAGNOSTIC_INVALID_TYPE = 0,
40 TF_DIAGNOSTIC_CODING_ERROR_TYPE,
41 TF_DIAGNOSTIC_FATAL_CODING_ERROR_TYPE,
42 TF_DIAGNOSTIC_RUNTIME_ERROR_TYPE,
43 TF_DIAGNOSTIC_FATAL_ERROR_TYPE,
44 TF_DIAGNOSTIC_NONFATAL_ERROR_TYPE,
45 TF_DIAGNOSTIC_WARNING_TYPE,
46 TF_DIAGNOSTIC_STATUS_TYPE,
47 TF_APPLICATION_EXIT_TYPE,
48};
49
50
51#if !defined(doxygen)
52
53struct Tf_DiagnosticLiteHelper {
54 constexpr Tf_DiagnosticLiteHelper(TfCallContext const &context,
56 : _context(context),
57 _type(type)
58 {
59 }
60
61 TF_API void IssueError(
62 char const *fmt, ...) const ARCH_PRINTF_FUNCTION(2,3);
63 [[noreturn]]
64 TF_API void IssueFatalError(
65 char const *fmt, ...) const ARCH_PRINTF_FUNCTION(2,3);
66 TF_API void IssueWarning(
67 char const *fmt, ...) const ARCH_PRINTF_FUNCTION(2,3);
68 TF_API void IssueStatus(
69 char const *fmt, ...) const ARCH_PRINTF_FUNCTION(2,3);
70
71private:
72 TfCallContext _context;
73 TfDiagnosticType _type;
74};
75
76#define TF_CODING_ERROR \
77 Tf_DiagnosticLiteHelper(TF_CALL_CONTEXT, \
78 TF_DIAGNOSTIC_CODING_ERROR_TYPE).IssueError
79
80#define TF_CODING_WARNING \
81 Tf_DiagnosticLiteHelper(TF_CALL_CONTEXT, \
82 TF_DIAGNOSTIC_CODING_ERROR_TYPE).IssueWarning \
83
84#define TF_FATAL_CODING_ERROR \
85 Tf_DiagnosticLiteHelper(TF_CALL_CONTEXT, \
86 TF_DIAGNOSTIC_CODING_ERROR_TYPE).IssueFatalError
87
88#define TF_RUNTIME_ERROR \
89 Tf_DiagnosticLiteHelper(TF_CALL_CONTEXT, \
90 TF_DIAGNOSTIC_RUNTIME_ERROR_TYPE).IssueError
91
92#define TF_FATAL_ERROR \
93 Tf_DiagnosticLiteHelper(TF_CALL_CONTEXT, \
94 TF_DIAGNOSTIC_FATAL_ERROR_TYPE).IssueFatalError
95
96#define TF_DIAGNOSTIC_FATAL_ERROR \
97 Tf_DiagnosticLiteHelper(TF_CALL_CONTEXT, \
98 TF_DIAGNOSTIC_RUNTIME_ERROR_TYPE).IssueFatalError
99
100#define TF_DIAGNOSTIC_NONFATAL_ERROR \
101 Tf_DiagnosticLiteHelper(TF_CALL_CONTEXT, \
102 TF_DIAGNOSTIC_WARNING_TYPE).IssueWarning
103
104#define TF_DIAGNOSTIC_WARNING \
105 Tf_DiagnosticLiteHelper(TF_CALL_CONTEXT.Hide(), \
106 TF_DIAGNOSTIC_WARNING_TYPE).IssueWarning
107
108#define TF_WARN \
109 Tf_DiagnosticLiteHelper(TF_CALL_CONTEXT, \
110 TF_DIAGNOSTIC_WARNING_TYPE).IssueWarning
111
112#define TF_STATUS \
113 Tf_DiagnosticLiteHelper(TF_CALL_CONTEXT, \
114 TF_DIAGNOSTIC_STATUS_TYPE).IssueStatus
115
116constexpr bool
117Tf_AxiomHelper(bool val, TfCallContext const &ctx, char const *txt) {
118 return (ARCH_LIKELY(val)) ? true :
119 (Tf_DiagnosticLiteHelper(ctx, TF_DIAGNOSTIC_FATAL_ERROR_TYPE).
120 IssueFatalError("Failed axiom: ' %s '", txt), false);
121}
122
123#define TF_AXIOM(cond) \
124 Tf_AxiomHelper(static_cast<bool>((cond)), TF_CALL_CONTEXT, #cond)
125
126#define TF_DEV_AXIOM(cond) \
127 Tf_AxiomHelper(!ARCH_DEV_BUILD || \
128 static_cast<bool>((cond)), TF_CALL_CONTEXT, #cond)
129
130#endif // !defined(doxygen)
131
132PXR_NAMESPACE_CLOSE_SCOPE
133
134#endif // PXR_BASE_TF_DIAGNOSTIC_LITE_H
Define function attributes.
#define ARCH_PRINTF_FUNCTION(_fmt, _firstArg)
Macro used to indicate a function takes a printf-like specification.
Definition: attributes.h:34
Functions for recording call locations.
TfDiagnosticType
Enum describing various diagnostic conditions.
Compiler hints.