HDK
 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 PXR_BASE_TF_DIAGNOSTIC_LITE_H
25 #define PXR_BASE_TF_DIAGNOSTIC_LITE_H
26 
27 /// \file tf/diagnosticLite.h
28 /// Stripped down version of \c diagnostic.h that doesn't define \c std::string.
29 ///
30 /// This file provides the same functionality as \c diagnostic.h, except that
31 /// all strings must be passed as plain \c const \c char*, and not by
32 /// \c std::string, and the macro \c TF_FUNCTION_NAME() is only defined by
33 /// \c diagnostic.h
34 ///
35 /// In particular, this header file does not include the C++ header file
36 /// \c < \c string \c >, making inclusion of this file a very light-weight
37 /// addition. Include this file, as opposed to pxr/base/tf/diagnostic.h in
38 /// header files that need to remain as light-weight as possible.
39 ///
40 /// These macros are safe to use in multiple threads.
41 
42 #include "pxr/pxr.h"
44 #include "pxr/base/tf/api.h"
46 #include "pxr/base/arch/hints.h"
48 
49 #include <stddef.h>
50 
52 
53 /// \enum TfDiagnosticType
54 /// Enum describing various diagnostic conditions.
55 enum TfDiagnosticType : int {
65 };
66 
67 
68 #if !defined(doxygen)
69 
73  : _context(context),
74  _type(type)
75  {
76  }
77 
78  TF_API void IssueError(
79  char const *fmt, ...) const ARCH_PRINTF_FUNCTION(2,3);
81  char const *fmt, ...) const ARCH_PRINTF_FUNCTION(2,3);
82  TF_API void IssueWarning(
83  char const *fmt, ...) const ARCH_PRINTF_FUNCTION(2,3);
84  TF_API void IssueStatus(
85  char const *fmt, ...) const ARCH_PRINTF_FUNCTION(2,3);
86 
87 private:
88  TfCallContext _context;
89  TfDiagnosticType _type;
90 };
91 
92 #define TF_CODING_ERROR \
93  Tf_DiagnosticLiteHelper(TF_CALL_CONTEXT, \
94  TF_DIAGNOSTIC_CODING_ERROR_TYPE).IssueError
95 
96 #define TF_CODING_WARNING \
97  Tf_DiagnosticLiteHelper(TF_CALL_CONTEXT, \
98  TF_DIAGNOSTIC_CODING_ERROR_TYPE).IssueWarning \
99 
100 #define TF_FATAL_CODING_ERROR \
101  Tf_DiagnosticLiteHelper(TF_CALL_CONTEXT, \
102  TF_DIAGNOSTIC_CODING_ERROR_TYPE).IssueFatalError
103 
104 #define TF_RUNTIME_ERROR \
105  Tf_DiagnosticLiteHelper(TF_CALL_CONTEXT, \
106  TF_DIAGNOSTIC_RUNTIME_ERROR_TYPE).IssueError
107 
108 #define TF_FATAL_ERROR \
109  Tf_DiagnosticLiteHelper(TF_CALL_CONTEXT, \
110  TF_DIAGNOSTIC_FATAL_ERROR_TYPE).IssueFatalError
111 
112 #define TF_DIAGNOSTIC_FATAL_ERROR \
113  Tf_DiagnosticLiteHelper(TF_CALL_CONTEXT, \
114  TF_DIAGNOSTIC_RUNTIME_ERROR_TYPE).IssueFatalError
115 
116 #define TF_DIAGNOSTIC_NONFATAL_ERROR \
117  Tf_DiagnosticLiteHelper(TF_CALL_CONTEXT, \
118  TF_DIAGNOSTIC_WARNING_TYPE).IssueWarning
119 
120 #define TF_DIAGNOSTIC_WARNING \
121  Tf_DiagnosticLiteHelper(TF_CALL_CONTEXT.Hide(), \
122  TF_DIAGNOSTIC_WARNING_TYPE).IssueWarning
123 
124 #define TF_WARN \
125  Tf_DiagnosticLiteHelper(TF_CALL_CONTEXT, \
126  TF_DIAGNOSTIC_WARNING_TYPE).IssueWarning
127 
128 #define TF_STATUS \
129  Tf_DiagnosticLiteHelper(TF_CALL_CONTEXT, \
130  TF_DIAGNOSTIC_STATUS_TYPE).IssueStatus
131 
132 constexpr bool
133 Tf_AxiomHelper(bool val, TfCallContext const &ctx, char const *txt) {
134  return (ARCH_LIKELY(val)) ? true :
136  IssueFatalError("Failed axiom: ' %s '", txt), false);
137 }
138 
139 #define TF_AXIOM(cond) \
140  Tf_AxiomHelper(static_cast<bool>((cond)), TF_CALL_CONTEXT, #cond)
141 
142 #define TF_DEV_AXIOM(cond) \
143  Tf_AxiomHelper(!ARCH_DEV_BUILD || \
144  static_cast<bool>((cond)), TF_CALL_CONTEXT, #cond)
145 
146 #endif // !defined(doxygen)
147 
149 
150 #endif // PXR_BASE_TF_DIAGNOSTIC_LITE_H
#define ARCH_LIKELY(x)
Definition: hints.h:46
#define TF_API
Definition: api.h:40
GLuint const GLfloat * val
Definition: glew.h:2794
constexpr Tf_DiagnosticLiteHelper(TfCallContext const &context, TfDiagnosticType type)
TF_API void IssueError(char const *fmt,...) const ARCH_PRINTF_FUNCTION(2
TF_API void TF_API void TF_API void IssueWarning(char const *fmt,...) const ARCH_PRINTF_FUNCTION(2
TF_API void TF_API void IssueFatalError(char const *fmt,...) const ARCH_PRINTF_FUNCTION(2
constexpr bool Tf_AxiomHelper(bool val, TfCallContext const &ctx, char const *txt)
TF_API void TF_API void TF_API void TF_API void IssueStatus(char const *fmt,...) const ARCH_PRINTF_FUNCTION(2
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1253
TfDiagnosticType
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1346
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:83
#define const
Definition: zconf.h:214