Loading...
Searching...
No Matches
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 PXR_BASE_TRACE_DYNAMIC_KEY_H
26#define PXR_BASE_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
32PXR_NAMESPACE_OPEN_SCOPE
33
43public:
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
80private:
82 TfToken _key;
83};
84
85PXR_NAMESPACE_CLOSE_SCOPE
86
87#endif // PXR_BASE_TRACE_DYNAMIC_KEY_H
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:88
char const * GetText() const
Return the text that this token represents.
Definition: token.h:196
size_t Hash() const
Return a size_t hash for this token.
Definition: token.h:432
This class stores data used to create dynamic keys which can be referenced in TraceEvent instances.
Definition: dynamicKey.h:42
const TraceStaticKeyData & GetData() const
Returns a reference to TraceStaticKeyData.
Definition: dynamicKey.h:78
TraceDynamicKey(const char *name)
Constructor for C string.
Definition: dynamicKey.h:55
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
TraceDynamicKey(const std::string &name)
Constructor for string.
Definition: dynamicKey.h:50
bool operator==(const TraceDynamicKey &other) const
Equality operator.
Definition: dynamicKey.h:60
This class holds data necessary to create keys for TraceEvent instances.
Definition: staticKeyData.h:43
STL namespace.
A Hash functor which uses the cached hash which may be used to store keys in a TfHashMap.
Definition: dynamicKey.h:71
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...