/* Copyright 2017 The MathWorks, Inc. */ #ifndef MATLAB_ENGINE_HPP #define MATLAB_ENGINE_HPP #include #include #include #include #include #include "engine_util.hpp" #include #include #include #include #include #include namespace matlab { namespace engine { class MATLABEngine { public: /** * Evaluate a MATLAB function synchronously * * @param function - The name of a MATLAB function * @param nlhs - The number of output to be expected * @param args - The arguments of the MATLAB function * @param output - The stream used to redirect standard output generated by MATLAB * @param error - The stream used to redirect standard error generated by MATLAB * @return std::vector - A vector of MATLAB Data Array as the result of the MATLAB function * * @throw MATLABSyntaxException, MATLABExecutionException */ std::vector feval(const String &function, const size_t nlhs, const std::vector &args, const std::shared_ptr &output = std::shared_ptr(), const std::shared_ptr &error = std::shared_ptr() ); /** * Evaluate a MATLAB function synchronously * * @param function - The name of a MATLAB function * @param args - The arguments of the MATLAB function * @param output - The stream used to redirect standard output generated by MATLAB * @param error - The stream used to redirect standard error generated by MATLAB * @return matlab::data::Array - A MATLAB Data Array as the result of the MATLAB function * * @throw MATLABSyntaxException, MATLABExecutionException */ matlab::data::Array feval(const String &function, const std::vector &args, const std::shared_ptr &output = std::shared_ptr(), const std::shared_ptr &error = std::shared_ptr() ); /** * Evaluate a MATLAB function synchronously * * @param function - The name of a MATLAB function * @param arg - The argument of the MATLAB function * @param output - The stream used to redirect standard output generated by MATLAB * @param error - The stream used to redirect standard error generated by MATLAB * @return matlab::data::Array - A MATLAB Data Array as the result of the MATLAB function * * @throw MATLABSyntaxException, MATLABExecutionException */ matlab::data::Array feval(const String &function, const matlab::data::Array &arg, const std::shared_ptr &output = std::shared_ptr(), const std::shared_ptr &error = std::shared_ptr() ); /** * Evaluate a MATLAB function synchronously * * @param function - The name of a MATLAB function * @param rhsArgs - The arguments of the MATLAB function * @param output - The stream used to redirect standard output generated by MATLAB * @param error - The stream used to redirect standard error generated by MATLAB * @return ReturnType - The result of the MATLAB function * * @throw MATLABSyntaxException, MATLABExecutionException */ template ReturnType feval(const String &function, const std::shared_ptr &output, const std::shared_ptr &error, RhsArgs&&... rhsArgs ); /** * Evaluate a MATLAB function synchronously * * @param function - The name of a MATLAB function * @param rhsArgs - The arguments of the MATLAB function * @return ReturnType - The result of the MATLAB function * * @throw MATLABSyntaxException, MATLABExecutionException */ template ReturnType feval(const String &function, RhsArgs&&... rhsArgs ); /** * Evaluate a MATLAB statement synchronously * * @param statement- The MATLAB statement to be evaluated * @param output - The stream used to redirect standard output generated by MATLAB * @param error - The stream used to redirect standard error generated by MATLAB * @return none * * @throw MATLABSyntaxException, MATLABExecutionException */ void eval(const String &statement, const std::shared_ptr &output = std::shared_ptr(), const std::shared_ptr &error = std::shared_ptr() ); /** * Obtain a variable from the MATLAB base or global workspace * * @param varName - The name of a MATLAB variable in the base or global workspace * @return matlab::data::Array - The variable returned from MATLAB base or global workspace * * @throw none */ matlab::data::Array getVariable(const String &varName, WorkspaceType workspaceType = WorkspaceType::BASE); /** * Send a variable to the MATLAB base or global workspace * * @param varName - The name of a MATLAB variable in the base or global workspace * @param var - The variable to be sent to the MATLAB base or global workspace * @return none * * @throw none */ void setVariable(const String &varName, const matlab::data::Array &var, WorkspaceType workspaceType = WorkspaceType::BASE); /** * Obtain the value of an object property * * @param object - An object * @param propertyName - The name of the property to set for the object * @return matlab::data::Array - The property from the object * * @throw none */ matlab::data::Array getProperty(const matlab::data::Array &object, const String &propertyName); /** * Set a property value of an object * * @param object - An object * @param propertyName - The name of the property to set for the object * @param property - The value of the property to set for the object * @return none * * @throw none */ void setProperty(matlab::data::Array &object, const String &propertyName, const matlab::data::Array &property); /** * Evaluate a MATLAB function asynchronously * * @param function - The name of a MATLAB function * @param nlhs - The number of output to be expected * @param args - The arguments of the MATLAB function * @param output - The stream used to redirect standard output generated by MATLAB * @param error - The stream used to redirect standard error generated by MATLAB * @return FutureResult> - A future of a vector of MATLAB Data Array as the result of the MATLAB function * * @throw none */ FutureResult > fevalAsync(const String &function, const size_t nlhs, const std::vector &args, const std::shared_ptr &output = std::shared_ptr(), const std::shared_ptr &error = std::shared_ptr() ); /** * Evaluate a MATLAB function asynchronously * * @param function - The name of a MATLAB function * @param args - The arguments of the MATLAB function * @param output - The stream used to redirect standard output generated by MATLAB * @param error - The stream used to redirect standard error generated by MATLAB * @return FutureResult - A future of a MATLAB Data Array as the result of the MATLAB function * * @throw none */ FutureResult fevalAsync(const String &function, const std::vector &args, const std::shared_ptr &output = std::shared_ptr(), const std::shared_ptr &error = std::shared_ptr() ); /** * Evaluate a MATLAB function asynchronously * * @param function - The name of a MATLAB function * @param arg - The argument of the MATLAB function * @param output - The stream used to redirect standard output generated by MATLAB * @param error - The stream used to redirect standard error generated by MATLAB * @return FutureResult - A future of a MATLAB Data Array as the result of the MATLAB function * * @throw none */ FutureResult fevalAsync(const String &function, const matlab::data::Array &arg, const std::shared_ptr &output = std::shared_ptr(), const std::shared_ptr &error = std::shared_ptr() ); /** * Evaluate a MATLAB function asynchronously * * @param function - The name of a MATLAB function * @param rhsArgs - The arguments of the MATLAB function * @param output - The stream used to redirect standard output generated by MATLAB * @param error - The stream used to redirect standard error generated by MATLAB * @return FutureResult - A future to the result of the MATLAB function * * @throw none */ template FutureResult fevalAsync(const String &function, const std::shared_ptr &output, const std::shared_ptr &error, RhsArgs&&... rhsArgs ); /** * Evaluate a MATLAB function asynchronously * * @param function - The name of a MATLAB function * @param rhsArgs - The arguments of the MATLAB function * @return FutureResult - A future to the result of the MATLAB function * * @throw none */ template FutureResult fevalAsync(const String &function, RhsArgs&&... rhsArgs ); /** * Evaluate a MATLAB statement asynchronously * * @param statement- The MATLAB statement to be evaluated * @param output - The stream used to redirect standard output generated by MATLAB * @param error - The stream used to redirect standard error generated by MATLAB * @return FutureResult - A future to the evaluate of the MATLAB statement * * @throw none */ FutureResult evalAsync(const String &str, const std::shared_ptr &output = std::shared_ptr(), const std::shared_ptr &error = std::shared_ptr() ); /** * Obtain a variable from the MATLAB base or global workspace asynchronously * * @param varName - The name of a MATLAB variable in the base or global workspace * @return FutureResult - A future to get the variable returned from MATLAB base or global workspace * * @throw none */ FutureResult getVariableAsync(const String &varName, WorkspaceType workspaceType = WorkspaceType::BASE); /** * Send a variable to the MATLAB base or global workspace asynchronously * * @param varName - The name of a MATLAB variable in the base or global workspace * @param var - The variable to be sent to the MATLAB base or global workspace * @return FutureResult - A future to the operation * * @throw none */ FutureResult setVariableAsync(const String &varName, const matlab::data::Array& var, WorkspaceType workspaceType = WorkspaceType::BASE); /** * Obtain the value of an object property asynchronously * * @param object - An object * @param propertyName - The name of the property to set for the object * @return FutureResult - A future to get the property from the object * * @throw none */ FutureResult getPropertyAsync(const matlab::data::Array &object, const String &propertyName); /** * Set a property value of an object asynchronously * * @param object - An object * @param propertyName - The name of the property to set for the object * @param property - The value of the property to set for the object * @return FutureResult - A future to the operation * * @throw none */ FutureResult setPropertyAsync(matlab::data::Array &object, const String &propertyName, const matlab::data::Array &property); /** * Constructor * * @param handle - The internal implementation * * @throw none */ MATLABEngine(uint64_t handle); /** * Destructor * * @throw none */ ~MATLABEngine(); private: uint64_t matlabHandle; }; void writeToStreamBuffer(void* buffer, const char16_t* stream, size_t n); void deleteStreamBufferImpl(void* impl); } } #endif /* MATLAB_ENGINE_HPP */