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