8#ifndef PXR_BASE_VT_ARRAY_EDIT_H
9#define PXR_BASE_VT_ARRAY_EDIT_H
14#include "pxr/base/vt/api.h"
17#include "pxr/base/vt/streamOut.h"
22#include "pxr/base/tf/functionRef.h"
30PXR_NAMESPACE_OPEN_SCOPE
66 return std::tie(x._literals, x._ops) == std::tie(y._literals, y._ops);
77 return _ops.IsEmpty();
101 return _ComposeEdits(weaker);
107 return std::move(weaker);
109 return _ComposeEdits(std::move(weaker));
117 return _ComposeEdits(weaker);
123 return std::move(weaker);
125 return _ComposeEdits(std::move(weaker));
133 return _ApplyEdits(weaker);
139 return std::move(weaker);
141 return _ApplyEdits(std::move(weaker));
170 friend std::ostream &
172 auto streamElem = [&](int64_t index) -> std::ostream & {
173 return VtStreamOut(self._literals[index], out);
175 return Vt_ArrayEditStreamImpl(
176 self._ops, self._literals.
size(), streamElem, out);
184 template <
class UnaryOp>
187 auto streamElem = [&](int64_t index) -> std::ostream & {
189 std::forward<UnaryOp>(unaryOp)(_literals[index]),
192 return Vt_ArrayEditStreamImpl(_ops, _literals.
size(), streamElem, out);
197 friend struct Vt_ArrayEditHashAccess;
200 std::ostream &Vt_ArrayEditStreamImpl(
201 Vt_ArrayEditOps
const &ops,
size_t literalsSize,
205 using _Ops = Vt_ArrayEditOps;
208 Array _ApplyEdits(
Array const &weaker)
const {
209 return _ApplyEdits(
Array {weaker});
216 return VtArrayEdit(*this)._ComposeEdits(std::move(weaker));
227std::ostream &Vt_ArrayEditStreamImpl(
228 Vt_ArrayEditOps
const &ops,
size_t literalsSize,
232struct Vt_ArrayEditHashAccess
234 template <
class HashState,
class Edit>
235 static void Append(HashState &h, Edit
const &edit) {
236 h.Append(edit._literals, edit._ops);
240template <
class HashState,
class ELEM>
241std::enable_if_t<VtIsHashable<ELEM>()>
243 Vt_ArrayEditHashAccess::Append(h, edit);
253 Array result = std::move(weaker);
254 Array
const &cresult = result;
256 Array
const &literals = _literals;
257 const auto numLiterals = literals.size();
275 _ops.ForEachValid(numLiterals, cresult.size(),
276 [&](_Ops::Op op, int64_t a1, int64_t a2) {
278 case _Ops::OpWriteLiteral:
279 result[a2] = literals[a1];
281 case _Ops::OpWriteRef:
282 result[a2] = cresult[a1];
284 case _Ops::OpInsertLiteral:
285 result.insert(result.cbegin() + a2, literals[a1]);
287 case _Ops::OpInsertRef:
288 result.insert(result.cbegin() + a2, cresult[a1]);
290 case _Ops::OpEraseRef:
291 result.erase(result.cbegin() + a1);
293 case _Ops::OpMinSize:
294 if (result.size() < static_cast<size_t>(a1)) {
298 case _Ops::OpMinSizeFill:
299 if (result.size() < static_cast<size_t>(a1)) {
300 result.resize(a1, literals[a2]);
303 case _Ops::OpSetSize:
306 case _Ops::OpSetSizeFill:
307 result.resize(a1, literals[a2]);
309 case _Ops::OpMaxSize:
310 if (result.size() > static_cast<size_t>(a1)) {
330 if (ARCH_UNLIKELY(
this == &weaker)) {
332 return std::move(*this)._ComposeEdits(std::move(weakerCopy));
346 const int64_t numWeakerLiterals = weaker._literals.size();
348 result._literals.
begin(),
349 weaker._literals.begin(), weaker._literals.end());
350 result._ops.OffsetLiteralIndexes(numWeakerLiterals);
352 result._ops._ins.insert(result._ops._ins.begin(),
353 weaker._ops._ins.begin(),
354 weaker._ops._ins.end());
370 if (ARCH_UNLIKELY(
this == &weaker)) {
372 return std::move(*this)._ComposeEdits(std::move(weakerCopy));
381 const int64_t numWeakerLiterals = weaker._literals.size();
385 weaker._literals.insert(
386 weaker._literals.end(),
387 std::make_move_iterator(result._literals.
begin()),
388 std::make_move_iterator(result._literals.
end()));
390 result._ops.OffsetLiteralIndexes(numWeakerLiterals);
393 weaker._ops._ins.insert(
394 weaker._ops._ins.end(),
395 std::make_move_iterator(result._ops._ins.begin()),
396 std::make_move_iterator(result._ops._ins.end()));
398 return std::move(weaker);
414PXR_NAMESPACE_CLOSE_SCOPE
Low-level utilities for informing users of various internal and external diagnostic conditions.
This class provides a non-owning reference to a type-erased callable object with a specified signatur...
Represents a range of contiguous elements.
A builder type that produces instances of VtArrayEdit representing sequences of array edit operations...
An array edit represents a sequence of per-element modifications to a VtArray.
bool IsIdentity() const
Return true if this edit is the identity edit.
friend bool operator!=(VtArrayEdit const &x, VtArrayEdit const &y)
Inequality comparison.
friend bool operator==(VtArrayEdit const &x, VtArrayEdit const &y)
Equality comparison.
TfSpan< const ElementType > GetLiterals() const
Return a view of the literal elements that this edit makes use of.
TfSpan< ElementType > GetMutableLiterals()
Return a mutable view of the literal elements that this edit makes use of.
Array ComposeOver(Array &&weaker) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
VtArray< ELEM > Array
Shorthand for the corresponding VtArray type.
std::ostream & StreamCustom(std::ostream &out, UnaryOp &&unaryOp) const
Insert self to the stream out, but call unaryOp on each contained value-type element and pass the res...
VtArrayEdit ComposeOver(VtArrayEdit &&weaker) &&
This is an overloaded member function, provided for convenience. It differs from the above function o...
friend std::ostream & operator<<(std::ostream &out, const VtArrayEdit self)
Insert self to the stream out using the following format:
Array ComposeOver(Array const &weaker) const
Apply the edits in *this to weaker and return the resulting array.
VtArrayEdit()=default
Construct an identity array edit that performs no edits.
VtArrayEdit ComposeOver(VtArrayEdit const &weaker) &&
Compose this edit over weaker and return a new result representing the function composition,...
VtArrayEdit ComposeOver(VtArrayEdit const &weaker) const &
This is an overloaded member function, provided for convenience. It differs from the above function o...
VtArrayEdit ComposeOver(VtArrayEdit &&weaker) const &
This is an overloaded member function, provided for convenience. It differs from the above function o...
Represents an arbitrary dimensional rectangular container class.
ELEM ElementType
Type this array holds.
size_t size() const
Return the total number of elements in this array.
iterator insert(const_iterator pos, value_type const &value)
Insert a copy of a single element at pos into the array.
iterator end()
Returns a non-const iterator to the end of the array.
iterator begin()
Return a non-const iterator to the start of the array.
A trait to detect instantiations of VtArrayEdit, specialized in arrayEdit.h.
A trait indicating whether VtValue compose-over functionality can be registered for a type.