MCPcopy Create free account
hub / github.com/davisking/dlib / mexFunction

Function mexFunction

dlib/matlab/mex_wrapper.cpp:5007–5159  ·  view source on GitHub ↗

The gateway function called by MATLAB*/

Source from the content-addressed store, hash-verified

5005
5006/* The gateway function called by MATLAB*/
5007void mexFunction( int nlhs, mxArray *plhs[],
5008 int nrhs, const mxArray *prhs[])
5009{
5010 // Only remap cout and cerr if we aren't using octave since octave already does this.
5011#if !defined(OCTAVE_IMPORT) && !defined(OCTAVE_API)
5012 // make it so cout prints to mexPrintf()
5013 mex_binding::mex_streambuf sb;
5014 // make it so cerr prints to mexWarnMsgTxt()
5015 mex_binding::mex_warn_streambuf wsb;
5016#endif
5017
5018 try
5019 {
5020#ifdef MEX_CLASS_NAME
5021 if (nrhs == 0)
5022 {
5023 #define DEF2STR(x) DEF2STR2((x))
5024 #define DEF2STR2(x) #x
5025
5026 string classname = trim(string(DEF2STR(MEX_CLASS_NAME)), " \t()");
5027 std::vector<string> methods = split(trim(string(DEF2STR(MEX_CLASS_METHODS)), " \t()"), " \t,");
5028
5029 string mex_filename = trim(string(DEF2STR(MEX_FILENAME))," \t()");
5030 bool has_load_obj = false;
5031 size_t load_obj_idx = 0;
5032
5033 cout << "classdef " << classname << " < handle\n"
5034 << " properties (Access = private)\n"
5035 << " cpp_ptr\n"
5036 << " end\n"
5037 << "\n"
5038 << " methods\n"
5039 << " function this = "<<classname<<"()\n"
5040 << " this.cpp_ptr = "<<mex_filename<<"('construct');\n"
5041 << " end\n"
5042 << "\n"
5043 << " function copied_obj = clone(this)\n"
5044 << " %Returns a new independent object that is a copy of this.\n"
5045 << " copied_obj = "<<classname<<"();\n"
5046 << " copied_obj.cpp_ptr = "<<mex_filename<<"(this.cpp_ptr,'clone');\n"
5047 << " end\n"
5048 << "\n";
5049 for (size_t i = 0; i < methods.size(); ++i)
5050 {
5051 if (methods[i] == "load_obj")
5052 {
5053 has_load_obj = true;
5054 load_obj_idx = i;
5055 }
5056 else
5057 {
5058 cout << " function varargout = "<<methods[i]<<"(this, varargin) \n"
5059 << " [varargout{1:nargout}] = "<<mex_filename<<"(this.cpp_ptr, "<<i+1<<", varargin{:}); \n"
5060 << " end \n\n";
5061 }
5062 }
5063 cout << " end\n\n";
5064

Callers

nothing calls this directly

Calls 11

trimFunction · 0.85
is_stringFunction · 0.85
visit_atFunction · 0.85
call_mex_functionFunction · 0.85
escape_percentFunction · 0.85
accessMethod · 0.80
splitFunction · 0.50
sizeMethod · 0.45
createMethod · 0.45
freeMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected