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"
21#include "pxr/base/tf/functionRef.h"
29PXR_NAMESPACE_OPEN_SCOPE
65 return std::tie(x._literals, x._ops) == std::tie(y._literals, y._ops);
76 return _ops.IsEmpty();
100 return _ComposeEdits(weaker);
106 return std::move(weaker);
108 return _ComposeEdits(std::move(weaker));
116 return _ComposeEdits(weaker);
122 return std::move(weaker);
124 return _ComposeEdits(std::move(weaker));
132 return _ApplyEdits(weaker);
138 return std::move(weaker);
140 return _ApplyEdits(weaker);
169 friend std::ostream &
171 auto streamElem = [&](int64_t index) -> std::ostream & {
172 return VtStreamOut(self._literals[index], out);
174 return Vt_ArrayEditStreamImpl(
175 self._ops, self._literals.
size(), streamElem, out);
183 template <
class UnaryOp>
186 auto streamElem = [&](int64_t index) -> std::ostream & {
188 std::forward<UnaryOp>(unaryOp)(_literals[index]),
191 return Vt_ArrayEditStreamImpl(_ops, _literals.
size(), streamElem, out);
196 friend struct Vt_ArrayEditHashAccess;
199 std::ostream &Vt_ArrayEditStreamImpl(
200 Vt_ArrayEditOps
const &ops,
size_t literalsSize,
204 using _Ops = Vt_ArrayEditOps;
207 Array _ApplyEdits(
Array const &weaker)
const {
208 return _ApplyEdits(
Array {weaker});
215 return VtArrayEdit(*this)._ComposeEdits(std::move(weaker));
226std::ostream &Vt_ArrayEditStreamImpl(
227 Vt_ArrayEditOps
const &ops,
size_t literalsSize,
233#define VT_ARRAY_EDIT_EXTERN_TMPL(unused, elem) \
234 VT_API_TEMPLATE_CLASS(VtArrayEdit< VT_TYPE(elem) >);
235TF_PP_SEQ_FOR_EACH(VT_ARRAY_EDIT_EXTERN_TMPL, ~, VT_SCALAR_VALUE_TYPES)
236#undef VT_ARRAY_EDIT_EXTERN_TMPL
238struct Vt_ArrayEditHashAccess
240 template <
class HashState,
class Edit>
241 static void Append(HashState &h, Edit
const &edit) {
242 h.Append(edit._literals, edit._ops);
246template <
class HashState,
class ELEM>
247std::enable_if_t<VtIsHashable<ELEM>()>
249 Vt_ArrayEditHashAccess::Append(h, edit);
259 Array result = std::move(weaker);
260 Array
const &cresult = result;
262 Array
const &literals = _literals;
263 const auto numLiterals = literals.size();
271 _ops.ForEachValid(numLiterals, cresult.size(),
272 [&](_Ops::Op op, int64_t a1, int64_t a2) {
274 case _Ops::OpWriteLiteral:
275 result[a2] = literals[a1];
277 case _Ops::OpWriteRef:
278 result[a2] = cresult[a1];
280 case _Ops::OpInsertLiteral:
281 result.insert(result.cbegin() + a2, literals[a1]);
283 case _Ops::OpInsertRef:
284 result.insert(result.cbegin() + a2, cresult[a1]);
286 case _Ops::OpEraseRef:
287 result.erase(result.cbegin() + a1);
289 case _Ops::OpMinSize:
290 if (result.size() < static_cast<size_t>(a1)) {
294 case _Ops::OpMinSizeFill:
295 if (result.size() < static_cast<size_t>(a1)) {
296 result.resize(a1, literals[a2]);
299 case _Ops::OpSetSize:
302 case _Ops::OpSetSizeFill:
303 result.resize(a1, literals[a2]);
305 case _Ops::OpMaxSize:
306 if (result.size() > static_cast<size_t>(a1)) {
335 result._literals.
begin(),
336 weaker._literals.begin(), weaker._literals.end());
340 const auto numWeakerLiterals = weaker._literals.size();
341 result._ops.ModifyEach([&](_Ops::Op op, int64_t &a1, int64_t) {
343 case _Ops::OpWriteLiteral:
344 case _Ops::OpInsertLiteral:
345 a1 += numWeakerLiterals;
351 result._ops._ins.insert(result._ops._ins.begin(),
352 weaker._ops._ins.begin(),
353 weaker._ops._ins.end());
374 const auto numWeakerLiterals = weaker._literals.size();
377 weaker._literals.insert(
378 weaker._literals.end(),
379 std::make_move_iterator(result._literals.
begin()),
380 std::make_move_iterator(result._literals.
end()));
384 result._ops.ModifyEach([&](_Ops::Op op, int64_t &a1, int64_t) {
386 case _Ops::OpWriteLiteral:
387 case _Ops::OpInsertLiteral:
388 a1 += 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.