7#ifndef PXR_USD_SDF_LIST_OP_H
8#define PXR_USD_SDF_LIST_OP_H
11#include "pxr/usd/sdf/api.h"
24PXR_NAMESPACE_OPEN_SCOPE
31 SdfListOpTypeExplicit,
35 SdfListOpTypePrepended,
45struct Sdf_ListOpTraits
47 typedef std::less<T> ItemComparator;
73 typedef std::vector<ItemType> ItemVector;
74 typedef ItemType value_type;
75 typedef ItemVector value_vector_type;
80 const ItemVector& explicitItems = ItemVector());
86 const ItemVector& prependedItems = ItemVector(),
87 const ItemVector& appendedItems = ItemVector(),
88 const ItemVector& deletedItems = ItemVector());
103 if (_addedItems.size() != 0 ||
104 _prependedItems.size() != 0 ||
105 _appendedItems.size() != 0 ||
106 _deletedItems.size() != 0) {
109 return _orderedItems.size() != 0;
124 return _explicitItems;
130 return _prependedItems;
136 return _appendedItems;
142 return _deletedItems;
146 SDF_API
const ItemVector&
GetItems(SdfListOpType type)
const;
184 SDF_API
bool SetItems(
const ItemVector &items, SdfListOpType type,
185 std::string* errMsg =
nullptr);
194 typedef std::function<
195 std::optional<ItemType>(SdfListOpType,
const ItemType&)
218 std::optional<SdfListOp<T>>
222 typedef std::function<
223 std::optional<ItemType>(
const ItemType&)
243 bool unusedRemoveDuplicates);
250 const ItemVector& newItems);
268 return _orderedItems;
278 friend inline size_t hash_value(
const SdfListOp &op) {
291 return _isExplicit == rhs._isExplicit &&
292 _explicitItems == rhs._explicitItems &&
293 _addedItems == rhs._addedItems &&
294 _prependedItems == rhs._prependedItems &&
295 _appendedItems == rhs._appendedItems &&
296 _deletedItems == rhs._deletedItems &&
297 _orderedItems == rhs._orderedItems;
301 return !(*
this == rhs);
305 void _SetExplicit(
bool isExplicit);
307 typedef typename Sdf_ListOpTraits<T>::ItemComparator _ItemComparator;
308 typedef std::list<ItemType> _ApplyList;
309 typedef std::map<ItemType, typename _ApplyList::iterator, _ItemComparator>
313 _ApplyList* result, _ApplyMap* search)
const;
315 _ApplyList* result, _ApplyMap* search)
const;
317 _ApplyList* result, _ApplyMap* search)
const;
322 _ApplyList* result, _ApplyMap* search)
const;
327 _ApplyList* result, _ApplyMap* search)
const;
328 static void _ReorderKeysHelper(ItemVector order,
const ApplyCallback& cb,
329 _ApplyList *result, _ApplyMap *search);
330 template <
class ItemType>
331 friend void SdfApplyListOrdering(std::vector<ItemType> *v,
332 const std::vector<ItemType> &order);
333 bool _MakeUnique(std::vector<T>& items,
bool reverse=
false,
334 std::string* errMsg =
nullptr);
338 ItemVector _explicitItems;
339 ItemVector _addedItems;
340 ItemVector _prependedItems;
341 ItemVector _appendedItems;
342 ItemVector _deletedItems;
343 ItemVector _orderedItems;
359template <
class ItemType>
361void SdfApplyListOrdering(std::vector<ItemType>* v,
362 const std::vector<ItemType>& order);
371typedef class SdfListOp<int> SdfIntListOp;
372typedef class SdfListOp<unsigned int> SdfUIntListOp;
373typedef class SdfListOp<int64_t> SdfInt64ListOp;
374typedef class SdfListOp<uint64_t> SdfUInt64ListOp;
377typedef class
SdfListOp<class SdfPath> SdfPathListOp;
378typedef class
SdfListOp<class SdfReference> SdfReferenceListOp;
379typedef class
SdfListOp<class SdfPayload> SdfPayloadListOp;
380typedef class
SdfListOp<class SdfUnregisteredValue> SdfUnregisteredValueListOp;
382PXR_NAMESPACE_CLOSE_SCOPE
SdfListOp is a value type representing an operation that edits a list.
SDF_API bool SetDeletedItems(const ItemVector &items, std::string *errMsg=nullptr)
Sets the deleted items.
SDF_API bool HasItem(const T &item) const
Returns true if the given item is in any of the item lists.
static SDF_API SdfListOp CreateExplicit(const ItemVector &explicitItems=ItemVector())
Create a ListOp in explicit mode with the given explicitItems.
SDF_API std::optional< SdfListOp< T > > ApplyOperations(const SdfListOp< T > &inner) const
Applies edit operations to the given ListOp.
SDF_API bool ModifyOperations(const ModifyCallback &callback, bool unusedRemoveDuplicates)
SDF_API void SetOrderedItems(const ItemVector &items)
std::function< std::optional< ItemType >(const ItemType &) > ModifyCallback
Callback type for ModifyOperations.
SDF_API bool ModifyOperations(const ModifyCallback &callback)
Modifies operations specified in this object.
SDF_API bool SetItems(const ItemVector &items, SdfListOpType type, std::string *errMsg=nullptr)
Sets the item vector for the given operation type.
SDF_API void SetAddedItems(const ItemVector &items)
SDF_API bool SetAppendedItems(const ItemVector &items, std::string *errMsg=nullptr)
Sets the appended items.
const ItemVector & GetOrderedItems() const
static SDF_API SdfListOp Create(const ItemVector &prependedItems=ItemVector(), const ItemVector &appendedItems=ItemVector(), const ItemVector &deletedItems=ItemVector())
Create a ListOp in non-explicit mode with the given prependedItems, appendedItems,...
const ItemVector & GetDeletedItems() const
Returns the deleted items.
SDF_API const ItemVector & GetItems(SdfListOpType type) const
Return the item vector identified by type.
bool IsExplicit() const
Returns true if the list is explicit.
SDF_API void Clear()
Removes all items and changes the list to be non-explicit.
const ItemVector & GetPrependedItems() const
Returns the explicit items.
const ItemVector & GetExplicitItems() const
Returns the explicit items.
SDF_API bool ReplaceOperations(const SdfListOpType op, size_t index, size_t n, const ItemVector &newItems)
Replaces the items in the specified operation vector in the range (index, index + n] with the given n...
SDF_API SdfListOp()
Create an empty ListOp in non-explicit mode.
SDF_API void ApplyOperations(ItemVector *vec, const ApplyCallback &cb=ApplyCallback()) const
Applies edit operations to the given ItemVector.
SDF_API void ClearAndMakeExplicit()
Removes all items and changes the list to be explicit.
SDF_API bool SetExplicitItems(const ItemVector &items, std::string *errMsg=nullptr)
Sets the explicit items.
SDF_API void ComposeOperations(const SdfListOp< T > &stronger, SdfListOpType op)
Composes a stronger SdfListOp's opinions for a given operation list over this one.
bool HasKeys() const
Returns true if the editor has an explicit list (even if it's empty) or it has any added,...
const ItemVector & GetAppendedItems() const
Returns the explicit items.
SDF_API ItemVector GetAppliedItems() const
Returns the effective list of items represented by the operations in this list op.
std::function< std::optional< ItemType >(SdfListOpType, const ItemType &) > ApplyCallback
Callback type for ApplyOperations.
SDF_API bool SetPrependedItems(const ItemVector &items, std::string *errMsg=nullptr)
Sets the prepended items.
const ItemVector & GetAddedItems() const
static size_t Combine(Args &&... args)
Produce a hash code by combining the hash codes of several objects.
Token for efficient comparison, assignment, and hashing of known strings.
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
A trait indicating whether VtValue compose-over functionality can be registered for a type.
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...