/* Copyright 2014-2017 The MathWorks, Inc. */ #ifndef MATLAB_DATA_STRUCT_ARRAY_HPP #define MATLAB_DATA_STRUCT_ARRAY_HPP #include "TypedArray.hpp" #include "Range.hpp" #include "MatlabFieldIdentifier.hpp" #include "StructRef.hpp" #include "ForwardIterator.hpp" #include "Struct.hpp" #include "detail/struct_interface.hpp" #include "detail/HelperFunctions.hpp" #include namespace matlab { namespace data { namespace impl { class ArrayImpl; } namespace detail { class Access; } /** * Struct Array */ class StructArray : public TypedArray { public: static const ArrayType type = ArrayType::STRUCT; /** * StructArray destructor * * @throw none */ ~StructArray() MW_NOEXCEPT {} /** * StructArray move constructor * * @rhs - StructArray to be moved * @return - newly constructed StructArray * @throw - none */ StructArray(StructArray&& rhs) MW_NOEXCEPT : TypedArray::TypedArray(std::move(rhs)) {} /** * StructArray move assignment * * @rhs - StructArray to be moved * @return - updated StructArray * @throw - none */ StructArray& operator=(StructArray&& rhs) MW_NOEXCEPT { TypedArray::operator=(std::move(rhs)); return *this; } /** * StructArray assignment operator - creates a shared copy of the input * * @rhs - StructArray to be copied * @return - updated StructArray * @throw - none */ StructArray& operator=(StructArray const& rhs) MW_NOEXCEPT { TypedArray::operator=(rhs); return *this; } /** * StructArray move constructor * * @rhs - StructArray to be moved * @return - newly constructed StructArray * @throw - none */ StructArray(const StructArray &rhs) MW_NOEXCEPT : TypedArray::TypedArray(rhs) {} /** * Construct a StructArray from an Array r-value * * @param rhs - Array to be moved into the StructArray * @return - newly constructed StructArray * @throw InvalidArrayTypeException if type of rhs doesn't match */ StructArray(Array&& rhs) : TypedArray(std::move(rhs)) {} /** * Construct a StructArray from an Array * * @param rhs - Array to be moved into the StructArray * @return - shared copy of the input rhs * @throw InvalidArrayTypeException if type of rhs doesn't match */ StructArray(const Array& rhs) : TypedArray(rhs) {} /** * assignment operator - creates a shared data copy fron an Array * * @param rhs - rvalue to be copied * @return StructArray& the updated instance * @throw InvalidArrayTypeException if type of rhs type is not STRUCT */ StructArray& operator=(const Array& rhs) { TypedArray::operator=(rhs); return *this; } /** * move assignment operator from an Array * * @param rhs - rvalue to be moved * @return StructArray& the updated instance * @throw InvalidArrayTypeException if type of rhs type is not a STRUCT */ StructArray& operator=(Array&& rhs) { TypedArray::operator=(std::move(rhs)); return *this; } /** * Returns a Range which will iterate over all * of the fieldNames in a struct array. * * @return Range * @throw none */ Range getFieldNames() const MW_NOEXCEPT { return Range(detail::Access::createObj>(struct_array_begin_id(detail::Access::getImpl(*this))), detail::Access::createObj>(struct_array_end_id(detail::Access::getImpl(*this)))); } /** * get the number of fields in this struct * * @return size_t the number of fields * @throw none */ size_t getNumberOfFields() const MW_NOEXCEPT { return struct_array_get_num_fields(detail::Access::getImpl(*this)); } private: friend class detail::Access; StructArray() = delete; StructArray(matlab::data::impl::ArrayImpl* impl) MW_NOEXCEPT : TypedArray(impl) {} }; } } #endif