HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
execNodeDebugName.h
Go to the documentation of this file.
1 //
2 // Copyright 2025 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_EXEC_VDF_EXEC_NODE_DEBUG_NAME_H
8 #define PXR_EXEC_VDF_EXEC_NODE_DEBUG_NAME_H
9 
10 #include "pxr/pxr.h"
11 
12 #include "pxr/exec/vdf/node.h"
13 #include "pxr/exec/vdf/types.h"
14 
15 #include "pxr/base/arch/demangle.h"
16 #include "pxr/base/tf/diagnostic.h"
17 #include "pxr/base/tf/token.h"
18 
19 #include <string>
20 #include <typeinfo>
21 #include <utility>
22 
24 
25 /// Stores all necessary information to lazily construct a node debug name.
26 ///
28 {
29 public:
30 
32  const VdfNode &node,
33  VdfNodeDebugNameCallback &&callback)
34  : _node(&node)
35  , _callback(std::move(callback))
36  {
37  TF_VERIFY(
38  _callback,
39  "Null callback for node: %s",
40  ArchGetDemangled(typeid(node)).c_str());
41  }
42 
43 private:
44  friend class VdfNetwork;
45 
46  // Helper to initialize debug name token.
47  //
48  void _InitializeDebugName() const
49  {
50  // The possibility of a null callback is handled silently here since
51  // the constructor shows an error.
52  _debugName = (_callback)
53  ? TfToken(ArchGetDemangled(typeid(*_node)) + " " + _callback())
54  : TfToken(ArchGetDemangled(typeid(*_node)));
55  }
56 
57  // Returns a debug name for the node. Only VdfNetwork should call this
58  // function.
59  //
60  const std::string _GetDebugName() const
61  {
62  if (_debugName.IsEmpty()) {
63  _InitializeDebugName();
64  }
65  return _debugName.GetString();
66  }
67 
68 private:
69  // Node that this debug name describes.
70  const VdfNode *_node;
71 
72  // Callback to construct node debug name.
73  const VdfNodeDebugNameCallback _callback;
74 
75  // Stored debug name. This is computed on-demand.
76  mutable TfToken _debugName;
77 
78 };
79 
81 
82 #endif
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
ARCH_API std::string ArchGetDemangled(const std::string &typeName)
Definition: node.h:52
std::string const & GetString() const
Return the string that this token represents.
Definition: token.h:190
Definition: token.h:70
Vdf_ExecNodeDebugName(const VdfNode &node, VdfNodeDebugNameCallback &&callback)
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
OIIO_UTIL_API const char * c_str(string_view str)
std::function< std::string()> VdfNodeDebugNameCallback
Type of callback for building a node debug name.
Definition: types.h:71
bool IsEmpty() const
Returns true iff this token contains the empty string "".
Definition: token.h:288