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 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 
10 /// \file tf/diagnosticLite.h
11 /// Stripped down version of \c diagnostic.h that doesn't define \c std::string.
12 ///
13 /// This file provides the same functionality as \c diagnostic.h, except that
14 /// all strings must be passed as plain \c const \c char*, and not by
15 /// \c std::string, and the macro \c TF_FUNCTION_NAME() is only defined by
16 /// \c diagnostic.h
17 ///
18 /// In particular, this header file does not include the C++ header file
19 /// \c < \c string \c >, making inclusion of this file a very light-weight
20 /// addition. Include this file, as opposed to pxr/base/tf/diagnostic.h in
21 /// header files that need to remain as light-weight as possible.
22 ///
23 /// These macros are safe to use in multiple threads.
24 
25 #include "pxr/pxr.h"
27 #include "pxr/base/tf/api.h"
29 #include "pxr/base/arch/hints.h"
31 
32 #include <stddef.h>
33 
35 
36 /// \enum TfDiagnosticType
37 /// Enum describing various diagnostic conditions.
38 enum TfDiagnosticType : int {
48 };
49 
50 
51 #if !defined(doxygen)
52 
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]]
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 
71 private:
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 
116 constexpr bool
117 Tf_AxiomHelper(bool val, TfCallContext const &ctx, char const *txt) {
118  return (ARCH_LIKELY(val)) ? true :
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 
133 
134 #endif // PXR_BASE_TF_DIAGNOSTIC_LITE_H
#define ARCH_LIKELY(x)
Definition: hints.h:29
#define TF_API
Definition: api.h:23
constexpr Tf_DiagnosticLiteHelper(TfCallContext const &context, TfDiagnosticType type)
TF_API void IssueError(char const *fmt,...) const ARCH_PRINTF_FUNCTION(2
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:108
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
TfDiagnosticType
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
GLuint GLfloat * val
Definition: glcorearb.h:1608
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74