This document is for a version of USD that is under development. See this page for the current release.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
namespaceEdit.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_NAMESPACE_EDIT_H
8#define PXR_USD_SDF_NAMESPACE_EDIT_H
9
11
12#include "pxr/pxr.h"
13#include "pxr/usd/sdf/api.h"
14#include "pxr/usd/sdf/path.h"
15
16#include <functional>
17#include <iosfwd>
18#include <string>
19#include <vector>
20
21PXR_NAMESPACE_OPEN_SCOPE
22
29public:
30 typedef SdfNamespaceEdit This;
31 typedef SdfPath Path;
32 typedef int Index;
33
35 static const Index AtEnd = -1;
36
39 static const Index Same = -2;
40
43
45 SdfNamespaceEdit(const Path& currentPath_, const Path& newPath_,
46 Index index_ = AtEnd) :
47 currentPath(currentPath_), newPath(newPath_), index(index_) { }
48
50 static This Remove(const Path& currentPath)
51 {
53 }
54
57 static This Rename(const Path& currentPath, const TfToken& name)
58 {
60 }
61
64 static This Reorder(const Path& currentPath, Index index)
65 {
67 }
68
72 const Path& newParentPath,
73 Index index)
74 {
75 return This(currentPath,
77 newParentPath),
78 index);
79 }
80
85 const Path& newParentPath,
86 const TfToken& name,
87 Index index)
88 {
89 return This(currentPath,
91 newParentPath).
92 ReplaceName(name),
93 index);
94 }
95
96 SDF_API bool operator==(const This& rhs) const;
97 SDF_API bool operator!=(const This& rhs) const;
98
99public:
102 Index index;
103};
104
106typedef std::vector<SdfNamespaceEdit> SdfNamespaceEditVector;
107
108SDF_API std::ostream& operator<<(std::ostream&, const SdfNamespaceEdit&);
109SDF_API std::ostream& operator<<(std::ostream&, const SdfNamespaceEditVector&);
110
116public:
118 enum Result {
122 };
123
124 SDF_API SdfNamespaceEditDetail();
126 const std::string& reason);
127
128 SDF_API bool operator==(const SdfNamespaceEditDetail& rhs) const;
129 SDF_API bool operator!=(const SdfNamespaceEditDetail& rhs) const;
130
131public:
134 std::string reason;
135};
136
138typedef std::vector<SdfNamespaceEditDetail> SdfNamespaceEditDetailVector;
139
140SDF_API std::ostream& operator<<(std::ostream&, const SdfNamespaceEditDetail&);
141SDF_API std::ostream& operator<<(std::ostream&, const SdfNamespaceEditDetailVector&);
142
144inline
149{
150 return lhs < rhs ? lhs : rhs;
151}
152
154inline
157{
159}
160
162inline
165{
167}
168
195public:
200 SDF_API ~SdfBatchNamespaceEdit();
201
202 SDF_API SdfBatchNamespaceEdit& operator=(const SdfBatchNamespaceEdit&);
203
205 void Add(const SdfNamespaceEdit& edit)
206 {
207 _edits.push_back(edit);
208 }
209
211 void Add(const SdfNamespaceEdit::Path& currentPath,
212 const SdfNamespaceEdit::Path& newPath,
213 SdfNamespaceEdit::Index index = SdfNamespaceEdit::AtEnd)
214 {
215 Add(SdfNamespaceEdit(currentPath, newPath, index));
216 }
217
220 {
221 return _edits;
222 }
223
225 typedef std::function<bool(const SdfPath&)> HasObjectAtPath;
226
229 typedef std::function<bool(const SdfNamespaceEdit&,std::string*)> CanEdit;
230
269 SDF_API
270 bool Process(SdfNamespaceEditVector* processedEdits,
271 const HasObjectAtPath& hasObjectAtPath,
272 const CanEdit& canEdit,
273 SdfNamespaceEditDetailVector* details = NULL,
274 bool fixBackpointers = true) const;
275
276private:
278};
279
280PXR_NAMESPACE_CLOSE_SCOPE
281
282#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:274
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:71
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:28
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:57
static This Remove(const Path &currentPath)
Returns a namespace edit that removes the object at currentPath.
Definition: namespaceEdit.h:50
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:71
static const Index Same
Special index that means don't move.
Definition: namespaceEdit.h:39
Index index
Index for prim insertion.
static const Index AtEnd
Special index that means at the end.
Definition: namespaceEdit.h:35
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:64
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...
Definition: namespaceEdit.h:84
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:45
SdfNamespaceEdit()
The default edit maps the empty path to the empty path.
Definition: namespaceEdit.h:42