All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 <boost/operators.hpp>
34 
35 #include <functional>
36 #include <iosfwd>
37 #include <string>
38 #include <vector>
39 
40 PXR_NAMESPACE_OPEN_SCOPE
41 
48  boost::equality_comparable<SdfNamespaceEdit> {
49 public:
50  typedef SdfNamespaceEdit This;
51  typedef SdfPath Path;
52  typedef int Index;
53 
55  static const Index AtEnd = -1;
56 
59  static const Index Same = -2;
60 
63 
65  SdfNamespaceEdit(const Path& currentPath_, const Path& newPath_,
66  Index index_ = AtEnd) :
67  currentPath(currentPath_), newPath(newPath_), index(index_) { }
68 
70  static This Remove(const Path& currentPath)
71  {
72  return This(currentPath, Path::EmptyPath());
73  }
74 
77  static This Rename(const Path& currentPath, const TfToken& name)
78  {
79  return This(currentPath, currentPath.ReplaceName(name), Same);
80  }
81 
84  static This Reorder(const Path& currentPath, Index index)
85  {
86  return This(currentPath, currentPath, index);
87  }
88 
91  static This Reparent(const Path& currentPath,
92  const Path& newParentPath,
93  Index index)
94  {
95  return This(currentPath,
96  currentPath.ReplacePrefix(currentPath.GetParentPath(),
97  newParentPath),
98  index);
99  }
100 
105  const Path& newParentPath,
106  const TfToken& name,
107  Index index)
108  {
109  return This(currentPath,
110  currentPath.ReplacePrefix(currentPath.GetParentPath(),
111  newParentPath).
112  ReplaceName(name),
113  index);
114  }
115 
116  SDF_API bool operator==(const This& rhs) const;
117 
118 public:
121  Index index;
122 };
123 
125 typedef std::vector<SdfNamespaceEdit> SdfNamespaceEditVector;
126 
127 SDF_API std::ostream& operator<<(std::ostream&, const SdfNamespaceEdit&);
128 SDF_API std::ostream& operator<<(std::ostream&, const SdfNamespaceEditVector&);
129 
135  boost::equality_comparable<SdfNamespaceEditDetail> {
136 public:
138  enum Result {
142  };
143 
144  SDF_API SdfNamespaceEditDetail();
146  const std::string& reason);
147 
148  SDF_API bool operator==(const SdfNamespaceEditDetail& rhs) const;
149 
150 public:
153  std::string reason;
154 };
155 
157 typedef std::vector<SdfNamespaceEditDetail> SdfNamespaceEditDetailVector;
158 
159 SDF_API std::ostream& operator<<(std::ostream&, const SdfNamespaceEditDetail&);
160 SDF_API std::ostream& operator<<(std::ostream&, const SdfNamespaceEditDetailVector&);
161 
163 inline
168 {
169  return lhs < rhs ? lhs : rhs;
170 }
171 
173 inline
176 {
178 }
179 
181 inline
184 {
186 }
187 
214 public:
216  SDF_API SdfBatchNamespaceEdit();
217  SDF_API SdfBatchNamespaceEdit(const SdfBatchNamespaceEdit&);
219  SDF_API ~SdfBatchNamespaceEdit();
220 
221  SDF_API SdfBatchNamespaceEdit& operator=(const SdfBatchNamespaceEdit&);
222 
224  void Add(const SdfNamespaceEdit& edit)
225  {
226  _edits.push_back(edit);
227  }
228 
230  void Add(const SdfNamespaceEdit::Path& currentPath,
231  const SdfNamespaceEdit::Path& newPath,
232  SdfNamespaceEdit::Index index = SdfNamespaceEdit::AtEnd)
233  {
234  Add(SdfNamespaceEdit(currentPath, newPath, index));
235  }
236 
239  {
240  return _edits;
241  }
242 
244  typedef std::function<bool(const SdfPath&)> HasObjectAtPath;
245 
248  typedef std::function<bool(const SdfNamespaceEdit&,std::string*)> CanEdit;
249 
288  SDF_API
289  bool Process(SdfNamespaceEditVector* processedEdits,
290  const HasObjectAtPath& hasObjectAtPath,
291  const CanEdit& canEdit,
292  SdfNamespaceEditDetailVector* details = NULL,
293  bool fixBackpointers = true) const;
294 
295 private:
296  SdfNamespaceEditVector _edits;
297 };
298 
299 PXR_NAMESPACE_CLOSE_SCOPE
300 
301 #endif // PXR_USD_SDF_NAMESPACE_EDIT_H
static const Index AtEnd
Special index that means at the end.
Definition: namespaceEdit.h:55
std::vector< SdfNamespaceEditDetail > SdfNamespaceEditDetailVector
A sequence of SdfNamespaceEditDetail.
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.
A single namespace edit.
Definition: namespaceEdit.h:47
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:91
Path newPath
Path of the object when this edit ends.
SdfNamespaceEditDetail::Result CombineResult(SdfNamespaceEditDetail::Result lhs, SdfNamespaceEditDetail::Result rhs)
Combine two results, yielding Error over Unbatched over Okay.
SDF_API SdfPath GetParentPath() const
Return the path that identifies this path&#39;s namespace parent.
static This Remove(const Path &currentPath)
Returns a namespace edit that removes the object at currentPath.
Definition: namespaceEdit.h:70
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:84
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...
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:87
SdfNamespaceEdit()
The default edit maps the empty path to the empty path.
Definition: namespaceEdit.h:62
std::function< bool(const SdfPath &)> HasObjectAtPath
Functor that returns true iff an object exists at the given path.
SdfNamespaceEditDetail::Result CombineUnbatched(SdfNamespaceEditDetail::Result other)
Combine a result with Unbatched, yielding Error over Unbatched over Okay.
SdfNamespaceEditDetail::Result CombineError(SdfNamespaceEditDetail::Result)
Combine a result with Error, yielding Error over Unbatched over Okay.
A description of an arbitrarily complex namespace edit.
void Add(const SdfNamespaceEdit::Path &currentPath, const SdfNamespaceEdit::Path &newPath, SdfNamespaceEdit::Index index=SdfNamespaceEdit::AtEnd)
Add a namespace edit.
SDF_API SdfPath ReplaceName(TfToken const &newName) const
Return a copy of this path with its final component changed to newName.
Result result
Validity.
Result
Validity of an edit.
static const Index Same
Special index that means don&#39;t move.
Definition: namespaceEdit.h:59
std::vector< SdfNamespaceEdit > SdfNamespaceEditVector
A sequence of SdfNamespaceEdit.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:288
std::function< bool(const SdfNamespaceEdit &, std::string *)> CanEdit
Functor that returns true iff the namespace edit will succeed.
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
SdfNamespaceEdit edit
The edit.
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...
const SdfNamespaceEditVector & GetEdits() const
Returns the edits.
Path currentPath
Path of the object when this edit starts.
Detailed information about a namespace edit.
Index index
Index for prim insertion.
static SDF_API const SdfPath & EmptyPath()
The empty path value, equivalent to SdfPath().
void Add(const SdfNamespaceEdit &edit)
Add a namespace edit.
Edit will succeed as a batch.
SDF_API SdfBatchNamespaceEdit()
Create an empty sequence of edits.
std::string reason
The reason the edit will not succeed cleanly.
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:77
Edit will succeed but not batched.
SdfNamespaceEdit(const Path &currentPath_, const Path &newPath_, Index index_=AtEnd)
The fully general edit.
Definition: namespaceEdit.h:65