C++ Template Classes and Matlab Mex -


i'm wondering if there elegant way write matlab/mex interface templated c++ code.

here situation: have written nice set of c++ template classes so:

template<footype t> foo{     private:          //some data     public:          //constructors, methods };  template<bartype s> bar{     private:          //some data     public:          //constructors, methods };  template<footype t, bartype s> myclass{     private:          foo<t> *d;         bar<s> *m;     public:          //constructors, methods }; 

if have say, n different footypes , m different bartypes, have n*m different parameter choices myclass (footype , bartype custom typenames, incedentally). now, if writing c++ program use these classes, simple:

int main() {     foo<footype1> *f = new foo<footype1>(params);     bar<bartype3> *b = new bar<bartype3>(params);      myclass<footype1,bartype3> *m = new myclass(f,b);      m->dothing();      return 0; }  

i compile main.cpp , run , rejoice. works because have selected template parameters @ compile time, per c++ template design. works me far, , design.

now suppose want write same type of program main.cpp, using matlab scripting language , mex interface classes.hpp. main reason wanting code add-on exisiting matlab package. there elegant way write mex file have access every possible pair of template parameters? have started write interface file lot of switch statements can select footype , bartype - mex file compiles every possible (n*m) class instance , leaves them sitting there matlab use. seems ok (i have n=3, m=2), seems sloppy , difficult maintain.

i have thought making "user" re-compile mex file every time want choose different footype , bartype, seems bit irritating (to average matlab user anyway). input!

i'm not familiar mex; i'm c++ user. describe not possible without direct matlab support run-time library generation, don't think thing exists. need pre-instantiate @ compile time. not simple.

the problem, have said, templates generated @ compile time, , aren't used until runtime, when type information gone. mangled names shouldn't issue, assuming matlab knows mangling scheme.

so you'll have solve @ c++ level. in c++, there's no type-safe way name of type string. solution use macros eliminate of bloat. unfortunate, because if possible, elegant solution possible std::tuple of valid parameter types, , little recursive template magic.


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

c# - MSDN OneNote Api: Navigate to never before opened page without opening a OneNote Application Window -