Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
m_trsolver_interface_mex.cpp
Go to the documentation of this file.
1 #include <iostream>
2 #include <string>
3 #include <cstring>
4 #include <map>
5 #include <typeinfo>
6 #include "mex.h"
7 #include "class_handle.hpp"
8 #include "mextrsolver.h"
9 
10 using namespace std;
11 
12 // Value-Defintions of the different class methods available
32  };
33 
34 // Map to associate the command strings with the class
35 // method enum values
36 std::map<std::string, ClassMethods> s_mapClassMethodStrs;
37 
38 void Initialize()
39 {
40  // Set up the class methods map
41  s_mapClassMethodStrs["prepare_netlist"] = prepare_netlist;
42  s_mapClassMethodStrs["init_sync"] = init_sync;
43  s_mapClassMethodStrs["init_async"] = init_async;
44  s_mapClassMethodStrs["stepsolve_sync"] = stepsolve_sync;
45  s_mapClassMethodStrs["acceptstep_sync"] = acceptstep_sync;
46  s_mapClassMethodStrs["stepsolve_async"] = stepsolve_async;
47  s_mapClassMethodStrs["acceptstep_async"] = acceptstep_async;
48  s_mapClassMethodStrs["rejectstep_async"] = rejectstep_async;
49  s_mapClassMethodStrs["getsolution"] = getsolution;
50  s_mapClassMethodStrs["debug"] = debug;
51  s_mapClassMethodStrs["printx"] = printx;
52  s_mapClassMethodStrs["getN"] = getN;
53  s_mapClassMethodStrs["getM"] = getM;
54  s_mapClassMethodStrs["getJac"] = getJac;
55  s_mapClassMethodStrs["setecvs"] = setecvs;
56  s_mapClassMethodStrs["getnodev"] = getnodev;
57  s_mapClassMethodStrs["getvprobe"] = getvprobe;
58  s_mapClassMethodStrs["getiprobe"] = getiprobe;
59 }
60 
61 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
62 {
63  // Get the command string
64  char cmd[128];
65 
66  Initialize();
67 
68  if (nrhs < 1 || mxGetString(prhs[0], cmd, sizeof(cmd)))
69  {
70  mexErrMsgTxt("First input should be a command string less than 128 characters long.");
71  }
72 
73  // New
74  if (!strcmp("new", cmd))
75  {
76  // Check parameters
77  if (nlhs != 1)
78  mexErrMsgTxt("New: One output expected.");
79  // Return a handle to a new C++ instance
80  plhs[0] = convertPtr2Mat<mextrsolver>(new mextrsolver);
81  return;
82  }
83 
84  // Check there is a second input, which should be the class instance handle
85  if (nrhs < 2)
86  mexErrMsgTxt("Second input should be a class instance handle.");
87 
88  // Delete
89  if (!strcmp("delete", cmd))
90  {
91  // Destroy the C++ object
92  destroyObject<mextrsolver>(prhs[1]);
93  // Warn if other commands were ignored
94  if (nlhs != 0 || nrhs != 2)
95  mexWarnMsgTxt("Delete: Unexpected arguments ignored.");
96  return;
97  }
98 
99  // Get the class instance pointer from the second input
100  mextrsolver *mextrsolver_instance = convertMat2Ptr<mextrsolver>(prhs[1]);
101 
102  // Call the various class methods
103  // Switch on the value
104  switch(s_mapClassMethodStrs[cmd])
105  {
106  case prepare_netlist:
107  mextrsolver_instance->prepare_netlist(nlhs, plhs, nrhs, prhs);
108  return;
109  case init_sync:
110  mextrsolver_instance->init_sync(nlhs, plhs, nrhs, prhs);
111  return;
112  case init_async:
113  mextrsolver_instance->init_async(nlhs, plhs, nrhs, prhs);
114  return;
115  case stepsolve_sync:
116  mextrsolver_instance->stepsolve_sync(nlhs, plhs, nrhs, prhs);
117  return;
118  case acceptstep_sync:
119  mextrsolver_instance->acceptstep_sync(nlhs, plhs, nrhs, prhs);
120  return;
121  case stepsolve_async:
122  mextrsolver_instance->stepsolve_async(nlhs, plhs, nrhs, prhs);
123  return;
124  case acceptstep_async:
125  mextrsolver_instance->acceptstep_async(nlhs, plhs, nrhs, prhs);
126  return;
127  case rejectstep_async:
128  mextrsolver_instance->rejectstep_async(nlhs, plhs, nrhs, prhs);
129  return;
130  case getsolution:
131  mextrsolver_instance->getsolution(nlhs, plhs, nrhs, prhs);
132  return;
133 // case debug:
134 // mextrsolver_instance->debug();
135 // return;
136  case printx:
137  mextrsolver_instance->printx();
138  return;
139  case getN:
140  mextrsolver_instance->getN(nlhs, plhs, nrhs, prhs);
141  return;
142  case getM:
143  mextrsolver_instance->getM(nlhs, plhs, nrhs, prhs);
144  return;
145  case getJac:
146  mextrsolver_instance->getJac(nlhs, plhs, nrhs, prhs);
147  return;
148  case setecvs:
149  mextrsolver_instance->setecvs(nlhs, plhs, nrhs, prhs);
150  return;
151  case getnodev:
152  mextrsolver_instance->getnodev(nlhs, plhs, nrhs, prhs);
153  return;
154  case getvprobe:
155  mextrsolver_instance->getvprobe(nlhs, plhs, nrhs, prhs);
156  return;
157  case getiprobe:
158  mextrsolver_instance->getiprobe(nlhs, plhs, nrhs, prhs);
159  return;
160  default:
161  mexErrMsgTxt("Unrecognised class command string.");
162  break;
163  }
164 
165  // Got here, so command not recognized
166  //mexErrMsgTxt("Command not recognized.");
167 }
std::map< std::string, ClassMethods > s_mapClassMethodStrs
void Initialize()
void printx(void)
Definition: mextrsolver.cpp:30
int stepsolve_async(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
void getiprobe(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
int stepsolve_sync(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
void acceptstep_sync(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
int prepare_netlist(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Definition: mextrsolver.cpp:35
void getJac(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
void getnodev(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
int getsolution(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
void init_sync(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
void init_async(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
void rejectstep_async(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
void getvprobe(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
void acceptstep_async(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
void setecvs(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
int getM(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
int getN(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])