HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
key.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_KEY_H
9 #define PXR_BASE_TRACE_KEY_H
10 
11 #include "pxr/pxr.h"
13 
14 
16 
17 ////////////////////////////////////////////////////////////////////////////////
18 /// \class TraceKey
19 ///
20 /// A wrapper around a TraceStaticKeyData pointer that is stored in TraceEvent
21 /// instances.
22 ///
23 class TraceKey {
24 public:
25  /// Constructor.
26  constexpr TraceKey(const TraceStaticKeyData& data) : _ptr(&data) {}
27 
28  /// Equality comparison.
29  bool operator == (const TraceKey& other) const {
30  if (_ptr == other._ptr) {
31  return true;
32  } else {
33  return *_ptr == *other._ptr;
34  }
35  }
36 
37  /// Hash function.
38  size_t Hash() const {
39  return reinterpret_cast<size_t>(_ptr)/sizeof(TraceStaticKeyData);
40  }
41 
42  /// A Hash functor which may be used to store keys in a TfHashMap.
43  struct HashFunctor {
44  size_t operator()(const TraceKey& key) const {
45  return key.Hash();
46  }
47  };
48 
49 private:
50  const TraceStaticKeyData* _ptr;
51 
52  // TraceCollection converts TraceKeys to TfTokens for visitors.
53  friend class TraceCollection;
54 };
55 
57 
58 #endif // PXR_BASE_TRACE_KEY_H
size_t operator()(const TraceKey &key) const
Definition: key.h:44
bool operator==(const TraceKey &other) const
Equality comparison.
Definition: key.h:29
A Hash functor which may be used to store keys in a TfHashMap.
Definition: key.h:43
constexpr TraceKey(const TraceStaticKeyData &data)
Constructor.
Definition: key.h:26
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
size_t Hash() const
Hash function.
Definition: key.h:38
Definition: format.h:1821
Definition: key.h:23