2013-03-18 08:35:43 +08:00
|
|
|
/*
|
2013-03-18 12:48:10 +08:00
|
|
|
* file: {{clss.name}}Bridge.cpp
|
2013-03-18 08:35:43 +08:00
|
|
|
* author: A trusty code generator
|
2013-03-18 10:37:42 +08:00
|
|
|
* date: {{time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime())}}
|
2013-03-18 08:35:43 +08:00
|
|
|
*
|
|
|
|
* This file was autogenerated, do not modify.
|
|
|
|
* See LICENCE for full modification and redistribution details.
|
2013-03-18 10:37:42 +08:00
|
|
|
* Copyright {{time.strftime("%Y", time.localtime())}} The OpenCV Foundation
|
2013-03-18 08:35:43 +08:00
|
|
|
*/
|
|
|
|
#include "mex.h"
|
|
|
|
#include "bridge.hpp"
|
|
|
|
#include <vector>
|
|
|
|
#include <unordered_map>
|
|
|
|
#include <string>
|
|
|
|
{% block includes %}
|
|
|
|
{% endblock %}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
typedef std::unordered_map Map;
|
2013-03-18 12:48:10 +08:00
|
|
|
typedef std::vector<Bridge> (*)({{clss.name}}&, const std::vector<Bridge>&) MethodSignature;
|
2013-03-18 08:35:43 +08:00
|
|
|
|
2013-03-18 12:48:10 +08:00
|
|
|
{% for function in clss.functions %}
|
2013-03-18 08:35:43 +08:00
|
|
|
// wrapper for {{function.name}}() method
|
2013-03-18 12:48:10 +08:00
|
|
|
std::vector<Bridge> {{function.name}}({{clss.name}}& inst, const std::vector<Bridge>& args) {
|
2013-03-18 08:35:43 +08:00
|
|
|
// setup
|
|
|
|
|
|
|
|
// invoke
|
|
|
|
|
|
|
|
// setdown
|
|
|
|
}
|
2013-03-18 12:48:10 +08:00
|
|
|
|
2013-03-18 08:35:43 +08:00
|
|
|
{% endfor %}
|
|
|
|
|
|
|
|
map<std::string, MethodSignature> createMethodMap() {
|
|
|
|
Map<std::string, MethodSignature> m;
|
2013-03-18 12:48:10 +08:00
|
|
|
{% for function in clss.functions -%}
|
2013-03-18 08:35:43 +08:00
|
|
|
m["{{function.name}}"] = &{{function.name}};
|
|
|
|
{% endfor %}
|
2013-03-18 12:48:10 +08:00
|
|
|
|
2013-03-18 08:35:43 +08:00
|
|
|
return m;
|
|
|
|
}
|
|
|
|
static const Map<std::string, MethodSignature> methods = createMethodMap();
|
|
|
|
|
2013-03-18 12:48:10 +08:00
|
|
|
// map of created {{clss.name}} instances. Don't trust the user to keep them safe...
|
|
|
|
static Map<void *, {{clss.name}}> instances;
|
2013-03-18 08:35:43 +08:00
|
|
|
|
|
|
|
/*
|
2013-03-18 12:48:10 +08:00
|
|
|
* {{ clss.name }}
|
2013-03-18 08:35:43 +08:00
|
|
|
* 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<Bridge> brhs(prhs+2, prhs+nrhs);
|
|
|
|
|
|
|
|
// retrieve the instance of interest
|
|
|
|
try {
|
2013-03-18 12:48:10 +08:00
|
|
|
{{clss.name}}& inst = instances.at(handle.address());
|
2013-03-18 08:35:43 +08:00
|
|
|
} catch (const std::out_of_range& e) {
|
|
|
|
mexErrMsgTxt("Invalid object instance provided");
|
|
|
|
}
|
|
|
|
|
|
|
|
// invoke the correct method on the data
|
|
|
|
try {
|
|
|
|
std::vector<Bridge> blhs = (*methods.at(method_name))(inst, brhs);
|
|
|
|
} catch (const std::out_of_range& e) {
|
|
|
|
mexErrMsgTxt("Unknown method specified");
|
|
|
|
}
|
|
|
|
|
|
|
|
{% block postfun %}
|
|
|
|
{% endblock %}
|
|
|
|
|
|
|
|
{% block cleanup %}
|
|
|
|
{% endblock %}
|
2013-03-18 12:48:10 +08:00
|
|
|
|
2013-03-18 08:35:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}; // end namespace
|