root/library/bdm/mex/mex_function.h @ 1187

Revision 1064, 1.0 kB (checked in by mido, 14 years ago)

astyle applied all over the library

Line 
1#ifndef MXFNC_H
2#define MXFNC_H
3
4
5#include <base/bdmbase.h>
6#include "mex_parser.h"
7
8namespace bdm {
9
10/*! class mapping fnc.eval to call of matlab function via mexCallMatlab
11*/
12class mexFnc: public fnc {
13protected:
14    string fname;
15public:
16    vec eval(const vec &cond) {
17        mxArray *mxinp = mxCreateDoubleMatrix ( cond.length(), 1, mxREAL );
18        mxArray *mxout;
19
20        vec2mxArray(cond,mxinp);
21        mexCallMATLAB ( 1, &mxout, 1, &mxinp, fname.c_str() );
22
23        bdm_assert(int(mxGetN(mxout))==(dimension()) || int(mxGetM(mxout))==(dimension()), "vector length mismatch");
24        vec tmp=mxArray2vec(mxout);
25        return tmp;
26    }
27    /*!
28    \code
29    function = 'matlab_function_name';
30    \endcode
31    */
32    void from_setting(const Setting &set) {
33        fnc::from_setting(set);
34        UI::get(fname, set, "function", UI::compulsory);
35    }
36    void to_setting(Setting &set) const {
37        fnc::to_setting(set);
38        UI::save(fname, set, "function");
39    }
40};
41UIREGISTER(mexFnc);
42}
43#endif //MXFNC_H
Note: See TracBrowser for help on using the browser.