Loading...
Searching...
No Matches
SdfListOp< T > Class Template Reference

Value type representing a list-edit operation. More...

#include <listOp.h>

Public Types

typedef T ItemType
 
typedef std::vector< ItemType > ItemVector
 
typedef ItemType value_type
 
typedef ItemVector value_vector_type
 
typedef std::function< std::optional< ItemType >(SdfListOpType, const ItemType &) > ApplyCallback
 Callback type for ApplyOperations.
 
typedef std::function< std::optional< ItemType >(const ItemType &) > ModifyCallback
 Callback type for ModifyOperations.
 

Public Member Functions

SDF_API SdfListOp ()
 Create an empty ListOp in non-explicit mode.
 
SDF_API void Swap (SdfListOp< T > &rhs)
 
bool HasKeys () const
 Returns true if the editor has an explicit list (even if it's empty) or it has any added, prepended, appended, deleted, or ordered keys.
 
SDF_API bool HasItem (const T &item) const
 Returns true if the given item is in any of the item lists.
 
bool IsExplicit () const
 Returns true if the list is explicit.
 
const ItemVector & GetExplicitItems () const
 Returns the explicit items.
 
const ItemVector & GetAddedItems () const
 Returns the explicit items.
 
const ItemVector & GetPrependedItems () const
 Returns the explicit items.
 
const ItemVector & GetAppendedItems () const
 Returns the explicit items.
 
const ItemVector & GetDeletedItems () const
 Returns the deleted items.
 
const ItemVector & GetOrderedItems () const
 Returns the ordered items.
 
SDF_API const ItemVector & GetItems (SdfListOpType type) const
 Return the item vector identified by type.
 
SDF_API ItemVector GetAppliedItems () const
 Returns the effective list of items represented by the operations in this list op.
 
SDF_API void SetExplicitItems (const ItemVector &items)
 
SDF_API void SetAddedItems (const ItemVector &items)
 
SDF_API void SetPrependedItems (const ItemVector &items)
 
SDF_API void SetAppendedItems (const ItemVector &items)
 
SDF_API void SetDeletedItems (const ItemVector &items)
 
SDF_API void SetOrderedItems (const ItemVector &items)
 
SDF_API void SetItems (const ItemVector &items, SdfListOpType type)
 Sets the item vector for the given operation type.
 
SDF_API void Clear ()
 Removes all items and changes the list to be non-explicit.
 
SDF_API void ClearAndMakeExplicit ()
 Removes all items and changes the list to be explicit.
 
SDF_API void ApplyOperations (ItemVector *vec, const ApplyCallback &cb=ApplyCallback()) const
 Applies edit operations to the given ItemVector.
 
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 removeDuplicates=false)
 Modifies operations specified in this object.
 
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 newItems.
 
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 operator== (const SdfListOp< T > &rhs) const
 
bool operator!= (const SdfListOp< T > &rhs) const
 

Static Public Member Functions

static SDF_API SdfListOp CreateExplicit (const ItemVector &explicitItems=ItemVector())
 Create a ListOp in explicit mode with the given explicitItems.
 
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, and deletedItems.
 

Friends

size_t hash_value (const SdfListOp &op)
 

Detailed Description

template<typename T>
class SdfListOp< T >

Value type representing a list-edit operation.

SdfListOp is a value type representing an operation that edits a list. It may add or remove items, reorder them, or replace the list entirely.

Definition at line 74 of file listOp.h.

Member Typedef Documentation

◆ ApplyCallback

typedef std::function< std::optional<ItemType>(SdfListOpType, const ItemType&) > ApplyCallback

Callback type for ApplyOperations.

Definition at line 191 of file listOp.h.

◆ ItemType

typedef T ItemType

Definition at line 76 of file listOp.h.

◆ ItemVector

typedef std::vector<ItemType> ItemVector

Definition at line 77 of file listOp.h.

◆ ModifyCallback

typedef std::function< std::optional<ItemType>(const ItemType&) > ModifyCallback

Callback type for ModifyOperations.

Definition at line 219 of file listOp.h.

◆ value_type

typedef ItemType value_type

Definition at line 78 of file listOp.h.

◆ value_vector_type

typedef ItemVector value_vector_type

Definition at line 79 of file listOp.h.

Constructor & Destructor Documentation

◆ SdfListOp()

SDF_API SdfListOp ( )

Create an empty ListOp in non-explicit mode.

Member Function Documentation

◆ ApplyOperations() [1/2]

SDF_API std::optional< SdfListOp< T > > ApplyOperations ( const SdfListOp< T > &  inner) const

Applies edit operations to the given ListOp.

The result is a ListOp that, when applied to a list, has the same effect as applying inner and then this in sequence.

