HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
callContext.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_CALL_CONTEXT_H
8 #define PXR_BASE_TF_CALL_CONTEXT_H
9 
10 /// \file tf/callContext.h
11 /// Functions for recording call locations.
12 ///
13 /// Many macros want to record the location in which they are invoked. In
14 /// fact, this is the most useful feature that function-like macros have over
15 /// regular functions. This code provides a standard way to collect and pass
16 /// that contextual information around. There are two parts. First is a
17 /// small structure which holds the contextual information. Next is a macro
18 /// which will produce a temporary structure containing the local contextual
19 /// information. The intended usage is in a macro.
20 
21 #include "pxr/pxr.h"
22 #include "pxr/base/tf/api.h"
24 
25 #include <stddef.h>
26 
28 
29 /// \hideinitializer
30 #define TF_CALL_CONTEXT \
31 TfCallContext(__ARCH_FILE__, __ARCH_FUNCTION__, __LINE__, __ARCH_PRETTY_FUNCTION__)
32 
34 {
35 public:
36  constexpr TfCallContext()
37  : _file(nullptr)
38  , _function(nullptr)
39  , _line(0)
40  , _prettyFunction(nullptr)
41  , _hidden(false) {}
42 
43  constexpr TfCallContext(char const *file,
44  char const *function,
45  size_t line,
46  char const *prettyFunction) :
47  _file(file),
48  _function(function),
49  _line(line),
50  _prettyFunction(prettyFunction),
51  _hidden(false)
52  {
53  }
54 
55  char const *GetFile() const {
56  return _file;
57  }
58 
59  char const *GetFunction() const {
60  return _function;
61  }
62 
63  size_t GetLine() const {
64  return _line;
65  }
66 
67  char const *GetPrettyFunction() const {
68  return _prettyFunction;
69  }
70 
71  TfCallContext const& Hide() const {
72  _hidden = true;
73  return *this;
74  }
75 
76  bool IsHidden() const {
77  return _hidden;
78  }
79 
80  explicit operator bool() const { return _file && _function; }
81 
82  private:
83 
84  char const *_file;
85  char const *_function;
86  size_t _line;
87  char const *_prettyFunction;
88  mutable bool _hidden;
89 };
90 
92 
93 #endif // PXR_BASE_TF_CALL_CONTEXT_H
constexpr TfCallContext()
Definition: callContext.h:36
char const * GetPrettyFunction() const
Definition: callContext.h:67
size_t GetLine() const
Definition: callContext.h:63
OutGridT const XformOp bool bool
char const * GetFile() const
Definition: callContext.h:55
bool IsHidden() const
Definition: callContext.h:76
TfCallContext const & Hide() const
Definition: callContext.h:71
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
constexpr TfCallContext(char const *file, char const *function, size_t line, char const *prettyFunction)
Definition: callContext.h:43
char const * GetFunction() const
Definition: callContext.h:59