HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
payload.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_SDF_PAYLOAD_H
8 #define PXR_USD_SDF_PAYLOAD_H
9 
10 /// \file sdf/payload.h
11 
12 #include "pxr/pxr.h"
13 #include "pxr/usd/sdf/api.h"
14 #include "pxr/usd/sdf/assetPath.h"
16 #include "pxr/usd/sdf/path.h"
17 #include "pxr/base/tf/hash.h"
18 
19 #include <iosfwd>
20 #include <string>
21 #include <vector>
22 
24 
25 class SdfPayload;
26 
27 typedef std::vector<SdfPayload> SdfPayloadVector;
28 
29 /// \class SdfPayload
30 ///
31 /// Represents a payload and all its meta data.
32 ///
33 /// A payload represents a prim reference to an external layer. A payload
34 /// is similar to a prim reference (see SdfReference) with the major
35 /// difference that payloads are explicitly loaded by the user.
36 ///
37 /// Unloaded payloads represent a boundary that lazy composition and
38 /// system behaviors will not traverse across, providing a user-visible
39 /// way to manage the working set of the scene.
40 ///
41 class SdfPayload {
42 public:
43  /// Create a payload. See SdfAssetPath for what characters are valid in \p
44  /// assetPath. If \p assetPath contains invalid characters, issue an error
45  /// and set this payload's asset path to the empty asset path.
46  ///
47  SDF_API
48  SdfPayload(
49  const std::string &assetPath = std::string(),
50  const SdfPath &primPath = SdfPath(),
51  const SdfLayerOffset &layerOffset = SdfLayerOffset());
52 
53  /// Returns the asset path of the layer that the payload uses.
54  const std::string &GetAssetPath() const {
55  return _assetPath;
56  }
57 
58  /// Sets a new asset path for the layer the payload uses. See SdfAssetPath
59  /// for what characters are valid in \p assetPath. If \p assetPath contains
60  /// invalid characters, issue an error and set this payload's asset path to
61  /// the empty asset path.
62  void SetAssetPath(const std::string &assetPath) {
63  // Go through SdfAssetPath() to raise an error if \p assetPath contains
64  // illegal characters (i.e. control characters).
65  _assetPath = SdfAssetPath(assetPath).GetAssetPath();
66  }
67 
68  /// Returns the scene path of the prim for the payload.
69  const SdfPath &GetPrimPath() const {
70  return _primPath;
71  }
72 
73  /// Sets a new prim path for the prim that the payload uses.
74  void SetPrimPath(const SdfPath &primPath) {
75  _primPath = primPath;
76  }
77 
78  /// Returns the layer offset associated with the payload.
79  const SdfLayerOffset &GetLayerOffset() const {
80  return _layerOffset;
81  }
82 
83  /// Sets a new layer offset.
84  void SetLayerOffset(const SdfLayerOffset &layerOffset) {
85  _layerOffset = layerOffset;
86  }
87 
88  /// Returns whether this payload equals \a rhs.
89  SDF_API bool operator==(const SdfPayload &rhs) const;
90 
91  /// \sa SdfPayload::operator==
92  bool operator!=(const SdfPayload& rhs) const {
93  return !(*this == rhs);
94  }
95 
96  /// Returns whether this payload is less than \a rhs.
97  /// The meaning of less than is arbitrary but stable.
98  SDF_API bool operator<(const SdfPayload &rhs) const;
99 
100  /// \sa SdfPayload::operator<
101  bool operator>(const SdfPayload& rhs) const {
102  return rhs < *this;
103  }
104 
105  /// \sa SdfPayload::operator<
106  bool operator<=(const SdfPayload& rhs) const {
107  return !(rhs < *this);
108  }
109 
110  /// \sa SdfPayload::operator<
111  bool operator>=(const SdfPayload& rhs) const {
112  return !(*this < rhs);
113  }
114 
115 private:
116  friend inline size_t hash_value(const SdfPayload &p) {
117  return TfHash::Combine(
118  p._assetPath,
119  p._primPath,
120  p._layerOffset
121  );
122  }
123 
124  // The asset path to the external layer.
125  std::string _assetPath;
126 
127  // The root prim path to the referenced prim in the external layer.
128  SdfPath _primPath;
129 
130  // The layer offset to transform time.
131  SdfLayerOffset _layerOffset;
132 };
133 
134 /// Writes the string representation of \a SdfPayload to \a out.
135 SDF_API
136 std::ostream & operator<<(std::ostream &out, const SdfPayload &payload);
137 
139 
140 #endif
const SdfPath & GetPrimPath() const
Returns the scene path of the prim for the payload.
Definition: payload.h:69
SDF_API std::ostream & operator<<(std::ostream &out, const SdfPayload &payload)
Writes the string representation of SdfPayload to out.
std::vector< SdfPayload > SdfPayloadVector
Definition: payload.h:25
SDF_API bool operator==(const SdfPayload &rhs) const
Returns whether this payload equals rhs.
const std::string & GetAssetPath() const
Returns the asset path of the layer that the payload uses.
Definition: payload.h:54
void SetPrimPath(const SdfPath &primPath)
Sets a new prim path for the prim that the payload uses.
Definition: payload.h:74
bool operator<=(const SdfPayload &rhs) const
Definition: payload.h:106
const std::string & GetAssetPath() const &
Definition: assetPath.h:199
SDF_API bool operator<(const SdfPayload &rhs) const
bool operator!=(const SdfPayload &rhs) const
Definition: payload.h:92
Definition: path.h:273
const SdfLayerOffset & GetLayerOffset() const
Returns the layer offset associated with the payload.
Definition: payload.h:79
friend size_t hash_value(const SdfPayload &p)
Definition: payload.h:116
#define SDF_API
Definition: api.h:23
static size_t Combine(Args &&...args)
Produce a hash code by combining the hash codes of several objects.
Definition: hash.h:487
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
void SetLayerOffset(const SdfLayerOffset &layerOffset)
Sets a new layer offset.
Definition: payload.h:84
bool operator>(const SdfPayload &rhs) const
Definition: payload.h:101
bool operator>=(const SdfPayload &rhs) const
Definition: payload.h:111
SDF_API SdfPayload(const std::string &assetPath=std::string(), const SdfPath &primPath=SdfPath(), const SdfLayerOffset &layerOffset=SdfLayerOffset())
void SetAssetPath(const std::string &assetPath)
Definition: payload.h:62