Qucs-core  0.0.19
m_trsolver_interface_mex.cpp
Go to the documentation of this file.
00001 #include <iostream>
00002 #include <string>
00003 #include <cstring>
00004 #include <map>
00005 #include <typeinfo>
00006 #include "mex.h"
00007 #include "class_handle.hpp"
00008 #include "mextrsolver.h"
00009 
00010 using namespace std;
00011 
00012 // Value-Defintions of the different class methods available
00013 enum ClassMethods { evNotDefined,
00014                     prepare_netlist,
00015                     init_sync,
00016                     init_async,
00017                     stepsolve_sync,
00018                     acceptstep_sync,
00019                     stepsolve_async,
00020                     acceptstep_async,
00021                     rejectstep_async,
00022                     getsolution,
00023                     debug,
00024                     printx,
00025                     getN,
00026                     getM,
00027                     getJac,
00028                     setecvs,
00029                     getnodev,
00030                     getvprobe,
00031                     getiprobe
00032                   };
00033 
00034 // Map to associate the command strings with the class
00035 // method enum values
00036 std::map<std::string, ClassMethods> s_mapClassMethodStrs;
00037 
00038 void Initialize()
00039 {
00040     // Set up the class methods map
00041     s_mapClassMethodStrs["prepare_netlist"]     = prepare_netlist;
00042     s_mapClassMethodStrs["init_sync"]           = init_sync;
00043     s_mapClassMethodStrs["init_async"]          = init_async;
00044     s_mapClassMethodStrs["stepsolve_sync"]      = stepsolve_sync;
00045     s_mapClassMethodStrs["acceptstep_sync"]     = acceptstep_sync;
00046     s_mapClassMethodStrs["stepsolve_async"]     = stepsolve_async;
00047     s_mapClassMethodStrs["acceptstep_async"]    = acceptstep_async;
00048     s_mapClassMethodStrs["rejectstep_async"]    = rejectstep_async;
00049     s_mapClassMethodStrs["getsolution"]         = getsolution;
00050     s_mapClassMethodStrs["debug"]               = debug;
00051     s_mapClassMethodStrs["printx"]              = printx;
00052     s_mapClassMethodStrs["getN"]                = getN;
00053     s_mapClassMethodStrs["getM"]                = getM;
00054     s_mapClassMethodStrs["getJac"]              = getJac;
00055     s_mapClassMethodStrs["setecvs"]             = setecvs;
00056     s_mapClassMethodStrs["getnodev"]            = getnodev;
00057     s_mapClassMethodStrs["getvprobe"]           = getvprobe;
00058     s_mapClassMethodStrs["getiprobe"]           = getiprobe;
00059 }
00060 
00061 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
00062 {
00063     // Get the command string
00064     char cmd[128];
00065 
00066     Initialize();
00067 
00068     if (nrhs < 1 || mxGetString(prhs[0], cmd, sizeof(cmd)))
00069     {
00070         mexErrMsgTxt("First input should be a command string less than 128 characters long.");
00071     }
00072 
00073     // New
00074     if (!strcmp("new", cmd))
00075     {
00076         // Check parameters
00077         if (nlhs != 1)
00078             mexErrMsgTxt("New: One output expected.");
00079         // Return a handle to a new C++ instance
00080         plhs[0] = convertPtr2Mat<mextrsolver>(new mextrsolver);
00081         return;
00082     }
00083 
00084     // Check there is a second input, which should be the class instance handle
00085     if (nrhs < 2)
00086         mexErrMsgTxt("Second input should be a class instance handle.");
00087 
00088     // Delete
00089     if (!strcmp("delete", cmd))
00090     {
00091         // Destroy the C++ object
00092         destroyObject<mextrsolver>(prhs[1]);
00093         // Warn if other commands were ignored
00094         if (nlhs != 0 || nrhs != 2)
00095             mexWarnMsgTxt("Delete: Unexpected arguments ignored.");
00096         return;
00097     }
00098 
00099     // Get the class instance pointer from the second input
00100     mextrsolver *mextrsolver_instance = convertMat2Ptr<mextrsolver>(prhs[1]);
00101 
00102     // Call the various class methods
00103     // Switch on the value
00104     switch(s_mapClassMethodStrs[cmd])
00105     {
00106     case prepare_netlist:
00107         mextrsolver_instance->prepare_netlist(nlhs, plhs, nrhs, prhs);
00108         return;
00109         case init_sync:
00110         mextrsolver_instance->init_sync(nlhs, plhs, nrhs, prhs);
00111         return;
00112         case init_async:
00113         mextrsolver_instance->init_async(nlhs, plhs, nrhs, prhs);
00114         return;
00115     case stepsolve_sync:
00116         mextrsolver_instance->stepsolve_sync(nlhs, plhs, nrhs, prhs);
00117         return;
00118     case acceptstep_sync:
00119         mextrsolver_instance->acceptstep_sync(nlhs, plhs, nrhs, prhs);
00120         return;
00121     case stepsolve_async:
00122         mextrsolver_instance->stepsolve_async(nlhs, plhs, nrhs, prhs);
00123         return;
00124         case acceptstep_async:
00125         mextrsolver_instance->acceptstep_async(nlhs, plhs, nrhs, prhs);
00126         return;
00127     case rejectstep_async:
00128         mextrsolver_instance->rejectstep_async(nlhs, plhs, nrhs, prhs);
00129         return;
00130     case getsolution:
00131         mextrsolver_instance->getsolution(nlhs, plhs, nrhs, prhs);
00132         return;
00133 //     case debug:
00134 //         mextrsolver_instance->debug();
00135 //         return;
00136     case printx:
00137         mextrsolver_instance->printx();
00138         return;
00139     case getN:
00140         mextrsolver_instance->getN(nlhs, plhs, nrhs, prhs);
00141         return;
00142     case getM:
00143         mextrsolver_instance->getM(nlhs, plhs, nrhs, prhs);
00144         return;
00145     case getJac:
00146         mextrsolver_instance->getJac(nlhs, plhs, nrhs, prhs);
00147         return;
00148     case setecvs:
00149         mextrsolver_instance->setecvs(nlhs, plhs, nrhs, prhs);
00150         return;
00151     case getnodev:
00152         mextrsolver_instance->getnodev(nlhs, plhs, nrhs, prhs);
00153         return;
00154     case getvprobe:
00155         mextrsolver_instance->getvprobe(nlhs, plhs, nrhs, prhs);
00156         return;
00157     case getiprobe:
00158         mextrsolver_instance->getiprobe(nlhs, plhs, nrhs, prhs);
00159         return;
00160     default:
00161         mexErrMsgTxt("Unrecognised class command string.");
00162         break;
00163     }
00164 
00165     // Got here, so command not recognized
00166     //mexErrMsgTxt("Command not recognized.");
00167 }