1 //
2 // Copyright 2019 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 #include "pxr/pxr.h"
25 #include "pxr/usd/usd/common.h"
26 #include "pxr/usd/usd/payloads.h"
27 #include "pxr/usd/usd/listEditImpl.h"
28 
29 PXR_NAMESPACE_OPEN_SCOPE
30 
31 // ------------------------------------------------------------------------- //
32 // UsdPayloads
33 // ------------------------------------------------------------------------- //
34 
35 using _ListEditImpl =
36     Usd_ListEditImpl<UsdPayloads, SdfPayloadsProxy>;
37 
38 // The implementation doesn't define this function as it needs to be specialized
39 // so we implement it here.
40 template <>
41 SdfPayloadsProxy
_GetListEditorForSpec(const SdfPrimSpecHandle & spec)42 _ListEditImpl::_GetListEditorForSpec(const SdfPrimSpecHandle &spec)
43 {
44     return spec->GetPayloadList();
45 }
46 
47 bool
AddPayload(const SdfPayload & refIn,UsdListPosition position)48 UsdPayloads::AddPayload(const SdfPayload& refIn, UsdListPosition position)
49 {
50     return _ListEditImpl::Add(*this, refIn, position);
51 }
52 
53 bool
AddPayload(const std::string & assetPath,const SdfPath & primPath,const SdfLayerOffset & layerOffset,UsdListPosition position)54 UsdPayloads::AddPayload(const std::string &assetPath,
55                         const SdfPath &primPath,
56                         const SdfLayerOffset &layerOffset,
57                         UsdListPosition position)
58 {
59     SdfPayload payload(assetPath, primPath, layerOffset);
60     return AddPayload(payload, position);
61 }
62 
63 bool
AddPayload(const std::string & assetPath,const SdfLayerOffset & layerOffset,UsdListPosition position)64 UsdPayloads::AddPayload(const std::string &assetPath,
65                         const SdfLayerOffset &layerOffset,
66                         UsdListPosition position)
67 {
68     SdfPayload payload(assetPath, SdfPath(), layerOffset);
69     return AddPayload(payload, position);
70 }
71 
72 bool
AddInternalPayload(const SdfPath & primPath,const SdfLayerOffset & layerOffset,UsdListPosition position)73 UsdPayloads::AddInternalPayload(const SdfPath &primPath,
74                                 const SdfLayerOffset &layerOffset,
75                                 UsdListPosition position)
76 {
77     SdfPayload payload(std::string(), primPath, layerOffset);
78     return AddPayload(payload, position);
79 }
80 
81 bool
RemovePayload(const SdfPayload & refIn)82 UsdPayloads::RemovePayload(const SdfPayload& refIn)
83 {
84     return _ListEditImpl::Remove(*this, refIn);
85 }
86 
87 bool
ClearPayloads()88 UsdPayloads::ClearPayloads()
89 {
90     return _ListEditImpl::Clear(*this);
91 }
92 
93 bool
SetPayloads(const SdfPayloadVector & itemsIn)94 UsdPayloads::SetPayloads(const SdfPayloadVector& itemsIn)
95 {
96     return _ListEditImpl::Set(*this, itemsIn);
97 }
98 
99 PXR_NAMESPACE_CLOSE_SCOPE
100 
101