HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
staticKeyData.h
Go to the documentation of this file.
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 
35 
36 ////////////////////////////////////////////////////////////////////////////////
37 ///
38 /// \class TraceStaticKeyData
39 ///
40 /// This class holds data necessary to create keys for TraceEvent instances.
41 /// This class is meant to be used as constexpr static data.
42 ///
44 public:
45  /// \class StringLiteral
46  ///
47  /// This is a helper class for the constructors of TraceStaticKeyData.
48  ///
49  class StringLiteral {
50  public:
51  /// Constructor from string literals.
52  template <size_t N>
53  constexpr StringLiteral(const char(&s)[N]) : str(s) {}
54 
55  /// Default Constructor.
56  constexpr StringLiteral() : str(nullptr) {}
57 
58  private:
59  const char* str;
60 
61  friend class TraceStaticKeyData;
62  };
63 
64  /// Constructor for a \p name.
66  : _name(name.str) {}
67 
68  /// Constructor for a function (\p func, \p prettyFunc) and optional
69  /// scope \p name.
70  constexpr TraceStaticKeyData(
71  const StringLiteral func,
72  const StringLiteral prettyFunc,
74  : _funcName(func.str)
75  , _prettyFuncName(prettyFunc.str)
76  , _name(name.str) {}
77 
78  /// Equality comparison. Inequality is also defined.
79  TRACE_API
80  bool operator == (const TraceStaticKeyData& other) const;
81 
82  bool operator != (const TraceStaticKeyData& other) const {
83  return !(*this == other);
84  }
85 
86  /// Returns the string representation of the key data.
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 
101 
102 #endif // PXR_BASE_TRACE_STATIC_KEY_DATA_H
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
constexpr StringLiteral(const char(&s)[N])
Constructor from string literals.
Definition: staticKeyData.h:53
GLdouble s
Definition: glad.h:3009
constexpr StringLiteral()
Default Constructor.
Definition: staticKeyData.h:56
constexpr TraceStaticKeyData(const StringLiteral name)
Constructor for a name.
Definition: staticKeyData.h:65
GLuint const GLchar * name
Definition: glcorearb.h:786
TRACE_API bool operator==(const TraceStaticKeyData &other) const
Equality comparison. Inequality is also defined.
GLenum func
Definition: glcorearb.h:783
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1441
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
GA_API const UT_StringHolder N
constexpr TraceStaticKeyData(const StringLiteral func, const StringLiteral prettyFunc, const StringLiteral name=StringLiteral())
Definition: staticKeyData.h:70
TRACE_API std::string GetString() const
Returns the string representation of the key data.
bool operator!=(const TraceStaticKeyData &other) const
Definition: staticKeyData.h:82
#define TRACE_API
Definition: api.h:40