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 terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_USD_PCP_INSTANCE_KEY_H
8 #define PXR_USD_PCP_INSTANCE_KEY_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/usd/pcp/api.h"
13 #include "pxr/usd/pcp/node.h"
14 #include "pxr/usd/pcp/site.h"
15 #include "pxr/usd/pcp/types.h"
16 
18 #include "pxr/base/tf/hash.h"
19 
20 #include <string>
21 #include <utility>
22 #include <vector>
23 
25 
26 class PcpPrimIndex;
27 
28 /// \class PcpInstanceKey
29 ///
30 /// A PcpInstanceKey identifies instanceable prim indexes that share the
31 /// same set of opinions. Instanceable prim indexes with equal instance
32 /// keys are guaranteed to have the same opinions for name children and
33 /// properties beneath those name children. They are NOT guaranteed to have
34 /// the same opinions for direct properties of the prim indexes themselves.
35 ///
37 {
38 public:
39  PCP_API
41 
42  /// Create an instance key for the given prim index.
43  PCP_API
44  explicit PcpInstanceKey(const PcpPrimIndex& primIndex);
45 
46  /// Comparison operators
47  PCP_API
48  bool operator==(const PcpInstanceKey& rhs) const;
49  PCP_API
50  bool operator!=(const PcpInstanceKey& rhs) const;
51 
52  /// Appends hash value for this instance key.
53  template <typename HashState>
54  friend void TfHashAppend(HashState& h, const PcpInstanceKey& key)
55  {
56  h.Append(key._hash);
57  }
58  /// Returns hash value for this instance key.
59  friend size_t hash_value(const PcpInstanceKey& key)
60  {
61  return key._hash;
62  }
63 
64  /// \struct Hash
65  ///
66  /// Hash functor.
67  ///
68  struct Hash {
69  inline size_t operator()(const PcpInstanceKey& key) const
70  {
71  return key._hash;
72  }
73  };
74 
75  /// Returns string representation of this instance key
76  /// for debugging purposes.
77  PCP_API
78  std::string GetString() const;
79 
80 private:
81  struct _Collector;
82 
83  struct _Arc
84  {
85  explicit _Arc(const PcpNodeRef& node)
86  : _arcType(node.GetArcType())
87  , _sourceSite(node.GetSite())
88  , _timeOffset(node.GetMapToRoot().GetTimeOffset())
89  {
90  }
91 
92  bool operator==(const _Arc& rhs) const
93  {
94  return _arcType == rhs._arcType &&
95  _sourceSite == rhs._sourceSite &&
96  _timeOffset == rhs._timeOffset;
97  }
98 
99  template <typename HashState>
100  friend void TfHashAppend(HashState &h, const _Arc& arc) {
101  h.Append(arc._arcType);
102  h.Append(arc._sourceSite);
103  h.Append(arc._timeOffset);
104  }
105 
106  PcpArcType _arcType;
107  PcpSite _sourceSite;
108  SdfLayerOffset _timeOffset;
109  };
110  std::vector<_Arc> _arcs;
111 
112  typedef std::pair<std::string, std::string> _VariantSelection;
113  std::vector<_VariantSelection> _variantSelection;
114 
115  size_t _hash;
116 };
117 
119 
120 #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:69
friend size_t hash_value(const PcpInstanceKey &key)
Returns hash value for this instance key.
Definition: instanceKey.h:59
Definition: site.h:28
friend void TfHashAppend(HashState &h, const PcpInstanceKey &key)
Appends hash value for this instance key.
Definition: instanceKey.h:54
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2002
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
GA_API const UT_StringHolder arc
PCP_API PcpInstanceKey()
PCP_API bool operator!=(const PcpInstanceKey &rhs) const
#define PCP_API
Definition: api.h:23
PcpArcType
Definition: types.h:27