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();
277 _ops.ForEachValid(numLiterals, cresult.size(),
278 [&](_Ops::Op op, int64_t a1, int64_t a2) {
280 case _Ops::OpWriteLiteral:
281 result[a2] = literals[a1];
283 case _Ops::OpWriteRef:
284 result[a2] = cresult[a1];
286 case _Ops::OpInsertLiteral:
287 result.insert(result.cbegin() + a2, literals[a1]);
289 case _Ops::OpInsertRef:
290 result.insert(result.cbegin() + a2, cresult[a1]);
292 case _Ops::OpEraseRef:
293 result.erase(result.cbegin() + a1);
295 case _Ops::OpMinSize:
296 if (result.size() < static_cast<size_t>(a1)) {
300 case _Ops::OpMinSizeFill:
301 if (result.size() < static_cast<size_t>(a1)) {
302 result.resize(a1, literals[a2]);
305 case _Ops::OpSetSize:
308 case _Ops::OpSetSizeFill:
309 result.resize(a1, literals[a2]);
311 case _Ops::OpMaxSize:
312 if (result.size() > static_cast<size_t>(a1)) {
332 if (ARCH_UNLIKELY(
this == &weaker)) {
334 return std::move(*this)._ComposeEdits(std::move(weakerCopy));
348 const int64_t numWeakerLiterals = weaker._literals.size();
350 result._literals.
begin(),
351 weaker._literals.begin(), weaker._literals.end());
352 result._ops.OffsetLiteralIndexes(numWeakerLiterals);
354 result._ops._ins.insert(result._ops._ins.begin(),
355 weaker._ops._ins.begin(),
356 weaker._ops._ins.end());
372 if (ARCH_UNLIKELY(
this == &weaker)) {
374 return std::move(*this)._ComposeEdits(std::move(weakerCopy));
383 const int64_t numWeakerLiterals = weaker._literals.size();
387 weaker._literals.insert(
388 weaker._literals.end(),
389 std::make_move_iterator(result._literals.
begin()),
390 std::make_move_iterator(result._literals.
end()));
392 result._ops.OffsetLiteralIndexes(numWeakerLiterals);
395 weaker._ops._ins.insert(
396 weaker._ops._ins.end(),
397 std::make_move_iterator(result._ops._ins.begin()),
398 std::make_move_iterator(result._ops._ins.end()));
400 return std::move(weaker);
416PXR_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.