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