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