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 terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 
8 #ifndef PXR_BASE_TRACE_STATIC_KEY_DATA_H
9 #define PXR_BASE_TRACE_STATIC_KEY_DATA_H
10 
11 #include "pxr/pxr.h"
12 #include "pxr/base/trace/api.h"
13 
14 #include <cstddef>
15 #include <string>
16 
18 
19 ////////////////////////////////////////////////////////////////////////////////
20 ///
21 /// \class TraceStaticKeyData
22 ///
23 /// This class holds data necessary to create keys for TraceEvent instances.
24 /// This class is meant to be used as constexpr static data.
25 ///
27 public:
28  /// \class StringLiteral
29  ///
30  /// This is a helper class for the constructors of TraceStaticKeyData.
31  ///
32  class StringLiteral {
33  public:
34  /// Constructor from string literals.
35  template <size_t N>
36  constexpr StringLiteral(const char(&s)[N]) : str(s) {}
37 
38  /// Default Constructor.
39  constexpr StringLiteral() : str(nullptr) {}
40 
41  private:
42  const char* str;
43 
44  friend class TraceStaticKeyData;
45  };
46 
47  /// Constructor for a \p name.
49  : _name(name.str) {}
50 
51  /// Constructor for a function (\p func, \p prettyFunc) and optional
52  /// scope \p name.
53  constexpr TraceStaticKeyData(
54  const StringLiteral func,
55  const StringLiteral prettyFunc,
57  : _funcName(func.str)
58  , _prettyFuncName(prettyFunc.str)
59  , _name(name.str) {}
60 
61  /// Equality comparison. Inequality is also defined.
62  TRACE_API
63  bool operator == (const TraceStaticKeyData& other) const;
64 
65  bool operator != (const TraceStaticKeyData& other) const {
66  return !(*this == other);
67  }
68 
69  /// Returns the string representation of the key data.
70  TRACE_API
71  std::string GetString() const;
72 
73 private:
75 
76  const char* _funcName = nullptr;
77  const char* _prettyFuncName = nullptr;
78  const char* _name = nullptr;
79 
80  friend class TraceDynamicKey;
81 };
82 
84 
85 #endif // PXR_BASE_TRACE_STATIC_KEY_DATA_H
constexpr StringLiteral(const char(&s)[N])
Constructor from string literals.
Definition: staticKeyData.h:36
GLdouble s
Definition: glad.h:3009
constexpr StringLiteral()
Default Constructor.
Definition: staticKeyData.h:39
constexpr TraceStaticKeyData(const StringLiteral name)
Constructor for a name.
Definition: staticKeyData.h:48
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:1425
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
GA_API const UT_StringHolder N
constexpr TraceStaticKeyData(const StringLiteral func, const StringLiteral prettyFunc, const StringLiteral name=StringLiteral())
Definition: staticKeyData.h:53
TRACE_API std::string GetString() const
Returns the string representation of the key data.
bool operator!=(const TraceStaticKeyData &other) const
Definition: staticKeyData.h:65
#define TRACE_API
Definition: api.h:23