Calling methods of C++ class in MEX from MATLAB

后端 未结 5 2085
一向
一向 2021-01-03 09:59

I have a DLP kit which I need to control via MATLAB using a C++ API.

Say, I have functions/methods using C/C++ for {load_data, load_settings,display_data}

5条回答
  •  时光说笑
    2021-01-03 10:54

    Alternative design, cleaner for the use case here, is to define a singleton class with init, fcnA, fcnB, fcnC, ... methods ... etc, with corresponding lightweight wrappers.. and then invoke the wrappers from the MEX.

    e.g.

    class A {
      public:
         A getInstance() {
            if ( !instance )
                 instance = new A(...);
            return instance;
         }
    
        void fcnA(T1 a1, T2 a2) {
               //yada yada
         }
    
      private:
        static A* instance;
    };
    A::instance = NULL;
    
    //begin wrappers for marshalling to class method
    A* getInstance( ) {
       return A::getInstance();
    }
    
    void fcnA(T1 a1, T2 a2) {
       getInstance()->fcnA(a1,a2);
    }
    
    //ad nauseum
    

提交回复
热议问题