HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
instanceKey.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 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 #ifndef PXR_USD_PCP_INSTANCE_KEY_H
25 #define PXR_USD_PCP_INSTANCE_KEY_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/usd/pcp/api.h"
30 #include "pxr/usd/pcp/node.h"
31 #include "pxr/usd/pcp/site.h"
32 #include "pxr/usd/pcp/types.h"
33 
35 
36 #include <hboost/functional/hash.hpp>
37 
38 #include <string>
39 #include <utility>
40 #include <vector>
41 
43 
44 class PcpPrimIndex;
45 
46 /// \class PcpInstanceKey
47 ///
48 /// A PcpInstanceKey identifies instanceable prim indexes that share the
49 /// same set of opinions. Instanceable prim indexes with equal instance
50 /// keys are guaranteed to have the same opinions for name children and
51 /// properties beneath those name children. They are NOT guaranteed to have
52 /// the same opinions for direct properties of the prim indexes themselves.
53 ///
55 {
56 public:
57  PCP_API
59 
60  /// Create an instance key for the given prim index.
61  PCP_API
62  explicit PcpInstanceKey(const PcpPrimIndex& primIndex);
63 
64  /// Comparison operators
65  PCP_API
66  bool operator==(const PcpInstanceKey& rhs) const;
67  PCP_API
68  bool operator!=(const PcpInstanceKey& rhs) const;
69 
70  /// Returns hash value for this instance key.
71  friend size_t hash_value(const PcpInstanceKey& key)
72  {
73  return key._hash;
74  }
75 
76  /// \struct Hash
77  ///
78  /// Hash functor.
79  ///
80  struct Hash {
81  inline size_t operator()(const PcpInstanceKey& key) const
82  {
83  return key._hash;
84  }
85  };
86 
87  /// Returns string representation of this instance key
88  /// for debugging purposes.
89  PCP_API
90  std::string GetString() const;
91 
92 private:
93  struct _Collector;
94 
95  struct _Arc
96  {
97  explicit _Arc(const PcpNodeRef& node)
98  : _arcType(node.GetArcType())
99  , _sourceSite(node.GetSite())
100  , _timeOffset(node.GetMapToRoot().GetTimeOffset())
101  {
102  }
103 
104  bool operator==(const _Arc& rhs) const
105  {
106  return _arcType == rhs._arcType &&
107  _sourceSite == rhs._sourceSite &&
108  _timeOffset == rhs._timeOffset;
109  }
110 
111  size_t GetHash() const
112  {
113  size_t hash = _arcType;
114  hboost::hash_combine(hash, _sourceSite);
115  hboost::hash_combine(hash, _timeOffset.GetHash());
116  return hash;
117  }
118 
119  PcpArcType _arcType;
120  PcpSite _sourceSite;
121  SdfLayerOffset _timeOffset;
122  };
123  std::vector<_Arc> _arcs;
124 
125  typedef std::pair<std::string, std::string> _VariantSelection;
126  std::vector<_VariantSelection> _variantSelection;
127 
128  size_t _hash;
129 };
130 
132 
133 #endif // PXR_USD_PCP_INSTANCE_KEY_H
PCP_API std::string GetString() const
PCP_API bool operator==(const PcpInstanceKey &rhs) const
Comparison operators.
size_t operator()(const PcpInstanceKey &key) const
Definition: instanceKey.h:81
friend size_t hash_value(const PcpInstanceKey &key)
Returns hash value for this instance key.
Definition: instanceKey.h:71
Definition: site.h:46
GLsizei const GLchar *const * string
Definition: glew.h:1844
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1346
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
PCP_API PcpInstanceKey()
PCP_API bool operator!=(const PcpInstanceKey &rhs) const
#define PCP_API
Definition: api.h:40
PcpArcType
Definition: types.h:46