Main Content

matlab::data::TypedArray<T>

배열 데이터에 액세스하기 위한 템플릿 기반 C++ 클래스

설명

템플릿 기반 TypedArray 클래스는 모든 MATLAB 배열 유형(희소 배열 제외)을 처리하는, 형식이 안전한(type-safe) API를 제공합니다. TypedArray를 만들려면, 템플릿 인스턴스화에 나와 있는 템플릿 중 하나를 사용하여 ArrayFactory 클래스에서 createArray 또는 createScalar를 호출하십시오.

이 클래스는 다음과 같은 이터레이터 유형을 정의합니다.

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

클래스 세부 정보

네임스페이스:

matlab::data

기본 클래스:

matlab::data::Array

포함:

TypedArray.hpp

템플릿 파라미터

T

참조되는 요소의 유형.

템플릿 인스턴스화

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

생성자

복사 생성자

TypedArray(const TypedArray<T>& rhs)

TypedArray(const Array& rhs)

설명

입력값의 공유된 데이터 복사본을 만듭니다.

파라미터

const TypedArray<T>& rhs

복사할 값.

const Array& rhs

matlab::data::Array 객체로 지정된 값.

발생되는 예외

matlab::data::InvalidArrayTypeException

입력값 Array의 유형은 TypedArray<T>의 유형과 일치하지 않습니다.

복사본 할당 연산자

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

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

설명

TypedArray<T>에 입력값의 공유된 데이터 복사본을 할당합니다.

파라미터

const TypedArray<T>& rhs

복사할 값.

const Array& rhs

matlab::data::Array 객체로 지정된 값.

반환되는 값

TypedArray<T>&

업데이트된 인스턴스.

발생되는 예외

matlab::data::InvalidArrayTypeException

입력값 Array의 유형은 TypedArray<T>의 유형과 일치하지 않습니다.

이동 생성자

TypedArray(TypedArray<T>&& rhs)

TypedArray(Array&& rhs)

설명

입력값의 내용을 새 인스턴스로 이동합니다.

파라미터

TypedArray<T>&& rhs

이동할 값.

Array&& rhs

matlab::data::Array 객체로 지정된 값.

발생되는 예외

matlab::data::InvalidArrayTypeException

입력값 유형이 일치하지 않습니다.

이동 할당 연산자

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

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

설명

입력값을 이 TypedArray<T> 객체로 이동합니다.

파라미터

TypedArray<T>&& rhs

이동할 값.

반환되는 값

TypedArray<T>&

업데이트된 인스턴스.

발생되는 예외

matlab::data::InvalidArrayTypeException

입력값 Array의 유형은 TypedArray<T>의 유형과 일치하지 않습니다.

소멸자

virtual ~TypedArray()

이터레이터

시작 이터레이터

iterator begin()

const_iterator begin() const

const_iterator cbegin() const

반환되는 값

iterator

배열 시작을 나타내는 이터레이터로, TypedIterator<T>로 지정됩니다.

const_iterator

이터레이터로, TypedIterator<typename std::add_const<T>::type>로 지정됩니다.

발생되는 예외

없음

끝 이터레이터

iterator end()

const_iterator end() const

const_iterator cend() const

반환되는 값

iterator

배열 끝을 나타내는 이터레이터로, TypedIterator<T>로 지정됩니다.

const_iterator

이터레이터로, TypedIterator<typename std::add_const<T>::type>로 지정됩니다.

발생되는 예외

없음

인덱싱 연산자

operator[]

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

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

설명

[] 인덱싱을 TypedArray에 사용합니다. 인덱싱은 0부터 시작합니다.

파라미터

size_t idx

첫 번째 배열 인덱스.

반환되는 값

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

지정된 인덱스를 포함하는 임시 객체. 유형 Tconst이면, 반환 값을 사용하여 배열 요소를 가져올 수는 있지만 수정할 수는 없습니다. 그 외의 경우에는 요소를 수정하거나 가져올 수 있습니다.

ArrayElementTypedRef<T, true>

지정된 인덱스를 포함하는 임시 객체. 반환 값을 사용하여 배열 요소를 가져올 수는 있지만 수정할 수는 없습니다.

발생되는 예외

없음

멤버 함수

release

buffer_ptr_t<T> release()
설명

배열에서 기본 버퍼를 해제합니다. 배열이 공유된 상태이면 버퍼의 복사본이 만들어지고, 그렇지 않으면 복사본이 만들어지지 않습니다. 버퍼가 해제되면 배열에는 아무런 요소가 포함되지 않습니다.

반환되는 값

buffer_ptr_t<T>

데이터 포인터를 포함한 unique_ptr.

발생되는 예외

matlab::data::InvalidArrayTypeException

TypedArray는 버퍼 해제를 지원하지 않습니다.

예제

모두 확장

MATLAB 배열 [1 2; 3 4]와 동일한 배열을 만든 다음, 배열의 각 요소를 단일 값으로 바꿉니다.

#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;
}

버전 내역

R2017b에 개발됨