Skip to content

Commit 1622e7c

Browse files
committed
Add wrap_and_manage function for arrow::DataType
1 parent 4171dfd commit 1622e7c

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

matlab/src/cpp/arrow/matlab/proxy/wrap.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,4 +189,17 @@ namespace arrow::matlab::proxy {
189189
WrapTypeFunctor functor;
190190
return wrap(datatype, functor);
191191
}
192+
193+
arrow::Result<::matlab::data::StructArray> wrap_and_manage(const std::shared_ptr<arrow::DataType>& datatype) {
194+
namespace mda = ::matlab::data;
195+
mda::ArrayFactory factory;
196+
197+
ARROW_ASSIGN_OR_RAISE(auto proxy, wrap(datatype));
198+
const auto proxy_id = libmexclass::proxy::ProxyManager::manageProxy(proxy);
199+
200+
mda::StructArray output = factory.createStructArray({1, 1}, {"ProxyID", "TypeID"});
201+
output[0]["ProxyID"] = factory.createScalar(proxy_id);
202+
output[0]["TypeID"] = factory.createScalar( static_cast<int32_t>(datatype->id()));
203+
return output;
204+
}
192205
}

matlab/src/cpp/arrow/matlab/proxy/wrap.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,8 @@ namespace arrow::matlab::proxy {
4040
/// \return arrow::result<std::shared_ptr<arrow::matlab::type::proxy::Type>>
4141
arrow::Result<std::shared_ptr<arrow::matlab::type::proxy::Type>> wrap(const std::shared_ptr<arrow::DataType>& datatype);
4242

43-
}
43+
/// \brief Wraps an DataType within a proxy::DataType and adds the proxy to the ProxyManager..
44+
///
45+
/// \return arrow::Result<mda::StructArray>. The mda::StructArray has two fields: ProxyID (uint64) and TypeID (int32).
46+
arrow::Result<std::shared_ptr<arrow::matlab::type::proxy::Type>> wrap(const std::shared_ptr<arrow::DataType>& datatype);
47+
}

0 commit comments

Comments
 (0)