HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
changeList.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_CHANGE_LIST_H
25 #define PXR_USD_SDF_CHANGE_LIST_H
26 
27 /// \file sdf/changeList.h
28 
29 #include "pxr/pxr.h"
30 #include "pxr/usd/sdf/api.h"
31 #include "pxr/usd/sdf/path.h"
32 #include "pxr/usd/sdf/types.h"
34 
35 #include <set>
36 #include <map>
37 #include <unordered_map>
38 #include <iosfwd>
39 
41 
43 typedef std::vector<
44  std::pair<SdfLayerHandle, SdfChangeList>
46 
47 /// \class SdfChangeList
48 ///
49 /// A list of scene description modifications, organized by the namespace
50 /// paths where the changes occur.
51 ///
53 {
54 public:
55 
56  SdfChangeList() = default;
58  SdfChangeList(SdfChangeList &&) = default;
59  SDF_API SdfChangeList &operator=(SdfChangeList const &);
60  SdfChangeList &operator=(SdfChangeList &&) = default;
61 
66  };
67 
69  void DidReloadLayerContent();
71  void DidChangeLayerIdentifier(const std::string &oldIdentifier);
72  void DidChangeSublayerPaths(const std::string &subLayerPath,
73  SubLayerChangeType changeType);
74 
75  void DidAddPrim(const SdfPath &primPath, bool inert);
76  void DidRemovePrim(const SdfPath &primPath, bool inert);
77  void DidMovePrim(const SdfPath &oldPath, const SdfPath &newPath);
78  void DidReorderPrims(const SdfPath &parentPath);
79  void DidChangePrimName(const SdfPath &oldPath, const SdfPath &newPath);
80  void DidChangePrimVariantSets(const SdfPath &primPath);
81  void DidChangePrimInheritPaths(const SdfPath &primPath);
82  void DidChangePrimReferences(const SdfPath &primPath);
83  void DidChangePrimSpecializes(const SdfPath &primPath);
84 
85  void DidAddProperty(const SdfPath &propPath, bool hasOnlyRequiredFields);
86  void DidRemoveProperty(const SdfPath &propPath, bool hasOnlyRequiredFields);
87  void DidReorderProperties(const SdfPath &propPath);
88  void DidChangePropertyName(const SdfPath &oldPath, const SdfPath &newPath);
89 
90  void DidChangeAttributeTimeSamples(const SdfPath &attrPath);
91  void DidChangeAttributeConnection(const SdfPath &attrPath);
92  void DidChangeRelationshipTargets(const SdfPath &relPath);
93  void DidAddTarget(const SdfPath &targetPath);
94  void DidRemoveTarget(const SdfPath &targetPath);
95 
96  void DidChangeInfo(const SdfPath &path, const TfToken &key,
97  VtValue &&oldValue, const VtValue &newValue);
98 
99  /// \struct Entry
100  ///
101  /// Entry of changes at a single path in namespace.
102  ///
103  /// If the path is SdfPath::AbsoluteRootPath(), that indicates a change
104  /// to the root of namespace (that is, a layer or stage).
105  ///
106  /// Note: Our language for invalidation used to be more precise
107  /// about items added, removed, or reordered. It might seem that
108  /// this would afford more opportunities for efficient updates,
109  /// but in practice it does not. Because our derived data typically
110  /// must recompose or reinstantiate based on the underlying data,
111  /// the particular delta might be ignored, overridden, or invalid.
112  /// It is simpler to treat all changes identically, and focus on
113  /// making the common base case fast, rather than have complicated
114  /// differential update logic. It also vastly simplifies the
115  /// language of invalidation.
116  ///
117  struct Entry {
118  // Map of info keys that have changed to (old, new) value pairs.
119  typedef std::pair<VtValue, VtValue> InfoChange;
120  // We usually change just a few fields on a spec in one go, so we store
121  // up to three locally (e.g. typeName, variability, default).
124 
125  /// Return the iterator in infoChanged whose first element is \p key, or
126  /// infoChanged.end() if there is no such element.
128  FindInfoChange(TfToken const &key) const {
131  iter != end; ++iter) {
132  if (iter->first == key) {
133  break;
134  }
135  }
136  return iter;
137  }
138 
139  /// Return true if this entry has an info change for \p key, false
140  /// otherwise.
141  bool HasInfoChange(TfToken const &key) const {
142  return FindInfoChange(key) != infoChanged.end();
143  }
144 
145  typedef std::pair<std::string, SubLayerChangeType> SubLayerChange;
146  std::vector<SubLayerChange> subLayerChanges;
147 
148  // Empty if didRename is not set
150 
151  // Empty if didChangeIdentifier is not set
153 
154  // Most changes are stored as simple bits.
155  struct _Flags {
156  _Flags() {
157  memset(this, 0, sizeof(*this));
158  }
159 
160  // SdfLayer
165 
166  // SdfLayer, SdfPrimSpec, SdfRelationshipTarget.
169 
170  // SdfPrimSpec, SdfPropertySpec
171  bool didRename:1;
172 
173  // SdfPrimSpec
178 
179  // SdfPropertySpec
183  bool didAddTarget:1;
185 
186  // SdfPrimSpec add/remove
191 
192  // Property add/remove
197  };
198 
200  };
201 
202  /// Map of change entries at various paths in a layer. We store one entry
203  /// in local space, since it's very common to edit just a single spec in a
204  /// single round of changes.
206 
207 public:
208  const EntryList & GetEntryList() const { return _entries; }
209 
210  // Change accessors/mutators
211  SDF_API
212  Entry const &GetEntry( const SdfPath & ) const;
213 
215 
216  SDF_API
217  const_iterator FindEntry(SdfPath const &) const;
218 
220  return _entries.begin();
221  }
222 
224  return _entries.cbegin();
225  }
226 
227  const_iterator end() const {
228  return _entries.end();
229  }
230 
232  return _entries.cend();
233  }
234 
235 private:
236  friend void swap(SdfChangeList &a, SdfChangeList &b) {
237  a._entries.swap(b._entries);
238  a._entriesAccel.swap(b._entriesAccel);
239  }
240 
241  Entry &_GetEntry(SdfPath const &);
242 
243  // If no entry with `newPath` exists, create one. If an entry with
244  // `oldPath` exists, move its contents over `newPath`'s and erase it.
245  // Return a reference to `newPath`'s entry.
246  Entry &_MoveEntry(SdfPath const &oldPath, SdfPath const &newPath);
247 
248  EntryList::iterator _MakeNonConstIterator(EntryList::const_iterator i);
249 
250  Entry &_AddNewEntry(SdfPath const &path);
251 
252  void _EraseEntry(SdfPath const &);
253 
254  void _RebuildAccel();
255 
256  EntryList _entries;
257  using _AccelTable = std::unordered_map<SdfPath, size_t, SdfPath::Hash>;
258  std::unique_ptr<_AccelTable> _entriesAccel;
259  static constexpr size_t _AccelThreshold = 64;
260 };
261 
262 // Stream-output operator
263 SDF_API std::ostream& operator<<(std::ostream&, const SdfChangeList &);
264 
266 
267 #endif // PXR_USD_SDF_CHANGE_LIST_H
SDF_API Entry const & GetEntry(const SdfPath &) const
void DidMovePrim(const SdfPath &oldPath, const SdfPath &newPath)
void DidReorderProperties(const SdfPath &propPath)
const_iterator cend() const
Definition: changeList.h:231
std::pair< VtValue, VtValue > InfoChange
Definition: changeList.h:119
iterator end()
Definition: smallVector.h:682
TfSmallVector< std::pair< SdfPath, Entry >, 1 > EntryList
Definition: changeList.h:205
void DidChangePrimInheritPaths(const SdfPath &primPath)
const_iterator cbegin() const
Definition: smallVector.h:673
bool didRemovePropertyWithOnlyRequiredFields
Definition: changeList.h:195
void DidAddPrim(const SdfPath &primPath, bool inert)
bool didChangeIdentifier
Definition: changeList.h:161
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
void DidReloadLayerContent()
Definition: changeList.h:155
bool didAddNonInertPrim
Definition: changeList.h:188
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
InfoChangeVec infoChanged
Definition: changeList.h:123
bool didAddInertPrim
Definition: changeList.h:187
SDF_API const_iterator FindEntry(SdfPath const &) const
TfSmallVector< std::pair< TfToken, InfoChange >, 3 > InfoChangeVec
Definition: changeList.h:122
bool didRemoveNonInertPrim
Definition: changeList.h:190
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
bool didRename
Definition: changeList.h:171
void DidChangeRelationshipTargets(const SdfPath &relPath)
std::vector< SubLayerChange > subLayerChanges
Definition: changeList.h:146
std::string oldIdentifier
Definition: changeList.h:152
std::pair< std::string, SubLayerChangeType > SubLayerChange
Definition: changeList.h:145
bool didReorderProperties
Definition: changeList.h:168
void DidChangeAttributeConnection(const SdfPath &attrPath)
friend void swap(SdfChangeList &a, SdfChangeList &b)
Definition: changeList.h:236
bool didChangeRelationshipTargets
Definition: changeList.h:182
bool didRemoveInertPrim
Definition: changeList.h:189
void DidChangePrimReferences(const SdfPath &primPath)
bool didAddPropertyWithOnlyRequiredFields
Definition: changeList.h:193
void DidRemoveProperty(const SdfPath &propPath, bool hasOnlyRequiredFields)
void DidRemovePrim(const SdfPath &primPath, bool inert)
Definition: token.h:87
_Flags flags
Definition: changeList.h:199
bool didChangeAttributeTimeSamples
Definition: changeList.h:180
bool didChangeResolvedPath
Definition: changeList.h:162
void DidChangeInfo(const SdfPath &path, const TfToken &key, VtValue &&oldValue, const VtValue &newValue)
bool didRemoveProperty
Definition: changeList.h:196
bool didAddProperty
Definition: changeList.h:194
iterator begin()
Definition: smallVector.h:665
void DidChangeLayerResolvedPath()
GLuint GLuint end
Definition: glcorearb.h:475
bool didChangePrimReferences
Definition: changeList.h:177
void DidChangeSublayerPaths(const std::string &subLayerPath, SubLayerChangeType changeType)
void DidReorderPrims(const SdfPath &parentPath)
SdfChangeList()=default
bool didReloadContent
Definition: changeList.h:164
bool didReorderChildren
Definition: changeList.h:167
bool didReplaceContent
Definition: changeList.h:163
bool didChangePrimSpecializes
Definition: changeList.h:176
Definition: path.h:290
SDF_API SdfChangeList & operator=(SdfChangeList const &)
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
void DidAddTarget(const SdfPath &targetPath)
#define SDF_API
Definition: api.h:40
EntryList::const_iterator const_iterator
Definition: changeList.h:214
std::vector< std::pair< SdfLayerHandle, SdfChangeList > > SdfLayerChangeListVec
Definition: changeList.h:42
_Flags()
Definition: changeList.h:156
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
void DidAddProperty(const SdfPath &propPath, bool hasOnlyRequiredFields)
const_iterator begin() const
Definition: changeList.h:219
const EntryList & GetEntryList() const
Definition: changeList.h:208
SDF_API std::ostream & operator<<(std::ostream &, const SdfChangeList &)
SdfPath oldPath
Definition: changeList.h:149
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
bool didChangePrimInheritPaths
Definition: changeList.h:175
std::pair< SdfPath, Entry > * iterator
Definition: smallVector.h:201
bool didChangeAttributeConnection
Definition: changeList.h:181
const_iterator cend() const
Definition: smallVector.h:690
const_iterator end() const
Definition: changeList.h:227
bool didAddTarget
Definition: changeList.h:183
void DidReplaceLayerContent()
void DidChangePrimName(const SdfPath &oldPath, const SdfPath &newPath)
const std::pair< TfToken, InfoChange > * const_iterator
Definition: smallVector.h:202
bool didChangePrimVariantSets
Definition: changeList.h:174
void DidChangePrimVariantSets(const SdfPath &primPath)
Definition: changeList.h:117
const_iterator cbegin() const
Definition: changeList.h:223
void DidChangeAttributeTimeSamples(const SdfPath &attrPath)
bool HasInfoChange(TfToken const &key) const
Definition: changeList.h:141
void DidChangePrimSpecializes(const SdfPath &primPath)
Definition: value.h:164
void DidChangeLayerIdentifier(const std::string &oldIdentifier)
void DidChangePropertyName(const SdfPath &oldPath, const SdfPath &newPath)
bool didRemoveTarget
Definition: changeList.h:184
void swap(TfSmallVector &rhs)
Definition: smallVector.h:330
void DidRemoveTarget(const SdfPath &targetPath)
InfoChangeVec::const_iterator FindInfoChange(TfToken const &key) const
Definition: changeList.h:128