kou commented on code in PR #34563: URL: https://github.com/apache/arrow/pull/34563#discussion_r1141021576
########## matlab/tools/cmake/BuildMatlabArrowInterface.cmake: ########## @@ -0,0 +1,80 @@ +# 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. + +# ------- +# Config +# ------- + +# Build configuration for libmexclass. +set(CUSTOM_PROXY_FACTORY_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy;${CMAKE_SOURCE_DIR}/src/cpp") +set(CUSTOM_PROXY_FACTORY_SOURCES "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy/factory.cc") +set(CUSTOM_PROXY_SOURCES "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/array/proxy/float64_array.cc") +set(CUSTOM_PROXY_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/src/cpp;${ARROW_INCLUDE_DIR}") +set(CUSTOM_PROXY_LINK_LIBRARIES ${ARROW_LINK_LIB}) +# On Windows, arrow.dll must be installed regardless of +# whether Arrow_FOUND is true or false. Therefore, we explicitly +# copy ARROW_SHARED_LIB to the installation folder +libmexclass/+proxy. +set(CUSTOM_PROXY_RUNTIME_LIBRARIES ${ARROW_SHARED_LIB}) +set(CUSTOM_PROXY_FACTORY_HEADER_FILENAME "factory.h") +set(CUSTOM_PROXY_FACTORY_CLASS_NAME "arrow::matlab::proxy::Factory") Review Comment: Thanks! I think that I understand. > this is [how MEX functions work, in general](https://www.mathworks.com/help/matlab/matlab_external/c-mex-functions.html) This link is helpful. This is what I want to know! How about providing the following `libmexclass/mex.h` by `libmexclass`: ```cpp #include "libmexclass/action/Action.h" #include "libmexclass/action/Factory.h" #include "libmexclass/mex/Arguments.h" #include "libmexclass/mex/State.h" #include "libmexclass/proxy/Factory.h" #include "mex.hpp" #include "mexAdapter.hpp" namespace libmexclass { namespace mex { template <typename ProxyFactory> CallMexFunction((matlab::mex::ArgumentList outputs, matlab::mex::ArgumentList inputs) { // Wrap the inputs and outputs. Arguments output_arguments{outputs.begin()}; Arguments input_arguments{inputs.begin()}; // Store the inputs, outputs, and MATLAB Engine pointer in a libmexclass::mex::State instance. State state{input_arguments, output_arguments, getEngine()}; // Create a polymorphic proxy::Factory instance. // NOTE: Clients provide the implementation for CustomProxyFactory. std::shared_ptr<proxy::Factory> proxy_factory = std::make_shared<ProxyFactory>(); // Create an action::Factory. action::Factory action_factory{proxy_factory}; // Create an Action. std::unique_ptr<action::Action> action = action_factory.makeAction(state); // Execute the Action. action->execute(); } } } ``` and `apache/arrow` has only the following small C++ code? ```cpp #include <libmexclass/mex.h> #include <arrow/matlab/proxy/factory.h> class MexFunction : public matlab::mex::Function { public: void operator()(matlab::mex::ArgumentList outputs, matlab::mex::ArgumentList inputs) { libmexclass::mex::CallMexFunction<arrow::matlab::proxy::Factory>(outputs, inputs); } }; ``` This approach doesn't use (a bit) tricky header/code injections by C preprocessor. It just uses a standard C++ feature instead of injection by C preprocessor. If the approach doesn't make sense, I'm OK with the current "template code" approach. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
