Loading...
Searching...
No Matches
namespaceEdit.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_NAMESPACE_EDIT_H
25#define PXR_USD_SDF_NAMESPACE_EDIT_H
26
28
29#include "pxr/pxr.h"
30#include "pxr/usd/sdf/api.h"
31#include "pxr/usd/sdf/path.h"
32
33#include <functional>
34#include <iosfwd>
35#include <string>
36#include <vector>
37
38PXR_NAMESPACE_OPEN_SCOPE
39
46public:
47 typedef SdfNamespaceEdit This;
48 typedef SdfPath Path;
49 typedef int Index;
50
52 static const Index AtEnd = -1;
53
56 static const Index Same = -2;
57
60
62 SdfNamespaceEdit(const Path& currentPath_, const Path& newPath_,
63 Index index_ = AtEnd) :
64 currentPath(currentPath_), newPath(newPath_), index(index_) { }
65
67 static This Remove(const Path& currentPath)
68 {
70 }
71
74 static This Rename(const Path& currentPath, const TfToken& name)
75 {
77 }
78
81 static This Reorder(const Path& currentPath, Index index)
82 {
84 }
85
89 const Path& newParentPath,
90 Index index)
91 {
92 return This(currentPath,
94 newParentPath),
95 index);
96 }
97
102 const Path& newParentPath,
103 const TfToken& name,
104 Index index)
105 {
106 return This(currentPath,
108 newParentPath).
109 ReplaceName(name),
110 index);
111 }
112
113 SDF_API bool operator==(const This& rhs) const;
114 SDF_API bool operator!=(const This& rhs) const;
115
116public:
119 Index index;
120};
121
123typedef std::vector<SdfNamespaceEdit> SdfNamespaceEditVector;
124
125SDF_API std::ostream& operator<<(std::ostream&, const SdfNamespaceEdit&);
126SDF_API std::ostream& operator<<(std::ostream&, const SdfNamespaceEditVector&);
127
133public:
135 enum Result {
139 };
140
141 SDF_API SdfNamespaceEditDetail();
143 const std::string& reason);
144
145 SDF_API bool operator==(const SdfNamespaceEditDetail& rhs) const;
146 SDF_API bool operator!=(const SdfNamespaceEditDetail& rhs) const;
147
148public:
151 std::string reason;
152};
153
155typedef std::vector<SdfNamespaceEditDetail> SdfNamespaceEditDetailVector;
156
157SDF_API std::ostream& operator<<(std::ostream&, const SdfNamespaceEditDetail&);
158SDF_API std::ostream& operator<<(std::ostream&, const SdfNamespaceEditDetailVector&);
159
161inline
166{
167 return lhs < rhs ? lhs : rhs;
168}
169
171inline
174{
176}
177
179inline
182{
184}
185
212public:
217 SDF_API ~SdfBatchNamespaceEdit();
218
219 SDF_API SdfBatchNamespaceEdit& operator=(const SdfBatchNamespaceEdit&);
220
222 void Add(const SdfNamespaceEdit& edit)
223 {
224 _edits.push_back(edit);
225 }
226
228 void Add(const SdfNamespaceEdit::Path& currentPath,
229 const SdfNamespaceEdit::Path& newPath,
230 SdfNamespaceEdit::Index index = SdfNamespaceEdit::AtEnd)
231 {
232 Add(SdfNamespaceEdit(currentPath, newPath, index));
233 }
234
237 {
238 return _edits;
239 }
240
242 typedef std::function<bool(const SdfPath&)> HasObjectAtPath;
243
246 typedef std::function<bool(const SdfNamespaceEdit&,std::string*)> CanEdit;
247
286 SDF_API
287 bool Process(SdfNamespaceEditVector* processedEdits,
288 const HasObjectAtPath& hasObjectAtPath,
289 const CanEdit& canEdit,
290 SdfNamespaceEditDetailVector* details = NULL,
291 bool fixBackpointers = true) const;
292
293private:
295};
296
297PXR_NAMESPACE_CLOSE_SCOPE
298
299#endif // PXR_USD_SDF_NAMESPACE_EDIT_H
A description of an arbitrarily complex namespace edit.
SDF_API SdfBatchNamespaceEdit()
Create an empty sequence of edits.
void Add(const SdfNamespaceEdit::Path &currentPath, const SdfNamespaceEdit::Path &newPath, SdfNamespaceEdit::Index index=SdfNamespaceEdit::AtEnd)
Add a namespace edit.
void Add(const SdfNamespaceEdit &edit)
Add a namespace edit.
const SdfNamespaceEditVector & GetEdits() const
Returns the edits.
std::function< bool(const SdfNamespaceEdit &, std::string *)> CanEdit
Functor that returns true iff the namespace edit will succeed.
SDF_API bool Process(SdfNamespaceEditVector *processedEdits, const HasObjectAtPath &hasObjectAtPath, const CanEdit &canEdit, SdfNamespaceEditDetailVector *details=NULL, bool fixBackpointers=true) const
Validate the edits and generate a possibly more efficient edit sequence.
std::function< bool(const SdfPath &)> HasObjectAtPath
Functor that returns true iff an object exists at the given path.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:291
SDF_API SdfPath GetParentPath() const
Return the path that identifies this path's namespace parent.
static SDF_API const SdfPath & EmptyPath()
The empty path value, equivalent to SdfPath().
SDF_API SdfPath ReplacePrefix(const SdfPath &oldPrefix, const SdfPath &newPrefix, bool fixTargetPaths=true) const
Returns a path with all occurrences of the prefix path oldPrefix replaced with the prefix path newPre...
SDF_API SdfPath ReplaceName(TfToken const &newName) const
Return a copy of this path with its final component changed to newName.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:88
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
std::vector< SdfNamespaceEditDetail > SdfNamespaceEditDetailVector
A sequence of SdfNamespaceEditDetail.
SdfNamespaceEditDetail::Result CombineResult(SdfNamespaceEditDetail::Result lhs, SdfNamespaceEditDetail::Result rhs)
Combine two results, yielding Error over Unbatched over Okay.
SdfNamespaceEditDetail::Result CombineUnbatched(SdfNamespaceEditDetail::Result other)
Combine a result with Unbatched, yielding Error over Unbatched over Okay.
std::vector< SdfNamespaceEdit > SdfNamespaceEditVector
A sequence of SdfNamespaceEdit.
SdfNamespaceEditDetail::Result CombineError(SdfNamespaceEditDetail::Result)
Combine a result with Error, yielding Error over Unbatched over Okay.
Detailed information about a namespace edit.
Result
Validity of an edit.
@ Okay
Edit will succeed as a batch.
@ Error
Edit will fail.
@ Unbatched
Edit will succeed but not batched.
Result result
Validity.
SdfNamespaceEdit edit
The edit.
std::string reason
The reason the edit will not succeed cleanly.
A single namespace edit.
Definition: namespaceEdit.h:45
static This Rename(const Path &currentPath, const TfToken &name)
Returns a namespace edit that renames the prim or property at currentPath to name.
Definition: namespaceEdit.h:74
static This Remove(const Path &currentPath)
Returns a namespace edit that removes the object at currentPath.
Definition: namespaceEdit.h:67
static This Reparent(const Path &currentPath, const Path &newParentPath, Index index)
Returns a namespace edit to reparent the prim or property at currentPath to be under newParentPath at...
Definition: namespaceEdit.h:88
static const Index Same
Special index that means don't move.
Definition: namespaceEdit.h:56
Index index
Index for prim insertion.
static const Index AtEnd
Special index that means at the end.
Definition: namespaceEdit.h:52
static This Reorder(const Path &currentPath, Index index)
Returns a namespace edit to reorder the prim or property at currentPath to index index.
Definition: namespaceEdit.h:81
Path newPath
Path of the object when this edit ends.
static This ReparentAndRename(const Path &currentPath, const Path &newParentPath, const TfToken &name, Index index)
Returns a namespace edit to reparent the prim or property at currentPath to be under newParentPath at...
Path currentPath
Path of the object when this edit starts.
SdfNamespaceEdit(const Path &currentPath_, const Path &newPath_, Index index_=AtEnd)
The fully general edit.
Definition: namespaceEdit.h:62
SdfNamespaceEdit()
The default edit maps the empty path to the empty path.
Definition: namespaceEdit.h:59