Loading...
Searching...
No Matches
scopeDescription.h
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_SCOPE_DESCRIPTION_H
8#define PXR_BASE_TF_SCOPE_DESCRIPTION_H
9
10#include "pxr/pxr.h"
11
14#include "pxr/base/tf/api.h"
15
16#include <optional>
17#include <vector>
18#include <string>
19
20PXR_NAMESPACE_OPEN_SCOPE
21
33{
34 TfScopeDescription() = delete;
35 TfScopeDescription(TfScopeDescription const &) = delete;
36 TfScopeDescription &operator=(TfScopeDescription const &) = delete;
37public:
41 TF_API explicit
42 TfScopeDescription(std::string const &description,
43 TfCallContext const &context = TfCallContext());
44
48 TF_API explicit
49 TfScopeDescription(std::string &&description,
50 TfCallContext const &context = TfCallContext());
51
55 TF_API explicit
56 TfScopeDescription(char const *description,
57 TfCallContext const &context = TfCallContext());
58
62
66 TF_API void SetDescription(std::string const &description);
67
70 TF_API void SetDescription(std::string &&description);
71
75 TF_API void SetDescription(char const *description);
76
77private:
78 friend inline TfScopeDescription *
79 Tf_GetPreviousScopeDescription(TfScopeDescription *d) {
80 return d->_prev;
81 }
82 friend inline char const *
83 Tf_GetScopeDescriptionText(TfScopeDescription *d) {
84 return d->_description;
85 }
86 friend inline TfCallContext const &
87 Tf_GetScopeDescriptionContext(TfScopeDescription *d) {
88 return d->_context;
89 }
90
91 inline void _Push();
92 inline void _Pop() const;
93
94 std::optional<std::string> _ownedString;
95 char const *_description;
96 TfCallContext _context;
97 void *_localStack;
98 TfScopeDescription *_prev; // link to parent scope.
99};
100
105TF_API std::vector<std::string>
106TfGetCurrentScopeDescriptionStack();
107
111TF_API std::vector<std::string>
112TfGetThisThreadScopeDescriptionStack();
113
116#define TF_DESCRIBE_SCOPE(...) \
117 TfScopeDescription __scope_description__ \
118 (Tf_DescribeScopeFormat(__VA_ARGS__), TF_CALL_CONTEXT); \
119
120template <typename... Args>
121inline std::string
122Tf_DescribeScopeFormat(const char* fmt, Args&&... args) {
123 return TfStringPrintf(fmt, std::forward<Args>(args)...);
124}
125
126// If there are no formatting arguments, the string can be forwarded to the
127// scope description constructor. In C++17, consider if std::string_view could
128// reduce the need for as many of these overloads
129inline const char*
130Tf_DescribeScopeFormat(const char* fmt) { return fmt; }
131
132inline std::string&&
133Tf_DescribeScopeFormat(std::string&& fmt) { return std::move(fmt); }
134
135inline const std::string&
136Tf_DescribeScopeFormat(const std::string& fmt) { return fmt; }
137
138PXR_NAMESPACE_CLOSE_SCOPE
139
140#endif // PXR_BASE_TF_SCOPE_DESCRIPTION_H
Functions for recording call locations.
This class is used to provide high-level descriptions about scopes of execution that could possibly b...
TF_API void SetDescription(std::string &&description)
Replace the description stack entry for this scope description.
TF_API TfScopeDescription(char const *description, TfCallContext const &context=TfCallContext())
Construct with a description.
TF_API TfScopeDescription(std::string const &description, TfCallContext const &context=TfCallContext())
Construct with a description.
TF_API void SetDescription(char const *description)
Replace the description stack entry for this scope description.
TF_API void SetDescription(std::string const &description)
Replace the description stack entry for this scope description.
TF_API TfScopeDescription(std::string &&description, TfCallContext const &context=TfCallContext())
Construct with a description.
TF_API ~TfScopeDescription()
Destructor.
TF_API std::string TfStringPrintf(const char *fmt,...)
Returns a string formed by a printf()-like specification.
Definitions of basic string utilities in tf.