diff options
Diffstat (limited to 'ml/dlib/dlib/matlab')
-rw-r--r-- | ml/dlib/dlib/matlab/CMakeLists.txt | 22 | ||||
-rw-r--r-- | ml/dlib/dlib/matlab/README.txt | 20 | ||||
-rw-r--r-- | ml/dlib/dlib/matlab/call_matlab.h | 852 | ||||
-rw-r--r-- | ml/dlib/dlib/matlab/cmake_mex_wrapper | 103 | ||||
-rw-r--r-- | ml/dlib/dlib/matlab/example.m | 16 | ||||
-rw-r--r-- | ml/dlib/dlib/matlab/example_mex_callback.cpp | 52 | ||||
-rw-r--r-- | ml/dlib/dlib/matlab/example_mex_class.cpp | 72 | ||||
-rw-r--r-- | ml/dlib/dlib/matlab/example_mex_function.cpp | 84 | ||||
-rw-r--r-- | ml/dlib/dlib/matlab/example_mex_struct.cpp | 55 | ||||
-rw-r--r-- | ml/dlib/dlib/matlab/mex_wrapper.cpp | 5144 | ||||
-rw-r--r-- | ml/dlib/dlib/matlab/subprocess_stream.cpp | 537 | ||||
-rw-r--r-- | ml/dlib/dlib/matlab/subprocess_stream.h | 223 |
12 files changed, 0 insertions, 7180 deletions
diff --git a/ml/dlib/dlib/matlab/CMakeLists.txt b/ml/dlib/dlib/matlab/CMakeLists.txt deleted file mode 100644 index b9a0beab9..000000000 --- a/ml/dlib/dlib/matlab/CMakeLists.txt +++ /dev/null @@ -1,22 +0,0 @@ - -cmake_minimum_required(VERSION 2.8.12) - -PROJECT(mex_functions) - -include(cmake_mex_wrapper) - -add_subdirectory(.. dlib_build) - - -# You can tell cmake where to put the mex files when you run 'make install' by -# setting this variable. The path is relative to this CMakeLists.txt file. -set(install_target_output_folder .) - -# Compile the example_mex_function.cpp file and link it to dlib. Note -# that you can give a list of things to link to here. E.g. -# add_mex_function(some_other_mex_function pthread dlib fftw) -add_mex_function(example_mex_function dlib::dlib) -add_mex_function(example_mex_callback dlib::dlib) -add_mex_function(example_mex_struct dlib::dlib) -add_mex_function(example_mex_class dlib::dlib) - diff --git a/ml/dlib/dlib/matlab/README.txt b/ml/dlib/dlib/matlab/README.txt deleted file mode 100644 index d571e2330..000000000 --- a/ml/dlib/dlib/matlab/README.txt +++ /dev/null @@ -1,20 +0,0 @@ -This folder contains a set of tools which make it easy to create MATLAB mex -functions. To understand how they work, you should read the -example_mex_function.cpp, example_mex_struct.cpp, and example_mex_callback.cpp examples. - -To compile them, you can use CMake. In particular, from this folder execute -these commands: - - mkdir build - cd build - cmake .. - cmake --build . --config release --target install - -That should build the mex files on any platform. - -Note that on windows you will probably need to tell CMake to use a 64bit -version of visual studio. You can do this by using a command like: - cmake -G "Visual Studio 10 Win64" .. -instead of - cmake .. - diff --git a/ml/dlib/dlib/matlab/call_matlab.h b/ml/dlib/dlib/matlab/call_matlab.h deleted file mode 100644 index cc06a6812..000000000 --- a/ml/dlib/dlib/matlab/call_matlab.h +++ /dev/null @@ -1,852 +0,0 @@ -// Copyright (C) 2012 Massachusetts Institute of Technology, Lincoln Laboratory -// License: Boost Software License See LICENSE.txt for the full license. -// Authors: Davis E. King (davis@dlib.net) -#ifndef MIT_LL_CALL_MATLAB_H__ -#define MIT_LL_CALL_MATLAB_H__ - -#include <string> -#include <sstream> -#include <dlib/error.h> -#include <dlib/assert.h> - -namespace dlib -{ - -// ---------------------------------------------------------------------------------------- - -struct invalid_args_exception : error -{ - /*! - WHAT THIS OBJECT REPRESENTS - This is the exception thrown when the mex wrapper tries to convert a matlab - object into a C++ object but for whatever reason can't (usually because the - types don't match). - !*/ - invalid_args_exception(const std::string& msg_): error(msg_) {} - invalid_args_exception(const std::ostringstream& msg_): error(msg_.str()) {} -}; - -// ---------------------------------------------------------------------------------------- - -void check_for_matlab_ctrl_c(); -/*! - ensures - - If the user of MATLAB has pressed ctrl+c then this function will throw an - exception. -!*/ - -// ---------------------------------------------------------------------------------------- - -class matlab_object -{ - /*! - WHAT THIS OBJECT REPRESENTS - This object is a simple wrapper around matlab's generic mxArray, which is the - thing that is matlab's "anything object". So a matlab_object can be used as an - argument to a mex_function() that can bind to any matlab object at all. It can - also bind to "nothing" and so is inherently also an optional argument when - present in a mex_funciton(). - !*/ -public: - matlab_object() : handle(0),should_free(false),arg_idx(0) {} - matlab_object(const matlab_object&) = delete; - - ~matlab_object(); - - - // Check if a matlab object is bound to this object. - bool is_empty() const { return handle==0; } - operator bool() const { return handle!=0; } - - // Convert from MATLAB to C++, throw invalid_args_exception if not possible. - template <typename T> operator T() const; - template <typename T> void get(T& item) const; - - // Convert from a C++ object to MATLAB - template <typename T> matlab_object& operator= (const T& new_val); - - - template <typename T> bool try_get(T& item) const - { - try { get(item); return true; } - catch(invalid_args_exception&) { return false; } - } - - const void* get_handle() const { return handle; } - /*! - ensures - - returns a pointer to the mxArray object. Might be NULL. - !*/ - - - matlab_object& operator=(const matlab_object&) = delete; - - // Users shouldn't call these functions - const void* release_object_to_matlab() { const void* temp=handle; handle = 0; return temp; } - void set_object_handle(int arg_idx_, const void* sh) { DLIB_CASSERT(!handle); handle = sh; arg_idx=arg_idx_; } -private: - - const void* handle; - bool should_free; - int arg_idx; -}; - -// ---------------------------------------------------------------------------------------- - -class matlab_struct -{ - /*! - WHAT THIS OBJECT REPRESENTS - This object lets you interface with MATLAB structs from C++. For example, - given a MATLAB struct named mystruct, you could access it's fields like this: - MATLAB way: mystruct.field - C++ way: mystruct["field"] - MATLAB way: mystruct.field.subfield - C++ way: mystruct["field"]["subfield"] - - To get the values as C++ types you do something like this: - int val = mystruct["field"]; - or - int val; - mystruct["field"].get(val); - - See also example_mex_struct.cpp for an example that uses this part of the API. - !*/ - - class sub; -public: - matlab_struct() : struct_handle(0),should_free(false),arg_idx(0) {} - matlab_struct(const matlab_struct&) = delete; - ~matlab_struct(); - - const sub operator[] (const std::string& name) const; - sub operator[] (const std::string& name); - bool has_field(const std::string& name) const; - - const void* release_struct_to_matlab() { const void* temp=struct_handle; struct_handle = 0; return temp; } - void set_struct_handle(int arg_idx_, const void* sh) { DLIB_CASSERT(!struct_handle); struct_handle = sh; arg_idx=arg_idx_; } -private: - - class sub - { - public: - sub() : struct_handle(0), field_idx(-1) {} - - template <typename T> operator T() const; - template <typename T> void get(T& item) const; - template <typename T> sub& operator= (const T& new_val); - const sub operator[] (const std::string& name) const; - sub operator[] (const std::string& name); - bool has_field(const std::string& name) const; - private: - friend class matlab_struct; - const void* struct_handle; - int field_idx; - sub& operator=(const sub&); - }; - const void* struct_handle; - bool should_free; - int arg_idx; - matlab_struct& operator=(const matlab_struct&); -}; - -// ---------------------------------------------------------------------------------------- -// ---------------------------------------------------------------------------------------- - -template <typename T> -struct output_decorator -{ - output_decorator(T& item_):item(item_){} - T& item; -}; - -template <typename T> -output_decorator<T> returns(T& item) { return output_decorator<T>(item); } -/*! - ensures - - decorates item as an output type. This stuff is used by the call_matlab() - functions to tell if an argument is an input to the function or is supposed - to be bound to one of the return arguments. -!*/ - -// ---------------------------------------------------------------------------------------- -// ---------------------------------------------------------------------------------------- - -struct function_handle -{ - /*! - WHAT THIS OBJECT REPRESENTS - This type is used to represent function handles passed from MATLAB into a - mex function. You can call the function referenced by the handle by - saying: - call_matlab(my_handle); - !*/ - - // These two lines are just implementation details, ignore them. - function_handle():h(0){} - void* const h; -}; - -// ---------------------------------------------------------------------------------------- -// ---------------------------------------------------------------------------------------- - -void call_matlab ( - const std::string& function_name -); -/*! - ensures - - Calls MATLAB's function of the given name -!*/ - -// ---------------------------------------------------------------------------------------- - -void call_matlab ( - const function_handle& funct -); -/*! - ensures - - Calls MATLAB's function represented by the handle funct -!*/ - -// ---------------------------------------------------------------------------------------- - -template < - typename T1 - > -void call_matlab ( - const std::string& function_name, - const T1& A1 -); -/*! - ensures - - calls MATLAB's function of the given name. - - if (A1 is not decorated as an output by returns()) then - - A1 is passed as an argument into the MATLAB function - - else - - A1 is treated as the first return value from the MATLAB function. -!*/ - -template < - typename T1 - > -void call_matlab ( - const function_handle& funct, - const T1& A1 -) { call_matlab("feval", funct, A1); } -/*! - ensures - - Calls MATLAB's function represented by the handle funct - - if (A1 is not decorated as an output by returns()) then - - A1 is passed as an argument into the MATLAB function - - else - - A1 is treated as the first return value from the MATLAB function. -!*/ - -// ---------------------------------------------------------------------------------------- -// ---------------------------------------------------------------------------------------- -/* - The rest of this file is just overloads of call_matlab() for up to 10 arguments (or - just 9 arguments if function_handle is used). They all do the same thing as the above - version of call_matlab(). Generally, any argument not decorated by returns() is an - input to the MATLAB function. On the other hand, all arguments decorated by returns() - are treated as outputs. -*/ -// ---------------------------------------------------------------------------------------- - -template < - typename T1, - typename T2 - > -void call_matlab ( - const std::string& function_name, - const T1& A1, - const T2& A2 -); - -// ---------------------------------------------------------------------------------------- - -template < - typename T1, - typename T2, - typename T3 - > -void call_matlab ( - const std::string& function_name, - const T1& A1, - const T2& A2, - const T3& A3 -); - -// ---------------------------------------------------------------------------------------- - -template < - typename T1, - typename T2, - typename T3, - typename T4 - > -void call_matlab ( - const std::string& function_name, - const T1& A1, - const T2& A2, - const T3& A3, - const T4& A4 -); - -// ---------------------------------------------------------------------------------------- - -template < - typename T1, - typename T2, - typename T3, - typename T4, - typename T5 - > -void call_matlab ( - const std::string& function_name, - const T1& A1, - const T2& A2, - const T3& A3, - const T4& A4, - const T5& A5 -); - -// ---------------------------------------------------------------------------------------- - -template < - typename T1, - typename T2, - typename T3, - typename T4, - typename T5, - typename T6 - > -void call_matlab ( - const std::string& function_name, - const T1& A1, - const T2& A2, - const T3& A3, - const T4& A4, - const T5& A5, - const T6& A6 -); - -// ---------------------------------------------------------------------------------------- - -template < - typename T1, - typename T2, - typename T3, - typename T4, - typename T5, - typename T6, - typename T7 - > -void call_matlab ( - const std::string& function_name, - const T1& A1, - const T2& A2, - const T3& A3, - const T4& A4, - const T5& A5, - const T6& A6, - const T7& A7 -); - -// ---------------------------------------------------------------------------------------- - -template < - typename T1, - typename T2, - typename T3, - typename T4, - typename T5, - typename T6, - typename T7, - typename T8 - > -void call_matlab ( - const std::string& function_name, - const T1& A1, - const T2& A2, - const T3& A3, - const T4& A4, - const T5& A5, - const T6& A6, - const T7& A7, - const T8& A8 -); - -// ---------------------------------------------------------------------------------------- - -template < - typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename - T7, typename T8, typename T9 - > -void call_matlab ( - const std::string& function_name, - const T1& A1, const T2& A2, const T3& A3, const T4& A4, const T5& A5, const T6& A6, - const T7& A7, const T8& A8, const T9& A9 -); - -// ---------------------------------------------------------------------------------------- - -template < - typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename - T7, typename T8, typename T9, typename T10 - > -void call_matlab ( - const std::string& function_name, - const T1& A1, const T2& A2, const T3& A3, const T4& A4, const T5& A5, const T6& A6, - const T7& A7, const T8& A8, const T9& A9, const T10& A10 -); - -// ---------------------------------------------------------------------------------------- - -template < - typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename - T7, typename T8, typename T9, typename T10, typename T11 - > -void call_matlab ( - const std::string& function_name, - const T1& A1, const T2& A2, const T3& A3, const T4& A4, const T5& A5, const T6& A6, - const T7& A7, const T8& A8, const T9& A9, const T10& A10, const T11& A11 -); - -// ---------------------------------------------------------------------------------------- - -template < - typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename - T7, typename T8, typename T9, typename T10, typename T11, typename T12 - > -void call_matlab ( - const std::string& function_name, - const T1& A1, const T2& A2, const T3& A3, const T4& A4, const T5& A5, const T6& A6, - const T7& A7, const T8& A8, const T9& A9, const T10& A10, const T11& A11, const T12& A12 -); - -// ---------------------------------------------------------------------------------------- - -template < - typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename - T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13 - > -void call_matlab ( - const std::string& function_name, - const T1& A1, const T2& A2, const T3& A3, const T4& A4, const T5& A5, const T6& A6, - const T7& A7, const T8& A8, const T9& A9, const T10& A10, const T11& A11, const T12& - A12, const T13& A13 -); - -// ---------------------------------------------------------------------------------------- - -template < - typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename - T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, - typename T14 - > -void call_matlab ( - const std::string& function_name, - const T1& A1, const T2& A2, const T3& A3, const T4& A4, const T5& A5, const T6& A6, - const T7& A7, const T8& A8, const T9& A9, const T10& A10, const T11& A11, const T12& - A12, const T13& A13, const T14& A14 -); - -// ---------------------------------------------------------------------------------------- - -template < - typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename - T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, - typename T14, typename T15 - > -void call_matlab ( - const std::string& function_name, - const T1& A1, const T2& A2, const T3& A3, const T4& A4, const T5& A5, const T6& A6, - const T7& A7, const T8& A8, const T9& A9, const T10& A10, const T11& A11, const T12& - A12, const T13& A13, const T14& A14, const T15& A15 -); - -// ---------------------------------------------------------------------------------------- - -template < - typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename - T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, - typename T14, typename T15, typename T16 - > -void call_matlab ( - const std::string& function_name, - const T1& A1, const T2& A2, const T3& A3, const T4& A4, const T5& A5, const T6& A6, - const T7& A7, const T8& A8, const T9& A9, const T10& A10, const T11& A11, const T12& - A12, const T13& A13, const T14& A14, const T15& A15, const T16& A16 -); - -// ---------------------------------------------------------------------------------------- - -template < - typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename - T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, - typename T14, typename T15, typename T16, typename T17 - > -void call_matlab ( - const std::string& function_name, - const T1& A1, const T2& A2, const T3& A3, const T4& A4, const T5& A5, const T6& A6, - const T7& A7, const T8& A8, const T9& A9, const T10& A10, const T11& A11, const T12& - A12, const T13& A13, const T14& A14, const T15& A15, const T16& A16, const T17& A17 -); - -// ---------------------------------------------------------------------------------------- - -template < - typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename - T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, - typename T14, typename T15, typename T16, typename T17, typename T18 - > -void call_matlab ( - const std::string& function_name, - const T1& A1, const T2& A2, const T3& A3, const T4& A4, const T5& A5, const T6& A6, - const T7& A7, const T8& A8, const T9& A9, const T10& A10, const T11& A11, const T12& - A12, const T13& A13, const T14& A14, const T15& A15, const T16& A16, const T17& A17, - const T18& A18 -); - -// ---------------------------------------------------------------------------------------- - -template < - typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename - T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, - typename T14, typename T15, typename T16, typename T17, typename T18, typename T19 - > -void call_matlab ( - const std::string& function_name, - const T1& A1, const T2& A2, const T3& A3, const T4& A4, const T5& A5, const T6& A6, - const T7& A7, const T8& A8, const T9& A9, const T10& A10, const T11& A11, const T12& - A12, const T13& A13, const T14& A14, const T15& A15, const T16& A16, const T17& A17, - const T18& A18, const T19& A19 -); - -// ---------------------------------------------------------------------------------------- - -template < - typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename - T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, - typename T14, typename T15, typename T16, typename T17, typename T18, typename T19, - typename T20 - > -void call_matlab ( - const std::string& function_name, - const T1& A1, const T2& A2, const T3& A3, const T4& A4, const T5& A5, const T6& A6, - const T7& A7, const T8& A8, const T9& A9, const T10& A10, const T11& A11, const T12& - A12, const T13& A13, const T14& A14, const T15& A15, const T16& A16, const T17& A17, - const T18& A18, const T19& A19, const T20& A20 -); - -// ---------------------------------------------------------------------------------------- -// ---------------------------------------------------------------------------------------- -// ---------------------------------------------------------------------------------------- -// ---------------------------------------------------------------------------------------- - -template < - typename T1, - typename T2 - > -void call_matlab ( - const function_handle& funct, - const T1& A1, - const T2& A2 -) -{ - call_matlab("feval", funct, A1, A2); -} - -template < - typename T1, - typename T2, - typename T3 - > -void call_matlab ( - const function_handle& funct, - const T1& A1, - const T2& A2, - const T3& A3 -) -{ - call_matlab("feval", funct, A1, A2, A3); -} - -template < - typename T1, - typename T2, - typename T3, - typename T4 - > -void call_matlab ( - const function_handle& funct, - const T1& A1, - const T2& A2, - const T3& A3, - const T4& A4 -) -{ - call_matlab("feval", funct, A1, A2, A3, A4); -} - -template < - typename T1, - typename T2, - typename T3, - typename T4, - typename T5 - > -void call_matlab ( - const function_handle& funct, - const T1& A1, - const T2& A2, - const T3& A3, - const T4& A4, - const T5& A5 -) -{ - call_matlab("feval", funct, A1, A2, A3, A4, A5); -} - -template < - typename T1, - typename T2, - typename T3, - typename T4, - typename T5, - typename T6 - > -void call_matlab ( - const function_handle& funct, - const T1& A1, - const T2& A2, - const T3& A3, - const T4& A4, - const T5& A5, - const T6& A6 -) -{ - call_matlab("feval", funct, A1, A2, A3, A4, A5, A6); -} - -template < - typename T1, - typename T2, - typename T3, - typename T4, - typename T5, - typename T6, - typename T7 - > -void call_matlab ( - const function_handle& funct, - const T1& A1, - const T2& A2, - const T3& A3, - const T4& A4, - const T5& A5, - const T6& A6, - const T7& A7 -) -{ - call_matlab("feval", funct, A1, A2, A3, A4, A5, A6, A7); -} - -template < - typename T1, - typename T2, - typename T3, - typename T4, - typename T5, - typename T6, - typename T7, - typename T8 - > -void call_matlab ( - const function_handle& funct, - const T1& A1, - const T2& A2, - const T3& A3, - const T4& A4, - const T5& A5, - const T6& A6, - const T7& A7, - const T8& A8 -) -{ - call_matlab("feval", funct, A1, A2, A3, A4, A5, A6, A7, A8); -} - -template < - typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename - T7, typename T8, typename T9 - > -void call_matlab ( - const function_handle& funct, - const T1& A1, const T2& A2, const T3& A3, const T4& A4, const T5& A5, const T6& A6, - const T7& A7, const T8& A8, const T9& A9 -) -{ - call_matlab("feval", funct, A1, A2, A3, A4, A5, A6, A7, A8, A9); -} - -template < - typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename - T7, typename T8, typename T9, typename T10 - > -void call_matlab ( - const function_handle& funct, - const T1& A1, const T2& A2, const T3& A3, const T4& A4, const T5& A5, const T6& A6, - const T7& A7, const T8& A8, const T9& A9, const T10& A10 -) -{ - call_matlab("feval", funct, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10); -} - -template < - typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename - T7, typename T8, typename T9, typename T10, typename T11 - > -void call_matlab ( - const function_handle& funct, - const T1& A1, const T2& A2, const T3& A3, const T4& A4, const T5& A5, const T6& A6, - const T7& A7, const T8& A8, const T9& A9, const T10& A10, const T11& A11 -) -{ - call_matlab("feval", funct, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11); -} - -template < - typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename - T7, typename T8, typename T9, typename T10, typename T11, typename T12 - > -void call_matlab ( - const function_handle& funct, - const T1& A1, const T2& A2, const T3& A3, const T4& A4, const T5& A5, const T6& A6, - const T7& A7, const T8& A8, const T9& A9, const T10& A10, const T11& A11, const T12& - A12 -) -{ - call_matlab("feval", funct, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12); -} - -template < - typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename - T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13 - > -void call_matlab ( - const function_handle& funct, - const T1& A1, const T2& A2, const T3& A3, const T4& A4, const T5& A5, const T6& A6, - const T7& A7, const T8& A8, const T9& A9, const T10& A10, const T11& A11, const T12& - A12, const T13& A13 -) -{ - call_matlab("feval", funct, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13); -} - -template < - typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename - T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, - typename T14 - > -void call_matlab ( - const function_handle& funct, - const T1& A1, const T2& A2, const T3& A3, const T4& A4, const T5& A5, const T6& A6, - const T7& A7, const T8& A8, const T9& A9, const T10& A10, const T11& A11, const T12& - A12, const T13& A13, const T14& A14 -) -{ - call_matlab("feval", funct, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14); -} - -template < - typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename - T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, - typename T14, typename T15 - > -void call_matlab ( - const function_handle& funct, - const T1& A1, const T2& A2, const T3& A3, const T4& A4, const T5& A5, const T6& A6, - const T7& A7, const T8& A8, const T9& A9, const T10& A10, const T11& A11, const T12& - A12, const T13& A13, const T14& A14, const T15& A15 -) -{ - call_matlab("feval", funct, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15); -} - -template < - typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename - T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, - typename T14, typename T15, typename T16 - > -void call_matlab ( - const function_handle& funct, - const T1& A1, const T2& A2, const T3& A3, const T4& A4, const T5& A5, const T6& A6, - const T7& A7, const T8& A8, const T9& A9, const T10& A10, const T11& A11, const T12& - A12, const T13& A13, const T14& A14, const T15& A15, const T16& A16 -) -{ - call_matlab("feval", funct, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16); -} - -template < - typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename - T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, - typename T14, typename T15, typename T16, typename T17 - > -void call_matlab ( - const function_handle& funct, - const T1& A1, const T2& A2, const T3& A3, const T4& A4, const T5& A5, const T6& A6, - const T7& A7, const T8& A8, const T9& A9, const T10& A10, const T11& A11, const T12& - A12, const T13& A13, const T14& A14, const T15& A15, const T16& A16, const T17& A17 -) -{ - call_matlab("feval", funct, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17); -} - -template < - typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename - T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, - typename T14, typename T15, typename T16, typename T17, typename T18 - > -void call_matlab ( - const function_handle& funct, - const T1& A1, const T2& A2, const T3& A3, const T4& A4, const T5& A5, const T6& A6, - const T7& A7, const T8& A8, const T9& A9, const T10& A10, const T11& A11, const T12& - A12, const T13& A13, const T14& A14, const T15& A15, const T16& A16, const T17& A17, - const T18& A18 -) -{ - call_matlab("feval", funct, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18); -} - -template < - typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename - T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, - typename T14, typename T15, typename T16, typename T17, typename T18, typename T19 - > -void call_matlab ( - const function_handle& funct, - const T1& A1, const T2& A2, const T3& A3, const T4& A4, const T5& A5, const T6& A6, - const T7& A7, const T8& A8, const T9& A9, const T10& A10, const T11& A11, const T12& - A12, const T13& A13, const T14& A14, const T15& A15, const T16& A16, const T17& A17, - const T18& A18, const T19& A19 -) -{ - call_matlab("feval", funct, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19); -} - -// ---------------------------------------------------------------------------------------- - -// We define this function here so that, if you write some code that has check_for_matlab_ctrl_c() -// sprinkled throughout it you can still compile that code outside the mex wrapper -// environment and these calls will simply be no-ops. -#ifndef MATLAB_MEX_FILE -inline void check_for_matlab_ctrl_c() {} -#endif - -} - -#endif // MIT_LL_CALL_MATLAB_H__ - diff --git a/ml/dlib/dlib/matlab/cmake_mex_wrapper b/ml/dlib/dlib/matlab/cmake_mex_wrapper deleted file mode 100644 index 67729ff70..000000000 --- a/ml/dlib/dlib/matlab/cmake_mex_wrapper +++ /dev/null @@ -1,103 +0,0 @@ -# This file figures out where MATLAB is and then defines a macro, add_mex_function(name) -# which when called instructs CMake to build a mex file from a file called name.cpp. Note -# that additional library dependencies can be added like this: add_mex_function(name lib1 dlib libetc). -# That is, just add more libraries after the name and they will be build into the mex file. - -cmake_minimum_required(VERSION 2.8.12) - -set(BUILDING_MATLAB_MEX_FILE true) -set(CMAKE_POSITION_INDEPENDENT_CODE True) - -# Trying to use cuda with matlab hasn't worked well, so just disable it. -SET(DLIB_USE_CUDA OFF CACHE BOOL "" FORCE) - -# Find MATLAB's include directory and needed libraries -find_program(MATLAB_EXECUTABLE matlab PATHS - "C:/Program Files/MATLAB/*/bin" - "C:/Program Files (x86)/MATLAB/*/bin" - ) -# Resolve symbolic links to try and get the real path to the MATLAB executable -get_filename_component(MATLAB_EXECUTABLE ${MATLAB_EXECUTABLE} REALPATH) -# Now get MATLAB root directory -get_filename_component(MATLAB_HOME ${MATLAB_EXECUTABLE} PATH) -get_filename_component(MATLAB_HOME ${MATLAB_HOME} PATH) -set(MATLAB_LIB_FOLDERS - "${MATLAB_HOME}/extern/lib/win64/microsoft" - "${MATLAB_HOME}/bin/glnxa64" - ) -# If there is a MATLAB_HOME environment variable then look there as well. -if (DEFINED ENV{MATLAB_HOME}) - set(MATLAB_LIB_FOLDERS - "$ENV{MATLAB_HOME}/extern/lib/win64/microsoft" - "$ENV{MATLAB_HOME}/bin/glnxa64" - ${MATLAB_LIB_FOLDERS} - ) -endif() -# Find the MATLAB libraries that need to get linked into the mex file -if (WIN32) - find_library(MATLAB_MEX_LIBRARY libmex PATHS ${MATLAB_LIB_FOLDERS} ) - find_library(MATLAB_MX_LIBRARY libmx PATHS ${MATLAB_LIB_FOLDERS} ) - find_library(MATLAB_ENG_LIBRARY libeng PATHS ${MATLAB_LIB_FOLDERS} ) -else() - find_library(MATLAB_MEX_LIBRARY mex PATHS ${MATLAB_LIB_FOLDERS} ) - find_library(MATLAB_MX_LIBRARY mx PATHS ${MATLAB_LIB_FOLDERS} ) - find_library(MATLAB_ENG_LIBRARY eng PATHS ${MATLAB_LIB_FOLDERS} ) -endif() -set(MATLAB_LIBRARIES ${MATLAB_MEX_LIBRARY} ${MATLAB_MX_LIBRARY} ${MATLAB_ENG_LIBRARY}) -# Figure out the path to MATLAB's mex.h so we can add it to the include search path. -find_path(mex_header_path mex.h - PATHS "$ENV{MATLAB_HOME}/extern/include" - "${MATLAB_HOME}/extern/include" - ) -INCLUDE_DIRECTORIES(${mex_header_path}) - -# Determine the path to cmake_mex_wrapper file so we can add it to the include search path.. -string(REGEX REPLACE "cmake_mex_wrapper$" "" dlib_matlab_binding_path ${CMAKE_CURRENT_LIST_FILE}) -INCLUDE_DIRECTORIES("${dlib_matlab_binding_path}") -# Also add dlib to the include search path -INCLUDE_DIRECTORIES(${dlib_matlab_binding_path}/../..) - -add_definitions(-DMATLAB_MEX_FILE) - -# Determine the path to our CMakeLists.txt file. This is the file that -# includeded the one you are reading right now. So here we make it so that -# when you run the install target it will copy the compiled mex files into the -# same folder as the parent CMakeLists.txt file. -string(REGEX REPLACE "CMakeLists.txt$" "" install_dir ${CMAKE_PARENT_LIST_FILE}) -set(CMAKE_INSTALL_PREFIX "${install_dir}") -set(CMAKE_INSTALL_SYSTEM_RUNTIME_DESTINATION "${install_dir}") -INCLUDE(InstallRequiredSystemLibraries) - - -MACRO(add_mex_function name ) - ADD_LIBRARY(${name} MODULE ${name}.cpp ) - target_compile_definitions(${name} PRIVATE -DMEX_FILENAME=${name}) - if (UNIX) - # Doing this prevents our mex function from exporting any symbols - # other than mexFunction(). This sometimes doesn't matter but sometimes - # avoids causing errors or otherwise bad behavior in MATLAB. - if (DEFINED ENV{MATLAB_HOME}) - set_target_properties(${name} PROPERTIES LINK_FLAGS "-Wl,--version-script,$ENV{MATLAB_HOME}/extern/lib/glnxa64/mexFunction.map") - else() - set_target_properties(${name} PROPERTIES LINK_FLAGS "-Wl,--version-script,${MATLAB_HOME}/extern/lib/glnxa64/mexFunction.map") - endif() - endif() - - # Change the output file extension to a mex extension. - if (WIN32) - set_target_properties(${name} PROPERTIES SUFFIX ".mexw64") - elseif(APPLE) - set_target_properties(${name} PROPERTIES SUFFIX ".mexmaci64") - else() - set_target_properties(${name} PROPERTIES SUFFIX ".mexa64") - endif() - set_target_properties(${name} PROPERTIES PREFIX "") - TARGET_LINK_LIBRARIES(${name} ${MATLAB_LIBRARIES} ${ARGN}) - if (install_target_output_folder) - install(TARGETS ${name} DESTINATION "${install_target_output_folder}") - else() - install(TARGETS ${name} DESTINATION "${install_dir}") - endif() -ENDMACRO() - - diff --git a/ml/dlib/dlib/matlab/example.m b/ml/dlib/dlib/matlab/example.m deleted file mode 100644 index 8ed47346b..000000000 --- a/ml/dlib/dlib/matlab/example.m +++ /dev/null @@ -1,16 +0,0 @@ -% This example calls the three mex functions defined in this folder. As you -% can see, you call them just like you would normal MATLAB functions. - -x = magic(3) -y = 2*magic(3) - -[out1, out2] = example_mex_function(x,y, 12345) - -z = example_mex_callback(x, @(a)a+a) - - -input = {} -input.val = 2 -input.stuff = 'some string' -output = example_mex_struct(input) - diff --git a/ml/dlib/dlib/matlab/example_mex_callback.cpp b/ml/dlib/dlib/matlab/example_mex_callback.cpp deleted file mode 100644 index a5a25dda1..000000000 --- a/ml/dlib/dlib/matlab/example_mex_callback.cpp +++ /dev/null @@ -1,52 +0,0 @@ -// The contents of this file are in the public domain. See LICENSE_FOR_EXAMPLE_PROGRAMS.txt - -#include "call_matlab.h" -#include "dlib/matrix.h" - -using namespace dlib; -using namespace std; - -/* - This mex function takes a MATLAB function handle, calls it, and - returns the results. - - For example, you can call this function in MATLAB like so: - A = magic(3) - y = example_mex_callback(A, @(x)x+x) - - This will result in y containing the value 2*A. -*/ - -void mex_function ( - const matrix<double>& A, - const function_handle& f, - matrix<double>& result -) -{ - // The f argument to this function is a function handle passed from MATLAB. To - // call it we use the following syntax: - call_matlab(f, A, returns(result)); - // This is equivalent to result = f(A). Therefore, the returns(variable) syntax - // is used to indicate which variables are outputs of the function. - - - - - // Another thing we can do is call MATLAB functions based on their string name - // rather than a function_handle. Here is an example of calling eigs(). - matrix<double> m(2,2); - m = 1,2, - 3,4; - matrix<double> v,d; - - // This is equivalent to [v,d] = eigs(m); - call_matlab("eigs", m, returns(v), returns(d)); - cout << "eigenvectors: \n" << v << endl; - cout << "eigenvalues: \n" << d << endl; -} - - - -// #including this brings in all the mex boiler plate needed by MATLAB. -#include "mex_wrapper.cpp" - diff --git a/ml/dlib/dlib/matlab/example_mex_class.cpp b/ml/dlib/dlib/matlab/example_mex_class.cpp deleted file mode 100644 index b4242721b..000000000 --- a/ml/dlib/dlib/matlab/example_mex_class.cpp +++ /dev/null @@ -1,72 +0,0 @@ -// The contents of this file are in the public domain. See LICENSE_FOR_EXAMPLE_PROGRAMS.txt -/* - This mex file will create a MATLAB function called example_mex_class. If you call it - with no arguments it will output the MATLAB .m code to create a MATLAB wrapper class. - Paste that code into a .m file. Then you will be able to work with this C++ class - directly in MATLAB. -*/ - -#include <iostream> -#include <dlib/matrix.h> - - -using namespace std; -using namespace dlib; - -class example_class -{ -public: - - // The class must have a default constructor. It's also the only kind of constructor - // you can call from MATLAB. - example_class() - { - xx.set_size(3,2); - xx = 1; - } - - // The rest of the member functions that you want to bind have to return void and - // generally have the same syntax limitations as regular mex funcitons. - void do_stuff(const matrix_colmajor& x) - { - cout << "in do_stuff" << endl; - cout << x << endl; - xx = x; - } - - void do_other_stuff(int x) - { - cout << "in do_other_stuff" << endl; - cout << "x: " << x << endl; - } - - void print_state() - { - cout << xx << endl; - } - - // saveobj() and load_obj() are special functions. If you provide these then you will - // be able to save() and load() your objects using MATLAB's built in object - // serialization. - void saveobj(matrix_colmajor& state) - { - // save this object's state to state. - state = xx; - } - void load_obj(const matrix_colmajor& state) - { - xx = state; - } - -private: - matrix_colmajor xx; -}; - -// Just tell the mex wrapper the name of your class and list the methods you want to bind. -#define MEX_CLASS_NAME example_class -#define MEX_CLASS_METHODS do_stuff, do_other_stuff, print_state, saveobj, load_obj - - -#include "mex_wrapper.cpp" - - diff --git a/ml/dlib/dlib/matlab/example_mex_function.cpp b/ml/dlib/dlib/matlab/example_mex_function.cpp deleted file mode 100644 index 49d2e35fa..000000000 --- a/ml/dlib/dlib/matlab/example_mex_function.cpp +++ /dev/null @@ -1,84 +0,0 @@ -// The contents of this file are in the public domain. See LICENSE_FOR_EXAMPLE_PROGRAMS.txt - -#include "dlib/matrix.h" -using namespace dlib; -using namespace std; - - -/*! - This file defines a function callable from MATLAB once you mex it. - - It computes the same thing as the following MATLAB function: - - function [A, B] = example_mex_function(x, y, some_number) - A = x+y; - B = sum(sum(x+y)); - disp(['some_number: ' num2str(some_number)]) - end - - - VALID INPUT AND OUTPUT ARGUMENTS - The mex wrapper can handle the following kinds of input and output arguments: - - Types corresponding to a MATLAB matrix - - a dlib::matrix containing any kind of scalar value. - - a dlib::array2d containing any kind of scalar value. - - a dlib::vector containing any kind of scalar value. - - a dlib::point - - matrix_colmajor or fmatrix_colmajor - These are just typedefs for matrix containing double or float and using a - column major memory layout. However, they have the special distinction - of being fast to use in mex files since they sit directly on top of - MATLAB's built in matrices. That is, while other types of arguments copy - a MATLAB object into themselves, the matrix_colmajor and fmatrix_colmajor - do no such copy and are effectively zero overhead methods for working on - MATLAB's matrices. - - - RGB color images - - dlib::array2d<dlib::rgb_pixel> can be used to represent - MATLAB uint8 MxNx3 images. - - - Types corresponding to a MATLAB scalar - - any kind of scalar value, e.g. double, int, etc. - - - Types corresponding to a MATLAB string - - std::string - - - Types corresponding to a MATLAB cell array - - a std::vector or dlib::array containing any of the above - types of objects or std::vector or dlib::array objects. - - - matlab_struct and matlab_object. These are special types defined in the - call_matlab.h file and correspond to matlab structs and arbitrary matlab - objects respectively. -!*/ - - -// You can also define default values for your input arguments. So -// here we say that if the user in MATLAB doesn't provide the "some_number" -// then it will get a value of 3.141. -#define ARG_5_DEFAULT 3.141 - -// Make a function named mex_function() and put your code inside it. -// Note that the return type should be void. Use non-const reference -// arguments to return outputs. Finally, mex_function() must have no -// more than 20 arguments. -void mex_function ( - const matrix_colmajor& x, - const matrix_colmajor& y, - matrix_colmajor& out1, - double& out2, - double some_number -) -{ - out1 = x + y; - out2 = sum(x+y); - - // we can also use cout to print things as usual: - cout << "some_number: "<< some_number << endl; -} - - - -// #including this brings in all the mex boiler plate needed by MATLAB. -#include "mex_wrapper.cpp" - diff --git a/ml/dlib/dlib/matlab/example_mex_struct.cpp b/ml/dlib/dlib/matlab/example_mex_struct.cpp deleted file mode 100644 index a948fbff9..000000000 --- a/ml/dlib/dlib/matlab/example_mex_struct.cpp +++ /dev/null @@ -1,55 +0,0 @@ -// The contents of this file are in the public domain. See LICENSE_FOR_EXAMPLE_PROGRAMS.txt - -#include "call_matlab.h" -#include "dlib/matrix.h" -using namespace dlib; -using namespace std; - - -/* - This mex function takes a MATLAB struct, prints a few of its fields, - and then returns a new struct. - - For example, you can call this function in MATLAB like so: - input = {} - input.val = 2 - input.stuff = 'some string' - output = example_mex_struct(input) - - output.number - output.number2 - output.sub.stuff - output.sub.some_matrix -*/ - - -void mex_function ( - const matlab_struct& input, - matlab_struct& output -) -{ - int val = input["val"]; - string stuff = input["stuff"]; - - if (input.has_field("val2")) - { - string val2 = input["val2"]; - cout << "The optional val2 field was set to: " << val2 << endl; - } - - cout << "val: "<< val << endl; - cout << "stuff: " << stuff << endl; - - output["number"] = 999; - - output["number2"] = 1000; - output["sub"]["stuff"] = "some other string"; - matrix<double> m = randm(2,2); - output["sub"]["some_matrix"] = m; -} - - - -// #including this brings in all the mex boiler plate needed by MATLAB. -#include "mex_wrapper.cpp" - diff --git a/ml/dlib/dlib/matlab/mex_wrapper.cpp b/ml/dlib/dlib/matlab/mex_wrapper.cpp deleted file mode 100644 index 30c7e12ac..000000000 --- a/ml/dlib/dlib/matlab/mex_wrapper.cpp +++ /dev/null @@ -1,5144 +0,0 @@ -// Copyright (C) 2012 Massachusetts Institute of Technology, Lincoln Laboratory -// License: Boost Software License See LICENSE.txt for the full license. -// Authors: Davis E. King (davis@dlib.net) -/* - READ THIS FIRST - ###### - ###### - ###### - ###### - ###### - ###### - ###### - ###### - ###### - ###### - ###### - ###### - ###### - \############/ - \##########/ - \########/ - \######/ - \####/ - \##/ - \/ - - !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - - See example_mex_function.cpp for a discussion of how to use the mex wrapper. - - !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - - /\ - /##\ - /####\ - /######\ - /########\ - /##########\ - /############\ - ###### - ###### - ###### - ###### - ###### - ###### - ###### - ###### - ###### - ###### - ###### - ###### - ###### - READ THIS FIRST -*/ - -// Copyright (C) 2012 Massachusetts Institute of Technology, Lincoln Laboratory -// License: Boost Software License See LICENSE.txt for the full license. -// Authors: Davis E. King (davis@dlib.net) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// ---------------------------------------------------------------------------------------- -// ---------------------------------------------------------------------------------------- -// BEGIN IMPLEMENTATION DETAILS -// ---------------------------------------------------------------------------------------- -// ---------------------------------------------------------------------------------------- - -#include "../matrix.h" -#include "../array2d.h" -#include "../array.h" -#include "../image_transforms.h" -#include "../is_kind.h" -#include "../string.h" -#include "../any.h" // for sig_traits -#include "../hash.h" -#include <tuple> -#include <map> - -#if defined(_MSC_VER) -#define DLL_EXPORT_SYM __declspec(dllexport) -#endif -#include "mex.h" -#include <sstream> -#include "call_matlab.h" - -// ---------------------------------------------------------------------------------------- - -#ifdef ARG_1_DEFAULT -#define ELSE_ASSIGN_ARG_1 else A1 = ARG_1_DEFAULT; -#else -#define ELSE_ASSIGN_ARG_1 -#endif - -#ifdef ARG_2_DEFAULT -#define ELSE_ASSIGN_ARG_2 else A2 = ARG_2_DEFAULT; -#else -#define ELSE_ASSIGN_ARG_2 -#endif - -#ifdef ARG_3_DEFAULT -#define ELSE_ASSIGN_ARG_3 else A3 = ARG_3_DEFAULT; -#else -#define ELSE_ASSIGN_ARG_3 -#endif - -#ifdef ARG_4_DEFAULT -#define ELSE_ASSIGN_ARG_4 else A4 = ARG_4_DEFAULT; -#else -#define ELSE_ASSIGN_ARG_4 -#endif - -#ifdef ARG_5_DEFAULT -#define ELSE_ASSIGN_ARG_5 else A5 = ARG_5_DEFAULT; -#else -#define ELSE_ASSIGN_ARG_5 -#endif - -#ifdef ARG_6_DEFAULT -#define ELSE_ASSIGN_ARG_6 else A6 = ARG_6_DEFAULT; -#else -#define ELSE_ASSIGN_ARG_6 -#endif - -#ifdef ARG_7_DEFAULT -#define ELSE_ASSIGN_ARG_7 else A7 = ARG_7_DEFAULT; -#else -#define ELSE_ASSIGN_ARG_7 -#endif - -#ifdef ARG_8_DEFAULT -#define ELSE_ASSIGN_ARG_8 else A8 = ARG_8_DEFAULT; -#else -#define ELSE_ASSIGN_ARG_8 -#endif - -#ifdef ARG_9_DEFAULT -#define ELSE_ASSIGN_ARG_9 else A9 = ARG_9_DEFAULT; -#else -#define ELSE_ASSIGN_ARG_9 -#endif - -#ifdef ARG_10_DEFAULT -#define ELSE_ASSIGN_ARG_10 else A10 = ARG_10_DEFAULT; -#else -#define ELSE_ASSIGN_ARG_10 -#endif - -#ifdef ARG_11_DEFAULT -#define ELSE_ASSIGN_ARG_11 else A11 = ARG_11_DEFAULT; -#else -#define ELSE_ASSIGN_ARG_11 -#endif - -#ifdef ARG_12_DEFAULT -#define ELSE_ASSIGN_ARG_12 else A12 = ARG_12_DEFAULT; -#else -#define ELSE_ASSIGN_ARG_12 -#endif - -#ifdef ARG_13_DEFAULT -#define ELSE_ASSIGN_ARG_13 else A13 = ARG_13_DEFAULT; -#else -#define ELSE_ASSIGN_ARG_13 -#endif - -#ifdef ARG_14_DEFAULT -#define ELSE_ASSIGN_ARG_14 else A14 = ARG_14_DEFAULT; -#else -#define ELSE_ASSIGN_ARG_14 -#endif - -#ifdef ARG_15_DEFAULT -#define ELSE_ASSIGN_ARG_15 else A15 = ARG_15_DEFAULT; -#else -#define ELSE_ASSIGN_ARG_15 -#endif - -#ifdef ARG_16_DEFAULT -#define ELSE_ASSIGN_ARG_16 else A16 = ARG_16_DEFAULT; -#else -#define ELSE_ASSIGN_ARG_16 -#endif - -#ifdef ARG_17_DEFAULT -#define ELSE_ASSIGN_ARG_17 else A17 = ARG_17_DEFAULT; -#else -#define ELSE_ASSIGN_ARG_17 -#endif - -#ifdef ARG_18_DEFAULT -#define ELSE_ASSIGN_ARG_18 else A18 = ARG_18_DEFAULT; -#else -#define ELSE_ASSIGN_ARG_18 -#endif - -#ifdef ARG_19_DEFAULT -#define ELSE_ASSIGN_ARG_19 else A19 = ARG_19_DEFAULT; -#else -#define ELSE_ASSIGN_ARG_19 -#endif - -#ifdef ARG_20_DEFAULT -#define ELSE_ASSIGN_ARG_20 else A20 = ARG_20_DEFAULT; -#else -#define ELSE_ASSIGN_ARG_20 -#endif - -// ---------------------------------------------------------------------------------------- - -namespace mex_binding -{ - using namespace dlib; - - template <typename T> - struct is_input_type - { - const static unsigned long value = (!is_same_type<void,T>::value && (!is_reference_type<T>::value || is_const_type<T>::value )) ? 1 : 0; - }; - template <typename T> - struct is_output_type - { - const static unsigned long value = (!is_same_type<void,T>::value && is_reference_type<T>::value && !is_const_type<T>::value) ? 1 : 0; - }; - - - template <typename funct> - struct funct_traits - { - const static unsigned long num_inputs = is_input_type<typename sig_traits<funct>::arg1_type>::value + - is_input_type<typename sig_traits<funct>::arg2_type>::value + - is_input_type<typename sig_traits<funct>::arg3_type>::value + - is_input_type<typename sig_traits<funct>::arg4_type>::value + - is_input_type<typename sig_traits<funct>::arg5_type>::value + - is_input_type<typename sig_traits<funct>::arg6_type>::value + - is_input_type<typename sig_traits<funct>::arg7_type>::value + - is_input_type<typename sig_traits<funct>::arg8_type>::value + - is_input_type<typename sig_traits<funct>::arg9_type>::value + - is_input_type<typename sig_traits<funct>::arg10_type>::value + - is_input_type<typename sig_traits<funct>::arg11_type>::value + - is_input_type<typename sig_traits<funct>::arg12_type>::value + - is_input_type<typename sig_traits<funct>::arg13_type>::value + - is_input_type<typename sig_traits<funct>::arg14_type>::value + - is_input_type<typename sig_traits<funct>::arg15_type>::value + - is_input_type<typename sig_traits<funct>::arg16_type>::value + - is_input_type<typename sig_traits<funct>::arg17_type>::value + - is_input_type<typename sig_traits<funct>::arg18_type>::value + - is_input_type<typename sig_traits<funct>::arg19_type>::value + - is_input_type<typename sig_traits<funct>::arg20_type>::value; - - const static unsigned long num_outputs= is_output_type<typename sig_traits<funct>::arg1_type>::value + - is_output_type<typename sig_traits<funct>::arg2_type>::value + - is_output_type<typename sig_traits<funct>::arg3_type>::value + - is_output_type<typename sig_traits<funct>::arg4_type>::value + - is_output_type<typename sig_traits<funct>::arg5_type>::value + - is_output_type<typename sig_traits<funct>::arg6_type>::value + - is_output_type<typename sig_traits<funct>::arg7_type>::value + - is_output_type<typename sig_traits<funct>::arg8_type>::value + - is_output_type<typename sig_traits<funct>::arg9_type>::value + - is_output_type<typename sig_traits<funct>::arg10_type>::value + - is_output_type<typename sig_traits<funct>::arg11_type>::value + - is_output_type<typename sig_traits<funct>::arg12_type>::value + - is_output_type<typename sig_traits<funct>::arg13_type>::value + - is_output_type<typename sig_traits<funct>::arg14_type>::value + - is_output_type<typename sig_traits<funct>::arg15_type>::value + - is_output_type<typename sig_traits<funct>::arg16_type>::value + - is_output_type<typename sig_traits<funct>::arg17_type>::value + - is_output_type<typename sig_traits<funct>::arg18_type>::value + - is_output_type<typename sig_traits<funct>::arg19_type>::value + - is_output_type<typename sig_traits<funct>::arg20_type>::value; - }; - -// ---------------------------------------------------------------------------------------- - - template <typename T> - struct is_array_type - { - // true if T is std::vector or dlib::array - const static bool value = is_std_vector<T>::value || dlib::is_array<T>::value; - - }; - -// ---------------------------------------------------------------------------------------- - - template < - typename T, - typename enabled = void - > - struct inner_type - { - typedef T type; - }; - - template < typename T> - struct inner_type<T, typename dlib::enable_if_c<is_matrix<T>::value || is_array2d<T>::value || dlib::is_array<T>::value >::type> - { - typedef typename T::type type; - }; - - template < typename T> - struct inner_type<T, typename dlib::enable_if<is_std_vector<T> >::type> - { - typedef typename T::value_type type; - }; - - -// ------------------------------------------------------- - - struct user_hit_ctrl_c {}; - -// ------------------------------------------------------- - - template <typename T> - void validate_and_populate_arg ( - long arg_idx, - const mxArray *prhs, - T& arg - ); - -// ------------------------------------------------------- - - template <typename T> - struct is_column_major_matrix : public default_is_kind_value {}; - - template < - typename T, - long num_rows, - long num_cols, - typename mem_manager - > - struct is_column_major_matrix<matrix<T,num_rows,num_cols,mem_manager,column_major_layout> > - { static const bool value = true; }; - -// ------------------------------------------------------- - - string escape_percent(const string& str) - { - string temp; - for(auto c : str) - { - if (c != '%') - { - temp += c; - } - else - { - temp += c; - temp += c; - } - } - return temp; - } - - string escape_percent(const std::ostringstream& sout) - { - return escape_percent(sout.str()); - } - -// ------------------------------------------------------- - - template < - typename matrix_type - > - typename dlib::enable_if_c<is_matrix<matrix_type>::value || is_array2d<matrix_type>::value >::type - clear_mat ( - matrix_type& m - ) - { - m.set_size(0,0); - } - - template < - typename matrix_type - > - typename dlib::disable_if_c<is_matrix<matrix_type>::value || is_array2d<matrix_type>::value >::type - clear_mat ( - matrix_type& - ) - { - } - -// ------------------------------------------------------- - - template < - typename matrix_type, - typename EXP - > - typename dlib::enable_if_c<is_matrix<matrix_type>::value && is_same_type<typename inner_type<matrix_type>::type,typename EXP::type>::value >::type - assign_mat ( - const long arg_idx, - matrix_type& m, - const matrix_exp<EXP>& src - ) - { - if (matrix_type::NR != 0 && matrix_type::NR != src.nc()) - { - std::ostringstream sout; - sout << "Argument " << arg_idx+1 << " expects a matrix with " << matrix_type::NR << " rows but got one with " << src.nc(); - throw invalid_args_exception(sout); - } - if (matrix_type::NC != 0 && matrix_type::NC != src.nr()) - { - std::ostringstream sout; - sout << "Argument " << arg_idx+1 << " expects a matrix with " << matrix_type::NC << " columns but got one with " << src.nr(); - throw invalid_args_exception(sout); - } - - - m = trans(src); - } - - template < - typename matrix_type, - typename EXP - > - typename dlib::enable_if_c<is_array2d<matrix_type>::value && is_same_type<typename inner_type<matrix_type>::type,typename EXP::type>::value >::type - assign_mat ( - const long arg_idx, - matrix_type& m, - const matrix_exp<EXP>& src - ) - { - assign_image(m , trans(src)); - } - - template < - typename matrix_type, - typename EXP - > - typename disable_if_c<(is_array2d<matrix_type>::value || is_matrix<matrix_type>::value) && - is_same_type<typename inner_type<matrix_type>::type,typename EXP::type>::value >::type - assign_mat ( - const long arg_idx, - matrix_type& , - const matrix_exp<EXP>& - ) - { - std::ostringstream sout; - sout << "mex_function has some bug in it related to processing input argument " << arg_idx+1; - throw invalid_args_exception(sout); - } - - -// ------------------------------------------------------- - - template < - typename T, - typename U - > - typename dlib::enable_if_c<is_built_in_scalar_type<T>::value || is_same_type<T,bool>::value >::type - assign_scalar ( - const long arg_idx, - T& dest, - const U& src - ) - { - if (is_signed_type<U>::value && src < 0 && is_unsigned_type<T>::value) - { - std::ostringstream sout; - sout << "Error, input argument " << arg_idx+1 << " must be a non-negative number."; - throw invalid_args_exception(sout); - } - else - { - dest = src; - } - } - - template < - typename T, - typename U - > - typename dlib::disable_if_c<is_built_in_scalar_type<T>::value || is_same_type<T,bool>::value >::type - assign_scalar ( - const long arg_idx, - T& , - const U& - ) - { - std::ostringstream sout; - sout << "mex_function has some bug in it related to processing input argument " << arg_idx+1; - throw invalid_args_exception(sout); - } - - -// ------------------------------------------------------- - - void assign_function_handle ( - const long arg_idx, - function_handle& dest, - const mxArray* src - ) - { - const_cast<void*&>(dest.h) = (void*)src; - } - - template < - typename T - > - void assign_function_handle ( - const long arg_idx, - T& , - const mxArray* - ) - { - std::ostringstream sout; - sout << "mex_function has some bug in it related to processing input argument " << arg_idx+1; - throw invalid_args_exception(sout); - } - - -// ------------------------------------------------------- - - template < - typename T - > - typename dlib::enable_if<is_array_type<T> >::type - assign_std_vector ( - const long arg_idx, - T& dest, - const mxArray* src - ) - { - const long nr = mxGetM(src); - const long nc = mxGetN(src); - - typedef typename inner_type<T>::type type; - - if (!mxIsCell(src)) - { - std::ostringstream sout; - sout << "Input argument " << arg_idx+1 << " must be a cell array"; - throw invalid_args_exception(sout); - } - if (nr != 1 && nc != 1) - { - std::ostringstream sout; - sout << "Input argument " << arg_idx+1 << " must be a cell array with exactly 1 row or 1 column (i.e. a row or column vector)"; - throw invalid_args_exception(sout); - } - - const long size = nr*nc; - dest.resize(size); - - for (unsigned long i = 0; i < dest.size(); ++i) - { - try - { - validate_and_populate_arg(i, mxGetCell(src, i), dest[i]); - } - catch (invalid_args_exception& e) - { - std::ostringstream sout; - sout << "Error in argument " << arg_idx+1 << ": element " << i+1 << " of cell array not the expected type.\n"; - sout << "\t" << e.what(); - throw invalid_args_exception(sout); - } - } - - } - - template < - typename T - > - typename disable_if<is_array_type<T> >::type - assign_std_vector ( - const long arg_idx, - T& , - const mxArray* - ) - { - std::ostringstream sout; - sout << "mex_function has some bug in it related to processing input argument " << arg_idx+1; - throw invalid_args_exception(sout); - } - -// ------------------------------------------------------- - - template <typename T> - void assign_image ( - const long arg_idx, - T&, - const dlib::uint8* data, - long nr, - long nc - ) - { - std::ostringstream sout; - sout << "mex_function has some bug in it related to processing input argument " << arg_idx+1; - throw invalid_args_exception(sout); - } - - template <typename MM> - void assign_image( - const long , - array2d<dlib::rgb_pixel,MM>& img, - const dlib::uint8* data, - long nr, - long nc - ) - { - img.set_size(nr, nc); - for (long c = 0; c < img.nc(); ++c) - for (long r = 0; r < img.nr(); ++r) - img[r][c].red = *data++; - for (long c = 0; c < img.nc(); ++c) - for (long r = 0; r < img.nr(); ++r) - img[r][c].green = *data++; - for (long c = 0; c < img.nc(); ++c) - for (long r = 0; r < img.nr(); ++r) - img[r][c].blue = *data++; - } - -// ------------------------------------------------------- - - template <typename T> - void call_private_set_mxArray(T&, mxArray*) {} - void call_private_set_mxArray(matrix_colmajor& item, mxArray* m) { item._private_set_mxArray(m); } - void call_private_set_mxArray(fmatrix_colmajor& item, mxArray* m) { item._private_set_mxArray(m); } - -// ------------------------------------------------------- - - template <typename T> - void validate_and_populate_arg ( - long arg_idx, - const mxArray *prhs, - T& arg - ) - { - using namespace mex_binding; - if (is_built_in_scalar_type<T>::value || is_same_type<T,bool>::value) - { - if( !(mxIsDouble(prhs) || mxIsSingle(prhs) || mxIsLogical(prhs) ) || - mxIsComplex(prhs) || - mxGetNumberOfElements(prhs)!=1 ) - { - std::ostringstream sout; - sout << "Input argument " << arg_idx+1 << " must be a scalar"; - throw invalid_args_exception(sout); - } - - assign_scalar(arg_idx, arg , mxGetScalar(prhs)); - } - else if (is_matrix<T>::value || is_array2d<T>::value) - { - if (prhs == NULL) - { - clear_mat(arg); - return; - } - - typedef typename inner_type<T>::type type; - - const int num_dims = mxGetNumberOfDimensions(prhs); - const long nr = mxGetM(prhs); - const long nc = mxGetN(prhs); - - if (is_same_type<type,dlib::rgb_pixel>::value) - { - if (!(num_dims == 3 && mxGetDimensions(prhs)[2] == 3 && mxIsUint8(prhs))) - { - std::ostringstream sout; - sout << "Input argument " << arg_idx+1 << " must be a 3-D NxMx3 image matrix of uint8"; - throw invalid_args_exception(sout); - } - - const long rows = mxGetDimensions(prhs)[0]; - const long cols = mxGetDimensions(prhs)[1]; - assign_image(arg_idx, arg , (const dlib::uint8*)mxGetData(prhs), rows, cols); - return; - } - - if (num_dims != 2) - { - std::ostringstream sout; - sout << "Input argument " << arg_idx+1 << " must be a 2-D matrix (got a " << num_dims << "-D matrix)"; - throw invalid_args_exception(sout); - } - - - if (is_same_type<type,double>::value) - { - if (!mxIsDouble(prhs) || mxIsComplex(prhs)) - { - std::ostringstream sout; - sout << "Input argument " << arg_idx+1 << " must be a matrix of doubles"; - throw invalid_args_exception(sout); - } - if (is_column_major_matrix<T>::value) - call_private_set_mxArray(arg, (mxArray*)prhs); - else - assign_mat(arg_idx, arg , pointer_to_matrix(mxGetPr(prhs), nc, nr)); - } - else if (is_same_type<type, float>::value) - { - if (!mxIsSingle(prhs) || mxIsComplex(prhs)) - { - std::ostringstream sout; - sout << "Input argument " << arg_idx+1 << " must be a matrix of single/float"; - throw invalid_args_exception(sout); - } - - if (is_column_major_matrix<T>::value) - call_private_set_mxArray(arg,(mxArray*)prhs); - else - assign_mat(arg_idx, arg , pointer_to_matrix((const float*)mxGetData(prhs), nc, nr)); - } - else if (is_same_type<type, bool>::value) - { - if (!mxIsLogical(prhs)) - { - std::ostringstream sout; - sout << "Input argument " << arg_idx+1 << " must be a matrix of logical elements."; - throw invalid_args_exception(sout); - } - DLIB_CASSERT(sizeof(mxLogical) == sizeof(bool),"logical matrices are not supported by the mex wrapper when mxLogical isn't a bool."); - - assign_mat(arg_idx, arg , pointer_to_matrix((const bool*)mxGetData(prhs), nc, nr)); - } - else if (is_same_type<type, dlib::uint8>::value) - { - if (!mxIsUint8(prhs) || mxIsComplex(prhs)) - { - std::ostringstream sout; - sout << "Input argument " << arg_idx+1 << " must be a matrix of uint8"; - throw invalid_args_exception(sout); - } - - assign_mat(arg_idx, arg , pointer_to_matrix((const dlib::uint8*)mxGetData(prhs), nc, nr)); - } - else if (is_same_type<type, dlib::int8>::value) - { - if (!mxIsInt8(prhs) || mxIsComplex(prhs)) - { - std::ostringstream sout; - sout << "Input argument " << arg_idx+1 << " must be a matrix of int8"; - throw invalid_args_exception(sout); - } - - assign_mat(arg_idx, arg , pointer_to_matrix((const dlib::int8*)mxGetData(prhs), nc, nr)); - } - else if (is_same_type<type, dlib::int16>::value || - (is_same_type<type, short>::value && sizeof(short) == sizeof(dlib::int16))) - { - if (!mxIsInt16(prhs) || mxIsComplex(prhs)) - { - std::ostringstream sout; - sout << "Input argument " << arg_idx+1 << " must be a matrix of int16"; - throw invalid_args_exception(sout); - } - - assign_mat(arg_idx, arg , pointer_to_matrix((const type*)mxGetData(prhs), nc, nr)); - } - else if (is_same_type<type, dlib::uint16>::value || - (is_same_type<type, unsigned short>::value && sizeof(unsigned short) == sizeof(dlib::uint16))) - { - if (!mxIsUint16(prhs) || mxIsComplex(prhs)) - { - std::ostringstream sout; - sout << "Input argument " << arg_idx+1 << " must be a matrix of uint16"; - throw invalid_args_exception(sout); - } - - assign_mat(arg_idx, arg , pointer_to_matrix((const type*)mxGetData(prhs), nc, nr)); - } - else if (is_same_type<type, dlib::int32>::value || - (is_same_type<type, int>::value && sizeof(int) == sizeof(dlib::int32)) || - (is_same_type<type, long>::value && sizeof(long) == sizeof(dlib::int32))) - { - if (!mxIsInt32(prhs) || mxIsComplex(prhs)) - { - std::ostringstream sout; - sout << "Input argument " << arg_idx+1 << " must be a matrix of int32"; - throw invalid_args_exception(sout); - } - - assign_mat(arg_idx, arg , pointer_to_matrix((const type*)mxGetData(prhs), nc, nr)); - } - else if (is_same_type<type, dlib::uint32>::value || - (is_same_type<type, unsigned int>::value && sizeof(unsigned int) == sizeof(dlib::uint32)) || - (is_same_type<type, unsigned long>::value && sizeof(unsigned long) == sizeof(dlib::uint32))) - { - if (!mxIsUint32(prhs) || mxIsComplex(prhs)) - { - std::ostringstream sout; - sout << "Input argument " << arg_idx+1 << " must be a matrix of uint32"; - throw invalid_args_exception(sout); - } - - assign_mat(arg_idx, arg , pointer_to_matrix((const type*)mxGetData(prhs), nc, nr)); - } - else if (is_same_type<type, dlib::uint64>::value || - (is_same_type<type, unsigned int>::value && sizeof(unsigned int) == sizeof(dlib::uint64)) || - (is_same_type<type, unsigned long>::value && sizeof(unsigned long) == sizeof(dlib::uint64))) - { - if (!mxIsUint64(prhs) || mxIsComplex(prhs)) - { - std::ostringstream sout; - sout << "Input argument " << arg_idx+1 << " must be a matrix of uint64"; - throw invalid_args_exception(sout); - } - - assign_mat(arg_idx, arg , pointer_to_matrix((const type*)mxGetData(prhs), nc, nr)); - } - else if (is_same_type<type, dlib::int64>::value || - (is_same_type<type, int>::value && sizeof(int) == sizeof(dlib::int64)) || - (is_same_type<type, long>::value && sizeof(long) == sizeof(dlib::int64))) - { - if (!mxIsInt64(prhs) || mxIsComplex(prhs)) - { - std::ostringstream sout; - sout << "Input argument " << arg_idx+1 << " must be a matrix of int64"; - throw invalid_args_exception(sout); - } - - assign_mat(arg_idx, arg , pointer_to_matrix((const type*)mxGetData(prhs), nc, nr)); - } - else - { - throw invalid_args_exception("mex_function uses unsupported matrix type"); - } - } - else if (is_array_type<T>::value) - { - assign_std_vector(arg_idx, arg, prhs); - - } - else if (is_same_type<T,function_handle>::value) - { - if (!mxIsClass(prhs, "function_handle")) - { - std::ostringstream sout; - sout << "Input argument " << arg_idx+1 << " must be a function handle."; - throw invalid_args_exception(sout); - } - assign_function_handle(arg_idx, arg, prhs); - } - else - { - throw invalid_args_exception("mex_function uses unsupported input argument type"); - } - } - - void validate_and_populate_arg( - long arg_idx, - const mxArray *prhs, - matlab_struct& arg - ) - { - if (!mxIsStruct(prhs)) - { - std::ostringstream sout; - sout << "Input argument " << arg_idx+1 << " must be a struct"; - throw invalid_args_exception(sout); - } - - arg.set_struct_handle(arg_idx, prhs); - } - - - void validate_and_populate_arg( - long arg_idx, - const mxArray *prhs, - matlab_object& arg - ) - { - arg.set_object_handle(arg_idx, prhs); - } - - - void validate_and_populate_arg( - long arg_idx, - const mxArray *prhs, - std::string& arg - ) - { - if (!mxIsChar(prhs)) - { - std::ostringstream sout; - sout << "Input argument " << arg_idx+1 << " must be a char string"; - throw invalid_args_exception(sout); - } - - const long nr = mxGetM(prhs); - const long nc = mxGetN(prhs); - const long size = nr*nc; - arg.resize(size+1); - if (mxGetString(prhs, &arg[0], arg.size())) - { - std::ostringstream sout; - sout << "Input argument " << arg_idx+1 << " encountered an error while calling mxGetString()"; - throw invalid_args_exception(sout); - } - arg.resize(size); - } - -// ---------------------------------------------------------------------------------------- - - template <typename EXP> - typename dlib::enable_if<is_same_type<dlib::rgb_pixel,typename EXP::type> >::type assign_image_to_matlab ( - dlib::uint8* mat, - const matrix_exp<EXP>& item - ) - { - for (long c = 0; c < item.nc(); ++c) - for (long r = 0; r < item.nr(); ++r) - *mat++ = item(r,c).red; - for (long c = 0; c < item.nc(); ++c) - for (long r = 0; r < item.nr(); ++r) - *mat++ = item(r,c).green; - for (long c = 0; c < item.nc(); ++c) - for (long r = 0; r < item.nr(); ++r) - *mat++ = item(r,c).blue; - } - - template <typename T, typename EXP> - typename disable_if<is_same_type<dlib::rgb_pixel,typename EXP::type> >::type assign_image_to_matlab ( - T* mat, - const matrix_exp<EXP>& - ) - { - mexErrMsgIdAndTxt("mex_function:validate_and_populate_arg", - "mex_function uses unsupported output image argument type"); - } - - template <typename T> - typename dlib::enable_if<is_matrix<T> >::type assign_to_matlab( - mxArray*& plhs, - const T& item - ) - { - typedef typename T::type type; - - type* mat = 0; - - if (is_same_type<double, type>::value) - { - plhs = mxCreateDoubleMatrix(item.nr(), - item.nc(), - mxREAL); - - mat = (type*)mxGetPr(plhs); - } - else if (is_same_type<float, type>::value ) - { - plhs = mxCreateNumericMatrix(item.nr(), - item.nc(), - mxSINGLE_CLASS, - mxREAL); - - mat = (type*)mxGetData(plhs); - } - else if (is_same_type<bool, type>::value ) - { - plhs = mxCreateLogicalMatrix(item.nr(), - item.nc()); - - mat = (type*)mxGetData(plhs); - } - else if (is_same_type<dlib::uint8, type>::value ) - { - plhs = mxCreateNumericMatrix(item.nr(), - item.nc(), - mxUINT8_CLASS, - mxREAL); - - mat = (type*)mxGetData(plhs); - } - else if (is_same_type<dlib::int8, type>::value ) - { - plhs = mxCreateNumericMatrix(item.nr(), - item.nc(), - mxINT8_CLASS, - mxREAL); - - mat = (type*)mxGetData(plhs); - } - else if (is_same_type<dlib::int16, type>::value || - (is_same_type<short,type>::value && sizeof(short) == sizeof(dlib::int16))) - { - plhs = mxCreateNumericMatrix(item.nr(), - item.nc(), - mxINT16_CLASS, - mxREAL); - - mat = (type*)mxGetData(plhs); - } - else if (is_same_type<dlib::uint16, type>::value || - (is_same_type<unsigned short,type>::value && sizeof(unsigned short) == sizeof(dlib::uint16))) - { - plhs = mxCreateNumericMatrix(item.nr(), - item.nc(), - mxUINT16_CLASS, - mxREAL); - - mat = (type*)mxGetData(plhs); - } - else if (is_same_type<dlib::int32, type>::value || - (is_same_type<long,type>::value && sizeof(long) == sizeof(dlib::int32))) - { - plhs = mxCreateNumericMatrix(item.nr(), - item.nc(), - mxINT32_CLASS, - mxREAL); - - mat = (type*)mxGetData(plhs); - } - else if (is_same_type<dlib::uint32, type>::value || - (is_same_type<unsigned long,type>::value && sizeof(unsigned long) == sizeof(dlib::uint32))) - { - plhs = mxCreateNumericMatrix(item.nr(), - item.nc(), - mxUINT32_CLASS, - mxREAL); - - mat = (type*)mxGetData(plhs); - } - else if (is_same_type<dlib::uint64, type>::value || - (is_same_type<unsigned long,type>::value && sizeof(unsigned long) == sizeof(dlib::uint64))) - { - plhs = mxCreateNumericMatrix(item.nr(), - item.nc(), - mxUINT64_CLASS, - mxREAL); - - mat = (type*)mxGetData(plhs); - } - else if (is_same_type<dlib::int64, type>::value || - (is_same_type<long,type>::value && sizeof(long) == sizeof(dlib::int64))) - { - plhs = mxCreateNumericMatrix(item.nr(), - item.nc(), - mxINT64_CLASS, - mxREAL); - - mat = (type*)mxGetData(plhs); - } - else if (is_same_type<dlib::rgb_pixel, type>::value) - { - mwSize dims[3] = {(mwSize)item.nr(), (mwSize)item.nc(), 3}; - plhs = mxCreateNumericArray(3, dims, mxUINT8_CLASS, mxREAL); - - assign_image_to_matlab((dlib::uint8*)mxGetData(plhs), item); - return; - } - else - { - mexErrMsgIdAndTxt("mex_function:validate_and_populate_arg", - "mex_function uses unsupported output argument type"); - } - - - const_temp_matrix<T> m(item); - - for (long c = 0; c < m.nc(); ++c) - { - for ( long r = 0; r < m.nr(); ++r) - { - *mat++ = m(r,c); - } - } - } - - void assign_to_matlab( - mxArray*& plhs, - matrix_colmajor& item - ) - { - if(item._private_is_owned_by_matlab()) - { - // Don't need to do a copy if it's this kind of matrix since we can just - // pull the underlying mxArray out directly and thus avoid a copy. - plhs = item._private_release_mxArray(); - // If there isn't anything there because the matrix is empty then set it to an - // empty matrix. - if (!plhs) - plhs = mxCreateDoubleMatrix(item.nr(), - item.nc(), - mxREAL); - } - else - { - plhs = mxCreateDoubleMatrix(item.nr(), - item.nc(), - mxREAL); - if (item.size() != 0) - memcpy(mxGetPr(plhs), &item(0,0), item.size()*sizeof(double)); - } - } - - void assign_to_matlab( - mxArray*& plhs, - fmatrix_colmajor& item - ) - { - if(item._private_is_owned_by_matlab()) - { - // Don't need to do a copy if it's this kind of matrix since we can just - // pull the underlying mxArray out directly and thus avoid a copy. - plhs = item._private_release_mxArray(); - // If there isn't anything there because the matrix is empty then set it to an - // empty matrix. - if (!plhs) - plhs = mxCreateNumericMatrix(item.nr(), - item.nc(), - mxSINGLE_CLASS, - mxREAL); - } - else - { - plhs = mxCreateNumericMatrix(item.nr(), - item.nc(), - mxSINGLE_CLASS, - mxREAL); - if (item.size() != 0) - memcpy(mxGetPr(plhs), &item(0,0), item.size()*sizeof(float)); - } - } - - void assign_to_matlab( - mxArray*& plhs, - matlab_struct& item - ) - { - plhs = (mxArray*)item.release_struct_to_matlab(); - } - - void assign_to_matlab( - mxArray*& plhs, - matlab_object& item - ) - { - plhs = (mxArray*)item.release_object_to_matlab(); - } - - void assign_to_matlab( - mxArray*& plhs, - const std::string& item - ) - { - plhs = mxCreateString(item.c_str()); - } - - template <typename T, typename MM> - void assign_to_matlab( - mxArray*& plhs, - const array2d<T,MM>& item - ) - { - assign_to_matlab(plhs,array_to_matrix(item)); - } - - template <typename T> - typename dlib::disable_if_c<is_matrix<T>::value || is_array_type<T>::value || - is_same_type<T,function_handle>::value>::type assign_to_matlab( - mxArray*& plhs, - const T& item - ) - { - plhs = mxCreateDoubleScalar(item); - } - - - void assign_to_matlab ( - mxArray*& plhs, - const char* str - ) - { - assign_to_matlab(plhs, std::string(str)); - } - - void assign_to_matlab( - mxArray*& plhs, - const function_handle& h - ) - { - } - - template <typename T> - typename dlib::enable_if<is_array_type<T> >::type assign_to_matlab( - mxArray*& plhs, - const T& item - ) - { - mwSize dims[1] = {item.size()}; - plhs = mxCreateCellArray(1,dims); - for (unsigned long i = 0; i < item.size(); ++i) - { - mxArray* next = 0; - assign_to_matlab(next, item[i]); - mxSetCell(plhs, i, next); - } - } - -// ---------------------------------------------------------------------------------------- - - template <typename T> - void mark_owned_by_matlab (const T&){} - - void mark_owned_by_matlab(matrix_colmajor& item) { item._private_mark_owned_by_matlab(); } - void mark_owned_by_matlab(fmatrix_colmajor& item) { item._private_mark_owned_by_matlab(); } - -// ---------------------------------------------------------------------------------------- - - template < - unsigned long num_args - > - struct call_mex_function_helper; - - template <> - struct call_mex_function_helper<0> - { - template <typename funct> - void callit( - const funct& f, - int , mxArray **, - int , const mxArray ** - ) const - { - f(); - } - }; - - template <> - struct call_mex_function_helper<1> - { - template <typename funct> - void callit( - const funct& f, - int nlhs, mxArray *plhs[], - int nrhs, const mxArray *prhs[] - ) const - { - typedef typename sig_traits<funct>::arg1_type arg1_type; - - typename basic_type<arg1_type>::type A1; - - mark_owned_by_matlab(A1); - - int i = 0; - if (i < nrhs && is_input_type<arg1_type>::value) {validate_and_populate_arg(i,prhs[i],A1); ++i;} ELSE_ASSIGN_ARG_1; - - f(A1); - - i = 0; - if (is_output_type<arg1_type>::value) {assign_to_matlab(plhs[i],A1); ++i;} - } - }; - - template <> - struct call_mex_function_helper<2> - { - template <typename funct> - void callit( - const funct& f, - int nlhs, mxArray *plhs[], - int nrhs, const mxArray *prhs[] - ) const - { - typedef typename sig_traits<funct>::arg1_type arg1_type; - typedef typename sig_traits<funct>::arg2_type arg2_type; - - typename basic_type<arg1_type>::type A1; - typename basic_type<arg2_type>::type A2; - - mark_owned_by_matlab(A1); - mark_owned_by_matlab(A2); - - int i = 0; - if (i < nrhs && is_input_type<arg1_type>::value) {validate_and_populate_arg(i,prhs[i],A1); ++i;} ELSE_ASSIGN_ARG_1; - if (i < nrhs && is_input_type<arg2_type>::value) {validate_and_populate_arg(i,prhs[i],A2); ++i;} ELSE_ASSIGN_ARG_2; - - f(A1,A2); - - i = 0; - if (is_output_type<arg1_type>::value) {assign_to_matlab(plhs[i],A1); ++i;} - if (is_output_type<arg2_type>::value) {assign_to_matlab(plhs[i],A2); ++i;} - } - }; - - template <> - struct call_mex_function_helper<3> - { - template <typename funct> - void callit( - const funct& f, - int nlhs, mxArray *plhs[], - int nrhs, const mxArray *prhs[] - ) const - { - typedef typename sig_traits<funct>::arg1_type arg1_type; - typedef typename sig_traits<funct>::arg2_type arg2_type; - typedef typename sig_traits<funct>::arg3_type arg3_type; - - typename basic_type<arg1_type>::type A1; - typename basic_type<arg2_type>::type A2; - typename basic_type<arg3_type>::type A3; - - mark_owned_by_matlab(A1); - mark_owned_by_matlab(A2); - mark_owned_by_matlab(A3); - - int i = 0; - if (i < nrhs && is_input_type<arg1_type>::value) {validate_and_populate_arg(i,prhs[i],A1); ++i;} ELSE_ASSIGN_ARG_1; - if (i < nrhs && is_input_type<arg2_type>::value) {validate_and_populate_arg(i,prhs[i],A2); ++i;} ELSE_ASSIGN_ARG_2; - if (i < nrhs && is_input_type<arg3_type>::value) {validate_and_populate_arg(i,prhs[i],A3); ++i;} ELSE_ASSIGN_ARG_3; - - f(A1,A2,A3); - - i = 0; - if (is_output_type<arg1_type>::value) {assign_to_matlab(plhs[i],A1); ++i;} - if (is_output_type<arg2_type>::value) {assign_to_matlab(plhs[i],A2); ++i;} - if (is_output_type<arg3_type>::value) {assign_to_matlab(plhs[i],A3); ++i;} - } - }; - - template <> - struct call_mex_function_helper<4> - { - template <typename funct> - void callit( - const funct& f, - int nlhs, mxArray *plhs[], - int nrhs, const mxArray *prhs[] - ) const - { - typedef typename sig_traits<funct>::arg1_type arg1_type; - typedef typename sig_traits<funct>::arg2_type arg2_type; - typedef typename sig_traits<funct>::arg3_type arg3_type; - typedef typename sig_traits<funct>::arg4_type arg4_type; - - typename basic_type<arg1_type>::type A1; - typename basic_type<arg2_type>::type A2; - typename basic_type<arg3_type>::type A3; - typename basic_type<arg4_type>::type A4; - - mark_owned_by_matlab(A1); - mark_owned_by_matlab(A2); - mark_owned_by_matlab(A3); - mark_owned_by_matlab(A4); - - int i = 0; - if (i < nrhs && is_input_type<arg1_type>::value) {validate_and_populate_arg(i,prhs[i],A1); ++i;} ELSE_ASSIGN_ARG_1; - if (i < nrhs && is_input_type<arg2_type>::value) {validate_and_populate_arg(i,prhs[i],A2); ++i;} ELSE_ASSIGN_ARG_2; - if (i < nrhs && is_input_type<arg3_type>::value) {validate_and_populate_arg(i,prhs[i],A3); ++i;} ELSE_ASSIGN_ARG_3; - if (i < nrhs && is_input_type<arg4_type>::value) {validate_and_populate_arg(i,prhs[i],A4); ++i;} ELSE_ASSIGN_ARG_4; - - f(A1,A2,A3,A4); - - - i = 0; - if (is_output_type<arg1_type>::value) {assign_to_matlab(plhs[i],A1); ++i;} - if (is_output_type<arg2_type>::value) {assign_to_matlab(plhs[i],A2); ++i;} - if (is_output_type<arg3_type>::value) {assign_to_matlab(plhs[i],A3); ++i;} - if (is_output_type<arg4_type>::value) {assign_to_matlab(plhs[i],A4); ++i;} - } - }; - - template <> - struct call_mex_function_helper<5> - { - template <typename funct> - void callit( - const funct& f, - int nlhs, mxArray *plhs[], - int nrhs, const mxArray *prhs[] - ) const - { - typedef typename sig_traits<funct>::arg1_type arg1_type; - typedef typename sig_traits<funct>::arg2_type arg2_type; - typedef typename sig_traits<funct>::arg3_type arg3_type; - typedef typename sig_traits<funct>::arg4_type arg4_type; - typedef typename sig_traits<funct>::arg5_type arg5_type; - - typename basic_type<arg1_type>::type A1; - typename basic_type<arg2_type>::type A2; - typename basic_type<arg3_type>::type A3; - typename basic_type<arg4_type>::type A4; - typename basic_type<arg5_type>::type A5; - - mark_owned_by_matlab(A1); - mark_owned_by_matlab(A2); - mark_owned_by_matlab(A3); - mark_owned_by_matlab(A4); - mark_owned_by_matlab(A5); - - int i = 0; - if (i < nrhs && is_input_type<arg1_type>::value) {validate_and_populate_arg(i,prhs[i],A1); ++i;} ELSE_ASSIGN_ARG_1; - if (i < nrhs && is_input_type<arg2_type>::value) {validate_and_populate_arg(i,prhs[i],A2); ++i;} ELSE_ASSIGN_ARG_2; - if (i < nrhs && is_input_type<arg3_type>::value) {validate_and_populate_arg(i,prhs[i],A3); ++i;} ELSE_ASSIGN_ARG_3; - if (i < nrhs && is_input_type<arg4_type>::value) {validate_and_populate_arg(i,prhs[i],A4); ++i;} ELSE_ASSIGN_ARG_4; - if (i < nrhs && is_input_type<arg5_type>::value) {validate_and_populate_arg(i,prhs[i],A5); ++i;} ELSE_ASSIGN_ARG_5; - - f(A1,A2,A3,A4,A5); - - - i = 0; - if (is_output_type<arg1_type>::value) {assign_to_matlab(plhs[i],A1); ++i;} - if (is_output_type<arg2_type>::value) {assign_to_matlab(plhs[i],A2); ++i;} - if (is_output_type<arg3_type>::value) {assign_to_matlab(plhs[i],A3); ++i;} - if (is_output_type<arg4_type>::value) {assign_to_matlab(plhs[i],A4); ++i;} - if (is_output_type<arg5_type>::value) {assign_to_matlab(plhs[i],A5); ++i;} - } - }; - - - template <> - struct call_mex_function_helper<6> - { - template <typename funct> - void callit( - const funct& f, - int nlhs, mxArray *plhs[], - int nrhs, const mxArray *prhs[] - ) const - { - typedef typename sig_traits<funct>::arg1_type arg1_type; - typedef typename sig_traits<funct>::arg2_type arg2_type; - typedef typename sig_traits<funct>::arg3_type arg3_type; - typedef typename sig_traits<funct>::arg4_type arg4_type; - typedef typename sig_traits<funct>::arg5_type arg5_type; - typedef typename sig_traits<funct>::arg6_type arg6_type; - - typename basic_type<arg1_type>::type A1; - typename basic_type<arg2_type>::type A2; - typename basic_type<arg3_type>::type A3; - typename basic_type<arg4_type>::type A4; - typename basic_type<arg5_type>::type A5; - typename basic_type<arg6_type>::type A6; - - mark_owned_by_matlab(A1); - mark_owned_by_matlab(A2); - mark_owned_by_matlab(A3); - mark_owned_by_matlab(A4); - mark_owned_by_matlab(A5); - mark_owned_by_matlab(A6); - - int i = 0; - if (i < nrhs && is_input_type<arg1_type>::value) {validate_and_populate_arg(i,prhs[i],A1); ++i;} ELSE_ASSIGN_ARG_1; - if (i < nrhs && is_input_type<arg2_type>::value) {validate_and_populate_arg(i,prhs[i],A2); ++i;} ELSE_ASSIGN_ARG_2; - if (i < nrhs && is_input_type<arg3_type>::value) {validate_and_populate_arg(i,prhs[i],A3); ++i;} ELSE_ASSIGN_ARG_3; - if (i < nrhs && is_input_type<arg4_type>::value) {validate_and_populate_arg(i,prhs[i],A4); ++i;} ELSE_ASSIGN_ARG_4; - if (i < nrhs && is_input_type<arg5_type>::value) {validate_and_populate_arg(i,prhs[i],A5); ++i;} ELSE_ASSIGN_ARG_5; - if (i < nrhs && is_input_type<arg6_type>::value) {validate_and_populate_arg(i,prhs[i],A6); ++i;} ELSE_ASSIGN_ARG_6; - - f(A1,A2,A3,A4,A5,A6); - - - i = 0; - if (is_output_type<arg1_type>::value) {assign_to_matlab(plhs[i],A1); ++i;} - if (is_output_type<arg2_type>::value) {assign_to_matlab(plhs[i],A2); ++i;} - if (is_output_type<arg3_type>::value) {assign_to_matlab(plhs[i],A3); ++i;} - if (is_output_type<arg4_type>::value) {assign_to_matlab(plhs[i],A4); ++i;} - if (is_output_type<arg5_type>::value) {assign_to_matlab(plhs[i],A5); ++i;} - if (is_output_type<arg6_type>::value) {assign_to_matlab(plhs[i],A6); ++i;} - } - }; - - - template <> - struct call_mex_function_helper<7> - { - template <typename funct> - void callit( - const funct& f, - int nlhs, mxArray *plhs[], - int nrhs, const mxArray *prhs[] - ) const - { - typedef typename sig_traits<funct>::arg1_type arg1_type; - typedef typename sig_traits<funct>::arg2_type arg2_type; - typedef typename sig_traits<funct>::arg3_type arg3_type; - typedef typename sig_traits<funct>::arg4_type arg4_type; - typedef typename sig_traits<funct>::arg5_type arg5_type; - typedef typename sig_traits<funct>::arg6_type arg6_type; - typedef typename sig_traits<funct>::arg7_type arg7_type; - - typename basic_type<arg1_type>::type A1; - typename basic_type<arg2_type>::type A2; - typename basic_type<arg3_type>::type A3; - typename basic_type<arg4_type>::type A4; - typename basic_type<arg5_type>::type A5; - typename basic_type<arg6_type>::type A6; - typename basic_type<arg7_type>::type A7; - - mark_owned_by_matlab(A1); - mark_owned_by_matlab(A2); - mark_owned_by_matlab(A3); - mark_owned_by_matlab(A4); - mark_owned_by_matlab(A5); - mark_owned_by_matlab(A6); - mark_owned_by_matlab(A7); - - int i = 0; - if (i < nrhs && is_input_type<arg1_type>::value) {validate_and_populate_arg(i,prhs[i],A1); ++i;} ELSE_ASSIGN_ARG_1; - if (i < nrhs && is_input_type<arg2_type>::value) {validate_and_populate_arg(i,prhs[i],A2); ++i;} ELSE_ASSIGN_ARG_2; - if (i < nrhs && is_input_type<arg3_type>::value) {validate_and_populate_arg(i,prhs[i],A3); ++i;} ELSE_ASSIGN_ARG_3; - if (i < nrhs && is_input_type<arg4_type>::value) {validate_and_populate_arg(i,prhs[i],A4); ++i;} ELSE_ASSIGN_ARG_4; - if (i < nrhs && is_input_type<arg5_type>::value) {validate_and_populate_arg(i,prhs[i],A5); ++i;} ELSE_ASSIGN_ARG_5; - if (i < nrhs && is_input_type<arg6_type>::value) {validate_and_populate_arg(i,prhs[i],A6); ++i;} ELSE_ASSIGN_ARG_6; - if (i < nrhs && is_input_type<arg7_type>::value) {validate_and_populate_arg(i,prhs[i],A7); ++i;} ELSE_ASSIGN_ARG_7; - - f(A1,A2,A3,A4,A5,A6,A7); - - - i = 0; - if (is_output_type<arg1_type>::value) {assign_to_matlab(plhs[i],A1); ++i;} - if (is_output_type<arg2_type>::value) {assign_to_matlab(plhs[i],A2); ++i;} - if (is_output_type<arg3_type>::value) {assign_to_matlab(plhs[i],A3); ++i;} - if (is_output_type<arg4_type>::value) {assign_to_matlab(plhs[i],A4); ++i;} - if (is_output_type<arg5_type>::value) {assign_to_matlab(plhs[i],A5); ++i;} - if (is_output_type<arg6_type>::value) {assign_to_matlab(plhs[i],A6); ++i;} - if (is_output_type<arg7_type>::value) {assign_to_matlab(plhs[i],A7); ++i;} - } - }; - - - template <> - struct call_mex_function_helper<8> - { - template <typename funct> - void callit( - const funct& f, - int nlhs, mxArray *plhs[], - int nrhs, const mxArray *prhs[] - ) const - { - typedef typename sig_traits<funct>::arg1_type arg1_type; - typedef typename sig_traits<funct>::arg2_type arg2_type; - typedef typename sig_traits<funct>::arg3_type arg3_type; - typedef typename sig_traits<funct>::arg4_type arg4_type; - typedef typename sig_traits<funct>::arg5_type arg5_type; - typedef typename sig_traits<funct>::arg6_type arg6_type; - typedef typename sig_traits<funct>::arg7_type arg7_type; - typedef typename sig_traits<funct>::arg8_type arg8_type; - - typename basic_type<arg1_type>::type A1; - typename basic_type<arg2_type>::type A2; - typename basic_type<arg3_type>::type A3; - typename basic_type<arg4_type>::type A4; - typename basic_type<arg5_type>::type A5; - typename basic_type<arg6_type>::type A6; - typename basic_type<arg7_type>::type A7; - typename basic_type<arg8_type>::type A8; - - mark_owned_by_matlab(A1); - mark_owned_by_matlab(A2); - mark_owned_by_matlab(A3); - mark_owned_by_matlab(A4); - mark_owned_by_matlab(A5); - mark_owned_by_matlab(A6); - mark_owned_by_matlab(A7); - mark_owned_by_matlab(A8); - - int i = 0; - if (i < nrhs && is_input_type<arg1_type>::value) {validate_and_populate_arg(i,prhs[i],A1); ++i;} ELSE_ASSIGN_ARG_1; - if (i < nrhs && is_input_type<arg2_type>::value) {validate_and_populate_arg(i,prhs[i],A2); ++i;} ELSE_ASSIGN_ARG_2; - if (i < nrhs && is_input_type<arg3_type>::value) {validate_and_populate_arg(i,prhs[i],A3); ++i;} ELSE_ASSIGN_ARG_3; - if (i < nrhs && is_input_type<arg4_type>::value) {validate_and_populate_arg(i,prhs[i],A4); ++i;} ELSE_ASSIGN_ARG_4; - if (i < nrhs && is_input_type<arg5_type>::value) {validate_and_populate_arg(i,prhs[i],A5); ++i;} ELSE_ASSIGN_ARG_5; - if (i < nrhs && is_input_type<arg6_type>::value) {validate_and_populate_arg(i,prhs[i],A6); ++i;} ELSE_ASSIGN_ARG_6; - if (i < nrhs && is_input_type<arg7_type>::value) {validate_and_populate_arg(i,prhs[i],A7); ++i;} ELSE_ASSIGN_ARG_7; - if (i < nrhs && is_input_type<arg8_type>::value) {validate_and_populate_arg(i,prhs[i],A8); ++i;} ELSE_ASSIGN_ARG_8; - - f(A1,A2,A3,A4,A5,A6,A7,A8); - - - i = 0; - if (is_output_type<arg1_type>::value) {assign_to_matlab(plhs[i],A1); ++i;} - if (is_output_type<arg2_type>::value) {assign_to_matlab(plhs[i],A2); ++i;} - if (is_output_type<arg3_type>::value) {assign_to_matlab(plhs[i],A3); ++i;} - if (is_output_type<arg4_type>::value) {assign_to_matlab(plhs[i],A4); ++i;} - if (is_output_type<arg5_type>::value) {assign_to_matlab(plhs[i],A5); ++i;} - if (is_output_type<arg6_type>::value) {assign_to_matlab(plhs[i],A6); ++i;} - if (is_output_type<arg7_type>::value) {assign_to_matlab(plhs[i],A7); ++i;} - if (is_output_type<arg8_type>::value) {assign_to_matlab(plhs[i],A8); ++i;} - } - }; - - - template <> - struct call_mex_function_helper<9> - { - template <typename funct> - void callit( - const funct& f, - int nlhs, mxArray *plhs[], - int nrhs, const mxArray *prhs[] - ) const - { - typedef typename sig_traits<funct>::arg1_type arg1_type; - typedef typename sig_traits<funct>::arg2_type arg2_type; - typedef typename sig_traits<funct>::arg3_type arg3_type; - typedef typename sig_traits<funct>::arg4_type arg4_type; - typedef typename sig_traits<funct>::arg5_type arg5_type; - typedef typename sig_traits<funct>::arg6_type arg6_type; - typedef typename sig_traits<funct>::arg7_type arg7_type; - typedef typename sig_traits<funct>::arg8_type arg8_type; - typedef typename sig_traits<funct>::arg9_type arg9_type; - - typename basic_type<arg1_type>::type A1; - typename basic_type<arg2_type>::type A2; - typename basic_type<arg3_type>::type A3; - typename basic_type<arg4_type>::type A4; - typename basic_type<arg5_type>::type A5; - typename basic_type<arg6_type>::type A6; - typename basic_type<arg7_type>::type A7; - typename basic_type<arg8_type>::type A8; - typename basic_type<arg9_type>::type A9; - - mark_owned_by_matlab(A1); - mark_owned_by_matlab(A2); - mark_owned_by_matlab(A3); - mark_owned_by_matlab(A4); - mark_owned_by_matlab(A5); - mark_owned_by_matlab(A6); - mark_owned_by_matlab(A7); - mark_owned_by_matlab(A8); - mark_owned_by_matlab(A9); - - int i = 0; - if (i < nrhs && is_input_type<arg1_type>::value) {validate_and_populate_arg(i,prhs[i],A1); ++i;} ELSE_ASSIGN_ARG_1; - if (i < nrhs && is_input_type<arg2_type>::value) {validate_and_populate_arg(i,prhs[i],A2); ++i;} ELSE_ASSIGN_ARG_2; - if (i < nrhs && is_input_type<arg3_type>::value) {validate_and_populate_arg(i,prhs[i],A3); ++i;} ELSE_ASSIGN_ARG_3; - if (i < nrhs && is_input_type<arg4_type>::value) {validate_and_populate_arg(i,prhs[i],A4); ++i;} ELSE_ASSIGN_ARG_4; - if (i < nrhs && is_input_type<arg5_type>::value) {validate_and_populate_arg(i,prhs[i],A5); ++i;} ELSE_ASSIGN_ARG_5; - if (i < nrhs && is_input_type<arg6_type>::value) {validate_and_populate_arg(i,prhs[i],A6); ++i;} ELSE_ASSIGN_ARG_6; - if (i < nrhs && is_input_type<arg7_type>::value) {validate_and_populate_arg(i,prhs[i],A7); ++i;} ELSE_ASSIGN_ARG_7; - if (i < nrhs && is_input_type<arg8_type>::value) {validate_and_populate_arg(i,prhs[i],A8); ++i;} ELSE_ASSIGN_ARG_8; - if (i < nrhs && is_input_type<arg9_type>::value) {validate_and_populate_arg(i,prhs[i],A9); ++i;} ELSE_ASSIGN_ARG_9; - - f(A1,A2,A3,A4,A5,A6,A7,A8,A9); - - - i = 0; - if (is_output_type<arg1_type>::value) {assign_to_matlab(plhs[i],A1); ++i;} - if (is_output_type<arg2_type>::value) {assign_to_matlab(plhs[i],A2); ++i;} - if (is_output_type<arg3_type>::value) {assign_to_matlab(plhs[i],A3); ++i;} - if (is_output_type<arg4_type>::value) {assign_to_matlab(plhs[i],A4); ++i;} - if (is_output_type<arg5_type>::value) {assign_to_matlab(plhs[i],A5); ++i;} - if (is_output_type<arg6_type>::value) {assign_to_matlab(plhs[i],A6); ++i;} - if (is_output_type<arg7_type>::value) {assign_to_matlab(plhs[i],A7); ++i;} - if (is_output_type<arg8_type>::value) {assign_to_matlab(plhs[i],A8); ++i;} - if (is_output_type<arg9_type>::value) {assign_to_matlab(plhs[i],A9); ++i;} - } - }; - - - - template <> - struct call_mex_function_helper<10> - { - template <typename funct> - void callit( - const funct& f, - int nlhs, mxArray *plhs[], - int nrhs, const mxArray *prhs[] - ) const - { - typedef typename sig_traits<funct>::arg1_type arg1_type; - typedef typename sig_traits<funct>::arg2_type arg2_type; - typedef typename sig_traits<funct>::arg3_type arg3_type; - typedef typename sig_traits<funct>::arg4_type arg4_type; - typedef typename sig_traits<funct>::arg5_type arg5_type; - typedef typename sig_traits<funct>::arg6_type arg6_type; - typedef typename sig_traits<funct>::arg7_type arg7_type; - typedef typename sig_traits<funct>::arg8_type arg8_type; - typedef typename sig_traits<funct>::arg9_type arg9_type; - typedef typename sig_traits<funct>::arg10_type arg10_type; - - typename basic_type<arg1_type>::type A1; - typename basic_type<arg2_type>::type A2; - typename basic_type<arg3_type>::type A3; - typename basic_type<arg4_type>::type A4; - typename basic_type<arg5_type>::type A5; - typename basic_type<arg6_type>::type A6; - typename basic_type<arg7_type>::type A7; - typename basic_type<arg8_type>::type A8; - typename basic_type<arg9_type>::type A9; - typename basic_type<arg10_type>::type A10; - - mark_owned_by_matlab(A1); - mark_owned_by_matlab(A2); - mark_owned_by_matlab(A3); - mark_owned_by_matlab(A4); - mark_owned_by_matlab(A5); - mark_owned_by_matlab(A6); - mark_owned_by_matlab(A7); - mark_owned_by_matlab(A8); - mark_owned_by_matlab(A9); - mark_owned_by_matlab(A10); - - int i = 0; - if (i < nrhs && is_input_type<arg1_type>::value) {validate_and_populate_arg(i,prhs[i],A1); ++i;} ELSE_ASSIGN_ARG_1; - if (i < nrhs && is_input_type<arg2_type>::value) {validate_and_populate_arg(i,prhs[i],A2); ++i;} ELSE_ASSIGN_ARG_2; - if (i < nrhs && is_input_type<arg3_type>::value) {validate_and_populate_arg(i,prhs[i],A3); ++i;} ELSE_ASSIGN_ARG_3; - if (i < nrhs && is_input_type<arg4_type>::value) {validate_and_populate_arg(i,prhs[i],A4); ++i;} ELSE_ASSIGN_ARG_4; - if (i < nrhs && is_input_type<arg5_type>::value) {validate_and_populate_arg(i,prhs[i],A5); ++i;} ELSE_ASSIGN_ARG_5; - if (i < nrhs && is_input_type<arg6_type>::value) {validate_and_populate_arg(i,prhs[i],A6); ++i;} ELSE_ASSIGN_ARG_6; - if (i < nrhs && is_input_type<arg7_type>::value) {validate_and_populate_arg(i,prhs[i],A7); ++i;} ELSE_ASSIGN_ARG_7; - if (i < nrhs && is_input_type<arg8_type>::value) {validate_and_populate_arg(i,prhs[i],A8); ++i;} ELSE_ASSIGN_ARG_8; - if (i < nrhs && is_input_type<arg9_type>::value) {validate_and_populate_arg(i,prhs[i],A9); ++i;} ELSE_ASSIGN_ARG_9; - if (i < nrhs && is_input_type<arg10_type>::value) {validate_and_populate_arg(i,prhs[i],A10); ++i;} ELSE_ASSIGN_ARG_10; - - f(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10); - - - i = 0; - if (is_output_type<arg1_type>::value) {assign_to_matlab(plhs[i],A1); ++i;} - if (is_output_type<arg2_type>::value) {assign_to_matlab(plhs[i],A2); ++i;} - if (is_output_type<arg3_type>::value) {assign_to_matlab(plhs[i],A3); ++i;} - if (is_output_type<arg4_type>::value) {assign_to_matlab(plhs[i],A4); ++i;} - if (is_output_type<arg5_type>::value) {assign_to_matlab(plhs[i],A5); ++i;} - if (is_output_type<arg6_type>::value) {assign_to_matlab(plhs[i],A6); ++i;} - if (is_output_type<arg7_type>::value) {assign_to_matlab(plhs[i],A7); ++i;} - if (is_output_type<arg8_type>::value) {assign_to_matlab(plhs[i],A8); ++i;} - if (is_output_type<arg9_type>::value) {assign_to_matlab(plhs[i],A9); ++i;} - if (is_output_type<arg10_type>::value) {assign_to_matlab(plhs[i],A10); ++i;} - } - }; - - template <> - struct call_mex_function_helper<11> - { - template <typename funct> - void callit( - const funct& f, - int nlhs, mxArray *plhs[], - int nrhs, const mxArray *prhs[] - ) const - { - typedef typename sig_traits<funct>::arg1_type arg1_type; - typedef typename sig_traits<funct>::arg2_type arg2_type; - typedef typename sig_traits<funct>::arg3_type arg3_type; - typedef typename sig_traits<funct>::arg4_type arg4_type; - typedef typename sig_traits<funct>::arg5_type arg5_type; - typedef typename sig_traits<funct>::arg6_type arg6_type; - typedef typename sig_traits<funct>::arg7_type arg7_type; - typedef typename sig_traits<funct>::arg8_type arg8_type; - typedef typename sig_traits<funct>::arg9_type arg9_type; - typedef typename sig_traits<funct>::arg10_type arg10_type; - typedef typename sig_traits<funct>::arg11_type arg11_type; - - typename basic_type<arg1_type>::type A1; - typename basic_type<arg2_type>::type A2; - typename basic_type<arg3_type>::type A3; - typename basic_type<arg4_type>::type A4; - typename basic_type<arg5_type>::type A5; - typename basic_type<arg6_type>::type A6; - typename basic_type<arg7_type>::type A7; - typename basic_type<arg8_type>::type A8; - typename basic_type<arg9_type>::type A9; - typename basic_type<arg10_type>::type A10; - typename basic_type<arg11_type>::type A11; - - mark_owned_by_matlab(A1); - mark_owned_by_matlab(A2); - mark_owned_by_matlab(A3); - mark_owned_by_matlab(A4); - mark_owned_by_matlab(A5); - mark_owned_by_matlab(A6); - mark_owned_by_matlab(A7); - mark_owned_by_matlab(A8); - mark_owned_by_matlab(A9); - mark_owned_by_matlab(A10); - mark_owned_by_matlab(A11); - - int i = 0; - if (i < nrhs && is_input_type<arg1_type>::value) {validate_and_populate_arg(i,prhs[i],A1); ++i;} ELSE_ASSIGN_ARG_1; - if (i < nrhs && is_input_type<arg2_type>::value) {validate_and_populate_arg(i,prhs[i],A2); ++i;} ELSE_ASSIGN_ARG_2; - if (i < nrhs && is_input_type<arg3_type>::value) {validate_and_populate_arg(i,prhs[i],A3); ++i;} ELSE_ASSIGN_ARG_3; - if (i < nrhs && is_input_type<arg4_type>::value) {validate_and_populate_arg(i,prhs[i],A4); ++i;} ELSE_ASSIGN_ARG_4; - if (i < nrhs && is_input_type<arg5_type>::value) {validate_and_populate_arg(i,prhs[i],A5); ++i;} ELSE_ASSIGN_ARG_5; - if (i < nrhs && is_input_type<arg6_type>::value) {validate_and_populate_arg(i,prhs[i],A6); ++i;} ELSE_ASSIGN_ARG_6; - if (i < nrhs && is_input_type<arg7_type>::value) {validate_and_populate_arg(i,prhs[i],A7); ++i;} ELSE_ASSIGN_ARG_7; - if (i < nrhs && is_input_type<arg8_type>::value) {validate_and_populate_arg(i,prhs[i],A8); ++i;} ELSE_ASSIGN_ARG_8; - if (i < nrhs && is_input_type<arg9_type>::value) {validate_and_populate_arg(i,prhs[i],A9); ++i;} ELSE_ASSIGN_ARG_9; - if (i < nrhs && is_input_type<arg10_type>::value) {validate_and_populate_arg(i,prhs[i],A10); ++i;} ELSE_ASSIGN_ARG_10; - if (i < nrhs && is_input_type<arg11_type>::value) {validate_and_populate_arg(i,prhs[i],A11); ++i;} ELSE_ASSIGN_ARG_11; - - f(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11); - - - i = 0; - if (is_output_type<arg1_type>::value) {assign_to_matlab(plhs[i],A1); ++i;} - if (is_output_type<arg2_type>::value) {assign_to_matlab(plhs[i],A2); ++i;} - if (is_output_type<arg3_type>::value) {assign_to_matlab(plhs[i],A3); ++i;} - if (is_output_type<arg4_type>::value) {assign_to_matlab(plhs[i],A4); ++i;} - if (is_output_type<arg5_type>::value) {assign_to_matlab(plhs[i],A5); ++i;} - if (is_output_type<arg6_type>::value) {assign_to_matlab(plhs[i],A6); ++i;} - if (is_output_type<arg7_type>::value) {assign_to_matlab(plhs[i],A7); ++i;} - if (is_output_type<arg8_type>::value) {assign_to_matlab(plhs[i],A8); ++i;} - if (is_output_type<arg9_type>::value) {assign_to_matlab(plhs[i],A9); ++i;} - if (is_output_type<arg10_type>::value) {assign_to_matlab(plhs[i],A10); ++i;} - if (is_output_type<arg11_type>::value) {assign_to_matlab(plhs[i],A11); ++i;} - } - }; - - template <> - struct call_mex_function_helper<12> - { - template <typename funct> - void callit( - const funct& f, - int nlhs, mxArray *plhs[], - int nrhs, const mxArray *prhs[] - ) const - { - typedef typename sig_traits<funct>::arg1_type arg1_type; - typedef typename sig_traits<funct>::arg2_type arg2_type; - typedef typename sig_traits<funct>::arg3_type arg3_type; - typedef typename sig_traits<funct>::arg4_type arg4_type; - typedef typename sig_traits<funct>::arg5_type arg5_type; - typedef typename sig_traits<funct>::arg6_type arg6_type; - typedef typename sig_traits<funct>::arg7_type arg7_type; - typedef typename sig_traits<funct>::arg8_type arg8_type; - typedef typename sig_traits<funct>::arg9_type arg9_type; - typedef typename sig_traits<funct>::arg10_type arg10_type; - typedef typename sig_traits<funct>::arg11_type arg11_type; - typedef typename sig_traits<funct>::arg12_type arg12_type; - - typename basic_type<arg1_type>::type A1; - typename basic_type<arg2_type>::type A2; - typename basic_type<arg3_type>::type A3; - typename basic_type<arg4_type>::type A4; - typename basic_type<arg5_type>::type A5; - typename basic_type<arg6_type>::type A6; - typename basic_type<arg7_type>::type A7; - typename basic_type<arg8_type>::type A8; - typename basic_type<arg9_type>::type A9; - typename basic_type<arg10_type>::type A10; - typename basic_type<arg11_type>::type A11; - typename basic_type<arg12_type>::type A12; - - mark_owned_by_matlab(A1); - mark_owned_by_matlab(A2); - mark_owned_by_matlab(A3); - mark_owned_by_matlab(A4); - mark_owned_by_matlab(A5); - mark_owned_by_matlab(A6); - mark_owned_by_matlab(A7); - mark_owned_by_matlab(A8); - mark_owned_by_matlab(A9); - mark_owned_by_matlab(A10); - mark_owned_by_matlab(A11); - mark_owned_by_matlab(A12); - - int i = 0; - if (i < nrhs && is_input_type<arg1_type>::value) {validate_and_populate_arg(i,prhs[i],A1); ++i;} ELSE_ASSIGN_ARG_1; - if (i < nrhs && is_input_type<arg2_type>::value) {validate_and_populate_arg(i,prhs[i],A2); ++i;} ELSE_ASSIGN_ARG_2; - if (i < nrhs && is_input_type<arg3_type>::value) {validate_and_populate_arg(i,prhs[i],A3); ++i;} ELSE_ASSIGN_ARG_3; - if (i < nrhs && is_input_type<arg4_type>::value) {validate_and_populate_arg(i,prhs[i],A4); ++i;} ELSE_ASSIGN_ARG_4; - if (i < nrhs && is_input_type<arg5_type>::value) {validate_and_populate_arg(i,prhs[i],A5); ++i;} ELSE_ASSIGN_ARG_5; - if (i < nrhs && is_input_type<arg6_type>::value) {validate_and_populate_arg(i,prhs[i],A6); ++i;} ELSE_ASSIGN_ARG_6; - if (i < nrhs && is_input_type<arg7_type>::value) {validate_and_populate_arg(i,prhs[i],A7); ++i;} ELSE_ASSIGN_ARG_7; - if (i < nrhs && is_input_type<arg8_type>::value) {validate_and_populate_arg(i,prhs[i],A8); ++i;} ELSE_ASSIGN_ARG_8; - if (i < nrhs && is_input_type<arg9_type>::value) {validate_and_populate_arg(i,prhs[i],A9); ++i;} ELSE_ASSIGN_ARG_9; - if (i < nrhs && is_input_type<arg10_type>::value) {validate_and_populate_arg(i,prhs[i],A10); ++i;} ELSE_ASSIGN_ARG_10; - if (i < nrhs && is_input_type<arg11_type>::value) {validate_and_populate_arg(i,prhs[i],A11); ++i;} ELSE_ASSIGN_ARG_11; - if (i < nrhs && is_input_type<arg12_type>::value) {validate_and_populate_arg(i,prhs[i],A12); ++i;} ELSE_ASSIGN_ARG_12; - - f(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12); - - - i = 0; - if (is_output_type<arg1_type>::value) {assign_to_matlab(plhs[i],A1); ++i;} - if (is_output_type<arg2_type>::value) {assign_to_matlab(plhs[i],A2); ++i;} - if (is_output_type<arg3_type>::value) {assign_to_matlab(plhs[i],A3); ++i;} - if (is_output_type<arg4_type>::value) {assign_to_matlab(plhs[i],A4); ++i;} - if (is_output_type<arg5_type>::value) {assign_to_matlab(plhs[i],A5); ++i;} - if (is_output_type<arg6_type>::value) {assign_to_matlab(plhs[i],A6); ++i;} - if (is_output_type<arg7_type>::value) {assign_to_matlab(plhs[i],A7); ++i;} - if (is_output_type<arg8_type>::value) {assign_to_matlab(plhs[i],A8); ++i;} - if (is_output_type<arg9_type>::value) {assign_to_matlab(plhs[i],A9); ++i;} - if (is_output_type<arg10_type>::value) {assign_to_matlab(plhs[i],A10); ++i;} - if (is_output_type<arg11_type>::value) {assign_to_matlab(plhs[i],A11); ++i;} - if (is_output_type<arg12_type>::value) {assign_to_matlab(plhs[i],A12); ++i;} - } - }; - - template <> - struct call_mex_function_helper<13> - { - template <typename funct> - void callit( - const funct& f, - int nlhs, mxArray *plhs[], - int nrhs, const mxArray *prhs[] - ) const - { - typedef typename sig_traits<funct>::arg1_type arg1_type; - typedef typename sig_traits<funct>::arg2_type arg2_type; - typedef typename sig_traits<funct>::arg3_type arg3_type; - typedef typename sig_traits<funct>::arg4_type arg4_type; - typedef typename sig_traits<funct>::arg5_type arg5_type; - typedef typename sig_traits<funct>::arg6_type arg6_type; - typedef typename sig_traits<funct>::arg7_type arg7_type; - typedef typename sig_traits<funct>::arg8_type arg8_type; - typedef typename sig_traits<funct>::arg9_type arg9_type; - typedef typename sig_traits<funct>::arg10_type arg10_type; - typedef typename sig_traits<funct>::arg11_type arg11_type; - typedef typename sig_traits<funct>::arg12_type arg12_type; - typedef typename sig_traits<funct>::arg13_type arg13_type; - - typename basic_type<arg1_type>::type A1; - typename basic_type<arg2_type>::type A2; - typename basic_type<arg3_type>::type A3; - typename basic_type<arg4_type>::type A4; - typename basic_type<arg5_type>::type A5; - typename basic_type<arg6_type>::type A6; - typename basic_type<arg7_type>::type A7; - typename basic_type<arg8_type>::type A8; - typename basic_type<arg9_type>::type A9; - typename basic_type<arg10_type>::type A10; - typename basic_type<arg11_type>::type A11; - typename basic_type<arg12_type>::type A12; - typename basic_type<arg13_type>::type A13; - - mark_owned_by_matlab(A1); - mark_owned_by_matlab(A2); - mark_owned_by_matlab(A3); - mark_owned_by_matlab(A4); - mark_owned_by_matlab(A5); - mark_owned_by_matlab(A6); - mark_owned_by_matlab(A7); - mark_owned_by_matlab(A8); - mark_owned_by_matlab(A9); - mark_owned_by_matlab(A10); - mark_owned_by_matlab(A11); - mark_owned_by_matlab(A12); - mark_owned_by_matlab(A13); - - int i = 0; - if (i < nrhs && is_input_type<arg1_type>::value) {validate_and_populate_arg(i,prhs[i],A1); ++i;} ELSE_ASSIGN_ARG_1; - if (i < nrhs && is_input_type<arg2_type>::value) {validate_and_populate_arg(i,prhs[i],A2); ++i;} ELSE_ASSIGN_ARG_2; - if (i < nrhs && is_input_type<arg3_type>::value) {validate_and_populate_arg(i,prhs[i],A3); ++i;} ELSE_ASSIGN_ARG_3; - if (i < nrhs && is_input_type<arg4_type>::value) {validate_and_populate_arg(i,prhs[i],A4); ++i;} ELSE_ASSIGN_ARG_4; - if (i < nrhs && is_input_type<arg5_type>::value) {validate_and_populate_arg(i,prhs[i],A5); ++i;} ELSE_ASSIGN_ARG_5; - if (i < nrhs && is_input_type<arg6_type>::value) {validate_and_populate_arg(i,prhs[i],A6); ++i;} ELSE_ASSIGN_ARG_6; - if (i < nrhs && is_input_type<arg7_type>::value) {validate_and_populate_arg(i,prhs[i],A7); ++i;} ELSE_ASSIGN_ARG_7; - if (i < nrhs && is_input_type<arg8_type>::value) {validate_and_populate_arg(i,prhs[i],A8); ++i;} ELSE_ASSIGN_ARG_8; - if (i < nrhs && is_input_type<arg9_type>::value) {validate_and_populate_arg(i,prhs[i],A9); ++i;} ELSE_ASSIGN_ARG_9; - if (i < nrhs && is_input_type<arg10_type>::value) {validate_and_populate_arg(i,prhs[i],A10); ++i;} ELSE_ASSIGN_ARG_10; - if (i < nrhs && is_input_type<arg11_type>::value) {validate_and_populate_arg(i,prhs[i],A11); ++i;} ELSE_ASSIGN_ARG_11; - if (i < nrhs && is_input_type<arg12_type>::value) {validate_and_populate_arg(i,prhs[i],A12); ++i;} ELSE_ASSIGN_ARG_12; - if (i < nrhs && is_input_type<arg13_type>::value) {validate_and_populate_arg(i,prhs[i],A13); ++i;} ELSE_ASSIGN_ARG_13; - - f(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13); - - - i = 0; - if (is_output_type<arg1_type>::value) {assign_to_matlab(plhs[i],A1); ++i;} - if (is_output_type<arg2_type>::value) {assign_to_matlab(plhs[i],A2); ++i;} - if (is_output_type<arg3_type>::value) {assign_to_matlab(plhs[i],A3); ++i;} - if (is_output_type<arg4_type>::value) {assign_to_matlab(plhs[i],A4); ++i;} - if (is_output_type<arg5_type>::value) {assign_to_matlab(plhs[i],A5); ++i;} - if (is_output_type<arg6_type>::value) {assign_to_matlab(plhs[i],A6); ++i;} - if (is_output_type<arg7_type>::value) {assign_to_matlab(plhs[i],A7); ++i;} - if (is_output_type<arg8_type>::value) {assign_to_matlab(plhs[i],A8); ++i;} - if (is_output_type<arg9_type>::value) {assign_to_matlab(plhs[i],A9); ++i;} - if (is_output_type<arg10_type>::value) {assign_to_matlab(plhs[i],A10); ++i;} - if (is_output_type<arg11_type>::value) {assign_to_matlab(plhs[i],A11); ++i;} - if (is_output_type<arg12_type>::value) {assign_to_matlab(plhs[i],A12); ++i;} - if (is_output_type<arg13_type>::value) {assign_to_matlab(plhs[i],A13); ++i;} - } - }; - - template <> - struct call_mex_function_helper<14> - { - template <typename funct> - void callit( - const funct& f, - int nlhs, mxArray *plhs[], - int nrhs, const mxArray *prhs[] - ) const - { - typedef typename sig_traits<funct>::arg1_type arg1_type; - typedef typename sig_traits<funct>::arg2_type arg2_type; - typedef typename sig_traits<funct>::arg3_type arg3_type; - typedef typename sig_traits<funct>::arg4_type arg4_type; - typedef typename sig_traits<funct>::arg5_type arg5_type; - typedef typename sig_traits<funct>::arg6_type arg6_type; - typedef typename sig_traits<funct>::arg7_type arg7_type; - typedef typename sig_traits<funct>::arg8_type arg8_type; - typedef typename sig_traits<funct>::arg9_type arg9_type; - typedef typename sig_traits<funct>::arg10_type arg10_type; - typedef typename sig_traits<funct>::arg11_type arg11_type; - typedef typename sig_traits<funct>::arg12_type arg12_type; - typedef typename sig_traits<funct>::arg13_type arg13_type; - typedef typename sig_traits<funct>::arg14_type arg14_type; - - typename basic_type<arg1_type>::type A1; - typename basic_type<arg2_type>::type A2; - typename basic_type<arg3_type>::type A3; - typename basic_type<arg4_type>::type A4; - typename basic_type<arg5_type>::type A5; - typename basic_type<arg6_type>::type A6; - typename basic_type<arg7_type>::type A7; - typename basic_type<arg8_type>::type A8; - typename basic_type<arg9_type>::type A9; - typename basic_type<arg10_type>::type A10; - typename basic_type<arg11_type>::type A11; - typename basic_type<arg12_type>::type A12; - typename basic_type<arg13_type>::type A13; - typename basic_type<arg14_type>::type A14; - - mark_owned_by_matlab(A1); - mark_owned_by_matlab(A2); - mark_owned_by_matlab(A3); - mark_owned_by_matlab(A4); - mark_owned_by_matlab(A5); - mark_owned_by_matlab(A6); - mark_owned_by_matlab(A7); - mark_owned_by_matlab(A8); - mark_owned_by_matlab(A9); - mark_owned_by_matlab(A10); - mark_owned_by_matlab(A11); - mark_owned_by_matlab(A12); - mark_owned_by_matlab(A13); - mark_owned_by_matlab(A14); - - int i = 0; - if (i < nrhs && is_input_type<arg1_type>::value) {validate_and_populate_arg(i,prhs[i],A1); ++i;} ELSE_ASSIGN_ARG_1; - if (i < nrhs && is_input_type<arg2_type>::value) {validate_and_populate_arg(i,prhs[i],A2); ++i;} ELSE_ASSIGN_ARG_2; - if (i < nrhs && is_input_type<arg3_type>::value) {validate_and_populate_arg(i,prhs[i],A3); ++i;} ELSE_ASSIGN_ARG_3; - if (i < nrhs && is_input_type<arg4_type>::value) {validate_and_populate_arg(i,prhs[i],A4); ++i;} ELSE_ASSIGN_ARG_4; - if (i < nrhs && is_input_type<arg5_type>::value) {validate_and_populate_arg(i,prhs[i],A5); ++i;} ELSE_ASSIGN_ARG_5; - if (i < nrhs && is_input_type<arg6_type>::value) {validate_and_populate_arg(i,prhs[i],A6); ++i;} ELSE_ASSIGN_ARG_6; - if (i < nrhs && is_input_type<arg7_type>::value) {validate_and_populate_arg(i,prhs[i],A7); ++i;} ELSE_ASSIGN_ARG_7; - if (i < nrhs && is_input_type<arg8_type>::value) {validate_and_populate_arg(i,prhs[i],A8); ++i;} ELSE_ASSIGN_ARG_8; - if (i < nrhs && is_input_type<arg9_type>::value) {validate_and_populate_arg(i,prhs[i],A9); ++i;} ELSE_ASSIGN_ARG_9; - if (i < nrhs && is_input_type<arg10_type>::value) {validate_and_populate_arg(i,prhs[i],A10); ++i;} ELSE_ASSIGN_ARG_10; - if (i < nrhs && is_input_type<arg11_type>::value) {validate_and_populate_arg(i,prhs[i],A11); ++i;} ELSE_ASSIGN_ARG_11; - if (i < nrhs && is_input_type<arg12_type>::value) {validate_and_populate_arg(i,prhs[i],A12); ++i;} ELSE_ASSIGN_ARG_12; - if (i < nrhs && is_input_type<arg13_type>::value) {validate_and_populate_arg(i,prhs[i],A13); ++i;} ELSE_ASSIGN_ARG_13; - if (i < nrhs && is_input_type<arg14_type>::value) {validate_and_populate_arg(i,prhs[i],A14); ++i;} ELSE_ASSIGN_ARG_14; - - f(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14); - - - i = 0; - if (is_output_type<arg1_type>::value) {assign_to_matlab(plhs[i],A1); ++i;} - if (is_output_type<arg2_type>::value) {assign_to_matlab(plhs[i],A2); ++i;} - if (is_output_type<arg3_type>::value) {assign_to_matlab(plhs[i],A3); ++i;} - if (is_output_type<arg4_type>::value) {assign_to_matlab(plhs[i],A4); ++i;} - if (is_output_type<arg5_type>::value) {assign_to_matlab(plhs[i],A5); ++i;} - if (is_output_type<arg6_type>::value) {assign_to_matlab(plhs[i],A6); ++i;} - if (is_output_type<arg7_type>::value) {assign_to_matlab(plhs[i],A7); ++i;} - if (is_output_type<arg8_type>::value) {assign_to_matlab(plhs[i],A8); ++i;} - if (is_output_type<arg9_type>::value) {assign_to_matlab(plhs[i],A9); ++i;} - if (is_output_type<arg10_type>::value) {assign_to_matlab(plhs[i],A10); ++i;} - if (is_output_type<arg11_type>::value) {assign_to_matlab(plhs[i],A11); ++i;} - if (is_output_type<arg12_type>::value) {assign_to_matlab(plhs[i],A12); ++i;} - if (is_output_type<arg13_type>::value) {assign_to_matlab(plhs[i],A13); ++i;} - if (is_output_type<arg14_type>::value) {assign_to_matlab(plhs[i],A14); ++i;} - } - }; - - template <> - struct call_mex_function_helper<15> - { - template <typename funct> - void callit( - const funct& f, - int nlhs, mxArray *plhs[], - int nrhs, const mxArray *prhs[] - ) const - { - typedef typename sig_traits<funct>::arg1_type arg1_type; - typedef typename sig_traits<funct>::arg2_type arg2_type; - typedef typename sig_traits<funct>::arg3_type arg3_type; - typedef typename sig_traits<funct>::arg4_type arg4_type; - typedef typename sig_traits<funct>::arg5_type arg5_type; - typedef typename sig_traits<funct>::arg6_type arg6_type; - typedef typename sig_traits<funct>::arg7_type arg7_type; - typedef typename sig_traits<funct>::arg8_type arg8_type; - typedef typename sig_traits<funct>::arg9_type arg9_type; - typedef typename sig_traits<funct>::arg10_type arg10_type; - typedef typename sig_traits<funct>::arg11_type arg11_type; - typedef typename sig_traits<funct>::arg12_type arg12_type; - typedef typename sig_traits<funct>::arg13_type arg13_type; - typedef typename sig_traits<funct>::arg14_type arg14_type; - typedef typename sig_traits<funct>::arg15_type arg15_type; - - typename basic_type<arg1_type>::type A1; - typename basic_type<arg2_type>::type A2; - typename basic_type<arg3_type>::type A3; - typename basic_type<arg4_type>::type A4; - typename basic_type<arg5_type>::type A5; - typename basic_type<arg6_type>::type A6; - typename basic_type<arg7_type>::type A7; - typename basic_type<arg8_type>::type A8; - typename basic_type<arg9_type>::type A9; - typename basic_type<arg10_type>::type A10; - typename basic_type<arg11_type>::type A11; - typename basic_type<arg12_type>::type A12; - typename basic_type<arg13_type>::type A13; - typename basic_type<arg14_type>::type A14; - typename basic_type<arg15_type>::type A15; - - mark_owned_by_matlab(A1); - mark_owned_by_matlab(A2); - mark_owned_by_matlab(A3); - mark_owned_by_matlab(A4); - mark_owned_by_matlab(A5); - mark_owned_by_matlab(A6); - mark_owned_by_matlab(A7); - mark_owned_by_matlab(A8); - mark_owned_by_matlab(A9); - mark_owned_by_matlab(A10); - mark_owned_by_matlab(A11); - mark_owned_by_matlab(A12); - mark_owned_by_matlab(A13); - mark_owned_by_matlab(A14); - mark_owned_by_matlab(A15); - - int i = 0; - if (i < nrhs && is_input_type<arg1_type>::value) {validate_and_populate_arg(i,prhs[i],A1); ++i;} ELSE_ASSIGN_ARG_1; - if (i < nrhs && is_input_type<arg2_type>::value) {validate_and_populate_arg(i,prhs[i],A2); ++i;} ELSE_ASSIGN_ARG_2; - if (i < nrhs && is_input_type<arg3_type>::value) {validate_and_populate_arg(i,prhs[i],A3); ++i;} ELSE_ASSIGN_ARG_3; - if (i < nrhs && is_input_type<arg4_type>::value) {validate_and_populate_arg(i,prhs[i],A4); ++i;} ELSE_ASSIGN_ARG_4; - if (i < nrhs && is_input_type<arg5_type>::value) {validate_and_populate_arg(i,prhs[i],A5); ++i;} ELSE_ASSIGN_ARG_5; - if (i < nrhs && is_input_type<arg6_type>::value) {validate_and_populate_arg(i,prhs[i],A6); ++i;} ELSE_ASSIGN_ARG_6; - if (i < nrhs && is_input_type<arg7_type>::value) {validate_and_populate_arg(i,prhs[i],A7); ++i;} ELSE_ASSIGN_ARG_7; - if (i < nrhs && is_input_type<arg8_type>::value) {validate_and_populate_arg(i,prhs[i],A8); ++i;} ELSE_ASSIGN_ARG_8; - if (i < nrhs && is_input_type<arg9_type>::value) {validate_and_populate_arg(i,prhs[i],A9); ++i;} ELSE_ASSIGN_ARG_9; - if (i < nrhs && is_input_type<arg10_type>::value) {validate_and_populate_arg(i,prhs[i],A10); ++i;} ELSE_ASSIGN_ARG_10; - if (i < nrhs && is_input_type<arg11_type>::value) {validate_and_populate_arg(i,prhs[i],A11); ++i;} ELSE_ASSIGN_ARG_11; - if (i < nrhs && is_input_type<arg12_type>::value) {validate_and_populate_arg(i,prhs[i],A12); ++i;} ELSE_ASSIGN_ARG_12; - if (i < nrhs && is_input_type<arg13_type>::value) {validate_and_populate_arg(i,prhs[i],A13); ++i;} ELSE_ASSIGN_ARG_13; - if (i < nrhs && is_input_type<arg14_type>::value) {validate_and_populate_arg(i,prhs[i],A14); ++i;} ELSE_ASSIGN_ARG_14; - if (i < nrhs && is_input_type<arg15_type>::value) {validate_and_populate_arg(i,prhs[i],A15); ++i;} ELSE_ASSIGN_ARG_15; - - f(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15); - - - i = 0; - if (is_output_type<arg1_type>::value) {assign_to_matlab(plhs[i],A1); ++i;} - if (is_output_type<arg2_type>::value) {assign_to_matlab(plhs[i],A2); ++i;} - if (is_output_type<arg3_type>::value) {assign_to_matlab(plhs[i],A3); ++i;} - if (is_output_type<arg4_type>::value) {assign_to_matlab(plhs[i],A4); ++i;} - if (is_output_type<arg5_type>::value) {assign_to_matlab(plhs[i],A5); ++i;} - if (is_output_type<arg6_type>::value) {assign_to_matlab(plhs[i],A6); ++i;} - if (is_output_type<arg7_type>::value) {assign_to_matlab(plhs[i],A7); ++i;} - if (is_output_type<arg8_type>::value) {assign_to_matlab(plhs[i],A8); ++i;} - if (is_output_type<arg9_type>::value) {assign_to_matlab(plhs[i],A9); ++i;} - if (is_output_type<arg10_type>::value) {assign_to_matlab(plhs[i],A10); ++i;} - if (is_output_type<arg11_type>::value) {assign_to_matlab(plhs[i],A11); ++i;} - if (is_output_type<arg12_type>::value) {assign_to_matlab(plhs[i],A12); ++i;} - if (is_output_type<arg13_type>::value) {assign_to_matlab(plhs[i],A13); ++i;} - if (is_output_type<arg14_type>::value) {assign_to_matlab(plhs[i],A14); ++i;} - if (is_output_type<arg15_type>::value) {assign_to_matlab(plhs[i],A15); ++i;} - } - }; - - template <> - struct call_mex_function_helper<16> - { - template <typename funct> - void callit( - const funct& f, - int nlhs, mxArray *plhs[], - int nrhs, const mxArray *prhs[] - ) const - { - typedef typename sig_traits<funct>::arg1_type arg1_type; - typedef typename sig_traits<funct>::arg2_type arg2_type; - typedef typename sig_traits<funct>::arg3_type arg3_type; - typedef typename sig_traits<funct>::arg4_type arg4_type; - typedef typename sig_traits<funct>::arg5_type arg5_type; - typedef typename sig_traits<funct>::arg6_type arg6_type; - typedef typename sig_traits<funct>::arg7_type arg7_type; - typedef typename sig_traits<funct>::arg8_type arg8_type; - typedef typename sig_traits<funct>::arg9_type arg9_type; - typedef typename sig_traits<funct>::arg10_type arg10_type; - typedef typename sig_traits<funct>::arg11_type arg11_type; - typedef typename sig_traits<funct>::arg12_type arg12_type; - typedef typename sig_traits<funct>::arg13_type arg13_type; - typedef typename sig_traits<funct>::arg14_type arg14_type; - typedef typename sig_traits<funct>::arg15_type arg15_type; - typedef typename sig_traits<funct>::arg16_type arg16_type; - - typename basic_type<arg1_type>::type A1; - typename basic_type<arg2_type>::type A2; - typename basic_type<arg3_type>::type A3; - typename basic_type<arg4_type>::type A4; - typename basic_type<arg5_type>::type A5; - typename basic_type<arg6_type>::type A6; - typename basic_type<arg7_type>::type A7; - typename basic_type<arg8_type>::type A8; - typename basic_type<arg9_type>::type A9; - typename basic_type<arg10_type>::type A10; - typename basic_type<arg11_type>::type A11; - typename basic_type<arg12_type>::type A12; - typename basic_type<arg13_type>::type A13; - typename basic_type<arg14_type>::type A14; - typename basic_type<arg15_type>::type A15; - typename basic_type<arg16_type>::type A16; - - mark_owned_by_matlab(A1); - mark_owned_by_matlab(A2); - mark_owned_by_matlab(A3); - mark_owned_by_matlab(A4); - mark_owned_by_matlab(A5); - mark_owned_by_matlab(A6); - mark_owned_by_matlab(A7); - mark_owned_by_matlab(A8); - mark_owned_by_matlab(A9); - mark_owned_by_matlab(A10); - mark_owned_by_matlab(A11); - mark_owned_by_matlab(A12); - mark_owned_by_matlab(A13); - mark_owned_by_matlab(A14); - mark_owned_by_matlab(A15); - mark_owned_by_matlab(A16); - - int i = 0; - if (i < nrhs && is_input_type<arg1_type>::value) {validate_and_populate_arg(i,prhs[i],A1); ++i;} ELSE_ASSIGN_ARG_1; - if (i < nrhs && is_input_type<arg2_type>::value) {validate_and_populate_arg(i,prhs[i],A2); ++i;} ELSE_ASSIGN_ARG_2; - if (i < nrhs && is_input_type<arg3_type>::value) {validate_and_populate_arg(i,prhs[i],A3); ++i;} ELSE_ASSIGN_ARG_3; - if (i < nrhs && is_input_type<arg4_type>::value) {validate_and_populate_arg(i,prhs[i],A4); ++i;} ELSE_ASSIGN_ARG_4; - if (i < nrhs && is_input_type<arg5_type>::value) {validate_and_populate_arg(i,prhs[i],A5); ++i;} ELSE_ASSIGN_ARG_5; - if (i < nrhs && is_input_type<arg6_type>::value) {validate_and_populate_arg(i,prhs[i],A6); ++i;} ELSE_ASSIGN_ARG_6; - if (i < nrhs && is_input_type<arg7_type>::value) {validate_and_populate_arg(i,prhs[i],A7); ++i;} ELSE_ASSIGN_ARG_7; - if (i < nrhs && is_input_type<arg8_type>::value) {validate_and_populate_arg(i,prhs[i],A8); ++i;} ELSE_ASSIGN_ARG_8; - if (i < nrhs && is_input_type<arg9_type>::value) {validate_and_populate_arg(i,prhs[i],A9); ++i;} ELSE_ASSIGN_ARG_9; - if (i < nrhs && is_input_type<arg10_type>::value) {validate_and_populate_arg(i,prhs[i],A10); ++i;} ELSE_ASSIGN_ARG_10; - if (i < nrhs && is_input_type<arg11_type>::value) {validate_and_populate_arg(i,prhs[i],A11); ++i;} ELSE_ASSIGN_ARG_11; - if (i < nrhs && is_input_type<arg12_type>::value) {validate_and_populate_arg(i,prhs[i],A12); ++i;} ELSE_ASSIGN_ARG_12; - if (i < nrhs && is_input_type<arg13_type>::value) {validate_and_populate_arg(i,prhs[i],A13); ++i;} ELSE_ASSIGN_ARG_13; - if (i < nrhs && is_input_type<arg14_type>::value) {validate_and_populate_arg(i,prhs[i],A14); ++i;} ELSE_ASSIGN_ARG_14; - if (i < nrhs && is_input_type<arg15_type>::value) {validate_and_populate_arg(i,prhs[i],A15); ++i;} ELSE_ASSIGN_ARG_15; - if (i < nrhs && is_input_type<arg16_type>::value) {validate_and_populate_arg(i,prhs[i],A16); ++i;} ELSE_ASSIGN_ARG_16; - - f(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15,A16); - - - i = 0; - if (is_output_type<arg1_type>::value) {assign_to_matlab(plhs[i],A1); ++i;} - if (is_output_type<arg2_type>::value) {assign_to_matlab(plhs[i],A2); ++i;} - if (is_output_type<arg3_type>::value) {assign_to_matlab(plhs[i],A3); ++i;} - if (is_output_type<arg4_type>::value) {assign_to_matlab(plhs[i],A4); ++i;} - if (is_output_type<arg5_type>::value) {assign_to_matlab(plhs[i],A5); ++i;} - if (is_output_type<arg6_type>::value) {assign_to_matlab(plhs[i],A6); ++i;} - if (is_output_type<arg7_type>::value) {assign_to_matlab(plhs[i],A7); ++i;} - if (is_output_type<arg8_type>::value) {assign_to_matlab(plhs[i],A8); ++i;} - if (is_output_type<arg9_type>::value) {assign_to_matlab(plhs[i],A9); ++i;} - if (is_output_type<arg10_type>::value) {assign_to_matlab(plhs[i],A10); ++i;} - if (is_output_type<arg11_type>::value) {assign_to_matlab(plhs[i],A11); ++i;} - if (is_output_type<arg12_type>::value) {assign_to_matlab(plhs[i],A12); ++i;} - if (is_output_type<arg13_type>::value) {assign_to_matlab(plhs[i],A13); ++i;} - if (is_output_type<arg14_type>::value) {assign_to_matlab(plhs[i],A14); ++i;} - if (is_output_type<arg15_type>::value) {assign_to_matlab(plhs[i],A15); ++i;} - if (is_output_type<arg16_type>::value) {assign_to_matlab(plhs[i],A16); ++i;} - } - }; - - template <> - struct call_mex_function_helper<17> - { - template <typename funct> - void callit( - const funct& f, - int nlhs, mxArray *plhs[], - int nrhs, const mxArray *prhs[] - ) const - { - typedef typename sig_traits<funct>::arg1_type arg1_type; - typedef typename sig_traits<funct>::arg2_type arg2_type; - typedef typename sig_traits<funct>::arg3_type arg3_type; - typedef typename sig_traits<funct>::arg4_type arg4_type; - typedef typename sig_traits<funct>::arg5_type arg5_type; - typedef typename sig_traits<funct>::arg6_type arg6_type; - typedef typename sig_traits<funct>::arg7_type arg7_type; - typedef typename sig_traits<funct>::arg8_type arg8_type; - typedef typename sig_traits<funct>::arg9_type arg9_type; - typedef typename sig_traits<funct>::arg10_type arg10_type; - typedef typename sig_traits<funct>::arg11_type arg11_type; - typedef typename sig_traits<funct>::arg12_type arg12_type; - typedef typename sig_traits<funct>::arg13_type arg13_type; - typedef typename sig_traits<funct>::arg14_type arg14_type; - typedef typename sig_traits<funct>::arg15_type arg15_type; - typedef typename sig_traits<funct>::arg16_type arg16_type; - typedef typename sig_traits<funct>::arg17_type arg17_type; - - typename basic_type<arg1_type>::type A1; - typename basic_type<arg2_type>::type A2; - typename basic_type<arg3_type>::type A3; - typename basic_type<arg4_type>::type A4; - typename basic_type<arg5_type>::type A5; - typename basic_type<arg6_type>::type A6; - typename basic_type<arg7_type>::type A7; - typename basic_type<arg8_type>::type A8; - typename basic_type<arg9_type>::type A9; - typename basic_type<arg10_type>::type A10; - typename basic_type<arg11_type>::type A11; - typename basic_type<arg12_type>::type A12; - typename basic_type<arg13_type>::type A13; - typename basic_type<arg14_type>::type A14; - typename basic_type<arg15_type>::type A15; - typename basic_type<arg16_type>::type A16; - typename basic_type<arg17_type>::type A17; - - mark_owned_by_matlab(A1); - mark_owned_by_matlab(A2); - mark_owned_by_matlab(A3); - mark_owned_by_matlab(A4); - mark_owned_by_matlab(A5); - mark_owned_by_matlab(A6); - mark_owned_by_matlab(A7); - mark_owned_by_matlab(A8); - mark_owned_by_matlab(A9); - mark_owned_by_matlab(A10); - mark_owned_by_matlab(A11); - mark_owned_by_matlab(A12); - mark_owned_by_matlab(A13); - mark_owned_by_matlab(A14); - mark_owned_by_matlab(A15); - mark_owned_by_matlab(A16); - mark_owned_by_matlab(A17); - - int i = 0; - if (i < nrhs && is_input_type<arg1_type>::value) {validate_and_populate_arg(i,prhs[i],A1); ++i;} ELSE_ASSIGN_ARG_1; - if (i < nrhs && is_input_type<arg2_type>::value) {validate_and_populate_arg(i,prhs[i],A2); ++i;} ELSE_ASSIGN_ARG_2; - if (i < nrhs && is_input_type<arg3_type>::value) {validate_and_populate_arg(i,prhs[i],A3); ++i;} ELSE_ASSIGN_ARG_3; - if (i < nrhs && is_input_type<arg4_type>::value) {validate_and_populate_arg(i,prhs[i],A4); ++i;} ELSE_ASSIGN_ARG_4; - if (i < nrhs && is_input_type<arg5_type>::value) {validate_and_populate_arg(i,prhs[i],A5); ++i;} ELSE_ASSIGN_ARG_5; - if (i < nrhs && is_input_type<arg6_type>::value) {validate_and_populate_arg(i,prhs[i],A6); ++i;} ELSE_ASSIGN_ARG_6; - if (i < nrhs && is_input_type<arg7_type>::value) {validate_and_populate_arg(i,prhs[i],A7); ++i;} ELSE_ASSIGN_ARG_7; - if (i < nrhs && is_input_type<arg8_type>::value) {validate_and_populate_arg(i,prhs[i],A8); ++i;} ELSE_ASSIGN_ARG_8; - if (i < nrhs && is_input_type<arg9_type>::value) {validate_and_populate_arg(i,prhs[i],A9); ++i;} ELSE_ASSIGN_ARG_9; - if (i < nrhs && is_input_type<arg10_type>::value) {validate_and_populate_arg(i,prhs[i],A10); ++i;} ELSE_ASSIGN_ARG_10; - if (i < nrhs && is_input_type<arg11_type>::value) {validate_and_populate_arg(i,prhs[i],A11); ++i;} ELSE_ASSIGN_ARG_11; - if (i < nrhs && is_input_type<arg12_type>::value) {validate_and_populate_arg(i,prhs[i],A12); ++i;} ELSE_ASSIGN_ARG_12; - if (i < nrhs && is_input_type<arg13_type>::value) {validate_and_populate_arg(i,prhs[i],A13); ++i;} ELSE_ASSIGN_ARG_13; - if (i < nrhs && is_input_type<arg14_type>::value) {validate_and_populate_arg(i,prhs[i],A14); ++i;} ELSE_ASSIGN_ARG_14; - if (i < nrhs && is_input_type<arg15_type>::value) {validate_and_populate_arg(i,prhs[i],A15); ++i;} ELSE_ASSIGN_ARG_15; - if (i < nrhs && is_input_type<arg16_type>::value) {validate_and_populate_arg(i,prhs[i],A16); ++i;} ELSE_ASSIGN_ARG_16; - if (i < nrhs && is_input_type<arg17_type>::value) {validate_and_populate_arg(i,prhs[i],A17); ++i;} ELSE_ASSIGN_ARG_17; - - f(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15,A16,A17); - - - i = 0; - if (is_output_type<arg1_type>::value) {assign_to_matlab(plhs[i],A1); ++i;} - if (is_output_type<arg2_type>::value) {assign_to_matlab(plhs[i],A2); ++i;} - if (is_output_type<arg3_type>::value) {assign_to_matlab(plhs[i],A3); ++i;} - if (is_output_type<arg4_type>::value) {assign_to_matlab(plhs[i],A4); ++i;} - if (is_output_type<arg5_type>::value) {assign_to_matlab(plhs[i],A5); ++i;} - if (is_output_type<arg6_type>::value) {assign_to_matlab(plhs[i],A6); ++i;} - if (is_output_type<arg7_type>::value) {assign_to_matlab(plhs[i],A7); ++i;} - if (is_output_type<arg8_type>::value) {assign_to_matlab(plhs[i],A8); ++i;} - if (is_output_type<arg9_type>::value) {assign_to_matlab(plhs[i],A9); ++i;} - if (is_output_type<arg10_type>::value) {assign_to_matlab(plhs[i],A10); ++i;} - if (is_output_type<arg11_type>::value) {assign_to_matlab(plhs[i],A11); ++i;} - if (is_output_type<arg12_type>::value) {assign_to_matlab(plhs[i],A12); ++i;} - if (is_output_type<arg13_type>::value) {assign_to_matlab(plhs[i],A13); ++i;} - if (is_output_type<arg14_type>::value) {assign_to_matlab(plhs[i],A14); ++i;} - if (is_output_type<arg15_type>::value) {assign_to_matlab(plhs[i],A15); ++i;} - if (is_output_type<arg16_type>::value) {assign_to_matlab(plhs[i],A16); ++i;} - if (is_output_type<arg17_type>::value) {assign_to_matlab(plhs[i],A17); ++i;} - } - }; - - template <> - struct call_mex_function_helper<18> - { - template <typename funct> - void callit( - const funct& f, - int nlhs, mxArray *plhs[], - int nrhs, const mxArray *prhs[] - ) const - { - typedef typename sig_traits<funct>::arg1_type arg1_type; - typedef typename sig_traits<funct>::arg2_type arg2_type; - typedef typename sig_traits<funct>::arg3_type arg3_type; - typedef typename sig_traits<funct>::arg4_type arg4_type; - typedef typename sig_traits<funct>::arg5_type arg5_type; - typedef typename sig_traits<funct>::arg6_type arg6_type; - typedef typename sig_traits<funct>::arg7_type arg7_type; - typedef typename sig_traits<funct>::arg8_type arg8_type; - typedef typename sig_traits<funct>::arg9_type arg9_type; - typedef typename sig_traits<funct>::arg10_type arg10_type; - typedef typename sig_traits<funct>::arg11_type arg11_type; - typedef typename sig_traits<funct>::arg12_type arg12_type; - typedef typename sig_traits<funct>::arg13_type arg13_type; - typedef typename sig_traits<funct>::arg14_type arg14_type; - typedef typename sig_traits<funct>::arg15_type arg15_type; - typedef typename sig_traits<funct>::arg16_type arg16_type; - typedef typename sig_traits<funct>::arg17_type arg17_type; - typedef typename sig_traits<funct>::arg18_type arg18_type; - - typename basic_type<arg1_type>::type A1; - typename basic_type<arg2_type>::type A2; - typename basic_type<arg3_type>::type A3; - typename basic_type<arg4_type>::type A4; - typename basic_type<arg5_type>::type A5; - typename basic_type<arg6_type>::type A6; - typename basic_type<arg7_type>::type A7; - typename basic_type<arg8_type>::type A8; - typename basic_type<arg9_type>::type A9; - typename basic_type<arg10_type>::type A10; - typename basic_type<arg11_type>::type A11; - typename basic_type<arg12_type>::type A12; - typename basic_type<arg13_type>::type A13; - typename basic_type<arg14_type>::type A14; - typename basic_type<arg15_type>::type A15; - typename basic_type<arg16_type>::type A16; - typename basic_type<arg17_type>::type A17; - typename basic_type<arg18_type>::type A18; - - mark_owned_by_matlab(A1); - mark_owned_by_matlab(A2); - mark_owned_by_matlab(A3); - mark_owned_by_matlab(A4); - mark_owned_by_matlab(A5); - mark_owned_by_matlab(A6); - mark_owned_by_matlab(A7); - mark_owned_by_matlab(A8); - mark_owned_by_matlab(A9); - mark_owned_by_matlab(A10); - mark_owned_by_matlab(A11); - mark_owned_by_matlab(A12); - mark_owned_by_matlab(A13); - mark_owned_by_matlab(A14); - mark_owned_by_matlab(A15); - mark_owned_by_matlab(A16); - mark_owned_by_matlab(A17); - mark_owned_by_matlab(A18); - - int i = 0; - if (i < nrhs && is_input_type<arg1_type>::value) {validate_and_populate_arg(i,prhs[i],A1); ++i;} ELSE_ASSIGN_ARG_1; - if (i < nrhs && is_input_type<arg2_type>::value) {validate_and_populate_arg(i,prhs[i],A2); ++i;} ELSE_ASSIGN_ARG_2; - if (i < nrhs && is_input_type<arg3_type>::value) {validate_and_populate_arg(i,prhs[i],A3); ++i;} ELSE_ASSIGN_ARG_3; - if (i < nrhs && is_input_type<arg4_type>::value) {validate_and_populate_arg(i,prhs[i],A4); ++i;} ELSE_ASSIGN_ARG_4; - if (i < nrhs && is_input_type<arg5_type>::value) {validate_and_populate_arg(i,prhs[i],A5); ++i;} ELSE_ASSIGN_ARG_5; - if (i < nrhs && is_input_type<arg6_type>::value) {validate_and_populate_arg(i,prhs[i],A6); ++i;} ELSE_ASSIGN_ARG_6; - if (i < nrhs && is_input_type<arg7_type>::value) {validate_and_populate_arg(i,prhs[i],A7); ++i;} ELSE_ASSIGN_ARG_7; - if (i < nrhs && is_input_type<arg8_type>::value) {validate_and_populate_arg(i,prhs[i],A8); ++i;} ELSE_ASSIGN_ARG_8; - if (i < nrhs && is_input_type<arg9_type>::value) {validate_and_populate_arg(i,prhs[i],A9); ++i;} ELSE_ASSIGN_ARG_9; - if (i < nrhs && is_input_type<arg10_type>::value) {validate_and_populate_arg(i,prhs[i],A10); ++i;} ELSE_ASSIGN_ARG_10; - if (i < nrhs && is_input_type<arg11_type>::value) {validate_and_populate_arg(i,prhs[i],A11); ++i;} ELSE_ASSIGN_ARG_11; - if (i < nrhs && is_input_type<arg12_type>::value) {validate_and_populate_arg(i,prhs[i],A12); ++i;} ELSE_ASSIGN_ARG_12; - if (i < nrhs && is_input_type<arg13_type>::value) {validate_and_populate_arg(i,prhs[i],A13); ++i;} ELSE_ASSIGN_ARG_13; - if (i < nrhs && is_input_type<arg14_type>::value) {validate_and_populate_arg(i,prhs[i],A14); ++i;} ELSE_ASSIGN_ARG_14; - if (i < nrhs && is_input_type<arg15_type>::value) {validate_and_populate_arg(i,prhs[i],A15); ++i;} ELSE_ASSIGN_ARG_15; - if (i < nrhs && is_input_type<arg16_type>::value) {validate_and_populate_arg(i,prhs[i],A16); ++i;} ELSE_ASSIGN_ARG_16; - if (i < nrhs && is_input_type<arg17_type>::value) {validate_and_populate_arg(i,prhs[i],A17); ++i;} ELSE_ASSIGN_ARG_17; - if (i < nrhs && is_input_type<arg18_type>::value) {validate_and_populate_arg(i,prhs[i],A18); ++i;} ELSE_ASSIGN_ARG_18; - - f(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15,A16,A17,A18); - - - i = 0; - if (is_output_type<arg1_type>::value) {assign_to_matlab(plhs[i],A1); ++i;} - if (is_output_type<arg2_type>::value) {assign_to_matlab(plhs[i],A2); ++i;} - if (is_output_type<arg3_type>::value) {assign_to_matlab(plhs[i],A3); ++i;} - if (is_output_type<arg4_type>::value) {assign_to_matlab(plhs[i],A4); ++i;} - if (is_output_type<arg5_type>::value) {assign_to_matlab(plhs[i],A5); ++i;} - if (is_output_type<arg6_type>::value) {assign_to_matlab(plhs[i],A6); ++i;} - if (is_output_type<arg7_type>::value) {assign_to_matlab(plhs[i],A7); ++i;} - if (is_output_type<arg8_type>::value) {assign_to_matlab(plhs[i],A8); ++i;} - if (is_output_type<arg9_type>::value) {assign_to_matlab(plhs[i],A9); ++i;} - if (is_output_type<arg10_type>::value) {assign_to_matlab(plhs[i],A10); ++i;} - if (is_output_type<arg11_type>::value) {assign_to_matlab(plhs[i],A11); ++i;} - if (is_output_type<arg12_type>::value) {assign_to_matlab(plhs[i],A12); ++i;} - if (is_output_type<arg13_type>::value) {assign_to_matlab(plhs[i],A13); ++i;} - if (is_output_type<arg14_type>::value) {assign_to_matlab(plhs[i],A14); ++i;} - if (is_output_type<arg15_type>::value) {assign_to_matlab(plhs[i],A15); ++i;} - if (is_output_type<arg16_type>::value) {assign_to_matlab(plhs[i],A16); ++i;} - if (is_output_type<arg17_type>::value) {assign_to_matlab(plhs[i],A17); ++i;} - if (is_output_type<arg18_type>::value) {assign_to_matlab(plhs[i],A18); ++i;} - } - }; - - template <> - struct call_mex_function_helper<19> - { - template <typename funct> - void callit( - const funct& f, - int nlhs, mxArray *plhs[], - int nrhs, const mxArray *prhs[] - ) const - { - typedef typename sig_traits<funct>::arg1_type arg1_type; - typedef typename sig_traits<funct>::arg2_type arg2_type; - typedef typename sig_traits<funct>::arg3_type arg3_type; - typedef typename sig_traits<funct>::arg4_type arg4_type; - typedef typename sig_traits<funct>::arg5_type arg5_type; - typedef typename sig_traits<funct>::arg6_type arg6_type; - typedef typename sig_traits<funct>::arg7_type arg7_type; - typedef typename sig_traits<funct>::arg8_type arg8_type; - typedef typename sig_traits<funct>::arg9_type arg9_type; - typedef typename sig_traits<funct>::arg10_type arg10_type; - typedef typename sig_traits<funct>::arg11_type arg11_type; - typedef typename sig_traits<funct>::arg12_type arg12_type; - typedef typename sig_traits<funct>::arg13_type arg13_type; - typedef typename sig_traits<funct>::arg14_type arg14_type; - typedef typename sig_traits<funct>::arg15_type arg15_type; - typedef typename sig_traits<funct>::arg16_type arg16_type; - typedef typename sig_traits<funct>::arg17_type arg17_type; - typedef typename sig_traits<funct>::arg18_type arg18_type; - typedef typename sig_traits<funct>::arg19_type arg19_type; - - typename basic_type<arg1_type>::type A1; - typename basic_type<arg2_type>::type A2; - typename basic_type<arg3_type>::type A3; - typename basic_type<arg4_type>::type A4; - typename basic_type<arg5_type>::type A5; - typename basic_type<arg6_type>::type A6; - typename basic_type<arg7_type>::type A7; - typename basic_type<arg8_type>::type A8; - typename basic_type<arg9_type>::type A9; - typename basic_type<arg10_type>::type A10; - typename basic_type<arg11_type>::type A11; - typename basic_type<arg12_type>::type A12; - typename basic_type<arg13_type>::type A13; - typename basic_type<arg14_type>::type A14; - typename basic_type<arg15_type>::type A15; - typename basic_type<arg16_type>::type A16; - typename basic_type<arg17_type>::type A17; - typename basic_type<arg18_type>::type A18; - typename basic_type<arg19_type>::type A19; - - mark_owned_by_matlab(A1); - mark_owned_by_matlab(A2); - mark_owned_by_matlab(A3); - mark_owned_by_matlab(A4); - mark_owned_by_matlab(A5); - mark_owned_by_matlab(A6); - mark_owned_by_matlab(A7); - mark_owned_by_matlab(A8); - mark_owned_by_matlab(A9); - mark_owned_by_matlab(A10); - mark_owned_by_matlab(A11); - mark_owned_by_matlab(A12); - mark_owned_by_matlab(A13); - mark_owned_by_matlab(A14); - mark_owned_by_matlab(A15); - mark_owned_by_matlab(A16); - mark_owned_by_matlab(A17); - mark_owned_by_matlab(A18); - mark_owned_by_matlab(A19); - - int i = 0; - if (i < nrhs && is_input_type<arg1_type>::value) {validate_and_populate_arg(i,prhs[i],A1); ++i;} ELSE_ASSIGN_ARG_1; - if (i < nrhs && is_input_type<arg2_type>::value) {validate_and_populate_arg(i,prhs[i],A2); ++i;} ELSE_ASSIGN_ARG_2; - if (i < nrhs && is_input_type<arg3_type>::value) {validate_and_populate_arg(i,prhs[i],A3); ++i;} ELSE_ASSIGN_ARG_3; - if (i < nrhs && is_input_type<arg4_type>::value) {validate_and_populate_arg(i,prhs[i],A4); ++i;} ELSE_ASSIGN_ARG_4; - if (i < nrhs && is_input_type<arg5_type>::value) {validate_and_populate_arg(i,prhs[i],A5); ++i;} ELSE_ASSIGN_ARG_5; - if (i < nrhs && is_input_type<arg6_type>::value) {validate_and_populate_arg(i,prhs[i],A6); ++i;} ELSE_ASSIGN_ARG_6; - if (i < nrhs && is_input_type<arg7_type>::value) {validate_and_populate_arg(i,prhs[i],A7); ++i;} ELSE_ASSIGN_ARG_7; - if (i < nrhs && is_input_type<arg8_type>::value) {validate_and_populate_arg(i,prhs[i],A8); ++i;} ELSE_ASSIGN_ARG_8; - if (i < nrhs && is_input_type<arg9_type>::value) {validate_and_populate_arg(i,prhs[i],A9); ++i;} ELSE_ASSIGN_ARG_9; - if (i < nrhs && is_input_type<arg10_type>::value) {validate_and_populate_arg(i,prhs[i],A10); ++i;} ELSE_ASSIGN_ARG_10; - if (i < nrhs && is_input_type<arg11_type>::value) {validate_and_populate_arg(i,prhs[i],A11); ++i;} ELSE_ASSIGN_ARG_11; - if (i < nrhs && is_input_type<arg12_type>::value) {validate_and_populate_arg(i,prhs[i],A12); ++i;} ELSE_ASSIGN_ARG_12; - if (i < nrhs && is_input_type<arg13_type>::value) {validate_and_populate_arg(i,prhs[i],A13); ++i;} ELSE_ASSIGN_ARG_13; - if (i < nrhs && is_input_type<arg14_type>::value) {validate_and_populate_arg(i,prhs[i],A14); ++i;} ELSE_ASSIGN_ARG_14; - if (i < nrhs && is_input_type<arg15_type>::value) {validate_and_populate_arg(i,prhs[i],A15); ++i;} ELSE_ASSIGN_ARG_15; - if (i < nrhs && is_input_type<arg16_type>::value) {validate_and_populate_arg(i,prhs[i],A16); ++i;} ELSE_ASSIGN_ARG_16; - if (i < nrhs && is_input_type<arg17_type>::value) {validate_and_populate_arg(i,prhs[i],A17); ++i;} ELSE_ASSIGN_ARG_17; - if (i < nrhs && is_input_type<arg18_type>::value) {validate_and_populate_arg(i,prhs[i],A18); ++i;} ELSE_ASSIGN_ARG_18; - if (i < nrhs && is_input_type<arg19_type>::value) {validate_and_populate_arg(i,prhs[i],A19); ++i;} ELSE_ASSIGN_ARG_19; - - f(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15,A16,A17,A18,A19); - - - i = 0; - if (is_output_type<arg1_type>::value) {assign_to_matlab(plhs[i],A1); ++i;} - if (is_output_type<arg2_type>::value) {assign_to_matlab(plhs[i],A2); ++i;} - if (is_output_type<arg3_type>::value) {assign_to_matlab(plhs[i],A3); ++i;} - if (is_output_type<arg4_type>::value) {assign_to_matlab(plhs[i],A4); ++i;} - if (is_output_type<arg5_type>::value) {assign_to_matlab(plhs[i],A5); ++i;} - if (is_output_type<arg6_type>::value) {assign_to_matlab(plhs[i],A6); ++i;} - if (is_output_type<arg7_type>::value) {assign_to_matlab(plhs[i],A7); ++i;} - if (is_output_type<arg8_type>::value) {assign_to_matlab(plhs[i],A8); ++i;} - if (is_output_type<arg9_type>::value) {assign_to_matlab(plhs[i],A9); ++i;} - if (is_output_type<arg10_type>::value) {assign_to_matlab(plhs[i],A10); ++i;} - if (is_output_type<arg11_type>::value) {assign_to_matlab(plhs[i],A11); ++i;} - if (is_output_type<arg12_type>::value) {assign_to_matlab(plhs[i],A12); ++i;} - if (is_output_type<arg13_type>::value) {assign_to_matlab(plhs[i],A13); ++i;} - if (is_output_type<arg14_type>::value) {assign_to_matlab(plhs[i],A14); ++i;} - if (is_output_type<arg15_type>::value) {assign_to_matlab(plhs[i],A15); ++i;} - if (is_output_type<arg16_type>::value) {assign_to_matlab(plhs[i],A16); ++i;} - if (is_output_type<arg17_type>::value) {assign_to_matlab(plhs[i],A17); ++i;} - if (is_output_type<arg18_type>::value) {assign_to_matlab(plhs[i],A18); ++i;} - if (is_output_type<arg19_type>::value) {assign_to_matlab(plhs[i],A19); ++i;} - } - }; - - template <> - struct call_mex_function_helper<20> - { - template <typename funct> - void callit( - const funct& f, - int nlhs, mxArray *plhs[], - int nrhs, const mxArray *prhs[] - ) const - { - typedef typename sig_traits<funct>::arg1_type arg1_type; - typedef typename sig_traits<funct>::arg2_type arg2_type; - typedef typename sig_traits<funct>::arg3_type arg3_type; - typedef typename sig_traits<funct>::arg4_type arg4_type; - typedef typename sig_traits<funct>::arg5_type arg5_type; - typedef typename sig_traits<funct>::arg6_type arg6_type; - typedef typename sig_traits<funct>::arg7_type arg7_type; - typedef typename sig_traits<funct>::arg8_type arg8_type; - typedef typename sig_traits<funct>::arg9_type arg9_type; - typedef typename sig_traits<funct>::arg10_type arg10_type; - typedef typename sig_traits<funct>::arg11_type arg11_type; - typedef typename sig_traits<funct>::arg12_type arg12_type; - typedef typename sig_traits<funct>::arg13_type arg13_type; - typedef typename sig_traits<funct>::arg14_type arg14_type; - typedef typename sig_traits<funct>::arg15_type arg15_type; - typedef typename sig_traits<funct>::arg16_type arg16_type; - typedef typename sig_traits<funct>::arg17_type arg17_type; - typedef typename sig_traits<funct>::arg18_type arg18_type; - typedef typename sig_traits<funct>::arg19_type arg19_type; - typedef typename sig_traits<funct>::arg20_type arg20_type; - - typename basic_type<arg1_type>::type A1; - typename basic_type<arg2_type>::type A2; - typename basic_type<arg3_type>::type A3; - typename basic_type<arg4_type>::type A4; - typename basic_type<arg5_type>::type A5; - typename basic_type<arg6_type>::type A6; - typename basic_type<arg7_type>::type A7; - typename basic_type<arg8_type>::type A8; - typename basic_type<arg9_type>::type A9; - typename basic_type<arg10_type>::type A10; - typename basic_type<arg11_type>::type A11; - typename basic_type<arg12_type>::type A12; - typename basic_type<arg13_type>::type A13; - typename basic_type<arg14_type>::type A14; - typename basic_type<arg15_type>::type A15; - typename basic_type<arg16_type>::type A16; - typename basic_type<arg17_type>::type A17; - typename basic_type<arg18_type>::type A18; - typename basic_type<arg19_type>::type A19; - typename basic_type<arg20_type>::type A20; - - mark_owned_by_matlab(A1); - mark_owned_by_matlab(A2); - mark_owned_by_matlab(A3); - mark_owned_by_matlab(A4); - mark_owned_by_matlab(A5); - mark_owned_by_matlab(A6); - mark_owned_by_matlab(A7); - mark_owned_by_matlab(A8); - mark_owned_by_matlab(A9); - mark_owned_by_matlab(A10); - mark_owned_by_matlab(A11); - mark_owned_by_matlab(A12); - mark_owned_by_matlab(A13); - mark_owned_by_matlab(A14); - mark_owned_by_matlab(A15); - mark_owned_by_matlab(A16); - mark_owned_by_matlab(A17); - mark_owned_by_matlab(A18); - mark_owned_by_matlab(A19); - mark_owned_by_matlab(A20); - - int i = 0; - if (i < nrhs && is_input_type<arg1_type>::value) {validate_and_populate_arg(i,prhs[i],A1); ++i;} ELSE_ASSIGN_ARG_1; - if (i < nrhs && is_input_type<arg2_type>::value) {validate_and_populate_arg(i,prhs[i],A2); ++i;} ELSE_ASSIGN_ARG_2; - if (i < nrhs && is_input_type<arg3_type>::value) {validate_and_populate_arg(i,prhs[i],A3); ++i;} ELSE_ASSIGN_ARG_3; - if (i < nrhs && is_input_type<arg4_type>::value) {validate_and_populate_arg(i,prhs[i],A4); ++i;} ELSE_ASSIGN_ARG_4; - if (i < nrhs && is_input_type<arg5_type>::value) {validate_and_populate_arg(i,prhs[i],A5); ++i;} ELSE_ASSIGN_ARG_5; - if (i < nrhs && is_input_type<arg6_type>::value) {validate_and_populate_arg(i,prhs[i],A6); ++i;} ELSE_ASSIGN_ARG_6; - if (i < nrhs && is_input_type<arg7_type>::value) {validate_and_populate_arg(i,prhs[i],A7); ++i;} ELSE_ASSIGN_ARG_7; - if (i < nrhs && is_input_type<arg8_type>::value) {validate_and_populate_arg(i,prhs[i],A8); ++i;} ELSE_ASSIGN_ARG_8; - if (i < nrhs && is_input_type<arg9_type>::value) {validate_and_populate_arg(i,prhs[i],A9); ++i;} ELSE_ASSIGN_ARG_9; - if (i < nrhs && is_input_type<arg10_type>::value) {validate_and_populate_arg(i,prhs[i],A10); ++i;} ELSE_ASSIGN_ARG_10; - if (i < nrhs && is_input_type<arg11_type>::value) {validate_and_populate_arg(i,prhs[i],A11); ++i;} ELSE_ASSIGN_ARG_11; - if (i < nrhs && is_input_type<arg12_type>::value) {validate_and_populate_arg(i,prhs[i],A12); ++i;} ELSE_ASSIGN_ARG_12; - if (i < nrhs && is_input_type<arg13_type>::value) {validate_and_populate_arg(i,prhs[i],A13); ++i;} ELSE_ASSIGN_ARG_13; - if (i < nrhs && is_input_type<arg14_type>::value) {validate_and_populate_arg(i,prhs[i],A14); ++i;} ELSE_ASSIGN_ARG_14; - if (i < nrhs && is_input_type<arg15_type>::value) {validate_and_populate_arg(i,prhs[i],A15); ++i;} ELSE_ASSIGN_ARG_15; - if (i < nrhs && is_input_type<arg16_type>::value) {validate_and_populate_arg(i,prhs[i],A16); ++i;} ELSE_ASSIGN_ARG_16; - if (i < nrhs && is_input_type<arg17_type>::value) {validate_and_populate_arg(i,prhs[i],A17); ++i;} ELSE_ASSIGN_ARG_17; - if (i < nrhs && is_input_type<arg18_type>::value) {validate_and_populate_arg(i,prhs[i],A18); ++i;} ELSE_ASSIGN_ARG_18; - if (i < nrhs && is_input_type<arg19_type>::value) {validate_and_populate_arg(i,prhs[i],A19); ++i;} ELSE_ASSIGN_ARG_19; - if (i < nrhs && is_input_type<arg20_type>::value) {validate_and_populate_arg(i,prhs[i],A20); ++i;} ELSE_ASSIGN_ARG_20; - - f(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15,A16,A17,A18,A19,A20); - - - i = 0; - if (is_output_type<arg1_type>::value) {assign_to_matlab(plhs[i],A1); ++i;} - if (is_output_type<arg2_type>::value) {assign_to_matlab(plhs[i],A2); ++i;} - if (is_output_type<arg3_type>::value) {assign_to_matlab(plhs[i],A3); ++i;} - if (is_output_type<arg4_type>::value) {assign_to_matlab(plhs[i],A4); ++i;} - if (is_output_type<arg5_type>::value) {assign_to_matlab(plhs[i],A5); ++i;} - if (is_output_type<arg6_type>::value) {assign_to_matlab(plhs[i],A6); ++i;} - if (is_output_type<arg7_type>::value) {assign_to_matlab(plhs[i],A7); ++i;} - if (is_output_type<arg8_type>::value) {assign_to_matlab(plhs[i],A8); ++i;} - if (is_output_type<arg9_type>::value) {assign_to_matlab(plhs[i],A9); ++i;} - if (is_output_type<arg10_type>::value) {assign_to_matlab(plhs[i],A10); ++i;} - if (is_output_type<arg11_type>::value) {assign_to_matlab(plhs[i],A11); ++i;} - if (is_output_type<arg12_type>::value) {assign_to_matlab(plhs[i],A12); ++i;} - if (is_output_type<arg13_type>::value) {assign_to_matlab(plhs[i],A13); ++i;} - if (is_output_type<arg14_type>::value) {assign_to_matlab(plhs[i],A14); ++i;} - if (is_output_type<arg15_type>::value) {assign_to_matlab(plhs[i],A15); ++i;} - if (is_output_type<arg16_type>::value) {assign_to_matlab(plhs[i],A16); ++i;} - if (is_output_type<arg17_type>::value) {assign_to_matlab(plhs[i],A17); ++i;} - if (is_output_type<arg18_type>::value) {assign_to_matlab(plhs[i],A18); ++i;} - if (is_output_type<arg19_type>::value) {assign_to_matlab(plhs[i],A19); ++i;} - if (is_output_type<arg20_type>::value) {assign_to_matlab(plhs[i],A20); ++i;} - } - }; - -// ---------------------------------------------------------------------------------------- - - template <typename T> struct is_matlab_object { const static bool value = false; }; - template <> struct is_matlab_object <matlab_object> { const static bool value = true; }; - template <> struct is_matlab_object <const matlab_object> { const static bool value = true; }; - template <> struct is_matlab_object <matlab_object&> { const static bool value = true; }; - template <> struct is_matlab_object <const matlab_object&> { const static bool value = true; }; - -// ---------------------------------------------------------------------------------------- - - template < - typename funct - > - void call_mex_function ( - const funct& f, - int nlhs, mxArray *plhs[], - int nrhs, const mxArray *prhs[] - ) - { - const long expected_nrhs = funct_traits<funct>::num_inputs; - const long expected_nlhs = funct_traits<funct>::num_outputs; - const long expected_args = expected_nrhs + expected_nlhs; - - long defaulted_args = 0; - - #ifdef ARG_1_DEFAULT - ++defaulted_args; - // You can only set an argument's default value if it is an input argument. - COMPILE_TIME_ASSERT(is_input_type<typename sig_traits<funct>::arg1_type>::value); - #ifndef ARG_2_DEFAULT - // You can't define a default for argument 1 if you don't define one for argument 2 also. - COMPILE_TIME_ASSERT(expected_args < 2); - #endif - COMPILE_TIME_ASSERT(1 <= expected_args); // You can't define a default for an argument that doesn't exist. - #endif - #ifdef ARG_2_DEFAULT - ++defaulted_args; - // You can only set an argument's default value if it is an input argument. - COMPILE_TIME_ASSERT(is_input_type<typename sig_traits<funct>::arg2_type>::value); - #ifndef ARG_3_DEFAULT - // You can't define a default for argument 2 if you don't define one for argument 3 also. - COMPILE_TIME_ASSERT(expected_args < 3); - #endif - COMPILE_TIME_ASSERT(2 <= expected_args); // You can't define a default for an argument that doesn't exist. - #endif - #ifdef ARG_3_DEFAULT - ++defaulted_args; - // You can only set an argument's default value if it is an input argument. - COMPILE_TIME_ASSERT(is_input_type<typename sig_traits<funct>::arg3_type>::value); - #ifndef ARG_4_DEFAULT - // You can't define a default for argument 3 if you don't define one for argument 4 also. - COMPILE_TIME_ASSERT(expected_args < 4); - #endif - COMPILE_TIME_ASSERT(3 <= expected_args); // You can't define a default for an argument that doesn't exist. - #endif - #ifdef ARG_4_DEFAULT - ++defaulted_args; - // You can only set an argument's default value if it is an input argument. - COMPILE_TIME_ASSERT(is_input_type<typename sig_traits<funct>::arg4_type>::value); - #ifndef ARG_5_DEFAULT - // You can't define a default for argument 4 if you don't define one for argument 5 also. - COMPILE_TIME_ASSERT(expected_args < 5); - #endif - COMPILE_TIME_ASSERT(4 <= expected_args); // You can't define a default for an argument that doesn't exist. - #endif - #ifdef ARG_5_DEFAULT - ++defaulted_args; - // You can only set an argument's default value if it is an input argument. - COMPILE_TIME_ASSERT(is_input_type<typename sig_traits<funct>::arg5_type>::value); - #ifndef ARG_6_DEFAULT - // You can't define a default for argument 5 if you don't define one for argument 6 also. - COMPILE_TIME_ASSERT(expected_args < 6); - #endif - COMPILE_TIME_ASSERT(5 <= expected_args); // You can't define a default for an argument that doesn't exist. - #endif - #ifdef ARG_6_DEFAULT - ++defaulted_args; - // You can only set an argument's default value if it is an input argument. - COMPILE_TIME_ASSERT(is_input_type<typename sig_traits<funct>::arg6_type>::value); - #ifndef ARG_7_DEFAULT - // You can't define a default for argument 6 if you don't define one for argument 7 also. - COMPILE_TIME_ASSERT(expected_args < 7); - #endif - COMPILE_TIME_ASSERT(6 <= expected_args); // You can't define a default for an argument that doesn't exist. - #endif - #ifdef ARG_7_DEFAULT - ++defaulted_args; - // You can only set an argument's default value if it is an input argument. - COMPILE_TIME_ASSERT(is_input_type<typename sig_traits<funct>::arg7_type>::value); - #ifndef ARG_8_DEFAULT - // You can't define a default for argument 7 if you don't define one for argument 8 also. - COMPILE_TIME_ASSERT(expected_args < 8); - #endif - COMPILE_TIME_ASSERT(7 <= expected_args); // You can't define a default for an argument that doesn't exist. - #endif - #ifdef ARG_8_DEFAULT - ++defaulted_args; - // You can only set an argument's default value if it is an input argument. - COMPILE_TIME_ASSERT(is_input_type<typename sig_traits<funct>::arg8_type>::value); - #ifndef ARG_9_DEFAULT - // You can't define a default for argument 8 if you don't define one for argument 9 also. - COMPILE_TIME_ASSERT(expected_args < 9); - #endif - COMPILE_TIME_ASSERT(8 <= expected_args); // You can't define a default for an argument that doesn't exist. - #endif - #ifdef ARG_9_DEFAULT - ++defaulted_args; - // You can only set an argument's default value if it is an input argument. - COMPILE_TIME_ASSERT(is_input_type<typename sig_traits<funct>::arg9_type>::value); - #ifndef ARG_10_DEFAULT - // You can't define a default for argument 9 if you don't define one for argument 10 also. - COMPILE_TIME_ASSERT(expected_args < 10); - #endif - COMPILE_TIME_ASSERT(9 <= expected_args); // You can't define a default for an argument that doesn't exist. - #endif - #ifdef ARG_10_DEFAULT - ++defaulted_args; - // You can only set an argument's default value if it is an input argument. - COMPILE_TIME_ASSERT(is_input_type<typename sig_traits<funct>::arg10_type>::value); - #ifndef ARG_11_DEFAULT - // You can't define a default for argument 10 if you don't define one for argument 11 also. - COMPILE_TIME_ASSERT(expected_args < 11); - #endif - COMPILE_TIME_ASSERT(10 <= expected_args); // You can't define a default for an argument that doesn't exist. - #endif - #ifdef ARG_11_DEFAULT - ++defaulted_args; - // You can only set an argument's default value if it is an input argument. - COMPILE_TIME_ASSERT(is_input_type<typename sig_traits<funct>::arg11_type>::value); - #ifndef ARG_12_DEFAULT - // You can't define a default for argument 11 if you don't define one for argument 12 also. - COMPILE_TIME_ASSERT(expected_args < 12); - #endif - COMPILE_TIME_ASSERT(11 <= expected_args); // You can't define a default for an argument that doesn't exist. - #endif - #ifdef ARG_12_DEFAULT - ++defaulted_args; - // You can only set an argument's default value if it is an input argument. - COMPILE_TIME_ASSERT(is_input_type<typename sig_traits<funct>::arg12_type>::value); - #ifndef ARG_13_DEFAULT - // You can't define a default for argument 12 if you don't define one for argument 13 also. - COMPILE_TIME_ASSERT(expected_args < 13); - #endif - COMPILE_TIME_ASSERT(12 <= expected_args); // You can't define a default for an argument that doesn't exist. - #endif - #ifdef ARG_13_DEFAULT - ++defaulted_args; - // You can only set an argument's default value if it is an input argument. - COMPILE_TIME_ASSERT(is_input_type<typename sig_traits<funct>::arg13_type>::value); - #ifndef ARG_14_DEFAULT - // You can't define a default for argument 13 if you don't define one for argument 14 also. - COMPILE_TIME_ASSERT(expected_args < 14); - #endif - COMPILE_TIME_ASSERT(13 <= expected_args); // You can't define a default for an argument that doesn't exist. - #endif - #ifdef ARG_14_DEFAULT - ++defaulted_args; - // You can only set an argument's default value if it is an input argument. - COMPILE_TIME_ASSERT(is_input_type<typename sig_traits<funct>::arg14_type>::value); - #ifndef ARG_15_DEFAULT - // You can't define a default for argument 14 if you don't define one for argument 15 also. - COMPILE_TIME_ASSERT(expected_args < 15); - #endif - COMPILE_TIME_ASSERT(14 <= expected_args); // You can't define a default for an argument that doesn't exist. - #endif - #ifdef ARG_15_DEFAULT - ++defaulted_args; - // You can only set an argument's default value if it is an input argument. - COMPILE_TIME_ASSERT(is_input_type<typename sig_traits<funct>::arg15_type>::value); - #ifndef ARG_16_DEFAULT - // You can't define a default for argument 15 if you don't define one for argument 16 also. - COMPILE_TIME_ASSERT(expected_args < 16); - #endif - COMPILE_TIME_ASSERT(15 <= expected_args); // You can't define a default for an argument that doesn't exist. - #endif - #ifdef ARG_16_DEFAULT - ++defaulted_args; - // You can only set an argument's default value if it is an input argument. - COMPILE_TIME_ASSERT(is_input_type<typename sig_traits<funct>::arg16_type>::value); - #ifndef ARG_17_DEFAULT - // You can't define a default for argument 16 if you don't define one for argument 17 also. - COMPILE_TIME_ASSERT(expected_args < 17); - #endif - COMPILE_TIME_ASSERT(16 <= expected_args); // You can't define a default for an argument that doesn't exist. - #endif - #ifdef ARG_17_DEFAULT - ++defaulted_args; - // You can only set an argument's default value if it is an input argument. - COMPILE_TIME_ASSERT(is_input_type<typename sig_traits<funct>::arg17_type>::value); - #ifndef ARG_18_DEFAULT - // You can't define a default for argument 17 if you don't define one for argument 18 also. - COMPILE_TIME_ASSERT(expected_args < 18); - #endif - COMPILE_TIME_ASSERT(17 <= expected_args); // You can't define a default for an argument that doesn't exist. - #endif - #ifdef ARG_18_DEFAULT - ++defaulted_args; - // You can only set an argument's default value if it is an input argument. - COMPILE_TIME_ASSERT(is_input_type<typename sig_traits<funct>::arg18_type>::value); - #ifndef ARG_19_DEFAULT - // You can't define a default for argument 18 if you don't define one for argument 19 also. - COMPILE_TIME_ASSERT(expected_args < 19); - #endif - COMPILE_TIME_ASSERT(18 <= expected_args); // You can't define a default for an argument that doesn't exist. - #endif - #ifdef ARG_19_DEFAULT - ++defaulted_args; - // You can only set an argument's default value if it is an input argument. - COMPILE_TIME_ASSERT(is_input_type<typename sig_traits<funct>::arg19_type>::value); - #ifndef ARG_20_DEFAULT - // You can't define a default for argument 19 if you don't define one for argument 20 also. - COMPILE_TIME_ASSERT(expected_args < 20); - #endif - COMPILE_TIME_ASSERT(19 <= expected_args); // You can't define a default for an argument that doesn't exist. - #endif - #ifdef ARG_20_DEFAULT - ++defaulted_args; - // You can only set an argument's default value if it is an input argument. - COMPILE_TIME_ASSERT(is_input_type<typename sig_traits<funct>::arg20_type>::value); - COMPILE_TIME_ASSERT(20 <= expected_args); // You can't define a default for an argument that doesn't exist. - #endif - - - // Arguments with type matlab_object are optional in both input and output. - int num_optional_inputs = 0; - int num_optional_outputs = 0; - if (is_matlab_object<typename sig_traits<funct>::arg20_type>::value) if (is_input_type<typename sig_traits<funct>::arg20_type>::value) ++num_optional_inputs; else ++num_optional_outputs; - if (is_matlab_object<typename sig_traits<funct>::arg19_type>::value) if (is_input_type<typename sig_traits<funct>::arg19_type>::value) ++num_optional_inputs; else ++num_optional_outputs; - if (is_matlab_object<typename sig_traits<funct>::arg18_type>::value) if (is_input_type<typename sig_traits<funct>::arg18_type>::value) ++num_optional_inputs; else ++num_optional_outputs; - if (is_matlab_object<typename sig_traits<funct>::arg17_type>::value) if (is_input_type<typename sig_traits<funct>::arg17_type>::value) ++num_optional_inputs; else ++num_optional_outputs; - if (is_matlab_object<typename sig_traits<funct>::arg16_type>::value) if (is_input_type<typename sig_traits<funct>::arg16_type>::value) ++num_optional_inputs; else ++num_optional_outputs; - if (is_matlab_object<typename sig_traits<funct>::arg15_type>::value) if (is_input_type<typename sig_traits<funct>::arg15_type>::value) ++num_optional_inputs; else ++num_optional_outputs; - if (is_matlab_object<typename sig_traits<funct>::arg14_type>::value) if (is_input_type<typename sig_traits<funct>::arg14_type>::value) ++num_optional_inputs; else ++num_optional_outputs; - if (is_matlab_object<typename sig_traits<funct>::arg13_type>::value) if (is_input_type<typename sig_traits<funct>::arg13_type>::value) ++num_optional_inputs; else ++num_optional_outputs; - if (is_matlab_object<typename sig_traits<funct>::arg12_type>::value) if (is_input_type<typename sig_traits<funct>::arg12_type>::value) ++num_optional_inputs; else ++num_optional_outputs; - if (is_matlab_object<typename sig_traits<funct>::arg11_type>::value) if (is_input_type<typename sig_traits<funct>::arg11_type>::value) ++num_optional_inputs; else ++num_optional_outputs; - if (is_matlab_object<typename sig_traits<funct>::arg10_type>::value) if (is_input_type<typename sig_traits<funct>::arg10_type>::value) ++num_optional_inputs; else ++num_optional_outputs; - if (is_matlab_object<typename sig_traits<funct>::arg9_type>::value) if (is_input_type<typename sig_traits<funct>::arg9_type>::value) ++num_optional_inputs; else ++num_optional_outputs; - if (is_matlab_object<typename sig_traits<funct>::arg8_type>::value) if (is_input_type<typename sig_traits<funct>::arg8_type>::value) ++num_optional_inputs; else ++num_optional_outputs; - if (is_matlab_object<typename sig_traits<funct>::arg7_type>::value) if (is_input_type<typename sig_traits<funct>::arg7_type>::value) ++num_optional_inputs; else ++num_optional_outputs; - if (is_matlab_object<typename sig_traits<funct>::arg6_type>::value) if (is_input_type<typename sig_traits<funct>::arg6_type>::value) ++num_optional_inputs; else ++num_optional_outputs; - if (is_matlab_object<typename sig_traits<funct>::arg5_type>::value) if (is_input_type<typename sig_traits<funct>::arg5_type>::value) ++num_optional_inputs; else ++num_optional_outputs; - if (is_matlab_object<typename sig_traits<funct>::arg4_type>::value) if (is_input_type<typename sig_traits<funct>::arg4_type>::value) ++num_optional_inputs; else ++num_optional_outputs; - if (is_matlab_object<typename sig_traits<funct>::arg3_type>::value) if (is_input_type<typename sig_traits<funct>::arg3_type>::value) ++num_optional_inputs; else ++num_optional_outputs; - if (is_matlab_object<typename sig_traits<funct>::arg2_type>::value) if (is_input_type<typename sig_traits<funct>::arg2_type>::value) ++num_optional_inputs; else ++num_optional_outputs; - if (is_matlab_object<typename sig_traits<funct>::arg1_type>::value) if (is_input_type<typename sig_traits<funct>::arg1_type>::value) ++num_optional_inputs; else ++num_optional_outputs; - - - /* check for proper number of arguments */ - if(nrhs > expected_nrhs || nrhs < expected_nrhs - defaulted_args - num_optional_inputs) - { - std::ostringstream sout; - sout << "Expected between " << expected_nrhs-defaulted_args - num_optional_inputs - << " and " << expected_nrhs << " input arguments, got " << nrhs << "."; - - mexErrMsgIdAndTxt("mex_function:nrhs", - escape_percent(sout).c_str()); - } - - if (nlhs > expected_nlhs) - { - std::ostringstream sout; - sout << "Expected at most " << expected_nlhs << " output arguments, got " << nlhs << "."; - - mexErrMsgIdAndTxt("mex_function:nlhs", - escape_percent(sout).c_str()); - } - - call_mex_function_helper<sig_traits<funct>::num_args> helper; - helper.callit(f, nlhs, plhs, nrhs, prhs); - - } - -// ---------------------------------------------------------------------------------------- - - class mex_streambuf : public std::streambuf - { - - public: - mex_streambuf ( - ) - { - buf.resize(1000); - setp(&buf[0], &buf[0] + buf.size()-2); - - // make cout send data to mex_streambuf - oldbuf = std::cout.rdbuf(this); - } - - ~mex_streambuf() - { - // put cout back to the way we found it before running our mex function. - std::cout.rdbuf(oldbuf); - } - - - protected: - - - int sync ( - ) - { - int num = static_cast<int>(pptr()-pbase()); - if (num != 0) - { - check_for_matlab_ctrl_c(); - - buf[num] = 0; // null terminate the string - mexPrintf("%s",&buf[0]); - mexEvalString("drawnow"); // flush print to screen - pbump(-num); - } - return 0; - } - - int_type overflow ( - int_type c - ) - { - if (c != EOF) - { - *pptr() = c; - pbump(1); - } - sync(); - return c; - } - - private: - std::vector<char> buf; - std::streambuf* oldbuf; - - }; - - class mex_warn_streambuf : public std::streambuf - { - - public: - mex_warn_streambuf ( - ) - { - buf.resize(1000); - setp(&buf[0], &buf[0] + buf.size()-2); - - // make cout send data to mex_warn_streambuf - oldbuf = std::cerr.rdbuf(this); - } - - ~mex_warn_streambuf() - { - // put cerr back to the way we found it before running our mex function. - std::cerr.rdbuf(oldbuf); - } - - protected: - - - int sync ( - ) - { - int num = static_cast<int>(pptr()-pbase()); - if (num != 0) - { - check_for_matlab_ctrl_c(); - - buf[num] = 0; // null terminate the string - mexWarnMsgTxt(&buf[0]); - mexEvalString("drawnow"); // flush print to screen - pbump(-num); - } - return 0; - } - - int_type overflow ( - int_type c - ) - { - if (c != EOF) - { - *pptr() = c; - pbump(1); - } - sync(); - return c; - } - - private: - std::vector<char> buf; - std::streambuf* oldbuf; - - }; - -// ---------------------------------------------------------------------------------------- -// ---------------------------------------------------------------------------------------- - - template <typename T> - void setup_input_args ( - mxArray*& array, - const T& item, - int& nrhs - ) - { - assign_to_matlab(array, item); - ++nrhs; - } - - void setup_input_args ( - mxArray*& array, - const function_handle& item, - int& nrhs - ) - { - array = static_cast<mxArray*>(item.h); - ++nrhs; - } - - template <typename T> - void setup_input_args ( - mxArray*& array, - const output_decorator<T>& item, - int& nrhs - ) - { - } - - template <typename T> - void setup_output_args ( - const std::string& function_name, - mxArray* array, - const T& item, - int& nrhs - ) - { - } - - template <typename T> - void setup_output_args ( - const std::string& function_name, - mxArray* array, - const output_decorator<T>& item, - int& i - ) - { - try - { - validate_and_populate_arg(i,array,const_cast<T&>(item.item)); - ++i; - } - catch (invalid_args_exception& e) - { - throw dlib::error("Error occurred calling MATLAB function '" + function_name + "' from mex file. \n" - "The MATLAB function didn't return what we expected it to. \nIn particular, return" + string(e.what())); - } - } - - void call_matlab_for_real ( - int nlhs, - mxArray* plhs[], - int nrhs, - mxArray* prhs[], - const std::string& function_name - ) - { - int status = mexCallMATLAB(nlhs, plhs, nrhs, prhs, function_name.c_str()); - if (status) - { - throw dlib::error("Error, an exception was thrown when we tried to call the MATLAB function '" + function_name + "'."); - } - } - -// ---------------------------------------------------------------------------------------- -// ---------------------------------------------------------------------------------------- - -} - -// ---------------------------------------------------------------------------------------- -// ---------------------------------------------------------------------------------------- - -namespace dlib -{ - void call_matlab ( - const std::string& function_name - ) - { - using namespace mex_binding; - - call_matlab_for_real(0,NULL,0,NULL, function_name); - } - - template <typename T1> - void free_callback_resources ( - int nlhs, - mxArray* plhs[], - int nrhs, - mxArray* prhs[] - ) - { - // free resources - for (int i = 0; i < nlhs; ++i) - mxDestroyArray(plhs[i]); - - for (int i = 0; i < nrhs; ++i) - { - // don't call mxDestroyArray() on function handles (which should only ever be in prhs[0]) - if (i == 0 && dlib::is_same_type<T1,function_handle>::value) - continue; - mxDestroyArray(prhs[i]); - } - } - - template < - typename T1 - > - void call_matlab ( - const std::string& function_name, - const T1& A1 - ) - { - using namespace mex_binding; - const int num_args = 1; - mxArray* plhs[num_args] = {0}; - mxArray* prhs[num_args] = {0}; - - int nrhs = 0; - setup_input_args(prhs[nrhs], A1, nrhs); - - const int nlhs = num_args - nrhs; - call_matlab_for_real(nlhs,plhs,nrhs,prhs, function_name); - - int i = 0; - setup_output_args(function_name, plhs[i], A1, i); - - free_callback_resources<T1>(nlhs,plhs,nrhs,prhs); - } - - template < - typename T1, - typename T2 - > - void call_matlab ( - const std::string& function_name, - const T1& A1, - const T2& A2 - ) - { - using namespace mex_binding; - const int num_args = 2; - mxArray* plhs[num_args] = {0}; - mxArray* prhs[num_args] = {0}; - - int nrhs = 0; - setup_input_args(prhs[nrhs], A1, nrhs); - setup_input_args(prhs[nrhs], A2, nrhs); - - const int nlhs = num_args - nrhs; - call_matlab_for_real(nlhs,plhs,nrhs,prhs, function_name); - - int i = 0; - setup_output_args(function_name, plhs[i], A1, i); - setup_output_args(function_name, plhs[i], A2, i); - - free_callback_resources<T1>(nlhs,plhs,nrhs,prhs); - } - - template < - typename T1, - typename T2, - typename T3 - > - void call_matlab ( - const std::string& function_name, - const T1& A1, - const T2& A2, - const T3& A3 - ) - { - using namespace mex_binding; - const int num_args = 3; - mxArray* plhs[num_args] = {0}; - mxArray* prhs[num_args] = {0}; - - int nrhs = 0; - setup_input_args(prhs[nrhs], A1, nrhs); - setup_input_args(prhs[nrhs], A2, nrhs); - setup_input_args(prhs[nrhs], A3, nrhs); - - const int nlhs = num_args - nrhs; - call_matlab_for_real(nlhs,plhs,nrhs,prhs, function_name); - - int i = 0; - setup_output_args(function_name, plhs[i], A1, i); - setup_output_args(function_name, plhs[i], A2, i); - setup_output_args(function_name, plhs[i], A3, i); - - free_callback_resources<T1>(nlhs,plhs,nrhs,prhs); - } - - - template < - typename T1, - typename T2, - typename T3, - typename T4 - > - void call_matlab ( - const std::string& function_name, - const T1& A1, - const T2& A2, - const T3& A3, - const T4& A4 - ) - { - using namespace mex_binding; - const int num_args = 4; - mxArray* plhs[num_args] = {0}; - mxArray* prhs[num_args] = {0}; - - int nrhs = 0; - setup_input_args(prhs[nrhs], A1, nrhs); - setup_input_args(prhs[nrhs], A2, nrhs); - setup_input_args(prhs[nrhs], A3, nrhs); - setup_input_args(prhs[nrhs], A4, nrhs); - - const int nlhs = num_args - nrhs; - call_matlab_for_real(nlhs,plhs,nrhs,prhs, function_name); - - int i = 0; - setup_output_args(function_name, plhs[i], A1, i); - setup_output_args(function_name, plhs[i], A2, i); - setup_output_args(function_name, plhs[i], A3, i); - setup_output_args(function_name, plhs[i], A4, i); - - free_callback_resources<T1>(nlhs,plhs,nrhs,prhs); - } - - - template < - typename T1, - typename T2, - typename T3, - typename T4, - typename T5 - > - void call_matlab ( - const std::string& function_name, - const T1& A1, - const T2& A2, - const T3& A3, - const T4& A4, - const T5& A5 - ) - { - using namespace mex_binding; - const int num_args = 5; - mxArray* plhs[num_args] = {0}; - mxArray* prhs[num_args] = {0}; - - int nrhs = 0; - setup_input_args(prhs[nrhs], A1, nrhs); - setup_input_args(prhs[nrhs], A2, nrhs); - setup_input_args(prhs[nrhs], A3, nrhs); - setup_input_args(prhs[nrhs], A4, nrhs); - setup_input_args(prhs[nrhs], A5, nrhs); - - const int nlhs = num_args - nrhs; - call_matlab_for_real(nlhs,plhs,nrhs,prhs, function_name); - - int i = 0; - setup_output_args(function_name, plhs[i], A1, i); - setup_output_args(function_name, plhs[i], A2, i); - setup_output_args(function_name, plhs[i], A3, i); - setup_output_args(function_name, plhs[i], A4, i); - setup_output_args(function_name, plhs[i], A5, i); - - free_callback_resources<T1>(nlhs,plhs,nrhs,prhs); - } - - - template < - typename T1, - typename T2, - typename T3, - typename T4, - typename T5, - typename T6 - > - void call_matlab ( - const std::string& function_name, - const T1& A1, - const T2& A2, - const T3& A3, - const T4& A4, - const T5& A5, - const T6& A6 - ) - { - using namespace mex_binding; - const int num_args = 6; - mxArray* plhs[num_args] = {0}; - mxArray* prhs[num_args] = {0}; - - int nrhs = 0; - setup_input_args(prhs[nrhs], A1, nrhs); - setup_input_args(prhs[nrhs], A2, nrhs); - setup_input_args(prhs[nrhs], A3, nrhs); - setup_input_args(prhs[nrhs], A4, nrhs); - setup_input_args(prhs[nrhs], A5, nrhs); - setup_input_args(prhs[nrhs], A6, nrhs); - - const int nlhs = num_args - nrhs; - call_matlab_for_real(nlhs,plhs,nrhs,prhs, function_name); - - int i = 0; - setup_output_args(function_name, plhs[i], A1, i); - setup_output_args(function_name, plhs[i], A2, i); - setup_output_args(function_name, plhs[i], A3, i); - setup_output_args(function_name, plhs[i], A4, i); - setup_output_args(function_name, plhs[i], A5, i); - setup_output_args(function_name, plhs[i], A6, i); - - free_callback_resources<T1>(nlhs,plhs,nrhs,prhs); - } - - - template < - typename T1, - typename T2, - typename T3, - typename T4, - typename T5, - typename T6, - typename T7 - > - void call_matlab ( - const std::string& function_name, - const T1& A1, - const T2& A2, - const T3& A3, - const T4& A4, - const T5& A5, - const T6& A6, - const T7& A7 - ) - { - using namespace mex_binding; - const int num_args = 7; - mxArray* plhs[num_args] = {0}; - mxArray* prhs[num_args] = {0}; - - int nrhs = 0; - setup_input_args(prhs[nrhs], A1, nrhs); - setup_input_args(prhs[nrhs], A2, nrhs); - setup_input_args(prhs[nrhs], A3, nrhs); - setup_input_args(prhs[nrhs], A4, nrhs); - setup_input_args(prhs[nrhs], A5, nrhs); - setup_input_args(prhs[nrhs], A6, nrhs); - setup_input_args(prhs[nrhs], A7, nrhs); - - const int nlhs = num_args - nrhs; - call_matlab_for_real(nlhs,plhs,nrhs,prhs, function_name); - - int i = 0; - setup_output_args(function_name, plhs[i], A1, i); - setup_output_args(function_name, plhs[i], A2, i); - setup_output_args(function_name, plhs[i], A3, i); - setup_output_args(function_name, plhs[i], A4, i); - setup_output_args(function_name, plhs[i], A5, i); - setup_output_args(function_name, plhs[i], A6, i); - setup_output_args(function_name, plhs[i], A7, i); - - free_callback_resources<T1>(nlhs,plhs,nrhs,prhs); - } - - - template < - typename T1, - typename T2, - typename T3, - typename T4, - typename T5, - typename T6, - typename T7, - typename T8 - > - void call_matlab ( - const std::string& function_name, - const T1& A1, - const T2& A2, - const T3& A3, - const T4& A4, - const T5& A5, - const T6& A6, - const T7& A7, - const T8& A8 - ) - { - using namespace mex_binding; - const int num_args = 8; - mxArray* plhs[num_args] = {0}; - mxArray* prhs[num_args] = {0}; - - int nrhs = 0; - setup_input_args(prhs[nrhs], A1, nrhs); - setup_input_args(prhs[nrhs], A2, nrhs); - setup_input_args(prhs[nrhs], A3, nrhs); - setup_input_args(prhs[nrhs], A4, nrhs); - setup_input_args(prhs[nrhs], A5, nrhs); - setup_input_args(prhs[nrhs], A6, nrhs); - setup_input_args(prhs[nrhs], A7, nrhs); - setup_input_args(prhs[nrhs], A8, nrhs); - - const int nlhs = num_args - nrhs; - call_matlab_for_real(nlhs,plhs,nrhs,prhs, function_name); - - int i = 0; - setup_output_args(function_name, plhs[i], A1, i); - setup_output_args(function_name, plhs[i], A2, i); - setup_output_args(function_name, plhs[i], A3, i); - setup_output_args(function_name, plhs[i], A4, i); - setup_output_args(function_name, plhs[i], A5, i); - setup_output_args(function_name, plhs[i], A6, i); - setup_output_args(function_name, plhs[i], A7, i); - setup_output_args(function_name, plhs[i], A8, i); - - free_callback_resources<T1>(nlhs,plhs,nrhs,prhs); - } - - - - template < - typename T1, - typename T2, - typename T3, - typename T4, - typename T5, - typename T6, - typename T7, - typename T8, - typename T9 - > - void call_matlab ( - const std::string& function_name, - const T1& A1, - const T2& A2, - const T3& A3, - const T4& A4, - const T5& A5, - const T6& A6, - const T7& A7, - const T8& A8, - const T9& A9 - ) - { - using namespace mex_binding; - const int num_args = 9; - mxArray* plhs[num_args] = {0}; - mxArray* prhs[num_args] = {0}; - - int nrhs = 0; - setup_input_args(prhs[nrhs], A1, nrhs); - setup_input_args(prhs[nrhs], A2, nrhs); - setup_input_args(prhs[nrhs], A3, nrhs); - setup_input_args(prhs[nrhs], A4, nrhs); - setup_input_args(prhs[nrhs], A5, nrhs); - setup_input_args(prhs[nrhs], A6, nrhs); - setup_input_args(prhs[nrhs], A7, nrhs); - setup_input_args(prhs[nrhs], A8, nrhs); - setup_input_args(prhs[nrhs], A9, nrhs); - - const int nlhs = num_args - nrhs; - call_matlab_for_real(nlhs,plhs,nrhs,prhs, function_name); - - int i = 0; - setup_output_args(function_name, plhs[i], A1, i); - setup_output_args(function_name, plhs[i], A2, i); - setup_output_args(function_name, plhs[i], A3, i); - setup_output_args(function_name, plhs[i], A4, i); - setup_output_args(function_name, plhs[i], A5, i); - setup_output_args(function_name, plhs[i], A6, i); - setup_output_args(function_name, plhs[i], A7, i); - setup_output_args(function_name, plhs[i], A8, i); - setup_output_args(function_name, plhs[i], A9, i); - - free_callback_resources<T1>(nlhs,plhs,nrhs,prhs); - } - - - template < - typename T1, - typename T2, - typename T3, - typename T4, - typename T5, - typename T6, - typename T7, - typename T8, - typename T9, - typename T10 - > - void call_matlab ( - const std::string& function_name, - const T1& A1, - const T2& A2, - const T3& A3, - const T4& A4, - const T5& A5, - const T6& A6, - const T7& A7, - const T8& A8, - const T9& A9, - const T10& A10 - ) - { - using namespace mex_binding; - const int num_args = 10; - mxArray* plhs[num_args] = {0}; - mxArray* prhs[num_args] = {0}; - - int nrhs = 0; - setup_input_args(prhs[nrhs], A1, nrhs); - setup_input_args(prhs[nrhs], A2, nrhs); - setup_input_args(prhs[nrhs], A3, nrhs); - setup_input_args(prhs[nrhs], A4, nrhs); - setup_input_args(prhs[nrhs], A5, nrhs); - setup_input_args(prhs[nrhs], A6, nrhs); - setup_input_args(prhs[nrhs], A7, nrhs); - setup_input_args(prhs[nrhs], A8, nrhs); - setup_input_args(prhs[nrhs], A9, nrhs); - setup_input_args(prhs[nrhs], A10, nrhs); - - const int nlhs = num_args - nrhs; - call_matlab_for_real(nlhs,plhs,nrhs,prhs, function_name); - - int i = 0; - setup_output_args(function_name, plhs[i], A1, i); - setup_output_args(function_name, plhs[i], A2, i); - setup_output_args(function_name, plhs[i], A3, i); - setup_output_args(function_name, plhs[i], A4, i); - setup_output_args(function_name, plhs[i], A5, i); - setup_output_args(function_name, plhs[i], A6, i); - setup_output_args(function_name, plhs[i], A7, i); - setup_output_args(function_name, plhs[i], A8, i); - setup_output_args(function_name, plhs[i], A9, i); - setup_output_args(function_name, plhs[i], A10, i); - - free_callback_resources<T1>(nlhs,plhs,nrhs,prhs); - } - - template < - typename T1, - typename T2, - typename T3, - typename T4, - typename T5, - typename T6, - typename T7, - typename T8, - typename T9, - typename T10, - typename T11 - > - void call_matlab ( - const std::string& function_name, - const T1& A1, - const T2& A2, - const T3& A3, - const T4& A4, - const T5& A5, - const T6& A6, - const T7& A7, - const T8& A8, - const T9& A9, - const T10& A10, - const T11& A11 - ) - { - using namespace mex_binding; - const int num_args = 11; - mxArray* plhs[num_args] = {0}; - mxArray* prhs[num_args] = {0}; - - int nrhs = 0; - setup_input_args(prhs[nrhs], A1, nrhs); - setup_input_args(prhs[nrhs], A2, nrhs); - setup_input_args(prhs[nrhs], A3, nrhs); - setup_input_args(prhs[nrhs], A4, nrhs); - setup_input_args(prhs[nrhs], A5, nrhs); - setup_input_args(prhs[nrhs], A6, nrhs); - setup_input_args(prhs[nrhs], A7, nrhs); - setup_input_args(prhs[nrhs], A8, nrhs); - setup_input_args(prhs[nrhs], A9, nrhs); - setup_input_args(prhs[nrhs], A10, nrhs); - setup_input_args(prhs[nrhs], A11, nrhs); - - const int nlhs = num_args - nrhs; - call_matlab_for_real(nlhs,plhs,nrhs,prhs, function_name); - - int i = 0; - setup_output_args(function_name, plhs[i], A1, i); - setup_output_args(function_name, plhs[i], A2, i); - setup_output_args(function_name, plhs[i], A3, i); - setup_output_args(function_name, plhs[i], A4, i); - setup_output_args(function_name, plhs[i], A5, i); - setup_output_args(function_name, plhs[i], A6, i); - setup_output_args(function_name, plhs[i], A7, i); - setup_output_args(function_name, plhs[i], A8, i); - setup_output_args(function_name, plhs[i], A9, i); - setup_output_args(function_name, plhs[i], A10, i); - setup_output_args(function_name, plhs[i], A11, i); - - free_callback_resources<T1>(nlhs,plhs,nrhs,prhs); - } - - template < - typename T1, - typename T2, - typename T3, - typename T4, - typename T5, - typename T6, - typename T7, - typename T8, - typename T9, - typename T10, - typename T11, - typename T12 - > - void call_matlab ( - const std::string& function_name, - const T1& A1, - const T2& A2, - const T3& A3, - const T4& A4, - const T5& A5, - const T6& A6, - const T7& A7, - const T8& A8, - const T9& A9, - const T10& A10, - const T11& A11, - const T12& A12 - ) - { - using namespace mex_binding; - const int num_args = 12; - mxArray* plhs[num_args] = {0}; - mxArray* prhs[num_args] = {0}; - - int nrhs = 0; - setup_input_args(prhs[nrhs], A1, nrhs); - setup_input_args(prhs[nrhs], A2, nrhs); - setup_input_args(prhs[nrhs], A3, nrhs); - setup_input_args(prhs[nrhs], A4, nrhs); - setup_input_args(prhs[nrhs], A5, nrhs); - setup_input_args(prhs[nrhs], A6, nrhs); - setup_input_args(prhs[nrhs], A7, nrhs); - setup_input_args(prhs[nrhs], A8, nrhs); - setup_input_args(prhs[nrhs], A9, nrhs); - setup_input_args(prhs[nrhs], A10, nrhs); - setup_input_args(prhs[nrhs], A11, nrhs); - setup_input_args(prhs[nrhs], A12, nrhs); - - const int nlhs = num_args - nrhs; - call_matlab_for_real(nlhs,plhs,nrhs,prhs, function_name); - - int i = 0; - setup_output_args(function_name, plhs[i], A1, i); - setup_output_args(function_name, plhs[i], A2, i); - setup_output_args(function_name, plhs[i], A3, i); - setup_output_args(function_name, plhs[i], A4, i); - setup_output_args(function_name, plhs[i], A5, i); - setup_output_args(function_name, plhs[i], A6, i); - setup_output_args(function_name, plhs[i], A7, i); - setup_output_args(function_name, plhs[i], A8, i); - setup_output_args(function_name, plhs[i], A9, i); - setup_output_args(function_name, plhs[i], A10, i); - setup_output_args(function_name, plhs[i], A11, i); - setup_output_args(function_name, plhs[i], A12, i); - - free_callback_resources<T1>(nlhs,plhs,nrhs,prhs); - } - - template < - typename T1, - typename T2, - typename T3, - typename T4, - typename T5, - typename T6, - typename T7, - typename T8, - typename T9, - typename T10, - typename T11, - typename T12, - typename T13 - > - void call_matlab ( - const std::string& function_name, - const T1& A1, - const T2& A2, - const T3& A3, - const T4& A4, - const T5& A5, - const T6& A6, - const T7& A7, - const T8& A8, - const T9& A9, - const T10& A10, - const T11& A11, - const T12& A12, - const T13& A13 - ) - { - using namespace mex_binding; - const int num_args = 13; - mxArray* plhs[num_args] = {0}; - mxArray* prhs[num_args] = {0}; - - int nrhs = 0; - setup_input_args(prhs[nrhs], A1, nrhs); - setup_input_args(prhs[nrhs], A2, nrhs); - setup_input_args(prhs[nrhs], A3, nrhs); - setup_input_args(prhs[nrhs], A4, nrhs); - setup_input_args(prhs[nrhs], A5, nrhs); - setup_input_args(prhs[nrhs], A6, nrhs); - setup_input_args(prhs[nrhs], A7, nrhs); - setup_input_args(prhs[nrhs], A8, nrhs); - setup_input_args(prhs[nrhs], A9, nrhs); - setup_input_args(prhs[nrhs], A10, nrhs); - setup_input_args(prhs[nrhs], A11, nrhs); - setup_input_args(prhs[nrhs], A12, nrhs); - setup_input_args(prhs[nrhs], A13, nrhs); - - const int nlhs = num_args - nrhs; - call_matlab_for_real(nlhs,plhs,nrhs,prhs, function_name); - - int i = 0; - setup_output_args(function_name, plhs[i], A1, i); - setup_output_args(function_name, plhs[i], A2, i); - setup_output_args(function_name, plhs[i], A3, i); - setup_output_args(function_name, plhs[i], A4, i); - setup_output_args(function_name, plhs[i], A5, i); - setup_output_args(function_name, plhs[i], A6, i); - setup_output_args(function_name, plhs[i], A7, i); - setup_output_args(function_name, plhs[i], A8, i); - setup_output_args(function_name, plhs[i], A9, i); - setup_output_args(function_name, plhs[i], A10, i); - setup_output_args(function_name, plhs[i], A11, i); - setup_output_args(function_name, plhs[i], A12, i); - setup_output_args(function_name, plhs[i], A13, i); - - free_callback_resources<T1>(nlhs,plhs,nrhs,prhs); - } - - template < - typename T1, - typename T2, - typename T3, - typename T4, - typename T5, - typename T6, - typename T7, - typename T8, - typename T9, - typename T10, - typename T11, - typename T12, - typename T13, - typename T14 - > - void call_matlab ( - const std::string& function_name, - const T1& A1, - const T2& A2, - const T3& A3, - const T4& A4, - const T5& A5, - const T6& A6, - const T7& A7, - const T8& A8, - const T9& A9, - const T10& A10, - const T11& A11, - const T12& A12, - const T13& A13, - const T14& A14 - ) - { - using namespace mex_binding; - const int num_args = 14; - mxArray* plhs[num_args] = {0}; - mxArray* prhs[num_args] = {0}; - - int nrhs = 0; - setup_input_args(prhs[nrhs], A1, nrhs); - setup_input_args(prhs[nrhs], A2, nrhs); - setup_input_args(prhs[nrhs], A3, nrhs); - setup_input_args(prhs[nrhs], A4, nrhs); - setup_input_args(prhs[nrhs], A5, nrhs); - setup_input_args(prhs[nrhs], A6, nrhs); - setup_input_args(prhs[nrhs], A7, nrhs); - setup_input_args(prhs[nrhs], A8, nrhs); - setup_input_args(prhs[nrhs], A9, nrhs); - setup_input_args(prhs[nrhs], A10, nrhs); - setup_input_args(prhs[nrhs], A11, nrhs); - setup_input_args(prhs[nrhs], A12, nrhs); - setup_input_args(prhs[nrhs], A13, nrhs); - setup_input_args(prhs[nrhs], A14, nrhs); - - const int nlhs = num_args - nrhs; - call_matlab_for_real(nlhs,plhs,nrhs,prhs, function_name); - - int i = 0; - setup_output_args(function_name, plhs[i], A1, i); - setup_output_args(function_name, plhs[i], A2, i); - setup_output_args(function_name, plhs[i], A3, i); - setup_output_args(function_name, plhs[i], A4, i); - setup_output_args(function_name, plhs[i], A5, i); - setup_output_args(function_name, plhs[i], A6, i); - setup_output_args(function_name, plhs[i], A7, i); - setup_output_args(function_name, plhs[i], A8, i); - setup_output_args(function_name, plhs[i], A9, i); - setup_output_args(function_name, plhs[i], A10, i); - setup_output_args(function_name, plhs[i], A11, i); - setup_output_args(function_name, plhs[i], A12, i); - setup_output_args(function_name, plhs[i], A13, i); - setup_output_args(function_name, plhs[i], A14, i); - - free_callback_resources<T1>(nlhs,plhs,nrhs,prhs); - } - - template < - typename T1, - typename T2, - typename T3, - typename T4, - typename T5, - typename T6, - typename T7, - typename T8, - typename T9, - typename T10, - typename T11, - typename T12, - typename T13, - typename T14, - typename T15 - > - void call_matlab ( - const std::string& function_name, - const T1& A1, - const T2& A2, - const T3& A3, - const T4& A4, - const T5& A5, - const T6& A6, - const T7& A7, - const T8& A8, - const T9& A9, - const T10& A10, - const T11& A11, - const T12& A12, - const T13& A13, - const T14& A14, - const T15& A15 - ) - { - using namespace mex_binding; - const int num_args = 15; - mxArray* plhs[num_args] = {0}; - mxArray* prhs[num_args] = {0}; - - int nrhs = 0; - setup_input_args(prhs[nrhs], A1, nrhs); - setup_input_args(prhs[nrhs], A2, nrhs); - setup_input_args(prhs[nrhs], A3, nrhs); - setup_input_args(prhs[nrhs], A4, nrhs); - setup_input_args(prhs[nrhs], A5, nrhs); - setup_input_args(prhs[nrhs], A6, nrhs); - setup_input_args(prhs[nrhs], A7, nrhs); - setup_input_args(prhs[nrhs], A8, nrhs); - setup_input_args(prhs[nrhs], A9, nrhs); - setup_input_args(prhs[nrhs], A10, nrhs); - setup_input_args(prhs[nrhs], A11, nrhs); - setup_input_args(prhs[nrhs], A12, nrhs); - setup_input_args(prhs[nrhs], A13, nrhs); - setup_input_args(prhs[nrhs], A14, nrhs); - setup_input_args(prhs[nrhs], A15, nrhs); - - const int nlhs = num_args - nrhs; - call_matlab_for_real(nlhs,plhs,nrhs,prhs, function_name); - - int i = 0; - setup_output_args(function_name, plhs[i], A1, i); - setup_output_args(function_name, plhs[i], A2, i); - setup_output_args(function_name, plhs[i], A3, i); - setup_output_args(function_name, plhs[i], A4, i); - setup_output_args(function_name, plhs[i], A5, i); - setup_output_args(function_name, plhs[i], A6, i); - setup_output_args(function_name, plhs[i], A7, i); - setup_output_args(function_name, plhs[i], A8, i); - setup_output_args(function_name, plhs[i], A9, i); - setup_output_args(function_name, plhs[i], A10, i); - setup_output_args(function_name, plhs[i], A11, i); - setup_output_args(function_name, plhs[i], A12, i); - setup_output_args(function_name, plhs[i], A13, i); - setup_output_args(function_name, plhs[i], A14, i); - setup_output_args(function_name, plhs[i], A15, i); - - free_callback_resources<T1>(nlhs,plhs,nrhs,prhs); - } - - template < - typename T1, - typename T2, - typename T3, - typename T4, - typename T5, - typename T6, - typename T7, - typename T8, - typename T9, - typename T10, - typename T11, - typename T12, - typename T13, - typename T14, - typename T15, - typename T16 - > - void call_matlab ( - const std::string& function_name, - const T1& A1, - const T2& A2, - const T3& A3, - const T4& A4, - const T5& A5, - const T6& A6, - const T7& A7, - const T8& A8, - const T9& A9, - const T10& A10, - const T11& A11, - const T12& A12, - const T13& A13, - const T14& A14, - const T15& A15, - const T16& A16 - ) - { - using namespace mex_binding; - const int num_args = 16; - mxArray* plhs[num_args] = {0}; - mxArray* prhs[num_args] = {0}; - - int nrhs = 0; - setup_input_args(prhs[nrhs], A1, nrhs); - setup_input_args(prhs[nrhs], A2, nrhs); - setup_input_args(prhs[nrhs], A3, nrhs); - setup_input_args(prhs[nrhs], A4, nrhs); - setup_input_args(prhs[nrhs], A5, nrhs); - setup_input_args(prhs[nrhs], A6, nrhs); - setup_input_args(prhs[nrhs], A7, nrhs); - setup_input_args(prhs[nrhs], A8, nrhs); - setup_input_args(prhs[nrhs], A9, nrhs); - setup_input_args(prhs[nrhs], A10, nrhs); - setup_input_args(prhs[nrhs], A11, nrhs); - setup_input_args(prhs[nrhs], A12, nrhs); - setup_input_args(prhs[nrhs], A13, nrhs); - setup_input_args(prhs[nrhs], A14, nrhs); - setup_input_args(prhs[nrhs], A15, nrhs); - setup_input_args(prhs[nrhs], A16, nrhs); - - const int nlhs = num_args - nrhs; - call_matlab_for_real(nlhs,plhs,nrhs,prhs, function_name); - - int i = 0; - setup_output_args(function_name, plhs[i], A1, i); - setup_output_args(function_name, plhs[i], A2, i); - setup_output_args(function_name, plhs[i], A3, i); - setup_output_args(function_name, plhs[i], A4, i); - setup_output_args(function_name, plhs[i], A5, i); - setup_output_args(function_name, plhs[i], A6, i); - setup_output_args(function_name, plhs[i], A7, i); - setup_output_args(function_name, plhs[i], A8, i); - setup_output_args(function_name, plhs[i], A9, i); - setup_output_args(function_name, plhs[i], A10, i); - setup_output_args(function_name, plhs[i], A11, i); - setup_output_args(function_name, plhs[i], A12, i); - setup_output_args(function_name, plhs[i], A13, i); - setup_output_args(function_name, plhs[i], A14, i); - setup_output_args(function_name, plhs[i], A15, i); - setup_output_args(function_name, plhs[i], A16, i); - - free_callback_resources<T1>(nlhs,plhs,nrhs,prhs); - } - - template < - typename T1, - typename T2, - typename T3, - typename T4, - typename T5, - typename T6, - typename T7, - typename T8, - typename T9, - typename T10, - typename T11, - typename T12, - typename T13, - typename T14, - typename T15, - typename T16, - typename T17 - > - void call_matlab ( - const std::string& function_name, - const T1& A1, - const T2& A2, - const T3& A3, - const T4& A4, - const T5& A5, - const T6& A6, - const T7& A7, - const T8& A8, - const T9& A9, - const T10& A10, - const T11& A11, - const T12& A12, - const T13& A13, - const T14& A14, - const T15& A15, - const T16& A16, - const T17& A17 - ) - { - using namespace mex_binding; - const int num_args = 17; - mxArray* plhs[num_args] = {0}; - mxArray* prhs[num_args] = {0}; - - int nrhs = 0; - setup_input_args(prhs[nrhs], A1, nrhs); - setup_input_args(prhs[nrhs], A2, nrhs); - setup_input_args(prhs[nrhs], A3, nrhs); - setup_input_args(prhs[nrhs], A4, nrhs); - setup_input_args(prhs[nrhs], A5, nrhs); - setup_input_args(prhs[nrhs], A6, nrhs); - setup_input_args(prhs[nrhs], A7, nrhs); - setup_input_args(prhs[nrhs], A8, nrhs); - setup_input_args(prhs[nrhs], A9, nrhs); - setup_input_args(prhs[nrhs], A10, nrhs); - setup_input_args(prhs[nrhs], A11, nrhs); - setup_input_args(prhs[nrhs], A12, nrhs); - setup_input_args(prhs[nrhs], A13, nrhs); - setup_input_args(prhs[nrhs], A14, nrhs); - setup_input_args(prhs[nrhs], A15, nrhs); - setup_input_args(prhs[nrhs], A16, nrhs); - setup_input_args(prhs[nrhs], A17, nrhs); - - const int nlhs = num_args - nrhs; - call_matlab_for_real(nlhs,plhs,nrhs,prhs, function_name); - - int i = 0; - setup_output_args(function_name, plhs[i], A1, i); - setup_output_args(function_name, plhs[i], A2, i); - setup_output_args(function_name, plhs[i], A3, i); - setup_output_args(function_name, plhs[i], A4, i); - setup_output_args(function_name, plhs[i], A5, i); - setup_output_args(function_name, plhs[i], A6, i); - setup_output_args(function_name, plhs[i], A7, i); - setup_output_args(function_name, plhs[i], A8, i); - setup_output_args(function_name, plhs[i], A9, i); - setup_output_args(function_name, plhs[i], A10, i); - setup_output_args(function_name, plhs[i], A11, i); - setup_output_args(function_name, plhs[i], A12, i); - setup_output_args(function_name, plhs[i], A13, i); - setup_output_args(function_name, plhs[i], A14, i); - setup_output_args(function_name, plhs[i], A15, i); - setup_output_args(function_name, plhs[i], A16, i); - setup_output_args(function_name, plhs[i], A17, i); - - free_callback_resources<T1>(nlhs,plhs,nrhs,prhs); - } - - template < - typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, - typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, - typename T13, typename T14, typename T15, typename T16, typename T17, typename T18 - > - void call_matlab ( - const std::string& function_name, - const T1& A1, const T2& A2, const T3& A3, const T4& A4, const T5& A5, const T6& A6, - const T7& A7, const T8& A8, const T9& A9, const T10& A10, const T11& A11, const - T12& A12, const T13& A13, const T14& A14, const T15& A15, const T16& A16, const - T17& A17, const T18& A18 - ) - { - using namespace mex_binding; - const int num_args = 18; - mxArray* plhs[num_args] = {0}; - mxArray* prhs[num_args] = {0}; - - int nrhs = 0; - setup_input_args(prhs[nrhs], A1, nrhs); - setup_input_args(prhs[nrhs], A2, nrhs); - setup_input_args(prhs[nrhs], A3, nrhs); - setup_input_args(prhs[nrhs], A4, nrhs); - setup_input_args(prhs[nrhs], A5, nrhs); - setup_input_args(prhs[nrhs], A6, nrhs); - setup_input_args(prhs[nrhs], A7, nrhs); - setup_input_args(prhs[nrhs], A8, nrhs); - setup_input_args(prhs[nrhs], A9, nrhs); - setup_input_args(prhs[nrhs], A10, nrhs); - setup_input_args(prhs[nrhs], A11, nrhs); - setup_input_args(prhs[nrhs], A12, nrhs); - setup_input_args(prhs[nrhs], A13, nrhs); - setup_input_args(prhs[nrhs], A14, nrhs); - setup_input_args(prhs[nrhs], A15, nrhs); - setup_input_args(prhs[nrhs], A16, nrhs); - setup_input_args(prhs[nrhs], A17, nrhs); - setup_input_args(prhs[nrhs], A18, nrhs); - - const int nlhs = num_args - nrhs; - call_matlab_for_real(nlhs,plhs,nrhs,prhs, function_name); - - int i = 0; - setup_output_args(function_name, plhs[i], A1, i); - setup_output_args(function_name, plhs[i], A2, i); - setup_output_args(function_name, plhs[i], A3, i); - setup_output_args(function_name, plhs[i], A4, i); - setup_output_args(function_name, plhs[i], A5, i); - setup_output_args(function_name, plhs[i], A6, i); - setup_output_args(function_name, plhs[i], A7, i); - setup_output_args(function_name, plhs[i], A8, i); - setup_output_args(function_name, plhs[i], A9, i); - setup_output_args(function_name, plhs[i], A10, i); - setup_output_args(function_name, plhs[i], A11, i); - setup_output_args(function_name, plhs[i], A12, i); - setup_output_args(function_name, plhs[i], A13, i); - setup_output_args(function_name, plhs[i], A14, i); - setup_output_args(function_name, plhs[i], A15, i); - setup_output_args(function_name, plhs[i], A16, i); - setup_output_args(function_name, plhs[i], A17, i); - setup_output_args(function_name, plhs[i], A18, i); - - free_callback_resources<T1>(nlhs,plhs,nrhs,prhs); - } - - template < - typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, - typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, - typename T13, typename T14, typename T15, typename T16, typename T17, typename T18, - typename T19 - > - void call_matlab ( - const std::string& function_name, - const T1& A1, const T2& A2, const T3& A3, const T4& A4, const T5& A5, const T6& A6, - const T7& A7, const T8& A8, const T9& A9, const T10& A10, const T11& A11, const - T12& A12, const T13& A13, const T14& A14, const T15& A15, const T16& A16, const - T17& A17, const T18& A18, const T19& A19 - ) - { - using namespace mex_binding; - const int num_args = 19; - mxArray* plhs[num_args] = {0}; - mxArray* prhs[num_args] = {0}; - - int nrhs = 0; - setup_input_args(prhs[nrhs], A1, nrhs); - setup_input_args(prhs[nrhs], A2, nrhs); - setup_input_args(prhs[nrhs], A3, nrhs); - setup_input_args(prhs[nrhs], A4, nrhs); - setup_input_args(prhs[nrhs], A5, nrhs); - setup_input_args(prhs[nrhs], A6, nrhs); - setup_input_args(prhs[nrhs], A7, nrhs); - setup_input_args(prhs[nrhs], A8, nrhs); - setup_input_args(prhs[nrhs], A9, nrhs); - setup_input_args(prhs[nrhs], A10, nrhs); - setup_input_args(prhs[nrhs], A11, nrhs); - setup_input_args(prhs[nrhs], A12, nrhs); - setup_input_args(prhs[nrhs], A13, nrhs); - setup_input_args(prhs[nrhs], A14, nrhs); - setup_input_args(prhs[nrhs], A15, nrhs); - setup_input_args(prhs[nrhs], A16, nrhs); - setup_input_args(prhs[nrhs], A17, nrhs); - setup_input_args(prhs[nrhs], A18, nrhs); - setup_input_args(prhs[nrhs], A19, nrhs); - - const int nlhs = num_args - nrhs; - call_matlab_for_real(nlhs,plhs,nrhs,prhs, function_name); - - int i = 0; - setup_output_args(function_name, plhs[i], A1, i); - setup_output_args(function_name, plhs[i], A2, i); - setup_output_args(function_name, plhs[i], A3, i); - setup_output_args(function_name, plhs[i], A4, i); - setup_output_args(function_name, plhs[i], A5, i); - setup_output_args(function_name, plhs[i], A6, i); - setup_output_args(function_name, plhs[i], A7, i); - setup_output_args(function_name, plhs[i], A8, i); - setup_output_args(function_name, plhs[i], A9, i); - setup_output_args(function_name, plhs[i], A10, i); - setup_output_args(function_name, plhs[i], A11, i); - setup_output_args(function_name, plhs[i], A12, i); - setup_output_args(function_name, plhs[i], A13, i); - setup_output_args(function_name, plhs[i], A14, i); - setup_output_args(function_name, plhs[i], A15, i); - setup_output_args(function_name, plhs[i], A16, i); - setup_output_args(function_name, plhs[i], A17, i); - setup_output_args(function_name, plhs[i], A18, i); - setup_output_args(function_name, plhs[i], A19, i); - - free_callback_resources<T1>(nlhs,plhs,nrhs,prhs); - } - - template < - typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, - typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, - typename T13, typename T14, typename T15, typename T16, typename T17, typename T18, - typename T19, typename T20 - > - void call_matlab ( - const std::string& function_name, - const T1& A1, const T2& A2, const T3& A3, const T4& A4, const T5& A5, const T6& A6, - const T7& A7, const T8& A8, const T9& A9, const T10& A10, const T11& A11, const - T12& A12, const T13& A13, const T14& A14, const T15& A15, const T16& A16, const - T17& A17, const T18& A18, const T19& A19, const T20& A20 - ) - { - using namespace mex_binding; - const int num_args = 20; - mxArray* plhs[num_args] = {0}; - mxArray* prhs[num_args] = {0}; - - int nrhs = 0; - setup_input_args(prhs[nrhs], A1, nrhs); - setup_input_args(prhs[nrhs], A2, nrhs); - setup_input_args(prhs[nrhs], A3, nrhs); - setup_input_args(prhs[nrhs], A4, nrhs); - setup_input_args(prhs[nrhs], A5, nrhs); - setup_input_args(prhs[nrhs], A6, nrhs); - setup_input_args(prhs[nrhs], A7, nrhs); - setup_input_args(prhs[nrhs], A8, nrhs); - setup_input_args(prhs[nrhs], A9, nrhs); - setup_input_args(prhs[nrhs], A10, nrhs); - setup_input_args(prhs[nrhs], A11, nrhs); - setup_input_args(prhs[nrhs], A12, nrhs); - setup_input_args(prhs[nrhs], A13, nrhs); - setup_input_args(prhs[nrhs], A14, nrhs); - setup_input_args(prhs[nrhs], A15, nrhs); - setup_input_args(prhs[nrhs], A16, nrhs); - setup_input_args(prhs[nrhs], A17, nrhs); - setup_input_args(prhs[nrhs], A18, nrhs); - setup_input_args(prhs[nrhs], A19, nrhs); - setup_input_args(prhs[nrhs], A20, nrhs); - - const int nlhs = num_args - nrhs; - call_matlab_for_real(nlhs,plhs,nrhs,prhs, function_name); - - int i = 0; - setup_output_args(function_name, plhs[i], A1, i); - setup_output_args(function_name, plhs[i], A2, i); - setup_output_args(function_name, plhs[i], A3, i); - setup_output_args(function_name, plhs[i], A4, i); - setup_output_args(function_name, plhs[i], A5, i); - setup_output_args(function_name, plhs[i], A6, i); - setup_output_args(function_name, plhs[i], A7, i); - setup_output_args(function_name, plhs[i], A8, i); - setup_output_args(function_name, plhs[i], A9, i); - setup_output_args(function_name, plhs[i], A10, i); - setup_output_args(function_name, plhs[i], A11, i); - setup_output_args(function_name, plhs[i], A12, i); - setup_output_args(function_name, plhs[i], A13, i); - setup_output_args(function_name, plhs[i], A14, i); - setup_output_args(function_name, plhs[i], A15, i); - setup_output_args(function_name, plhs[i], A16, i); - setup_output_args(function_name, plhs[i], A17, i); - setup_output_args(function_name, plhs[i], A18, i); - setup_output_args(function_name, plhs[i], A19, i); - setup_output_args(function_name, plhs[i], A20, i); - - free_callback_resources<T1>(nlhs,plhs,nrhs,prhs); - } - -// ---------------------------------------------------------------------------------------- -// ---------------------------------------------------------------------------------------- - - matlab_object::~matlab_object( - ) - { - if (handle && should_free) - { - mxDestroyArray((mxArray*)handle); - handle = 0; - } - } - - template <typename T> - matlab_object:: - operator T( - ) const - { - T item; - get(item); - return item; - } - - template <typename T> - void matlab_object:: - get( - T& item - ) const - { - if (handle == 0) - throw dlib::invalid_args_exception("An attempt was made to access an empty matlab_object."); - - mex_binding::validate_and_populate_arg(arg_idx,(mxArray*)handle,item); - } - - template <typename T> - matlab_object& matlab_object:: - operator= ( - const T& new_val - ) - { - mxArray* item; - mex_binding::assign_to_matlab(item, new_val); - handle = item; - should_free = true; - return *this; - } - -// ---------------------------------------------------------------------------------------- -// ---------------------------------------------------------------------------------------- - - template <typename T> - matlab_struct::sub::operator T() const - { - T item; - get(item); - return item; - } - - template <typename T> - void matlab_struct::sub::get(T& item) const - { - if (struct_handle == 0) - throw dlib::error("Attempt to access data in an empty struct."); - - mxArray* temp = mxGetFieldByNumber((const mxArray*)struct_handle, 0, field_idx); - if (temp == 0) - throw dlib::error("Attempt to access data in an empty struct."); - - try - { - mex_binding::validate_and_populate_arg(0,temp,item); - } - catch(mex_binding::invalid_args_exception& e) - { - std::ostringstream sout; - sout << "Struct field '" << mxGetFieldNameByNumber((const mxArray*)struct_handle, field_idx) << "' can't be interpreted as the requested type." - << endl << e.what(); - throw dlib::error(sout.str()); - } - } - - const matlab_struct::sub matlab_struct:: - operator[] (const std::string& name) const - { - if (struct_handle == 0) - throw dlib::error("Struct does not have a field named '" + name + "'."); - - matlab_struct::sub temp; - temp.struct_handle = struct_handle; - temp.field_idx = mxGetFieldNumber((const mxArray*)struct_handle, name.c_str()); - if (temp.field_idx == -1 ) - throw dlib::error("Struct does not have a field named '" + name + "'."); - return temp; - } - - matlab_struct::sub matlab_struct:: - operator[] (const std::string& name) - { - if (struct_handle == 0) - { - // We make a struct from scratch and mark that we will free it unless it gets - // written back to matlab by assign_to_matlab(). - mwSize dims[1] = {1}; - const char* name_str = name.c_str(); - struct_handle = mxCreateStructArray(1, dims, 1, &name_str); - should_free = true; - if (struct_handle == 0) - throw dlib::error("Error creating struct from within mex function."); - } - - - matlab_struct::sub temp; - temp.struct_handle = struct_handle; - if ((temp.field_idx=mxGetFieldNumber((mxArray*)struct_handle, name.c_str())) == -1) - { - if ((temp.field_idx=mxAddField((mxArray*)struct_handle, name.c_str())) == -1) - { - throw dlib::error("Unable to add field '"+name + "' to struct."); - } - } - return temp; - } - - const matlab_struct::sub matlab_struct::sub:: - operator[] (const std::string& name) const - { - if (struct_handle == 0) - throw dlib::error("Struct does not have a field named '" + name + "'."); - - matlab_struct::sub temp; - temp.struct_handle = mxGetFieldByNumber((const mxArray*)struct_handle, 0, field_idx); - if (temp.struct_handle == 0) - throw dlib::error("Failure to get struct field while calling mxGetFieldByNumber()"); - - if (!mxIsStruct((const mxArray*)temp.struct_handle)) - throw dlib::error("Struct sub-field element '"+name+"' is not another struct."); - - temp.field_idx = mxGetFieldNumber((const mxArray*)temp.struct_handle, name.c_str()); - if (temp.field_idx == -1 ) - throw dlib::error("Struct does not have a field named '" + name + "'."); - return temp; - } - - matlab_struct::sub matlab_struct::sub:: - operator[] (const std::string& name) - { - if (struct_handle == 0) - throw dlib::error("Struct does not have a field named '" + name + "'."); - - matlab_struct::sub temp; - temp.struct_handle = mxGetFieldByNumber((const mxArray*)struct_handle, 0, field_idx); - // We are replacing this field with a struct if it exists and isn't already a struct - if (temp.struct_handle != 0 && !mxIsStruct((const mxArray*)temp.struct_handle)) - { - mxDestroyArray((mxArray*)temp.struct_handle); - temp.struct_handle = 0; - } - if (temp.struct_handle == 0) - { - mwSize dims[1] = {1}; - temp.struct_handle = mxCreateStructArray(1, dims, 0, 0); - if (temp.struct_handle == 0) - throw dlib::error("Failure to create new sub-struct field"); - mxSetFieldByNumber((mxArray*)struct_handle, 0, field_idx, (mxArray*)temp.struct_handle); - } - - - if ((temp.field_idx=mxGetFieldNumber((mxArray*)temp.struct_handle, name.c_str())) == -1) - { - if ((temp.field_idx=mxAddField((mxArray*)temp.struct_handle, name.c_str())) == -1) - { - throw dlib::error("Unable to add field '"+name + "' to struct."); - } - } - return temp; - } - - bool matlab_struct::has_field ( - const std::string& name - ) const - { - if (struct_handle == 0) - return false; - return mxGetFieldNumber((const mxArray*)struct_handle, name.c_str()) != -1; - } - - bool matlab_struct::sub::has_field ( - const std::string& name - ) const - { - if (struct_handle == 0) - return false; - mxArray* temp = mxGetFieldByNumber((const mxArray*)struct_handle, 0, field_idx); - if (temp == 0 || !mxIsStruct(temp)) - return false; - return mxGetFieldNumber(temp, name.c_str()) != -1; - } - - template <typename T> - matlab_struct::sub& matlab_struct::sub::operator= ( - const T& new_val - ) - { - // Delete anything in the field before we overwrite it - mxArray* item = mxGetFieldByNumber((mxArray*)struct_handle, 0, field_idx); - if (item != 0) - { - mxDestroyArray((mxArray*)item); - item = 0; - } - - // Now set the field - mex_binding::assign_to_matlab(item, new_val); - mxSetFieldByNumber((mxArray*)struct_handle, 0, field_idx, item); - - return *this; - } - - matlab_struct:: - ~matlab_struct ( - ) - { - if (struct_handle && should_free) - { - mxDestroyArray((mxArray*)struct_handle); - struct_handle = 0; - } - } - -// ---------------------------------------------------------------------------------------- -// ---------------------------------------------------------------------------------------- - - void call_matlab ( - const function_handle& funct - ) - { - call_matlab("feval", funct); - } - - extern "C" bool utIsInterruptPending(); - void check_for_matlab_ctrl_c( - ) - { - if (utIsInterruptPending()) - throw mex_binding::user_hit_ctrl_c(); - } -} - -// ---------------------------------------------------------------------------------------- -// ---------------------------------------------------------------------------------------- - -#ifdef MEX_CLASS_NAME -template <typename T, typename mfp_type> -class mex_class_wrapper -{ -public: - mex_class_wrapper(T& obj_, mfp_type mfp_) : obj(obj_), mfp(mfp_) {} - - template <typename... Args> - void operator()(Args&&... args) const - { - (obj.*mfp)(std::forward<Args>(args)...); - } - - mfp_type mfp; - T& obj; -}; - -template <typename T, typename mfp_type> -mex_class_wrapper<T,mfp_type> wrap_mex_class(T& obj, mfp_type mfp) { return mex_class_wrapper<T,mfp_type>(obj, mfp); } - -namespace dlib -{ - template <typename T, typename mfp_type> - struct sig_traits<mex_class_wrapper<T,mfp_type>> - : public sig_traits<mfp_type> - {}; - - template <size_t i, typename T, bool is_good = i < std::tuple_size<T>::value> - struct tuple_element_default_void - { - typedef void type; - }; - - template <size_t i, typename T> - struct tuple_element_default_void<i,T,true> - { - typedef typename std::tuple_element<i,T>::type type; - }; - - template <typename class_type, typename return_type, typename... Args> - struct sig_traits<return_type(class_type::*)(Args...) > - { - enum { num_args = sizeof...(Args) }; - - typedef return_type result_type; - - template <size_t i> - struct arg - { - typedef typename tuple_element_default_void<i-1, std::tuple<Args...>>::type type; - }; - - // These are here because that's how things are defined in sig_traits (since it is - // older than C++11, along with most of the other code in this file) - typedef typename arg<1>::type arg1_type; - typedef typename arg<2>::type arg2_type; - typedef typename arg<3>::type arg3_type; - typedef typename arg<4>::type arg4_type; - typedef typename arg<5>::type arg5_type; - typedef typename arg<6>::type arg6_type; - typedef typename arg<7>::type arg7_type; - typedef typename arg<8>::type arg8_type; - typedef typename arg<9>::type arg9_type; - typedef typename arg<10>::type arg10_type; - typedef typename arg<11>::type arg11_type; - typedef typename arg<12>::type arg12_type; - typedef typename arg<13>::type arg13_type; - typedef typename arg<14>::type arg14_type; - typedef typename arg<15>::type arg15_type; - typedef typename arg<16>::type arg16_type; - typedef typename arg<17>::type arg17_type; - typedef typename arg<18>::type arg18_type; - typedef typename arg<19>::type arg19_type; - typedef typename arg<20>::type arg20_type; - }; - - template <typename class_type, typename return_type, typename... Args> - struct sig_traits<return_type(class_type::*)(Args...) const> - { - enum { num_args = sizeof...(Args) }; - - typedef return_type result_type; - - template <size_t i> - struct arg - { - typedef typename tuple_element_default_void<i-1, std::tuple<Args...>>::type type; - }; - - // These are here because that's how things are defined in sig_traits (since it is - // older than C++11, along with most of the other code in this file) - typedef typename arg<1>::type arg1_type; - typedef typename arg<2>::type arg2_type; - typedef typename arg<3>::type arg3_type; - typedef typename arg<4>::type arg4_type; - typedef typename arg<5>::type arg5_type; - typedef typename arg<6>::type arg6_type; - typedef typename arg<7>::type arg7_type; - typedef typename arg<8>::type arg8_type; - typedef typename arg<9>::type arg9_type; - typedef typename arg<10>::type arg10_type; - typedef typename arg<11>::type arg11_type; - typedef typename arg<12>::type arg12_type; - typedef typename arg<13>::type arg13_type; - typedef typename arg<14>::type arg14_type; - typedef typename arg<15>::type arg15_type; - typedef typename arg<16>::type arg16_type; - typedef typename arg<17>::type arg17_type; - typedef typename arg<18>::type arg18_type; - typedef typename arg<19>::type arg19_type; - typedef typename arg<20>::type arg20_type; - }; -} - -// ---------------------------------------------------------------------------------------- - - -template <size_t I> -struct visit_impl -{ - template <typename T, typename F> - static void visit(T& tup, size_t idx, F fun) - { - if (idx == I - 1) fun(std::get<I - 1>(tup)); - else visit_impl<I - 1>::visit(tup, idx, fun); - } -}; - -template <> -struct visit_impl<0> -{ - template <typename T, typename F> - static void visit(T& tup, size_t idx, F fun) { DLIB_CASSERT(false,"this should never happen"); } -}; - -template <typename F, typename... Ts> -void visit_at(std::tuple<Ts...> const& tup, size_t idx, F fun) -{ - visit_impl<sizeof...(Ts)>::visit(tup, idx, fun); -} - -template <typename F, typename... Ts> -void visit_at(std::tuple<Ts...>& tup, size_t idx, F fun) -{ - visit_impl<sizeof...(Ts)>::visit(tup, idx, fun); -} - -class mex_class_dispatch -{ -public: - mex_class_dispatch( - MEX_CLASS_NAME* ptr_, - int nlhs_, - mxArray** plhs_, - int nrhs_, - const mxArray** prhs_ - ) : - ptr(ptr_), - nlhs(nlhs_), - plhs(plhs_), - nrhs(nrhs_), - prhs(prhs_) - {} - - template <typename funct> - void operator() (const funct& mfp) - { - mex_binding::call_mex_function(wrap_mex_class(*ptr,mfp), nlhs, plhs, nrhs, prhs); - } - -private: - MEX_CLASS_NAME* ptr; - int nlhs; - mxArray** plhs; - int nrhs; - const mxArray** prhs; -}; - -class class_factory_type : dlib::noncopyable -{ - /*! - WHAT THIS OBJECT REPRESENTS - This is a container class for all the MEX_CLASS_NAME objects we create. It allows - us to track what we have created and make sure the MATLAB user doesn't do any - double frees or use any stale pointers. - - It also helps us deal with the problem that would otherwise arise when a mex file - is unloaded from MATLAB when there are still active pointers to MEX_CLASS_NAME objects - in MATLAB, since we will be able to detect stale pointers. - !*/ -public: - - class_factory_type() - { - seed = (uint64)time(0); - } - - ~class_factory_type() - { - for (auto i : object_table) - delete i.second; - } - - template <typename ...T> - uint64 create(T&& ...args) - { - MEX_CLASS_NAME* item = new MEX_CLASS_NAME(std::forward<T>(args)...); - uint64 id = (uint64)item; - // Now generate a unique id that incorporates our seed value. The point of doing - // this is to avoid any chance that a mex file will get unloaded and then reloaded - // and start constructing objects with the same addresses, while old stale objects - // at those addresses are still stored in matlab, which would then call into the - // mex file and make things go crazy. So here we try to generate ID numbers that - // are globally unique. - uint64 i = 0; - id = murmur_hash3_128bit_3(id, seed, ++i).first; - // very unlikely but make sure there aren't any hash collisions. - while(object_table.count(id) != 0) - id = murmur_hash3_128bit_3(id, seed, ++i).first; - - object_table[id] = item; - return id; - } - - void free(uint64 item) - { - if (object_table.count(item) == 0) - { - throw dlib::error("An attempt to deallocate a mex class object with an invalid pointer was detected."); - } - - delete object_table[item]; - object_table.erase(item); - } - - MEX_CLASS_NAME* access(uint64 item) // convert numeric ID to pointer to object that can be used. - { - if (object_table.count(item) == 0) - { - throw dlib::error("An attempt to access a mex class object with an invalid pointer was detected."); - } - - return object_table[item]; - } - -private: - - std::map<uint64, MEX_CLASS_NAME*> object_table; - uint64 seed; -} class_factory; - -// ---------------------------------------------------------------------------------------- - -// Make a FOREACH macro -#define FE_1(WHAT, X) WHAT(X) -#define FE_2(WHAT, X, ...) WHAT(X),FE_1(WHAT, __VA_ARGS__) -#define FE_3(WHAT, X, ...) WHAT(X),FE_2(WHAT, __VA_ARGS__) -#define FE_4(WHAT, X, ...) WHAT(X),FE_3(WHAT, __VA_ARGS__) -#define FE_5(WHAT, X, ...) WHAT(X),FE_4(WHAT, __VA_ARGS__) -#define FE_6(WHAT, X, ...) WHAT(X),FE_5(WHAT, __VA_ARGS__) -#define FE_7(WHAT, X, ...) WHAT(X),FE_6(WHAT, __VA_ARGS__) -#define FE_8(WHAT, X, ...) WHAT(X),FE_7(WHAT, __VA_ARGS__) -#define FE_9(WHAT, X, ...) WHAT(X),FE_8(WHAT, __VA_ARGS__) -#define FE_10(WHAT, X, ...) WHAT(X),FE_9(WHAT, __VA_ARGS__) -#define FE_11(WHAT, X, ...) WHAT(X),FE_10(WHAT, __VA_ARGS__) -#define FE_12(WHAT, X, ...) WHAT(X),FE_11(WHAT, __VA_ARGS__) -#define FE_13(WHAT, X, ...) WHAT(X),FE_12(WHAT, __VA_ARGS__) -#define FE_14(WHAT, X, ...) WHAT(X),FE_13(WHAT, __VA_ARGS__) -#define FE_15(WHAT, X, ...) WHAT(X),FE_14(WHAT, __VA_ARGS__) -#define FE_16(WHAT, X, ...) WHAT(X),FE_15(WHAT, __VA_ARGS__) -#define FE_17(WHAT, X, ...) WHAT(X),FE_16(WHAT, __VA_ARGS__) -#define FE_18(WHAT, X, ...) WHAT(X),FE_17(WHAT, __VA_ARGS__) -#define FE_19(WHAT, X, ...) WHAT(X),FE_18(WHAT, __VA_ARGS__) -#define FE_20(WHAT, X, ...) WHAT(X),FE_19(WHAT, __VA_ARGS__) -//... repeat as needed -#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,_11,_12,_13,_14,_15,_16,_17,_18,_19,_20,NAME,...) NAME -#define FOR_EACH(action,...) GET_MACRO(__VA_ARGS__,FE_20,FE_19,FE_18,FE_17,FE_16,FE_15,FE_14,FE_13,FE_12,FE_11,FE_10,FE_9,FE_8,FE_7,FE_6,FE_5,FE_4,FE_3,FE_2,FE_1)(action,__VA_ARGS__) -#define MEX_CLASS_ANNOTATE(x) &MEX_CLASS_NAME::x - -// Now make a tuple containing all the member function pointers to our MEX_CLASS_NAME -auto mex_class_methods = std::make_tuple(FOR_EACH(MEX_CLASS_ANNOTATE, MEX_CLASS_METHODS)); - - -#endif // MEX_CLASS_NAME - -// ---------------------------------------------------------------------------------------- - -bool is_string(const mxArray* arr, const char* str) -{ - if (mxIsChar(arr)) - { - char ch[20]; - DLIB_CASSERT(mxGetString(arr, ch, sizeof(ch))==0, "Unable to retrieve string"); - ch[sizeof(ch)-1] = 0;// ensure NULL termination regardless of what MATLAB does. - return strcmp(str,ch)==0; - } - return false; -} - -// ---------------------------------------------------------------------------------------- - -/* The gateway function called by MATLAB*/ -void mexFunction( int nlhs, mxArray *plhs[], - int nrhs, const mxArray *prhs[]) -{ - // Only remap cout and cerr if we aren't using octave since octave already does this. -#if !defined(OCTAVE_IMPORT) && !defined(OCTAVE_API) - // make it so cout prints to mexPrintf() - mex_binding::mex_streambuf sb; - // make it so cerr prints to mexWarnMsgTxt() - mex_binding::mex_warn_streambuf wsb; -#endif - - try - { -#ifdef MEX_CLASS_NAME - if (nrhs == 0) - { - #define DEF2STR(x) DEF2STR2((x)) - #define DEF2STR2(x) #x - - string classname = trim(string(DEF2STR(MEX_CLASS_NAME)), " \t()"); - std::vector<string> methods = split(trim(string(DEF2STR(MEX_CLASS_METHODS)), " \t()"), " \t,"); - - string mex_filename = trim(string(DEF2STR(MEX_FILENAME))," \t()"); - bool has_load_obj = false; - size_t load_obj_idx = 0; - - cout << "classdef " << classname << " < handle\n" - << " properties (Access = private)\n" - << " cpp_ptr\n" - << " end\n" - << "\n" - << " methods\n" - << " function this = "<<classname<<"()\n" - << " this.cpp_ptr = "<<mex_filename<<"('construct');\n" - << " end\n" - << "\n" - << " function copied_obj = clone(this)\n" - << " %Returns a new independent object that is a copy of this.\n" - << " copied_obj = "<<classname<<"();\n" - << " copied_obj.cpp_ptr = "<<mex_filename<<"(this.cpp_ptr,'clone');\n" - << " end\n" - << "\n"; - for (size_t i = 0; i < methods.size(); ++i) - { - if (methods[i] == "load_obj") - { - has_load_obj = true; - load_obj_idx = i; - } - else - { - cout << " function varargout = "<<methods[i]<<"(this, varargin) \n" - << " [varargout{1:nargout}] = "<<mex_filename<<"(this.cpp_ptr, "<<i+1<<", varargin{:}); \n" - << " end \n\n"; - } - } - cout << " end\n\n"; - - cout << " methods(Access=private) \n" - << " function delete(this) \n" - << " "<<mex_filename<<"(this.cpp_ptr); \n" - << " end \n"; - if (has_load_obj) - { - cout << " function varargout = load_obj(this, varargin) \n" - << " [varargout{1:nargout}] = "<<mex_filename<<"(this.cpp_ptr, "<<load_obj_idx+1<<", varargin{:}); \n" - << " end \n"; - } - cout << " end \n\n"; - - if (has_load_obj) - { - cout << " methods(Static) \n" - << " function this = loadobj(in) \n" - << " this = "<<classname<<"(); \n" - << " this.load_obj(in); \n" - << " end \n" - << " end \n"; - } - cout << "end \n"; - } - else if (nrhs == 1) - { - // this is a constructor call - if (is_string(prhs[0],"construct")) - { - DLIB_CASSERT(nlhs == 1, "If you want to construct a new object then you must assign the pointer to something."); - plhs[0] = mxCreateNumericMatrix(1, 1, mxUINT64_CLASS, mxREAL); - uint64* ptr_int = (uint64*)mxGetData(plhs[0]); - *ptr_int = class_factory.create(); - } - else // destructor call - { - DLIB_CASSERT(mxIsUint64(prhs[0]) && mxGetNumberOfElements(prhs[0])==1, "When calling a class destructor the first argument must be a pointer (a UINT64 in matlab)"); - const uint64 ptr_int = *((uint64*)mxGetData(prhs[0])); - class_factory.free(ptr_int); - } - } - else // a regular function call - { - DLIB_CASSERT(mxIsUint64(prhs[0]) && mxGetNumberOfElements(prhs[0])==1, "When calling a class member function the first argument must be a pointer (a UINT64 in matlab)"); - if (is_string(prhs[1], "clone")) - { - DLIB_CASSERT(nlhs == 1, "If you want to construct a new object then you must assign the pointer to something."); - const uint64 ptr_int = *((uint64*)mxGetData(prhs[0])); - - MEX_CLASS_NAME* ptr = class_factory.access(ptr_int); - - plhs[0] = mxCreateNumericMatrix(1, 1, mxUINT64_CLASS, mxREAL); - uint64* ptr_int2 = (uint64*)mxGetData(plhs[0]); - // copy construct a new object - *ptr_int2 = class_factory.create(*ptr); - } - else - { - DLIB_CASSERT(mxIsDouble(prhs[1]) && mxGetNumberOfElements(prhs[1])==1, "When calling a class member function the second argument must be a number indicating which member function"); - const uint64 ptr_int = *((uint64*)mxGetData(prhs[0])); - const int funct_idx = *(mxGetPr(prhs[1])); - - auto num_registered_functions = std::tuple_size<decltype(mex_class_methods)>::value; - DLIB_CASSERT(1 <= funct_idx && funct_idx <= num_registered_functions, "Invalid function index provided."); - - MEX_CLASS_NAME* ptr = class_factory.access(ptr_int); - - // we used the first two arguments to decide what function to call. So adjust nrhs - // and prhs so the member function never sees them. - mex_class_dispatch dispatch(ptr, nlhs, plhs, nrhs-2, prhs+2); - // now invoke the member function, subtract 1 to convert to 0 indexing. - visit_at(mex_class_methods, funct_idx-1, dispatch); - } - } -#else - mex_binding::call_mex_function(mex_function, nlhs, plhs, nrhs, prhs); -#endif - } - catch (mex_binding::invalid_args_exception& e) - { - mexErrMsgIdAndTxt("mex_function:validate_and_populate_arg", - mex_binding::escape_percent(e.what()).c_str()); - } - catch (mex_binding::user_hit_ctrl_c& ) - { - // do nothing, just return to matlab - } - catch (std::exception& e) - { - mexErrMsgIdAndTxt("mex_function:error", - mex_binding::escape_percent(e.what()).c_str()); - } - - cout << flush; - cerr << flush; -} - -// ---------------------------------------------------------------------------------------- - diff --git a/ml/dlib/dlib/matlab/subprocess_stream.cpp b/ml/dlib/dlib/matlab/subprocess_stream.cpp deleted file mode 100644 index 4d4d53af0..000000000 --- a/ml/dlib/dlib/matlab/subprocess_stream.cpp +++ /dev/null @@ -1,537 +0,0 @@ -// Copyright (C) 2016 Davis E. King (davis@dlib.net) -// License: Boost Software License See LICENSE.txt for the full license. - -#include "subprocess_stream.h" - -#include <sstream> -#include <utility> -#include <iostream> -#include <cstdio> -#include <fcntl.h> -#include <signal.h> -#include <sys/wait.h> -#include <sys/select.h> -#include "call_matlab.h" - -using namespace std; - -// ---------------------------------------------------------------------------------------- - -namespace dlib -{ - -// ---------------------------------------------------------------------------------------- - - void make_fd_non_blocking(int fd) - { - int flags = fcntl(fd, F_GETFL, 0); - fcntl(fd, F_SETFL, flags | O_NONBLOCK); - } - -// ---------------------------------------------------------------------------------------- - - // Block until fd is ready to read, while also echoing whatever is in fd_printf to - // cout. - int read_echoing_select(int fd, int fd_printf) - { - // run until fd has data ready - while(fd_printf >= 0) - { - fd_set rfds; - int retval; - - while(true) - { - FD_ZERO(&rfds); - FD_SET(fd, &rfds); - FD_SET(fd_printf, &rfds); - - // select times out every second just so we can check for matlab ctrl+c. - struct timeval tv; - tv.tv_sec = 1; - tv.tv_usec = 0; - - try{check_for_matlab_ctrl_c();} catch(...) { return 1; } - retval = select(std::max(fd,fd_printf)+1, &rfds, NULL, NULL, &tv); - try{check_for_matlab_ctrl_c();} catch(...) { return 1; } - if (retval == 0) // keep going if it was just a timeout. - continue; - else if (retval == -1 && errno == EINTR) - continue; - - break; - } - - if (retval == -1) - { - return 1; - } - else - { - if (FD_ISSET(fd,&rfds)) - { - return 0; - } - else - { - char buf[1024]; - int num = read(fd_printf,buf, sizeof(buf)-1); - if (num == -1) - return 1; - if (num > 0) - { - buf[num] = 0; - cout << buf << flush; - } - } - } - } - return 0; - } - - int write_echoing_select(int fd, int fd_printf) - { - // run until fd has data ready - while(fd_printf >= 0) - { - fd_set rfds, wfds; - int retval; - while(true) - { - FD_ZERO(&rfds); - FD_ZERO(&wfds); - FD_SET(fd, &wfds); - FD_SET(fd_printf, &rfds); - - // select times out every second just so we can check for matlab ctrl+c. - struct timeval tv; - tv.tv_sec = 1; - tv.tv_usec = 0; - - try{check_for_matlab_ctrl_c();} catch(...) { return 1; } - retval = select(std::max(fd,fd_printf)+1, &rfds, &wfds, NULL, &tv); - try{check_for_matlab_ctrl_c();} catch(...) { return 1; } - if (retval == 0) // keep going if it was just a timeout. - continue; - else if (retval == -1 && errno == EINTR) - continue; - - break; - } - - if (retval == -1) - { - return 1; - } - else - { - if (FD_ISSET(fd,&wfds)) - { - return 0; - } - else - { - char buf[1024]; - int num = read(fd_printf,buf, sizeof(buf)-1); - if (num == -1) - return 1; - if (num > 0) - { - buf[num] = 0; - cout << buf << flush; - } - } - } - } - return 0; - } - -// ---------------------------------------------------------------------------------------- - - class filestreambuf : public std::streambuf - { - /*! - INITIAL VALUE - - fd == the file descriptor we read from. - - in_buffer == an array of in_buffer_size bytes - - out_buffer == an array of out_buffer_size bytes - - CONVENTION - - in_buffer == the input buffer used by this streambuf - - out_buffer == the output buffer used by this streambuf - - max_putback == the maximum number of chars to have in the put back buffer. - !*/ - - public: - - filestreambuf ( - int fd_, - int fd_printf_ - ) : - fd(fd_), - fd_printf(fd_printf_), - out_buffer(0), - in_buffer(0) - { - init(); - } - - virtual ~filestreambuf ( - ) - { - sync(); - delete [] out_buffer; - delete [] in_buffer; - } - - int sync ( - ) - { - if (flush_out_buffer() == EOF) - { - // an error occurred - return -1; - } - return 0; - } - protected: - - void init ( - ) - { - try - { - out_buffer = new char[out_buffer_size]; - in_buffer = new char[in_buffer_size]; - } - catch (...) - { - if (out_buffer) delete [] out_buffer; - throw; - } - setp(out_buffer, out_buffer + (out_buffer_size-1)); - setg(in_buffer+max_putback, - in_buffer+max_putback, - in_buffer+max_putback); - } - - int flush_out_buffer ( - ) - { - int num = static_cast<int>(pptr()-pbase()); - const int num_written = num; - char* buf = out_buffer; - while(num != 0) - { - if(write_echoing_select(fd, fd_printf)) - return EOF; - int status = write(fd,buf,num); - if (status < 0) - { - // the write was not successful so return EOF - return EOF; - } - num -= status; - buf += status; - } - pbump(-num_written); - return num_written; - } - - // output functions - int_type overflow ( - int_type c - ) - { - if (c != EOF) - { - *pptr() = c; - pbump(1); - } - if (flush_out_buffer() == EOF) - { - // an error occurred - return EOF; - } - return c; - } - - - std::streamsize xsputn ( - const char* s, - std::streamsize num - ) - { - // Add a sanity check here - DLIB_ASSERT(num >= 0, - "\tstd::streamsize filestreambuf::xsputn" - << "\n\tThe number of bytes to write can't be negative" - << "\n\tnum: " << num - << "\n\tthis: " << this - ); - - std::streamsize space_left = static_cast<std::streamsize>(epptr()-pptr()); - if (num <= space_left) - { - std::memcpy(pptr(),s,static_cast<size_t>(num)); - pbump(static_cast<int>(num)); - return num; - } - else - { - std::memcpy(pptr(),s,static_cast<size_t>(space_left)); - s += space_left; - pbump(space_left); - std::streamsize num_left = num - space_left; - - if (flush_out_buffer() == EOF) - { - // the write was not successful so return that 0 bytes were written - return 0; - } - - if (num_left < out_buffer_size) - { - std::memcpy(pptr(),s,static_cast<size_t>(num_left)); - pbump(num_left); - return num; - } - else - { - while(num_left != 0) - { - if(write_echoing_select(fd, fd_printf)) - return EOF; - int status = write(fd,s,num_left); - if (status < 0) - { - // the write was not successful so return that 0 bytes were written - return 0; - } - num_left -= status; - s += status; - } - return num; - } - } - } - - // input functions - int_type underflow( - ) - { - if (gptr() < egptr()) - { - return static_cast<unsigned char>(*gptr()); - } - - int num_put_back = static_cast<int>(gptr() - eback()); - if (num_put_back > max_putback) - { - num_put_back = max_putback; - } - - // copy the putback characters into the putback end of the in_buffer - std::memmove(in_buffer+(max_putback-num_put_back), gptr()-num_put_back, num_put_back); - - - if (read_echoing_select(fd, fd_printf)) - return EOF; - int num = read(fd,in_buffer+max_putback, in_buffer_size-max_putback); - if (num <= 0) - { - // an error occurred or the connection is over which is EOF - return EOF; - } - - // reset in_buffer pointers - setg (in_buffer+(max_putback-num_put_back), - in_buffer+max_putback, - in_buffer+max_putback+num); - - return static_cast<unsigned char>(*gptr()); - } - - std::streamsize xsgetn ( - char_type* s, - std::streamsize n - ) - { - std::streamsize temp = n; - while (n > 0) - { - int num = static_cast<int>(egptr() - gptr()); - if (num >= n) - { - // copy data from our buffer - std::memcpy(s, gptr(), static_cast<size_t>(n)); - gbump(static_cast<int>(n)); - return temp; - } - - // read more data into our buffer - if (num == 0) - { - if (underflow() == EOF) - break; - continue; - } - - // copy all the data from our buffer - std::memcpy(s, gptr(), num); - n -= num; - gbump(num); - s += num; - } - return temp-n; - } - - private: - - // member data - int fd; - int fd_printf; - static const std::streamsize max_putback = 4; - static const std::streamsize out_buffer_size = 10000; - static const std::streamsize in_buffer_size = 10000; - char* out_buffer; - char* in_buffer; - - }; - - namespace impl - { - int get_data_fd() - { - char* env_fd = getenv("DLIB_SUBPROCESS_DATA_FD"); - DLIB_CASSERT(env_fd != 0,""); - return atoi(env_fd); - } - - std::iostream& get_data_iostream() - { - static filestreambuf dbuff(get_data_fd(), -1); - static iostream out(&dbuff); - return out; - } - } - -// ---------------------------------------------------------------------------------------- - - subprocess_stream:: - subprocess_stream(const char* program_name) : stderr(NULL), iosub(NULL) - { - if (access(program_name, F_OK)) - throw dlib::error("Error: '" + std::string(program_name) + "' file does not exist."); - if (access(program_name, X_OK)) - throw dlib::error("Error: '" + std::string(program_name) + "' file is not executable."); - - child_pid = fork(); - if (child_pid == -1) - throw dlib::error("Failed to start child process"); - - if (child_pid == 0) - { - // In child process - dup2(stdout_pipe.child_fd(), STDOUT_FILENO); - dup2(stderr_pipe.child_fd(), STDERR_FILENO); - stdout_pipe.close(); - stderr_pipe.close(); - - char* argv[] = {(char*)program_name, nullptr}; - char* cudadevs = getenv("CUDA_VISIBLE_DEVICES"); - if (cudadevs) - { - std::ostringstream sout; - sout << "DLIB_SUBPROCESS_DATA_FD="<<data_pipe.child_fd(); - std::string extra = sout.str(); - - std::string extra2 = std::string("CUDA_VISIBLE_DEVICES=") + cudadevs; - char* envp[] = {(char*)extra.c_str(), (char*)extra2.c_str(), nullptr}; - execve(argv[0], argv, envp); - } - else - { - std::ostringstream sout; - sout << "DLIB_SUBPROCESS_DATA_FD="<<data_pipe.child_fd(); - std::string extra = sout.str(); - char* envp[] = {(char*)extra.c_str(), nullptr}; - execve(argv[0], argv, envp); - } - - - // If launching the child didn't work then bail immediately so the parent - // process has no chance to get tweaked out (*cough* MATLAB *cough*). - _Exit(1); - } - else - { - // In parent process - close(data_pipe.child_fd()); - close(stdout_pipe.child_fd()); - close(stderr_pipe.child_fd()); - make_fd_non_blocking(data_pipe.parent_fd()); - make_fd_non_blocking(stdout_pipe.parent_fd()); - make_fd_non_blocking(stderr_pipe.parent_fd()); - inout_buf = std::unique_ptr<filestreambuf>(new filestreambuf(data_pipe.parent_fd(), stdout_pipe.parent_fd())); - err_buf = std::unique_ptr<filestreambuf>(new filestreambuf(stderr_pipe.parent_fd(), stdout_pipe.parent_fd())); - iosub.rdbuf(inout_buf.get()); - stderr.rdbuf(err_buf.get()); - iosub.tie(&iosub); - stderr.tie(&iosub); - } - } - -// ---------------------------------------------------------------------------------------- - - subprocess_stream:: - ~subprocess_stream() - { - try - { - wait(); - } - catch (dlib::error& e) - { - std::cerr << e.what() << std::endl; - } - } - -// ---------------------------------------------------------------------------------------- - - void subprocess_stream:: - wait() - { - if (!wait_called) - { - wait_called = true; - send_eof(); - - std::ostringstream sout; - sout << stderr.rdbuf(); - - try{check_for_matlab_ctrl_c();} catch(...) - { - kill(child_pid, SIGTERM); - } - - int status; - waitpid(child_pid, &status, 0); - if (status) - throw dlib::error("Child process terminated with an error.\n" + sout.str()); - - if (sout.str().size() != 0) - throw dlib::error("Child process terminated with an error.\n" + sout.str()); - } - } - -// ---------------------------------------------------------------------------------------- - - void subprocess_stream:: - send_eof() { inout_buf->sync(); ::close(data_pipe.parent_fd()); } - -// ---------------------------------------------------------------------------------------- - -} - - diff --git a/ml/dlib/dlib/matlab/subprocess_stream.h b/ml/dlib/dlib/matlab/subprocess_stream.h deleted file mode 100644 index b00904c12..000000000 --- a/ml/dlib/dlib/matlab/subprocess_stream.h +++ /dev/null @@ -1,223 +0,0 @@ -// Copyright (C) 2016 Davis E. King (davis@dlib.net) -// License: Boost Software License See LICENSE.txt for the full license. -#ifndef DLIB_SUBPROCeSS_STREAM_H_ -#define DLIB_SUBPROCeSS_STREAM_H_ - -#include <utility> -#include <unistd.h> -#include <iostream> -#include <memory> -#include <dlib/matrix.h> -#include <sys/types.h> -#include <sys/socket.h> - - -namespace dlib -{ - -// -------------------------------------------------------------------------------------- - - // Call dlib's serialize and deserialize by default. The point of this version of - // serialize is to do something fast that normally we wouldn't do, like directly copy - // memory. This is safe since this is an interprocess communication happening the same - // machine. - template <typename T> void interprocess_serialize ( const T& item, std::ostream& out) { serialize(item, out); } - template <typename T> void interprocess_deserialize (T& item, std::istream& in) { deserialize(item, in); } - - // But have overloads for direct memory copies for some types since this is faster than - // their default serialization. - template <typename T, long NR, long NC, typename MM, typename L> - void interprocess_serialize(const dlib::matrix<T,NR,NC,MM,L>& item, std::ostream& out) - { - dlib::serialize(item.nr(), out); - dlib::serialize(item.nc(), out); - if (item.size() != 0) - out.write((const char*)&item(0,0), sizeof(T)*item.size()); - if (!out) - throw dlib::serialization_error("Error writing matrix to interprocess iostream."); - } - - template <typename T, long NR, long NC, typename MM, typename L> - void interprocess_deserialize(dlib::matrix<T,NR,NC,MM,L>& item, std::istream& in) - { - long nr, nc; - dlib::deserialize(nr, in); - dlib::deserialize(nc, in); - item.set_size(nr,nc); - if (item.size() != 0) - in.read((char*)&item(0,0), sizeof(T)*item.size()); - if (!in) - throw dlib::serialization_error("Error reading matrix from interprocess iostream."); - } - -// ---------------------------------------------------------------------------------------- - - namespace impl{ std::iostream& get_data_iostream(); } - - inline void send_to_parent_process() {impl::get_data_iostream().flush();} - template <typename U, typename ...T> - void send_to_parent_process(U&& arg1, T&& ...args) - /*! - ensures - - sends all the arguments to send_to_parent_process() to the parent process by - serializing them with interprocess_serialize(). - !*/ - { - interprocess_serialize(arg1, impl::get_data_iostream()); - send_to_parent_process(std::forward<T>(args)...); - if (!impl::get_data_iostream()) - throw dlib::error("Error sending object to parent process."); - } - - inline void receive_from_parent_process() {} - template <typename U, typename ...T> - void receive_from_parent_process(U&& arg1, T&& ...args) - /*! - ensures - - receives all the arguments to receive_from_parent_process() from the parent - process by deserializing them from interprocess_serialize(). - !*/ - { - interprocess_deserialize(arg1, impl::get_data_iostream()); - receive_from_parent_process(std::forward<T>(args)...); - if (!impl::get_data_iostream()) - throw dlib::error("Error receiving object from parent process."); - } - - -// ---------------------------------------------------------------------------------------- - - class filestreambuf; - - class subprocess_stream : noncopyable - { - /*! - WHAT THIS OBJECT REPRESENTS - This is a tool for spawning a subprocess and communicating with it. Here - is an example: - - subprocess_stream s("/usr/bin/some_program"); - s.send(obj1, obj2, obj3); - s.receive(obj4, obj5); - s.wait(); // wait for sub process to terminate - - Then in the sub process you would have: - - receive_from_parent_process(obj1, obj2, obj3); - // do stuff - cout << "echo this text to parent cout" << endl; - send_to_parent_process(obj4, obj5); - - - Additionally, if the sub process writes to its standard out then that will - be echoed to std::cout in the parent process. Writing to std::cerr or - returning a non-zero value from main will also be noted by the parent - process and an appropriate exception will be thrown. - !*/ - - public: - - explicit subprocess_stream( - const char* program_name - ); - /*! - ensures - - spawns a sub process by executing the file with the given program_name. - !*/ - - ~subprocess_stream( - ); - /*! - ensures - - calls wait(). Note that the destructor never throws even though wait() can. - If an exception is thrown by wait() it is just logged to std::cerr. - !*/ - - void wait( - ); - /*! - ensures - - closes the input stream to the child process and then waits for the child - to terminate. - - If the child returns an error (by returning != 0 from its main) or - outputs to its standard error then wait() throws a dlib::error() with the - standard error output in it. - !*/ - - int get_child_pid() const { return child_pid; } - /*! - ensures - - returns the PID of the child process - !*/ - - template <typename U, typename ...T> - void send(U&& arg1, T&& ...args) - /*! - ensures - - sends all the arguments to send() to the subprocess by serializing them - with interprocess_serialize(). - !*/ - { - interprocess_serialize(arg1, iosub); - send(std::forward<T>(args)...); - if (!iosub) - { - std::ostringstream sout; - sout << stderr.rdbuf(); - throw dlib::error("Error sending object to child process.\n" + sout.str()); - } - } - void send() {iosub.flush();} - - template <typename U, typename ...T> - void receive(U&& arg1, T&& ...args) - /*! - ensures - - receives all the arguments to receive() to the subprocess by deserializing - them with interprocess_deserialize(). - !*/ - { - interprocess_deserialize(arg1, iosub); - receive(std::forward<T>(args)...); - if (!iosub) - { - std::ostringstream sout; - sout << stderr.rdbuf(); - throw dlib::error("Error receiving object from child process.\n" + sout.str() ); - } - } - void receive() {} - - - private: - - void send_eof(); - - class cpipe : noncopyable - { - private: - int fd[2]; - public: - cpipe() { if (socketpair(AF_LOCAL, SOCK_STREAM, 0, fd)) throw dlib::error("Failed to create pipe"); } - ~cpipe() { close(); } - int parent_fd() const { return fd[0]; } - int child_fd() const { return fd[1]; } - void close() { ::close(fd[0]); ::close(fd[1]); } - }; - - cpipe data_pipe; - cpipe stdout_pipe; - cpipe stderr_pipe; - bool wait_called = false; - std::unique_ptr<filestreambuf> inout_buf; - std::unique_ptr<filestreambuf> err_buf; - int child_pid = -1; - std::istream stderr; - std::iostream iosub; - }; -} - -// ---------------------------------------------------------------------------------------- - -#endif // DLIB_SUBPROCeSS_STREAM_H_ - |