Loading...
Searching...
No Matches
scopeDescription.h
1//
2// Copyright 2016 Pixar
3//
4// Licensed under the Apache License, Version 2.0 (the "Apache License")
5// with the following modification; you may not use this file except in
6// compliance with the Apache License and the following modification to it:
7// Section 6. Trademarks. is deleted and replaced with:
8//
9// 6. Trademarks. This License does not grant permission to use the trade
10// names, trademarks, service marks, or product names of the Licensor
11// and its affiliates, except as required to comply with Section 4(c) of
12// the License and to reproduce the content of the NOTICE file.
13//
14// You may obtain a copy of the Apache License at
15//
16// http://www.apache.org/licenses/LICENSE-2.0
17//
18// Unless required by applicable law or agreed to in writing, software
19// distributed under the Apache License with the above modification is
20// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21// KIND, either express or implied. See the Apache License for the specific
22// language governing permissions and limitations under the Apache License.
23//
24#ifndef PXR_BASE_TF_SCOPE_DESCRIPTION_H
25#define PXR_BASE_TF_SCOPE_DESCRIPTION_H
26
27#include "pxr/pxr.h"
28
31#include "pxr/base/tf/api.h"
32
33#include <optional>
34#include <vector>
35#include <string>
36
37PXR_NAMESPACE_OPEN_SCOPE
38
50{
51 TfScopeDescription() = delete;
52 TfScopeDescription(TfScopeDescription const &) = delete;
53 TfScopeDescription &operator=(TfScopeDescription const &) = delete;
54public:
58 TF_API explicit
59 TfScopeDescription(std::string const &description,
60 TfCallContext const &context = TfCallContext());
61
65 TF_API explicit
66 TfScopeDescription(std::string &&description,
67 TfCallContext const &context = TfCallContext());
68
72 TF_API explicit
73 TfScopeDescription(char const *description,
74 TfCallContext const &context = TfCallContext());
75
79
83 TF_API void SetDescription(std::string const &description);
84
87 TF_API void SetDescription(std::string &&description);
88
92 TF_API void SetDescription(char const *description);
93
94private:
95 friend inline TfScopeDescription *
96 Tf_GetPreviousScopeDescription(TfScopeDescription *d) {
97 return d->_prev;
98 }
99 friend inline char const *
100 Tf_GetScopeDescriptionText(TfScopeDescription *d) {
101 return d->_description;
102 }
103 friend inline TfCallContext const &
104 Tf_GetScopeDescriptionContext(TfScopeDescription *d) {
105 return d->_context;
106 }
107
108 inline void _Push();
109 inline void _Pop() const;
110
111 std::optional<std::string> _ownedString;
112 char const *_description;
113 TfCallContext _context;
114 void *_localStack;
115 TfScopeDescription *_prev; // link to parent scope.
116};
117
122TF_API std::vector<std::string>
123TfGetCurrentScopeDescriptionStack();
124
128TF_API std::vector<std::string>
129TfGetThisThreadScopeDescriptionStack();
130
133#define TF_DESCRIBE_SCOPE(...) \
134 TfScopeDescription __scope_description__ \
135 (Tf_DescribeScopeFormat(__VA_ARGS__), TF_CALL_CONTEXT); \
136
137template <typename... Args>
138inline std::string
139Tf_DescribeScopeFormat(const char* fmt, Args&&... args) {
140 return TfStringPrintf(fmt, std::forward<Args>(args)...);
141}
142
143// If there are no formatting arguments, the string can be forwarded to the
144// scope description constructor. In C++17, consider if std::string_view could
145// reduce the need for as many of these overloads
146inline const char*
147Tf_DescribeScopeFormat(const char* fmt) { return fmt; }
148
149inline std::string&&
150Tf_DescribeScopeFormat(std::string&& fmt) { return std::move(fmt); }
151
152inline const std::string&
153Tf_DescribeScopeFormat(const std::string& fmt) { return fmt; }
154
155PXR_NAMESPACE_CLOSE_SCOPE
156
157#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.