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