This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

matlab::data::TypedArray<T>

Templated C++ class to access array data

Description

The templated TypedArray class provides typesafe APIs to handle all array types (except sparse arrays) inside an array. This class defines the following iterator types:

using iterator = TypedIterator<T>;
using const_iterator = TypedIterator<T const>;

Class Details

Namespace:

matlab::data

Base class:

matlab::data::Array

Include:

TypedArray.hpp

Template Parameters

T

Type of element referred to.

Template Instantiations

double

float

int8_t

uint8_t

int16_t

uint16_t

int32_t

uint32_t

int64_t

uint64_t

char16_t

bool

std::complex<double>

std::complex<float>

std::complex<int8_t>

std::complex<uint8_t>

std::complex<int16_t>

std::complex<uint16_t>

std::complex<int32_t>

std::complex<uint32_t>

std::complex<int64_t>

std::complex<uint64_t>

matlab::data::Array
matlab::data::Struct
matlab::data::Enumeration

matlab::data::MATLABString

Constructors

Copy Constructor

TypedArray(const TypedArray<T>& rhs)

TypedArray(const Array& rhs)

Description

Creates a shared data copy of the input.

Parameters

const TypedArray<T>& rhs

Value to be copied.

const Array& rhs

Value specified as matlab::data::Array object.

Throws

InvalidArrayTypeException

Type of input Array does not match the type for TypedArray<T>.

Copy Assignment Operator

TypedArray<T>& operator=(const TypedArray<T>& rhs)

TypedArray<T>& operator=(const Array& rhs)

Description

Assigns a shared data copy of the input to this TypedArray<T>.

Parameters

const TypedArray<T>& rhs

Value to be copied.

const Array& rhs

Value specified as matlab::data::Array object.

Returns

TypedArray<T>&

Updated instance.

Throws

InvalidArrayTypeException

Type of input Array does not match the type for TypedArray<T>.

Move Constructor

TypedArray(TypedArray<T>&& rhs)

TypedArray(Array&& rhs)

Description

Moves contents of the input to a new instance.

Parameters

TypedArray<T>&& rhs

Value to be moved.

Array&& rhs

Value specified as matlab::data::Array object.

Throws

InvalidArrayTypeException

Type of input does not match.

Move Assignment Operator

TypedArray<T>& operator=(TypedArray<T>&& rhs)

TypedArray<T>& operator=(Array&& rhs)

Description

Moves the input to this TypedArray<T> object.

Parameters

TypedArray<T>&& rhs

Value to move.

Returns

TypedArray<T>&

Updated instance.

Throws

InvalidArrayTypeException

Type of input Array does not match the type for TypedArray<T>.

Destructor

virtual ~TypedArray()

Iterators

Begin Iterators

iterator begin()

const_iterator begin() const

const_iterator cbegin() const

Returns

iterator

Iterator to beginning of array, specified as TypedIterator<T>.

const_iterator

Iterator, specified as TypedIterator<typename std::add_const<T>::type>.

Throws

None

End Iterators

iterator end()

const_iterator end() const

const_iterator cend() const

Returns

iterator

Iterator to end of array, specified as TypedIterator<T>.

const_iterator

Iterator, specified as TypedIterator<typename std::add_const<T>::type>.

Throws

None

Indexing Operators

operator[]

ArrayElementTypedRef<T, std::is_const<T>::value> operator[](size_t idx)

ArrayElementTypedRef<T, true> operator[](size_t idx) const

Description

Enables [] indexing on a TypedArray. Indexing is 0-based.

Parameters

size_t idx

First array index.

Returns

ArrayElementTypedRef<T, std::is_const<T>::value>

Temporary object containing index specified. If type T is const, then the return value allows the element of the array to be retrieved, but not modified. Otherwise, the element can be modified or retrieved.

ArrayElementTypedRef<T, true>

Temporary object containing index specified. The return value allows the element of the array to be retrieved, but not modified.

Throws

None

Examples

Suppose that you have a cell array c. Assign a value to a Reference<Array> object and call the member function getType.

Reference<Array> r = c[0][0];
auto t = c[0][0].getType;

Member Functions

release

buffer_ptr_t<T> release()

Description

Release the underlying buffer from the Array. If the Array is shared, a copy of the buffer is made; otherwise, no copy is made. After the buffer is released, the array contains no elements.

Returns

buffer_ptr_t<T>

unique_ptr containing data pointer.

Throws

InvalidArrayTypeException

TypedArray does not support releasing the buffer.

Examples

expand all

Create an array equivalent to the MATLAB array [1 2; 3 4], then replace each element of the array with a single value.

#include "MatlabDataArray.hpp"

int main() {
	matlab::data::ArrayFactory factory;
	// Create an array equivalent to the MATLAB array [1 2; 3 4].
	matlab::data::TypedArray<double> D = factory.createArray<double>({ 2,2 }, { 1,3,2,4 });
	// Change the values.
	for (auto& elem : D) {
		elem = 5.5;
	}
	return 0;
}

Introduced in R2017b