All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
dynamicKey.h
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_DYNAMIC_KEY_H
9#define PXR_BASE_TRACE_DYNAMIC_KEY_H
10
11#include "pxr/pxr.h"
12#include "pxr/base/trace/staticKeyData.h"
13#include "pxr/base/tf/token.h"
14
15PXR_NAMESPACE_OPEN_SCOPE
16
26public:
28 TraceDynamicKey(TfToken name) : _key(std::move(name)) {
29 _data._name = _key.GetText();
30 }
31
33 TraceDynamicKey(const std::string& name) : _key(name) {
34 _data._name = _key.GetText();
35 }
36
38 TraceDynamicKey(const char* name) : _key(name) {
39 _data._name = _key.GetText();
40 }
41
43 bool operator == (const TraceDynamicKey& other) const {
44 return _key == other._key;
45 }
46
48 size_t Hash() const {
49 return _key.Hash();
50 }
51
54 struct HashFunctor {
55 size_t operator()(const TraceDynamicKey& key) const {
56 return key.Hash();
57 }
58 };
59
61 const TraceStaticKeyData& GetData() const { return _data; }
62
63private:
65 TfToken _key;
66};
67
68PXR_NAMESPACE_CLOSE_SCOPE
69
70#endif // PXR_BASE_TRACE_DYNAMIC_KEY_H
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
char const * GetText() const
Return the text that this token represents.
Definition: token.h:179
size_t Hash() const
Return a size_t hash for this token.
Definition: token.h:415
This class stores data used to create dynamic keys which can be referenced in TraceEvent instances.
Definition: dynamicKey.h:25
const TraceStaticKeyData & GetData() const
Returns a reference to TraceStaticKeyData.
Definition: dynamicKey.h:61
TraceDynamicKey(const char *name)
Constructor for C string.
Definition: dynamicKey.h:38
TraceDynamicKey(TfToken name)
Constructor for TfToken.
Definition: dynamicKey.h:28
size_t Hash() const
Return a cached hash code for this key.
Definition: dynamicKey.h:48
TraceDynamicKey(const std::string &name)
Constructor for string.
Definition: dynamicKey.h:33
bool operator==(const TraceDynamicKey &other) const
Equality operator.
Definition: dynamicKey.h:43
This class holds data necessary to create keys for TraceEvent instances.
Definition: staticKeyData.h:26
STL namespace.
A Hash functor which uses the cached hash which may be used to store keys in a TfHashMap.
Definition: dynamicKey.h:54
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...