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 #include "pxr/base/tf/hash.h"
36 
37 #include <string>
38 #include <utility>
39 #include <vector>
40 
42 
43 class PcpPrimIndex;
44 
45 /// \class PcpInstanceKey
46 ///
47 /// A PcpInstanceKey identifies instanceable prim indexes that share the
48 /// same set of opinions. Instanceable prim indexes with equal instance
49 /// keys are guaranteed to have the same opinions for name children and
50 /// properties beneath those name children. They are NOT guaranteed to have
51 /// the same opinions for direct properties of the prim indexes themselves.
52 ///
54 {
55 public:
56  PCP_API
58 
59  /// Create an instance key for the given prim index.
60  PCP_API
61  explicit PcpInstanceKey(const PcpPrimIndex& primIndex);
62 
63  /// Comparison operators
64  PCP_API
65  bool operator==(const PcpInstanceKey& rhs) const;
66  PCP_API
67  bool operator!=(const PcpInstanceKey& rhs) const;
68 
69  /// Appends hash value for this instance key.
70  template <typename HashState>
71  friend void TfHashAppend(HashState& h, const PcpInstanceKey& key)
72  {
73  h.Append(key._hash);
74  }
75  /// Returns hash value for this instance key.
76  friend size_t hash_value(const PcpInstanceKey& key)
77  {
78  return key._hash;
79  }
80 
81  /// \struct Hash
82  ///
83  /// Hash functor.
84  ///
85  struct Hash {
86  inline size_t operator()(const PcpInstanceKey& key) const
87  {
88  return key._hash;
89  }
90  };
91 
92  /// Returns string representation of this instance key
93  /// for debugging purposes.
94  PCP_API
95  std::string GetString() const;
96 
97 private:
98  struct _Collector;
99 
100  struct _Arc
101  {
102  explicit _Arc(const PcpNodeRef& node)
103  : _arcType(node.GetArcType())
104  , _sourceSite(node.GetSite())
105  , _timeOffset(node.GetMapToRoot().GetTimeOffset())
106  {
107  }
108 
109  bool operator==(const _Arc& rhs) const
110  {
111  return _arcType == rhs._arcType &&
112  _sourceSite == rhs._sourceSite &&
113  _timeOffset == rhs._timeOffset;
114  }
115 
116  template <typename HashState>
117  friend void TfHashAppend(HashState &h, const _Arc& arc) {
118  h.Append(arc._arcType);
119  h.Append(arc._sourceSite);
120  h.Append(arc._timeOffset);
121  }
122 
123  PcpArcType _arcType;
124  PcpSite _sourceSite;
125  SdfLayerOffset _timeOffset;
126  };
127  std::vector<_Arc> _arcs;
128 
129  typedef std::pair<std::string, std::string> _VariantSelection;
130  std::vector<_VariantSelection> _variantSelection;
131 
132  size_t _hash;
133 };
134 
136 
137 #endif // PXR_USD_PCP_INSTANCE_KEY_H
PCP_API std::string GetString() const
PCP_API bool operator==(const PcpInstanceKey &rhs) const
Comparison operators.
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
size_t operator()(const PcpInstanceKey &key) const
Definition: instanceKey.h:86
friend size_t hash_value(const PcpInstanceKey &key)
Returns hash value for this instance key.
Definition: instanceKey.h:76
Definition: site.h:45
friend void TfHashAppend(HashState &h, const PcpInstanceKey &key)
Appends hash value for this instance key.
Definition: instanceKey.h:71
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2002
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
GA_API const UT_StringHolder arc
PCP_API PcpInstanceKey()
PCP_API bool operator!=(const PcpInstanceKey &rhs) const
#define PCP_API
Definition: api.h:40
PcpArcType
Definition: types.h:44