Skip to content

Commit

Permalink
Add wrap.cc
Browse files Browse the repository at this point in the history
  • Loading branch information
sgilmore10 committed Aug 3, 2023
1 parent c80811e commit ee2318d
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 2 deletions.
65 changes: 65 additions & 0 deletions matlab/src/cpp/arrow/matlab/array/proxy/wrap.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

#pragma once

#include "arrow/array.h"
#include "arrow/result.h"

#include "arrow/matlab/array/proxy/array.h"
#include "arrow/matlab/array/proxy/boolean_array.h"
#include "arrow/matlab/array/proxy/numeric_array.h"
#include "arrow/matlab/array/proxy/string-array.h"

namespace arrow::matlab::array::proxy {

arrow::Result<std::shared_ptr<proxy::Array>> wrap(const std::shared_ptr<arrow::Array>& array) {

using ID = arrow::Type::type;
switch (array->type_id()) {
case ID::BOOL:
return std::make_shared<proxy::BooleanArray>(std::static_pointer_cast<arrow::BooleanArray>(type));
case ID::UINT8:
return std::make_shared<proxy::NumericArray<arrow::UInt8Type>>(std::static_pointer_cast<arrow::UInt8Array>(type));
case ID::UINT16:
return std::make_shared<proxy::NumericArray<arrow::UInt16Type>>(std::static_pointer_cast<arrow::UInt16Array>(array));
case ID::UINT32:
return std::make_shared<proxy::NumericArray<arrow::UInt32Type>>(std::static_pointer_cast<arrow::UInt32Array>(array));
case ID::UINT64:
return std::make_shared<proxy::NumericArray<arrow::UInt64Type>>(std::static_pointer_cast<arrow::UInt64Array>(array));
case ID::INT8:
return std::make_shared<proxy::NumericArray<arrow::Int8Type>>(std::static_pointer_cast<arrow::Int8Array>(array));
case ID::INT16:
return std::make_shared<proxy::NumericArray<rrow::Int16Type>>(std::static_pointer_cast<arrow::Int16Array>(array));
case ID::INT32:
return std::make_shared<proxy::NumericArray<rrow::Int32Type>>(std::static_pointer_cast<arrow::Int32Array>(array));
case ID::INT64:
return std::make_shared<proxy::NumericArray<rrow::Int64Type>>(std::static_pointer_cast<arrow::Int64Array>(array));
case ID::FLOAT:
return std::make_shared<proxy::NumericArray<arrow::FloatType>>(std::static_pointer_cast<arrow::FloatArray>(array));
case ID::DOUBLE:
return std::make_shared<proxy::NumericArray<arrow::DoubleArray>>(std::static_pointer_cast<arrow::DoubleArray>(array));
case ID::TIMESTAMP:
return std::make_shared<proxy::NumericArray<arrow::TimestampType>>(std::static_pointer_cast<arrow::TimestampArray>(array));
case ID::STRING:
return std::make_shared<proxy::StringArray>(std::static_pointer_cast<arrow::StringArray>(array));
default:
return arrow::Status::NotImplemented("Unsupported DataType: " + array->type()->ToString());
}
}

}
4 changes: 2 additions & 2 deletions matlab/src/cpp/arrow/matlab/array/proxy/wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

#include "arrow/matlab/array/proxy/array.h"

namespace arrow::matlab::type::proxy {
namespace arrow::matlab::array::proxy {

arrow::Result<std::shared_ptr<Array>> wrap(const std::shared_ptr<arrow::Array>& array);
arrow::Result<std::shared_ptr<proxy::Array>> wrap(const std::shared_ptr<arrow::Array>& array);

}
1 change: 1 addition & 0 deletions matlab/tools/cmake/BuildMatlabArrowInterface.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ set(MATLAB_ARROW_LIBMEXCLASS_CLIENT_PROXY_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/src/c
set(MATLAB_ARROW_LIBMEXCLASS_CLIENT_PROXY_SOURCES "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/array/proxy/array.cc"
"${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/array/proxy/boolean_array.cc"
"${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/array/proxy/string_array.cc"
"${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/array/proxy/wrap.cc"
"${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/tabular/proxy/record_batch.cc"
"${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/bit/pack.cc"
"${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/bit/unpack.cc"
Expand Down

0 comments on commit ee2318d

Please sign in to comment.