The result will be empty if the result is not well defined. The result is well-defined when inner and this do not use the 'ordered' or 'added' item lists. In other words, only the explicit, prepended, appended, and deleted portions of SdfListOp are closed under composition with ApplyOperations().

◆ ApplyOperations() [2/2]

SDF_API void ApplyOperations ( ItemVector *  vec,
const ApplyCallback cb = ApplyCallback() 
) const

Applies edit operations to the given ItemVector.

If supplied, cb will be called on each item in the operation vectors before they are applied to vec. Consumers can use this to transform the items stored in the operation vectors to match what's stored in vec.

◆ Clear()

SDF_API void Clear ( )

Removes all items and changes the list to be non-explicit.

◆ ClearAndMakeExplicit()

SDF_API void ClearAndMakeExplicit ( )

Removes all items and changes the list to be explicit.

◆ ComposeOperations()

SDF_API void ComposeOperations ( const SdfListOp< T > &  stronger,
SdfListOpType  op 
)

Composes a stronger SdfListOp's opinions for a given operation list over this one.

◆ Create()

static SDF_API SdfListOp Create ( const ItemVector &  prependedItems = ItemVector(),
const ItemVector &  appendedItems = ItemVector(),
const ItemVector &  deletedItems = ItemVector() 
)
static

Create a ListOp in non-explicit mode with the given prependedItems, appendedItems, and deletedItems.

◆ CreateExplicit()

static SDF_API SdfListOp CreateExplicit ( const ItemVector &  explicitItems = ItemVector())
static

Create a ListOp in explicit mode with the given explicitItems.

◆ GetAddedItems()

const ItemVector & GetAddedItems ( ) const
inline

Returns the explicit items.

Definition at line 132 of file listOp.h.

◆ GetAppendedItems()

const ItemVector & GetAppendedItems ( ) const
inline

Returns the explicit items.

Definition at line 144 of file listOp.h.

◆ GetAppliedItems()

SDF_API ItemVector GetAppliedItems ( ) const

Returns the effective list of items represented by the operations in this list op.

This function should be used to determine the final list of items added instead of looking at the individual explicit, prepended, and appended item lists.

This is equivalent to calling ApplyOperations on an empty item vector.

◆ GetDeletedItems()

const ItemVector & GetDeletedItems ( ) const
inline

Returns the deleted items.

Definition at line 150 of file listOp.h.

◆ GetExplicitItems()

const ItemVector & GetExplicitItems ( ) const
inline

Returns the explicit items.

Definition at line 126 of file listOp.h.

◆ GetItems()

SDF_API const ItemVector & GetItems ( SdfListOpType  type) const

Return the item vector identified by type.

◆ GetOrderedItems()

const ItemVector & GetOrderedItems ( ) const
inline

Returns the ordered items.

Definition at line 156 of file listOp.h.

◆ GetPrependedItems()

const ItemVector & GetPrependedItems ( ) const
inline

Returns the explicit items.

Definition at line 138 of file listOp.h.

◆ HasItem()

SDF_API bool HasItem ( const T &  item) const

Returns true if the given item is in any of the item lists.

◆ HasKeys()

bool HasKeys ( ) const
inline

Returns true if the editor has an explicit list (even if it's empty) or it has any added, prepended, appended, deleted, or ordered keys.

Definition at line 102 of file listOp.h.

◆ IsExplicit()

bool IsExplicit ( ) const
inline

Returns true if the list is explicit.

Definition at line 120 of file listOp.h.

◆ ModifyOperations()

SDF_API bool ModifyOperations ( const ModifyCallback callback,
bool  removeDuplicates = false 
)

Modifies operations specified in this object.

callback is called for every item in all operation vectors. If the returned key is empty then the key is removed, otherwise it's replaced with the returned key.

If removeDuplicates is true and callback returns a key that was previously returned for the current operation vector being processed, the returned key will be removed.

Returns true if a change was made, false otherwise.

◆ operator!=()

bool operator!= ( const SdfListOp< T > &  rhs) const
inline

Definition at line 269 of file listOp.h.

◆ operator==()

bool operator== ( const SdfListOp< T > &  rhs) const
inline

Definition at line 259 of file listOp.h.

◆ ReplaceOperations()

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 newItems.

If newItems is empty the items in the range will simply be removed.

◆ SetItems()

SDF_API void SetItems ( const ItemVector &  items,
SdfListOpType  type 
)

Sets the item vector for the given operation type.

Friends And Related Function Documentation

◆ hash_value

size_t hash_value ( const SdfListOp< T > &  op)
friend

Definition at line 247 of file listOp.h.


The documentation for this class was generated from the following file: