2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2008 - INRIA - Vincent COUVERT
4 * Copyright (C) 2010 - DIGITEO - Yann COLLETTE
6 * Copyright (C) 2012 - 2016 - Scilab Enterprises
8 * This file is hereby licensed under the terms of the GNU GPL v2.0,
9 * pursuant to article 5.3.4 of the CeCILL v.2.1.
10 * This file was originally licensed under the terms of the CeCILL v2.1,
11 * and continues to be available under such terms.
12 * For more information, see the COPYING file which you should have received
13 * along with this program.
17 #include "gatewaystruct.hxx"
20 #include "context.hxx"
21 #include "CreateMatlabTreeVariable.hxx"
25 #include "CreateMatlabVariable.h"
26 #include "api_scilab.h"
27 #include "sci_malloc.h"
28 #include "localization.h"
33 int CreateStructVariable(void *pvApiCtx, int iVar, matvar_t *matVariable, int * parent, int item_position)
35 types::GatewayStruct* pStr = (types::GatewayStruct*)pvApiCtx;
36 types::typed_list in = *pStr->m_pIn;
37 types::InternalType** out = pStr->m_pOut;
40 int rhs = iVar - *getNbInputArgument(pvApiCtx);
42 int iRank = matVariable->rank;
43 int* piDims = (int *)MALLOC(iRank * sizeof(int));
45 for (int i = 0; i < iRank; ++i)
47 piDims[i] = (int)matVariable->dims[i];
51 if (matVariable->data == NULL)
53 types::Struct* pStruct = new types::Struct();
54 out[rhs - 1] = pStruct;
59 types::Struct* pStruct = new types::Struct(iRank, piDims);
61 matvar_t** allData = (matvar_t**)(matVariable->data);
64 int iSizeStruct = Mat_VarGetNumberOfFields(matVariable);
65 for (int i = 0; i < iSizeStruct; i++)
67 temp = to_wide_string((char*)allData[i]->name);
68 std::wstring wstField(temp);
70 pStruct->addField(wstField);
73 for (int i = 0; i < iSize; i++)
75 for (int j = 0; j < iSizeStruct; j++)
77 temp = to_wide_string((char*)allData[j]->name);
78 std::wstring wstField(temp);
80 pStruct->get(i)->set(wstField, CreateMatlabTreeVariable(allData[i * iSizeStruct + j]));
84 out[rhs - 1] = pStruct;