HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
reference.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_SDF_REFERENCE_H
25 #define PXR_USD_SDF_REFERENCE_H
26 
27 /// \file sdf/reference.h
28 
29 #include "pxr/pxr.h"
30 #include "pxr/usd/sdf/api.h"
32 #include "pxr/usd/sdf/path.h"
33 #include "pxr/base/vt/dictionary.h"
34 #include "pxr/base/vt/value.h"
35 
36 #include <hboost/operators.hpp>
37 
38 #include <iosfwd>
39 #include <string>
40 #include <vector>
41 
43 
45 
46 typedef std::vector<SdfReference> SdfReferenceVector;
47 
48 /// \class SdfReference
49 ///
50 /// Represents a reference and all its meta data.
51 ///
52 /// A reference is expressed on a prim in a given layer and it identifies a
53 /// prim in a layer stack. All opinions in the namespace hierarchy
54 /// under the referenced prim will be composed with the opinions in the
55 /// namespace hierarchy under the referencing prim.
56 ///
57 /// The asset path specifies the layer stack being referenced. If this
58 /// asset path is non-empty, this reference is considered an 'external'
59 /// reference to the layer stack rooted at the specified layer. If this
60 /// is empty, this reference is considered an 'internal' reference to the
61 /// layer stack containing (but not necessarily rooted at) the layer where
62 /// the reference is authored.
63 ///
64 /// The prim path specifies the prim in the referenced layer stack from
65 /// which opinions will be composed. If this prim path is empty, it will
66 /// be considered a reference to the default prim specified in the root layer
67 /// of the referenced layer stack -- see SdfLayer::GetDefaultPrim.
68 ///
69 /// The meta data for a reference is its layer offset and custom data. The
70 /// layer offset is an affine transformation applied to all anim splines in
71 /// the referenced prim's namespace hierarchy, see SdfLayerOffset for details.
72 /// Custom data is for use by plugins or other non-tools supplied extensions
73 /// that need to be able to store data associated with references.
74 ///
75 class SdfReference : hboost::totally_ordered<SdfReference> {
76 public:
77  /// Creates a reference with all its meta data. The default
78  /// reference is an internal reference to the default prim.
79  ///
81  const std::string &assetPath = std::string(),
82  const SdfPath &primPath = SdfPath(),
83  const SdfLayerOffset &layerOffset = SdfLayerOffset(),
84  const VtDictionary &customData = VtDictionary());
85 
86  /// Returns the asset path to the root layer of the referenced layer
87  /// stack. This will be empty in the case of an internal reference.
88  ///
89  const std::string &GetAssetPath() const {
90  return _assetPath;
91  }
92 
93  /// Sets the asset path for the root layer of the referenced layer stack.
94  /// This may be set to an empty string to specify an internal reference.
95  ///
96  void SetAssetPath(const std::string &assetPath) {
97  _assetPath = assetPath;
98  }
99 
100  /// Returns the path of the referenced prim.
101  /// This will be empty if the referenced prim is the default prim specified
102  /// in the referenced layer stack.
103  ///
104  const SdfPath &GetPrimPath() const {
105  return _primPath;
106  }
107 
108  /// Sets the path of the referenced prim.
109  /// This may be set to an empty path to specify a reference to the default
110  /// prim in the referenced layer stack.
111  ///
112  void SetPrimPath(const SdfPath &primPath) {
113  _primPath = primPath;
114  }
115 
116  /// Returns the layer offset associated with the reference.
117  ///
119  return _layerOffset;
120  }
121 
122  /// Sets a new layer offset.
123  ///
124  void SetLayerOffset(const SdfLayerOffset &layerOffset) {
125  _layerOffset = layerOffset;
126  }
127 
128  /// Returns the custom data associated with the reference.
129  ///
130  const VtDictionary &GetCustomData() const {
131  return _customData;
132  }
133 
134  /// Sets the custom data associated with the reference.
135  ///
136  void SetCustomData(const VtDictionary &customData) {
137  _customData = customData;
138  }
139 
140  /// Sets a custom data entry for the reference.
141  ///
142  /// If \a value is empty, then this removes the given custom data entry.
143  ///
144  SDF_API void SetCustomData(const std::string &name, const VtValue &value);
145 
146  /// Swaps the custom data dictionary for this reference.
147  void SwapCustomData(VtDictionary &customData) {
148  _customData.swap(customData);
149  }
150 
151  /// Returns \c true in the case of an internal reference.
152  ///
153  /// An internal reference is a reference with an empty asset path.
154  ///
155  SDF_API bool IsInternal() const;
156 
157  friend inline size_t hash_value(const SdfReference &r) {
158  size_t h = 0;
159  hboost::hash_combine(h, r._assetPath);
160  hboost::hash_combine(h, r._primPath);
161  hboost::hash_combine(h, r._layerOffset);
162  hboost::hash_combine(h, r._customData);
163  return h;
164  }
165 
166  /// Returns whether this reference equals \a rhs.
167  SDF_API bool operator==(const SdfReference &rhs) const;
168 
169  /// Returns whether this reference is less than \a rhs. The meaning
170  /// of less than is somewhat arbitrary.
171  SDF_API bool operator<(const SdfReference &rhs) const;
172 
173  /// Struct that defines equality of SdfReferences based on their
174  /// identity (the asset path and prim path).
175  ///
176  struct IdentityEqual {
177  bool operator()(const SdfReference &lhs, const SdfReference &rhs) const {
178  return lhs._assetPath == rhs._assetPath &&
179  lhs._primPath == rhs._primPath;
180  }
181  };
182 
183  /// Struct that defines a strict weak ordering of SdfReferences based on
184  /// their identity (the asset path and prim path).
185  ///
187  bool operator()(const SdfReference &lhs, const SdfReference &rhs) const {
188  return lhs._assetPath < rhs._assetPath ||
189  (lhs._assetPath == rhs._assetPath &&
190  lhs._primPath < rhs._primPath);
191  }
192  };
193 
194 private:
195  // The asset path to the external layer.
196  std::string _assetPath;
197 
198  // The path to the referenced prim in the external layer.
199  SdfPath _primPath;
200 
201  // The layer offset to transform time.
202  SdfLayerOffset _layerOffset;
203 
204  // The custom data associated with the reference.
205  VtDictionary _customData;
206 };
207 
208 /// Convenience function to find the index of the reference in \a references
209 /// that has the same identity as the given reference \a referenceId.
210 ///
211 /// A reference's identity is given by its asset path and prim path alone
212 /// (i.e. the layer offset and custom data is ignored).
213 ///
214 /// If no reference with the same identity exists in \a reference, -1 is
215 /// returned. If more than one reference with the same identity exist in
216 /// \a references the index of the first one is returned.
217 ///
219  const SdfReferenceVector &references,
220  const SdfReference &referenceId);
221 
222 /// Writes the string representation of \a SdfReference to \a out.
223 SDF_API std::ostream & operator<<( std::ostream &out,
224  const SdfReference &reference );
225 
227 
228 #endif // PXR_USD_SDF_REFERENCE_H
const VtDictionary & GetCustomData() const
Definition: reference.h:130
bool operator()(const SdfReference &lhs, const SdfReference &rhs) const
Definition: reference.h:187
SDF_API std::ostream & operator<<(std::ostream &out, const SdfReference &reference)
Writes the string representation of SdfReference to out.
GLuint const GLchar * name
Definition: glew.h:1814
SDF_API bool IsInternal() const
void SetPrimPath(const SdfPath &primPath)
Definition: reference.h:112
const std::string & GetAssetPath() const
Definition: reference.h:89
bool operator()(const SdfReference &lhs, const SdfReference &rhs) const
Definition: reference.h:177
void SetAssetPath(const std::string &assetPath)
Definition: reference.h:96
void SetLayerOffset(const SdfLayerOffset &layerOffset)
Definition: reference.h:124
GLfloat GLfloat GLfloat GLfloat h
Definition: glew.h:8011
Definition: path.h:288
friend size_t hash_value(const SdfReference &r)
Definition: reference.h:157
SDF_API SdfReference(const std::string &assetPath=std::string(), const SdfPath &primPath=SdfPath(), const SdfLayerOffset &layerOffset=SdfLayerOffset(), const VtDictionary &customData=VtDictionary())
#define SDF_API
Definition: api.h:40
GLsizei const GLchar *const * string
Definition: glew.h:1844
std::vector< SdfReference > SdfReferenceVector
Definition: reference.h:44
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1346
const SdfPath & GetPrimPath() const
Definition: reference.h:104
SDF_API bool operator<(const SdfReference &rhs) const
const SdfLayerOffset & GetLayerOffset() const
Definition: reference.h:118
void SetCustomData(const VtDictionary &customData)
Definition: reference.h:136
GLdouble GLdouble GLdouble r
Definition: glew.h:1406
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
SDF_API bool operator==(const SdfReference &rhs) const
Returns whether this reference equals rhs.
GLenum const void GLuint GLint reference
Definition: glew.h:13644
SDF_API int SdfFindReferenceByIdentity(const SdfReferenceVector &references, const SdfReference &referenceId)
VT_API void swap(VtDictionary &dict)
Swaps the contents of two VtDictionaries.
GLsizei const GLfloat * value
Definition: glew.h:1849
Definition: value.h:174
void SwapCustomData(VtDictionary &customData)
Swaps the custom data dictionary for this reference.
Definition: reference.h:147