| 90 | } |
| 91 | |
| 92 | void StructArray::getFieldByIndex(libmexclass::proxy::method::Context& context) { |
| 93 | namespace mda = ::matlab::data; |
| 94 | using namespace libmexclass::proxy; |
| 95 | |
| 96 | mda::StructArray args = context.inputs[0]; |
| 97 | const mda::TypedArray<int32_t> index_mda = args[0]["Index"]; |
| 98 | const auto matlab_index = int32_t(index_mda[0]); |
| 99 | |
| 100 | auto struct_array = std::static_pointer_cast<arrow::StructArray>(array); |
| 101 | |
| 102 | const auto num_fields = struct_array->type()->num_fields(); |
| 103 | |
| 104 | // Validate there is at least 1 field |
| 105 | MATLAB_ERROR_IF_NOT_OK_WITH_CONTEXT(index::validateNonEmptyContainer(num_fields), |
| 106 | context, error::INDEX_EMPTY_CONTAINER); |
| 107 | |
| 108 | // Validate the matlab index provided is within the range [1, num_fields] |
| 109 | MATLAB_ERROR_IF_NOT_OK_WITH_CONTEXT(index::validateInRange(matlab_index, num_fields), |
| 110 | context, error::INDEX_OUT_OF_RANGE); |
| 111 | |
| 112 | // Note: MATLAB uses 1-based indexing, so subtract 1. |
| 113 | const int32_t index = matlab_index - 1; |
| 114 | |
| 115 | auto field_array = struct_array->field(index); |
| 116 | MATLAB_ASSIGN_OR_ERROR_WITH_CONTEXT(context.outputs[0], |
| 117 | arrow::matlab::proxy::wrap_and_manage(field_array), |
| 118 | context, error::UNKNOWN_PROXY_FOR_ARRAY_TYPE); |
| 119 | } |
| 120 | |
| 121 | void StructArray::getFieldByName(libmexclass::proxy::method::Context& context) { |
| 122 | namespace mda = ::matlab::data; |
nothing calls this directly
no test coverage detected