Loading...
Searching...
No Matches
execNodeDebugName.h
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
17#include "pxr/base/tf/token.h"
18
19#include <string>
20#include <typeinfo>
21#include <utility>
22
23PXR_NAMESPACE_OPEN_SCOPE
24
28{
29public:
30
32 const VdfNode &node,
33 VdfNodeDebugNameCallback &&callback)
34 : _node(&node)
35 , _callback(std::move(callback))
36 {
38 _callback,
39 "Null callback for node: %s",
40 ArchGetDemangled(typeid(node)).c_str());
41 }
42
43private:
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
68private:
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
80PXR_NAMESPACE_CLOSE_SCOPE
81
82#endif
Low-level utilities for informing users of various internal and external diagnostic conditions.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
bool IsEmpty() const
Returns true iff this token contains the empty string "".
Definition: token.h:288
std::string const & GetString() const
Return the string that this token represents.
Definition: token.h:190
Stores all necessary information to lazily construct a node debug name.
A VdfNetwork is a collection of VdfNodes and their connections.
Definition: network.h:60
This is the base class for all nodes in a VdfNetwork.
Definition: node.h:53
Demangle C++ typenames generated by the typeid() facility.
std::function< std::string()> VdfNodeDebugNameCallback
Type of callback for building a node debug name.
Definition: types.h:71
std::string ArchGetDemangled()
Return demangled RTTI generated-type name.
Definition: demangle.h:86
#define TF_VERIFY(cond, format,...)
Checks a condition and reports an error if it evaluates false.
Definition: diagnostic.h:266
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...