All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
staticKeyData.h
1 //
2 // Copyright 2018 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 
25 #ifndef PXR_BASE_TRACE_STATIC_KEY_DATA_H
26 #define PXR_BASE_TRACE_STATIC_KEY_DATA_H
27 
28 #include "pxr/pxr.h"
29 #include "pxr/base/trace/api.h"
30 
31 #include <cstddef>
32 #include <string>
33 
34 PXR_NAMESPACE_OPEN_SCOPE
35 
44 public:
49  class StringLiteral {
50  public:
52  template <size_t N>
53  constexpr StringLiteral(const char(&s)[N]) : str(s) {}
54 
56  constexpr StringLiteral() : str(nullptr) {}
57 
58  private:
59  const char* str;
60 
61  friend class TraceStaticKeyData;
62  };
63 
65  constexpr TraceStaticKeyData(const StringLiteral name)
66  : _name(name.str) {}
67 
70  constexpr TraceStaticKeyData(
71  const StringLiteral func,
72  const StringLiteral prettyFunc,
73  const StringLiteral name = StringLiteral())
74  : _funcName(func.str)
75  , _prettyFuncName(prettyFunc.str)
76  , _name(name.str) {}
77 
79  TRACE_API
80  bool operator == (const TraceStaticKeyData& other) const;
81 
82  bool operator != (const TraceStaticKeyData& other) const {
83  return !(*this == other);
84  }
85 
87  TRACE_API
88  std::string GetString() const;
89 
90 private:
92 
93  const char* _funcName = nullptr;
94  const char* _prettyFuncName = nullptr;
95  const char* _name = nullptr;
96 
97  friend class TraceDynamicKey;
98 };
99 
100 PXR_NAMESPACE_CLOSE_SCOPE
101 
102 #endif // PXR_BASE_TRACE_STATIC_KEY_DATA_H
This is a helper class for the constructors of TraceStaticKeyData.
Definition: staticKeyData.h:49
constexpr StringLiteral()
Default Constructor.
Definition: staticKeyData.h:56
This class stores data used to create dynamic keys which can be referenced in TraceEvent instances...
Definition: dynamicKey.h:42
TRACE_API bool operator==(const TraceStaticKeyData &other) const
Equality comparison. Inequality is also defined.
TRACE_API std::string GetString() const
Returns the string representation of the key data.
constexpr TraceStaticKeyData(const StringLiteral func, const StringLiteral prettyFunc, const StringLiteral name=StringLiteral())
Constructor for a function (func, prettyFunc) and optional scope name.
Definition: staticKeyData.h:70
constexpr StringLiteral(const char(&s)[N])
Constructor from string literals.
Definition: staticKeyData.h:53
constexpr TraceStaticKeyData(const StringLiteral name)
Constructor for a name.
Definition: staticKeyData.h:65
This class holds data necessary to create keys for TraceEvent instances.
Definition: staticKeyData.h:43