/* * file: {{class.name}}Bridge.cpp * author: A trusty code generator * date: {{time.strftime("%a, %d %b %Y %H:%M:%S", time.gmtime())}} * * This file was autogenerated, do not modify. * See LICENCE for full modification and redistribution details. * Copyright {{time.strftime("%Y", time.gmtime())}} The OpenCV Foundation */ #include "mex.h" #include "bridge.hpp" #include #include #include {% block includes %} {% endblock %} namespace { typedef std::unordered_map Map; typedef std::vector (*)({{class.name}}&, const std::vector&) MethodSignature; {% for function in class.functions %} // wrapper for {{function.name}}() method std::vector {{function.name}}({{class.name}}& inst, const std::vector& args) { // setup // invoke // setdown } {% endfor %} map createMethodMap() { Map m; {% for function in class.functions %} m["{{function.name}}"] = &{{function.name}}; {% endfor %} return m; } static const Map methods = createMethodMap(); // map of created {{class.name}} instances. Don't trust the user to keep them safe... static Map instances; /* * {{ class.name }} * Gateway routine * nlhs - number of return arguments * plhs - pointers to return arguments * nrhs - number of input arguments * prhs - pointers to input arguments */ void mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) { // parse the inputs Bridge method_name(prhs[0]); Bridge handle(prhs[1]); std::vector brhs(prhs+2, prhs+nrhs); // retrieve the instance of interest try { {{class.name}}& inst = instances.at(handle.address()); } catch (const std::out_of_range& e) { mexErrMsgTxt("Invalid object instance provided"); } // invoke the correct method on the data try { std::vector blhs = (*methods.at(method_name))(inst, brhs); } catch (const std::out_of_range& e) { mexErrMsgTxt("Unknown method specified"); } {% block postfun %} {% endblock %} {% block cleanup %} {% endblock %} } }; // end namespace