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"
28PXR_NAMESPACE_OPEN_SCOPE
64 return std::tie(x._literals, x._ops) == std::tie(y._literals, y._ops);
75 return _ops.IsEmpty();
87 return _ComposeEdits(weaker);
93 return std::move(weaker);
95 return _ComposeEdits(std::move(weaker));
103 return _ComposeEdits(weaker);
109 return std::move(weaker);
111 return _ComposeEdits(std::move(weaker));
119 return _ApplyEdits(weaker);
125 return std::move(weaker);
127 return _ApplyEdits(weaker);
156 friend std::ostream &
158 auto streamElem = [&](int64_t index) -> std::ostream & {
159 return VtStreamOut(self._literals[index], out);
161 return Vt_ArrayEditStreamImpl(
162 self._ops, self._literals.
size(), streamElem, out);
170 template <
class UnaryOp>
173 auto streamElem = [&](int64_t index) -> std::ostream & {
175 std::forward<UnaryOp>(unaryOp)(_literals[index]),
178 return Vt_ArrayEditStreamImpl(_ops, _literals.
size(), streamElem, out);
183 friend struct Vt_ArrayEditHashAccess;
186 std::ostream &Vt_ArrayEditStreamImpl(
187 Vt_ArrayEditOps
const &ops,
size_t literalsSize,
191 using _Ops = Vt_ArrayEditOps;
194 Array _ApplyEdits(
Array const &weaker)
const {
195 return _ApplyEdits(
Array {weaker});
202 return VtArrayEdit(*this)._ComposeEdits(std::move(weaker));
213std::ostream &Vt_ArrayEditStreamImpl(
214 Vt_ArrayEditOps
const &ops,
size_t literalsSize,
220#define VT_ARRAY_EDIT_EXTERN_TMPL(unused, elem) \
221 VT_API_TEMPLATE_CLASS(VtArrayEdit< VT_TYPE(elem) >);
222TF_PP_SEQ_FOR_EACH(VT_ARRAY_EDIT_EXTERN_TMPL, ~, VT_SCALAR_VALUE_TYPES)
223#undef VT_ARRAY_EDIT_EXTERN_TMPL
225struct Vt_ArrayEditHashAccess
227 template <
class HashState,
class Edit>
228 static void Append(HashState &h, Edit
const &edit) {
229 h.Append(edit._literals, edit._ops);
233template <
class HashState,
class ELEM>
234std::enable_if_t<VtIsHashable<ELEM>()>
236 Vt_ArrayEditHashAccess::Append(h, edit);
246 Array result = std::move(weaker);
247 Array
const &cresult = result;
249 Array
const &literals = _literals;
250 const auto numLiterals = literals.size();
258 _ops.ForEachValid(numLiterals, cresult.size(),
259 [&](_Ops::Op op, int64_t a1, int64_t a2) {
261 case _Ops::OpWriteLiteral:
262 result[a2] = literals[a1];
264 case _Ops::OpWriteRef:
265 result[a2] = cresult[a1];
267 case _Ops::OpInsertLiteral:
268 result.insert(result.cbegin() + a2, literals[a1]);
270 case _Ops::OpInsertRef:
271 result.insert(result.cbegin() + a2, cresult[a1]);
273 case _Ops::OpEraseRef:
274 result.erase(result.cbegin() + a1);
276 case _Ops::OpMinSize:
277 if (result.size() < static_cast<size_t>(a1)) {
281 case _Ops::OpMinSizeFill:
282 if (result.size() < static_cast<size_t>(a1)) {
283 result.resize(a1, literals[a2]);
286 case _Ops::OpSetSize:
289 case _Ops::OpSetSizeFill:
290 result.resize(a1, literals[a2]);
292 case _Ops::OpMaxSize:
293 if (result.size() > static_cast<size_t>(a1)) {
322 result._literals.
begin(),
323 weaker._literals.begin(), weaker._literals.end());
327 const auto numWeakerLiterals = weaker._literals.size();
328 result._ops.ModifyEach([&](_Ops::Op op, int64_t &a1, int64_t) {
330 case _Ops::OpWriteLiteral:
331 case _Ops::OpInsertLiteral:
332 a1 += numWeakerLiterals;
338 result._ops._ins.insert(result._ops._ins.begin(),
339 weaker._ops._ins.begin(),
340 weaker._ops._ins.end());
361 const auto numWeakerLiterals = weaker._literals.size();
364 weaker._literals.insert(
365 weaker._literals.end(),
366 std::make_move_iterator(result._literals.
begin()),
367 std::make_move_iterator(result._literals.
end()));
371 result._ops.ModifyEach([&](_Ops::Op op, int64_t &a1, int64_t) {
373 case _Ops::OpWriteLiteral:
374 case _Ops::OpInsertLiteral:
375 a1 += numWeakerLiterals;
382 weaker._ops._ins.insert(
383 weaker._ops._ins.end(),
384 std::make_move_iterator(result._ops._ins.begin()),
385 std::make_move_iterator(result._ops._ins.end()));
387 return std::move(weaker);
394PXR_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...
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.
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.