Skip to content

Commit d888536

Browse files
committed
Add wrap_and_manage function
1 parent f1794a6 commit d888536

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
#include "arrow/visitor.h"
19-
#include "arrow/matlab/proxy/wrap.h"
2018

2119
#include "arrow/matlab/array/proxy/boolean_array.h"
2220
#include "arrow/matlab/array/proxy/list_array.h"
2321
#include "arrow/matlab/array/proxy/numeric_array.h"
2422
#include "arrow/matlab/array/proxy/string_array.h"
2523
#include "arrow/matlab/array/proxy/struct_array.h"
24+
#include "arrow/matlab/error/error.h"
25+
#include "arrow/matlab/proxy/wrap.h"
26+
#include "arrow/visitor.h"
27+
#include "libmexclass/proxy/ProxyManager.h"
2628

2729
namespace arrow::matlab::proxy {
2830

@@ -189,4 +191,19 @@ namespace arrow::matlab::proxy {
189191
ArrayProxyWrapperVisitor visitor{array};
190192
return visitor.wrap();
191193
}
192-
}
194+
195+
arrow::Result<std::shared_ptr<arrow::matlab::array::proxy::Array>> wrap(const std::shared_ptr<arrow::Array>& array) {
196+
namespace mda = ::matlab::data;
197+
mda::ArrayFactory factory;
198+
199+
ArrayProxyWrapperVisitor visitor{array};
200+
ARROW_ASSIGN_OR_RAISE(auto proxy, visitor.wrap());
201+
const auto proxy_id = ProxyManager::manageProxy(proxy);
202+
203+
mda::StructArray output = factory.createStructArray({1, 1}, {"ProxyID", "TypeID"});
204+
output[0]["ProxyID"] = factory.createScalar(proxy_id);
205+
output[0]["TypeID"] = factory.createScalar(array->type()->type_id());
206+
207+
return output;
208+
}
209+
}

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,19 @@
1919

2020
#include "arrow/array.h"
2121
#include "arrow/result.h"
22-
// #include "MatlabDataArray.hpp"
2322
#include "arrow/matlab/array/proxy/array.h"
23+
#include "MatlabDataArray.hpp"
2424

2525
namespace arrow::matlab::proxy {
26+
27+
/// \brief Wraps an array with a proxy::Array.
28+
///
29+
/// \return arrow::result<std::shared_ptr<arrow::matlab::array::proxy::Array>>
2630
arrow::Result<std::shared_ptr<arrow::matlab::array::proxy::Array>> wrap(const std::shared_ptr<arrow::Array>& array);
31+
32+
/// \brief Wraps an array with a proxy::Array and adds the proxy to the ProxyManager.
33+
///
34+
/// \return arrow::Result<mda::StructArray>. The mda::StructArray has two fields: ProxyID (uint64) and TypeID (int32).
35+
arrow::Result<::matlab::data::StructArray> wrap_and_manage(const std::shared_ptr<arrow::Array>& array);
36+
2737
}

0 commit comments

Comments
 (0)