template_function_base.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. {% import 'functional.cpp' as functional %}
  2. /*
  3. * file: {{fun.name}}.cpp
  4. * author: A trusty code generator
  5. *
  6. * This file was autogenerated, do not modify.
  7. * See LICENSE for full modification and redistribution details.
  8. * Copyright 2018 The OpenCV Foundation
  9. */
  10. #include <string>
  11. #include <vector>
  12. #include <cassert>
  13. #include <exception>
  14. #include <opencv2/matlab/bridge.hpp>
  15. #include <opencv2/{{includes}}.hpp>
  16. using namespace cv;
  17. using namespace matlab;
  18. using namespace bridge;
  19. /*
  20. * {{ fun.name }}
  21. * {{ fun }}
  22. * Gateway routine
  23. * nlhs - number of return arguments
  24. * plhs - pointers to return arguments
  25. * nrhs - number of input arguments
  26. * prhs - pointers to input arguments
  27. */
  28. void mexFunction(int nlhs, mxArray*{% if fun|noutputs %} plhs[]{% else %}*{% endif %},
  29. int nrhs, const mxArray*{% if fun|ninputs %} prhs[]{% else %}*{% endif %}) {
  30. {% if fun|ninputs %}
  31. // parse the inputs
  32. ArgumentParser parser("{{fun.name}}");
  33. parser.{{ functional.composeVariant(fun) }};
  34. MxArrayVector sorted = parser.parse(MxArrayVector(prhs, prhs+nrhs));
  35. {% endif %}
  36. {% if fun|ninputs or fun|noutputs %}
  37. // setup
  38. {% if fun|ninputs %}
  39. BridgeVector inputs(sorted.begin(), sorted.end());
  40. {% endif -%}
  41. {%- if fun|noutputs %}
  42. BridgeVector outputs({{fun|noutputs}});
  43. {% endif %}
  44. {% endif %}
  45. {{ functional.handleInputs(fun) }}
  46. {{ functional.composeWithExceptionHandler(fun) }}
  47. {{ functional.handleOutputs(fun) }}
  48. {% if fun|noutputs %}
  49. // push the outputs back to matlab
  50. for (size_t n = 0; n < static_cast<size_t>(std::max(nlhs,1)); ++n) {
  51. plhs[n] = outputs[n].toMxArray().releaseOwnership();
  52. }
  53. {% endif %}
  54. }