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
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
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
23PXR_NAMESPACE_OPEN_SCOPE
24
25class SdfChangeList;
26typedef std::vector<
27 std::pair<SdfLayerHandle, SdfChangeList>
28 > SdfLayerChangeListVec;
29
36{
37public:
38
39 SdfChangeList() = default;
40 SDF_API SdfChangeList(SdfChangeList const &);
41 SdfChangeList(SdfChangeList &&) = default;
42 SDF_API SdfChangeList &operator=(SdfChangeList const &);
43 SdfChangeList &operator=(SdfChangeList &&) = default;
44
45 enum SubLayerChangeType {
46 SubLayerAdded,
47 SubLayerRemoved,
48 SubLayerOffset
49 };
50
51 SDF_API void DidReplaceLayerContent();
52 SDF_API void DidReloadLayerContent();
53 SDF_API void DidChangeLayerResolvedPath();
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
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).
106 InfoChangeVec infoChanged;
107
110 InfoChangeVec::const_iterator
111 FindInfoChange(TfToken const &key) const {
112 InfoChangeVec::const_iterator iter = infoChanged.begin();
113 for (InfoChangeVec::const_iterator end = infoChanged.end();
114 iter != end; ++iter) {
115 if (iter->first == key) {
116 break;
117 }
118 }
119 return iter;
120 }
121
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
132 SdfPath oldPath;
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
144 bool didChangeIdentifier:1;
145 bool didChangeResolvedPath:1;
146 bool didReplaceContent:1;
147 bool didReloadContent:1;
148
149 // SdfLayer, SdfPrimSpec, SdfRelationshipTarget.
150 bool didReorderChildren:1;
151 bool didReorderProperties:1;
152
153 // SdfPrimSpec, SdfPropertySpec
154 bool didRename:1;
155
156 // SdfPrimSpec
157 bool didChangePrimVariantSets:1;
158 bool didChangePrimInheritPaths:1;
159 bool didChangePrimSpecializes:1;
160 bool didChangePrimReferences:1;
161
162 // SdfPropertySpec
163 bool didChangeAttributeTimeSamples:1;
164 bool didChangeAttributeConnection:1;
165 bool didChangeRelationshipTargets:1;
166 bool didAddTarget:1;
167 bool didRemoveTarget:1;
168
169 // SdfPrimSpec add/remove
170 bool didAddInertPrim:1;
171 bool didAddNonInertPrim:1;
172 bool didRemoveInertPrim:1;
173 bool didRemoveNonInertPrim:1;
174
175 // Property add/remove
176 bool didAddPropertyWithOnlyRequiredFields:1;
177 bool didAddProperty:1;
178 bool didRemovePropertyWithOnlyRequiredFields:1;
179 bool didRemoveProperty:1;
180 };
181
182 _Flags flags;
183 };
184
189
190public:
191 const EntryList & GetEntryList() const { return _entries; }
192
193 // Change accessors/mutators
194 SDF_API
195 Entry const &GetEntry( const SdfPath & ) const;
196
197 using const_iterator = EntryList::const_iterator;
198
199 SDF_API
200 const_iterator FindEntry(SdfPath const &) const;
201
202 const_iterator begin() const {
203 return _entries.begin();
204 }
205
206 const_iterator cbegin() const {
207 return _entries.cbegin();
208 }
209
210 const_iterator end() const {
211 return _entries.end();
212 }
213
214 const_iterator cend() const {
215 return _entries.cend();
216 }
217
218private:
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
246SDF_API std::ostream& operator<<(std::ostream&, const SdfChangeList &);
247
248PXR_NAMESPACE_CLOSE_SCOPE
249
250#endif // PXR_USD_SDF_CHANGE_LIST_H
A list of scene description modifications, organized by the namespace paths where the changes occur.
Definition: changeList.h:36
TfSmallVector< std::pair< SdfPath, Entry >, 1 > EntryList
Map of change entries at various paths in a layer.
Definition: changeList.h:188
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:274
This is a small-vector class with local storage optimization, the local storage can be specified via ...
Definition: smallVector.h:157
void swap(TfSmallVector &rhs)
Swap two vector instances.
Definition: smallVector.h:298
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:147
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
Entry of changes at a single path in namespace.
Definition: changeList.h:100
bool HasInfoChange(TfToken const &key) const
Return true if this entry has an info change for key, false otherwise.
Definition: changeList.h:124
InfoChangeVec::const_iterator FindInfoChange(TfToken const &key) const
Return the iterator in infoChanged whose first element is key, or infoChanged.end() if there is no su...
Definition: changeList.h:111
Basic Sdf data types.