HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dynamicKey.h
Go to the documentation of this file.
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"
30 #include "pxr/base/tf/token.h"
31 
33 
34 ////////////////////////////////////////////////////////////////////////////////
35 /// \class TraceDynamicKey
36 ///
37 /// This class stores data used to create dynamic keys which can be referenced
38 /// in TraceEvent instances.
39 ///
40 /// Is a key is known at compile time, it is preferable to use
41 /// a static constexpr TraceStaticKeyData instance instead.
43 public:
44  /// Constructor for TfToken.
45  TraceDynamicKey(TfToken name) : _key(std::move(name)) {
46  _data._name = _key.GetText();
47  }
48 
49  /// Constructor for string.
50  TraceDynamicKey(const std::string& name) : _key(name) {
51  _data._name = _key.GetText();
52  }
53 
54  /// Constructor for C string.
55  TraceDynamicKey(const char* name) : _key(name) {
56  _data._name = _key.GetText();
57  }
58 
59  /// Equality operator.
60  bool operator == (const TraceDynamicKey& other) const {
61  return _key == other._key;
62  }
63 
64  /// Return a cached hash code for this key.
65  size_t Hash() const {
66  return _key.Hash();
67  }
68 
69  /// A Hash functor which uses the cached hash which may be used to store
70  /// keys in a TfHashMap.
71  struct HashFunctor {
72  size_t operator()(const TraceDynamicKey& key) const {
73  return key.Hash();
74  }
75  };
76 
77  /// Returns a reference to TraceStaticKeyData.
78  const TraceStaticKeyData& GetData() const { return _data; }
79 
80 private:
81  TraceStaticKeyData _data;
82  TfToken _key;
83 };
84 
86 
87 #endif // PXR_BASE_TRACE_DYNAMIC_KEY_H
TraceDynamicKey(const std::string &name)
Constructor for string.
Definition: dynamicKey.h:50
const TraceStaticKeyData & GetData() const
Returns a reference to TraceStaticKeyData.
Definition: dynamicKey.h:78
GLuint const GLchar * name
Definition: glcorearb.h:785
size_t Hash() const
Return a cached hash code for this key.
Definition: dynamicKey.h:65
size_t operator()(const TraceDynamicKey &key) const
Definition: dynamicKey.h:72
Definition: token.h:87
GLsizei const GLchar *const * string
Definition: glcorearb.h:813
TraceDynamicKey(TfToken name)
Constructor for TfToken.
Definition: dynamicKey.h:45
char const * GetText() const
Definition: token.h:196
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1375
TraceDynamicKey(const char *name)
Constructor for C string.
Definition: dynamicKey.h:55
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
bool operator==(const TraceDynamicKey &other) const
Equality operator.
Definition: dynamicKey.h:60
size_t Hash() const
Return a size_t hash for this token.
Definition: token.h:417