carb::variant::VariantArray

Defined in carb/variant/VariantTypes.h

class VariantArray : public carb::IObject

An array-of-variants type that can itself be contained in a Variant.

Similar in many respects to std::vector, but reference-counted and implemented within carb.variant.plugin.

Created via IVariant::createArray().

Public Types

using iterator = omni::detail::PointerIterator<Variant*, VariantArray>

A type conforming to RandomAccessIterator.

using const_iterator = omni::detail::PointerIterator<const Variant*, VariantArray>

A type conforming to RandomAccessIterator.

Public Functions

virtual Variant *data() noexcept = 0

Provides direct access to the underlying array.

Returns

the beginning of the underlying array.

virtual const Variant *data() const noexcept = 0

Provides direct access to the underlying array.

Returns

the beginning of the underlying array.

virtual size_t size() const noexcept = 0

Returns the number of variants contained.

Returns

the number of variants contained.

virtual void push_back(Variant v) noexcept = 0

Adds a variant to the end of the array.

Parameters

v – The Variant to add to the array.

virtual bool insert(size_t offset, Variant v) noexcept = 0

Attempts to insert a variant at the given offset.

The given offset must be in [0, size()], otherwise false is returned.

Warning

This is an O(n) operation.

Parameters
  • offset – The 0-based offset indicating where to insert. The elements at that position (and all subsequent elements) will be pushed back to make room for v.

  • v – The Variant to insert.

Returns

true if the given variant was inserted; false otherwise.

virtual bool erase(size_t offset) noexcept = 0

Attempts to erase the variant at the given offset.

The given offset must be in [0, size()), otherwise false is returned.

Warning

This is an O(n) operation.

Parameters

offset – The 0-based offset indicating which element to erase. The elements following that position will be moved forward to fill in the gap removed at offset.

Returns

true if the variant was erased; false otherwise.

virtual bool pop_back() noexcept = 0

Pops the last element from the array.

Returns

true if the element was popped; false if the array is empty.

virtual void assign(const Variant *p, size_t count) noexcept = 0

Clears the existing array elements and assigns new elements.

Parameters
  • p – The beginning of the new array elements.

  • count – The number of array elements in the raw array p.

virtual void reserve(size_t count) noexcept = 0

Reserves space for elements.

Parameters

count – The number of elements to reserve space for, exactly. If this amount is less than the current space, the request is ignored.

virtual void resize(size_t count) noexcept = 0

Changes the number of elements stored.

Parameters

count – The number of elements to store in the array. Elements at the end of the array are added (as via Variant default construction) or removed so that following this call size() matches count. Note that resizing heuristics may be applied, so capacity() following this call may be greater than count.

virtual size_t capacity() const noexcept = 0

Returns the number of elements that can be stored with the current allocated space.

Returns

The number of elements that can be stored with the current allocated space.

void clear() noexcept

Erases all elements from the array and leaves the array empty.

bool empty() const noexcept

Checks whether the array is empty.

Returns

true if the array is empty (contains no elements); false otherwise.

Variant &at(size_t index)

Accesses an element with bounds checking.

Throws

std::out_of_range – if index is outside of [0, size()).

Parameters

index – The index of the array to access.

Returns

a reference to the element at the requested index.

const Variant &at(size_t index) const

Accesses an element with bounds checking.

Throws

std::out_of_range – if index is outside of [0, size()).

Parameters

index – The index of the array to access.

Returns

a reference to the element at the requested index.

Variant &operator[](size_t index) noexcept

Accesses an element without bounds checking.

Warning

Providing an index value outside of [0, size()) is undefined behavior.

Parameters

index – The index of the array to access.

Returns

a reference to the element at the requested index.

const Variant &operator[](size_t index) const noexcept

Accesses an element without bounds checking.

Warning

Providing an index value outside of [0, size()) is undefined behavior.

Parameters

index – The index of the array to access.

Returns

a reference to the element at the requested index.

Variant &front() noexcept

Accesses the element at the front of the array.

Warning

Undefined behavior if empty().

Returns

a reference to the element at the front of the array.

const Variant &front() const noexcept

Accesses the element at the front of the array.

Warning

Undefined behavior if empty().

Returns

a reference to the element at the front of the array.

Variant &back() noexcept

Accesses the element at the back of the array.

Warning

Undefined behavior if empty().

Returns

a reference to the element at the back of the array.

const Variant &back() const noexcept

Accesses the element at the back of the array.

Warning

Undefined behavior if empty().

Returns

a reference to the element at the back of the array.

iterator begin() noexcept

Provides iteration and ranged-for support; returns an iterator to the first element.

Warning

Iterators follow invalidation rules for std::vector.

Returns

An iterator to the first element.

iterator end() noexcept

Provides iteration and ranged-for support; returns an iterator representing the iteration end.

Warning

Iterators follow invalidation rules for std::vector.

Returns

An iterator representing the iteration end.

const_iterator begin() const noexcept

Provides iteration and ranged-for support; returns an iterator to the first element.

Warning

Iterators follow invalidation rules for std::vector.

Returns

An iterator to the first element.

const_iterator end() const noexcept

Provides iteration and ranged-for support; returns an iterator representing the iteration end.

Warning

Iterators follow invalidation rules for std::vector.

Returns

An iterator representing the iteration end.

virtual size_t addRef() = 0

Atomically add one to the reference count.

Returns

The current reference count after one was added, though this value may change before read if other threads are also modifying the reference count. The return value is guaranteed to be non-zero.

virtual size_t release() = 0

Atomically subtracts one from the reference count.

If the result is zero, carb::deleteHandler() is called for this.

Returns

The current reference count after one was subtracted. If zero is returned, carb::deleteHandler() was called for this.

Public Static Functions

static inline constexpr carb::InterfaceDesc getInterfaceDesc() noexcept

Returns information about this interface.

Auto-generated by CARB_PLUGIN_INTERFACE() or CARB_PLUGIN_INTERFACE_EX.

Returns

The carb::InterfaceDesc struct with information about this interface.

static inline constexpr carb::InterfaceDesc getLatestInterfaceDesc() noexcept

Returns information about the latest version of this interface.

Auto-generated by CARB_PLUGIN_INTERFACE() or CARB_PLUGIN_INTERFACE_EX.

Returns

The carb::InterfaceDesc struct with information about the latest version of this interface.