⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 displaystruct.c

📁 the interface method bettwen matlab and c++:MWStruct 结构体阵列操作
💻 C
字号:
/*
 * MATLAB Compiler: 3.0
 * Date: Fri Sep 26 08:59:13 2003
 * Arguments: "-B" "macro_default" "-O" "all" "-O" "fold_scalar_mxarrays:on"
 * "-O" "fold_non_scalar_mxarrays:on" "-O" "optimize_integer_for_loops:on" "-O"
 * "array_indexing:on" "-O" "optimize_conditionals:on" "-M" "-silentsetup" "-d"
 * "C:/TEMP/structdemo/structfiles/src" "-v" "-B"
 * "ccom:structfiles,structutils,1.0" "-t" "-W"
 * "com:structfiles,structutils,1.0" "-T" "link:lib" "-h" "libmmfile.mlib" "-i"
 * "-i" "C:/TEMP/structdemo/displaystruct.m" "C:/TEMP/structdemo/getstruct.m" 
 */
#include "displaystruct.h"
#include "libmatlbm.h"
#include "libmmfile.h"

static mxChar _array1_[12] = { 'N', 'o', 't', ' ', 'a', ' ',
                               's', 't', 'r', 'u', 'c', 't' };
static mxArray * _mxarray0_;
static mxArray * _mxarray2_;

void InitializeModule_displaystruct(void) {
    _mxarray0_ = mclInitializeString(12, _array1_);
    _mxarray2_ = mclInitializeDoubleVector(0, 0, (double *)NULL);
}

void TerminateModule_displaystruct(void) {
    mxDestroyArray(_mxarray2_);
    mxDestroyArray(_mxarray0_);
}

static void Mdisplaystruct(mxArray * x);

_mexLocalFunctionTable _local_function_table_displaystruct
  = { 0, (mexFunctionTableEntry *)NULL };

/*
 * The function "mlfDisplaystruct" contains the normal interface for the
 * "displaystruct" M-function from file "c:\temp\structdemo\displaystruct.m"
 * (lines 1-13). This function processes any input arguments and passes them to
 * the implementation version of the function, appearing above.
 */
void mlfDisplaystruct(mxArray * x) {
    mlfEnterNewContext(0, 1, x);
    Mdisplaystruct(x);
    mlfRestorePreviousContext(0, 1, x);
}

/*
 * The function "mlxDisplaystruct" contains the feval interface for the
 * "displaystruct" M-function from file "c:\temp\structdemo\displaystruct.m"
 * (lines 1-13). The feval function calls the implementation version of
 * displaystruct through this function. This function processes any input
 * arguments and passes them to the implementation version of the function,
 * appearing above.
 */
void mlxDisplaystruct(int nlhs, mxArray * plhs[], int nrhs, mxArray * prhs[]) {
    mxArray * mprhs[1];
    int i;
    if (nlhs > 0) {
        mlfError(
          mxCreateString(
            "Run-time Error: File: displaystruct Line: 1 Column"
            ": 1 The function \"displaystruct\" was called with"
            " more than the declared number of outputs (0)."),
          NULL);
    }
    if (nrhs > 1) {
        mlfError(
          mxCreateString(
            "Run-time Error: File: displaystruct Line: 1 Colum"
            "n: 1 The function \"displaystruct\" was called wi"
            "th more than the declared number of inputs (1)."),
          NULL);
    }
    for (i = 0; i < 1 && i < nrhs; ++i) {
        mprhs[i] = prhs[i];
    }
    for (; i < 1; ++i) {
        mprhs[i] = NULL;
    }
    mlfEnterNewContext(0, 1, mprhs[0]);
    Mdisplaystruct(mprhs[0]);
    mlfRestorePreviousContext(0, 1, mprhs[0]);
}

/*
 * The function "Mdisplaystruct" is the implementation version of the
 * "displaystruct" M-function from file "c:\temp\structdemo\displaystruct.m"
 * (lines 1-13). It contains the actual compiled code for that M-function. It
 * is a static function and must only be called from one of the interface
 * functions, appearing below.
 */
/*
 * function displaystruct(x)
 */
static void Mdisplaystruct(mxArray * x) {
    mexLocalFunctionTable save_local_function_table_
      = mclSetCurrentLocalFunctionTable(&_local_function_table_displaystruct);
    mxArray * f = NULL;
    mxArray * i = NULL;
    mxArray * n = NULL;
    mxArray * field_names = NULL;
    mxArray * ans = NULL;
    mclCopyArray(&x);
    /*
     * if (~isstruct(x))
     */
    if (mclNotBool(mlfIsstruct(mclVa(x, "x")))) {
        /*
         * error('Not a struct');
         */
        mlfError(_mxarray0_, NULL);
        /*
         * return;
         */
        goto return_;
    /*
     * end
     */
    }
    /*
     * field_names = fieldnames(x);
     */
    mlfAssign(&field_names, mlfFieldnames(mclVa(x, "x")));
    /*
     * n = size(field_names);
     */
    mlfAssign(
      &n,
      mlfSize(mclValueVarargout(), mclVv(field_names, "field_names"), NULL));
    /*
     * for i=1:n(1)
     */
    {
        int v_ = mclForIntStart(1);
        int e_ = mclForIntEnd(mclIntArrayRef1(mclVv(n, "n"), 1));
        if (v_ > e_) {
            mlfAssign(&i, _mxarray2_);
        } else {
            /*
             * f = getfield(x, field_names{i});
             * disp(field_names{i})
             * disp(f)
             * end
             */
            for (; ; ) {
                mlfAssign(
                  &f,
                  mlfGetfield(
                    mclVa(x, "x"),
                    mlfIndexRef(
                      mclVv(field_names, "field_names"), "{?}", mlfScalar(v_)),
                    NULL));
                mclFeval(
                  mclAnsVarargout(),
                  mlxDisp,
                  mlfIndexRef(
                    mclVv(field_names, "field_names"), "{?}", mlfScalar(v_)),
                  NULL);
                mlfDisp(mclVv(f, "f"));
                if (v_ == e_) {
                    break;
                }
                ++v_;
            }
            mlfAssign(&i, mlfScalar(v_));
        }
    }
    return_:
    mxDestroyArray(ans);
    mxDestroyArray(field_names);
    mxDestroyArray(n);
    mxDestroyArray(i);
    mxDestroyArray(f);
    mxDestroyArray(x);
    mclSetCurrentLocalFunctionTable(save_local_function_table_);
    /*
     * 
     */
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -