All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dynamicKey.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 TRACE_DYNAMIC_KEY_H
26 #define TRACE_DYNAMIC_KEY_H
27 
28 #include "pxr/pxr.h"
29 #include "pxr/base/trace/staticKeyData.h"
30 #include "pxr/base/tf/token.h"
31 
32 PXR_NAMESPACE_OPEN_SCOPE
33 
43 public:
45  TraceDynamicKey(TfToken name) : _key(std::move(name)) {
46  _data._name = _key.GetText();
47  }
48 
50  TraceDynamicKey(const std::string& name) : _key(name) {
51  _data._name = _key.GetText();
52  }
53 
55  TraceDynamicKey(const char* name) : _key(name) {
56  _data._name = _key.GetText();
57  }
58 
60  bool operator == (const TraceDynamicKey& other) const {
61  return _key == other._key;
62  }
63 
65  size_t Hash() const {
66  return _key.Hash();
67  }
68 
71  struct HashFunctor {
72  size_t operator()(const TraceDynamicKey& key) const {
73  return key.Hash();
74  }
75  };
76 
78  const TraceStaticKeyData& GetData() const { return _data; }
79 
80 private:
81  TraceStaticKeyData _data;
82  TfToken _key;
83 };
84 
85 PXR_NAMESPACE_CLOSE_SCOPE
86 
87 #endif // TRACE_DYNAMIC_KEY_H
size_t Hash() const
Return a size_t hash for this token.
Definition: token.h:165
TraceDynamicKey(const char *name)
Constructor for C string.
Definition: dynamicKey.h:55
This class stores data used to create dynamic keys which can be referenced in TraceEvent instances...
Definition: dynamicKey.h:42
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:89
const TraceStaticKeyData & GetData() const
Returns a reference to TraceStaticKeyData.
Definition: dynamicKey.h:78
A Hash functor which uses the cached hash which may be used to store keys in a TfHashMap.
Definition: dynamicKey.h:71
bool operator==(const TraceDynamicKey &other) const
Equality operator.
Definition: dynamicKey.h:60
TraceDynamicKey(const std::string &name)
Constructor for string.
Definition: dynamicKey.h:50
TraceDynamicKey(TfToken name)
Constructor for TfToken.
Definition: dynamicKey.h:45
size_t Hash() const
Return a cached hash code for this key.
Definition: dynamicKey.h:65
This class holds data necessary to create keys for TraceEvent instances.
Definition: staticKeyData.h:42
char const * GetText() const
Return the text that this token represents.
Definition: token.h:198