diagnosticLite.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_DIAGNOSTIC_LITE_H
25 #define PXR_BASE_TF_DIAGNOSTIC_LITE_H
26 
41 
42 #include "pxr/pxr.h"
44 #include "pxr/base/tf/api.h"
45 #include "pxr/base/arch/buildMode.h"
46 #include "pxr/base/arch/hints.h"
48 
49 #include <stddef.h>
50 
51 PXR_NAMESPACE_OPEN_SCOPE
52 
55 enum TfDiagnosticType : int {
56  TF_DIAGNOSTIC_INVALID_TYPE = 0,
57  TF_DIAGNOSTIC_CODING_ERROR_TYPE,
58  TF_DIAGNOSTIC_FATAL_CODING_ERROR_TYPE,
59  TF_DIAGNOSTIC_RUNTIME_ERROR_TYPE,
60  TF_DIAGNOSTIC_FATAL_ERROR_TYPE,
61  TF_DIAGNOSTIC_NONFATAL_ERROR_TYPE,
62  TF_DIAGNOSTIC_WARNING_TYPE,
63  TF_DIAGNOSTIC_STATUS_TYPE,
64  TF_APPLICATION_EXIT_TYPE,
65 };
66 
67 
68 #if !defined(doxygen)
69 
70 struct Tf_DiagnosticLiteHelper {
71  constexpr Tf_DiagnosticLiteHelper(TfCallContext const &context,
72  TfDiagnosticType type)
73  : _context(context),
74  _type(type)
75  {
76  }
77 
78  TF_API void IssueError(
79  char const *fmt, ...) const ARCH_PRINTF_FUNCTION(2,3);
80  [[noreturn]]
81  TF_API void IssueFatalError(
82  char const *fmt, ...) const ARCH_PRINTF_FUNCTION(2,3);
83  TF_API void IssueWarning(
84  char const *fmt, ...) const ARCH_PRINTF_FUNCTION(2,3);
85  TF_API void IssueStatus(
86  char const *fmt, ...) const ARCH_PRINTF_FUNCTION(2,3);
87 
88 private:
89  TfCallContext _context;
90  TfDiagnosticType _type;
91 };
92 
93 #define TF_CODING_ERROR \
94  Tf_DiagnosticLiteHelper(TF_CALL_CONTEXT, \
95  TF_DIAGNOSTIC_CODING_ERROR_TYPE).IssueError
96 
97 #define TF_CODING_WARNING \
98  Tf_DiagnosticLiteHelper(TF_CALL_CONTEXT, \
99  TF_DIAGNOSTIC_CODING_ERROR_TYPE).IssueWarning \
100 
101 #define TF_FATAL_CODING_ERROR \
102  Tf_DiagnosticLiteHelper(TF_CALL_CONTEXT, \
103  TF_DIAGNOSTIC_CODING_ERROR_TYPE).IssueFatalError
104 
105 #define TF_RUNTIME_ERROR \
106  Tf_DiagnosticLiteHelper(TF_CALL_CONTEXT, \
107  TF_DIAGNOSTIC_RUNTIME_ERROR_TYPE).IssueError
108 
109 #define TF_FATAL_ERROR \
110  Tf_DiagnosticLiteHelper(TF_CALL_CONTEXT, \
111  TF_DIAGNOSTIC_FATAL_ERROR_TYPE).IssueFatalError
112 
113 #define TF_DIAGNOSTIC_FATAL_ERROR \
114  Tf_DiagnosticLiteHelper(TF_CALL_CONTEXT, \
115  TF_DIAGNOSTIC_RUNTIME_ERROR_TYPE).IssueFatalError
116 
117 #define TF_DIAGNOSTIC_NONFATAL_ERROR \
118  Tf_DiagnosticLiteHelper(TF_CALL_CONTEXT, \
119  TF_DIAGNOSTIC_WARNING_TYPE).IssueWarning
120 
121 #define TF_DIAGNOSTIC_WARNING \
122  Tf_DiagnosticLiteHelper(TF_CALL_CONTEXT.Hide(), \
123  TF_DIAGNOSTIC_WARNING_TYPE).IssueWarning
124 
125 #define TF_WARN \
126  Tf_DiagnosticLiteHelper(TF_CALL_CONTEXT, \
127  TF_DIAGNOSTIC_WARNING_TYPE).IssueWarning
128 
129 #define TF_STATUS \
130  Tf_DiagnosticLiteHelper(TF_CALL_CONTEXT, \
131  TF_DIAGNOSTIC_STATUS_TYPE).IssueStatus
132 
133 constexpr bool
134 Tf_AxiomHelper(bool val, TfCallContext const &ctx, char const *txt) {
135  return (ARCH_LIKELY(val)) ? true :
136  (Tf_DiagnosticLiteHelper(ctx, TF_DIAGNOSTIC_FATAL_ERROR_TYPE).
137  IssueFatalError("Failed axiom: ' %s '", txt), false);
138 }
139 
140 #define TF_AXIOM(cond) \
141  Tf_AxiomHelper(static_cast<bool>((cond)), TF_CALL_CONTEXT, #cond)
142 
143 #define TF_DEV_AXIOM(cond) \
144  Tf_AxiomHelper(!ARCH_DEV_BUILD || \
145  static_cast<bool>((cond)), TF_CALL_CONTEXT, #cond)
146 
147 #endif // !defined(doxygen)
148 
149 PXR_NAMESPACE_CLOSE_SCOPE
150 
151 #endif // PXR_BASE_TF_DIAGNOSTIC_LITE_H
Functions for recording call locations.
Define function attributes.
Compiler hints.
#define ARCH_PRINTF_FUNCTION(_fmt, _firstArg)
Macro used to indicate a function takes a printf-like specification.
Definition: attributes.h:51
TfDiagnosticType
Enum describing various diagnostic conditions.