1 /*
2  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  * Copyright (C) 2006 - INRIA - Jean-Baptiste Silvy
4  *
5  * Copyright (C) 2012 - 2016 - Scilab Enterprises
6  *
7  * This file is hereby licensed under the terms of the GNU GPL v2.0,
8  * pursuant to article 5.3.4 of the CeCILL v.2.1.
9  * This file was originally licensed under the terms of the CeCILL v2.1,
10  * and continues to be available under such terms.
11  * For more information, see the COPYING file which you should have received
12  * along with this program.
13  *
14  */
15 
16 /*------------------------------------------------------------------------*/
17 /* file: getPropertyAssignedValue.h                                       */
18 /* desc : a set of functions used to get the values which will be         */
19 /*        assigned to handles properties from the stack                   */
20 /*------------------------------------------------------------------------*/
21 
22 #ifndef _GET_PROPERTY_ASSIGNEMENT_VALUE_H_
23 #define _GET_PROPERTY_ASSIGNEMENT_VALUE_H_
24 
25 #include <stdlib.h> /* for size_t */
26 #include "dynlib_graphics.h"
27 #include "sci_types.h"
28 #include "api_scilab.h"
29 #include "BOOL.h"
30 /*------------------------------------------------------------------------------*/
31 /* Basic type parameters */
32 
33 /**
34  * copy a double vector from the scilab stack to an int array
35  * with int cast for each parameter.
36  */
37 GRAPHICS_IMPEXP void copyDoubleVectorToIntFromStack(void* _pvData, int dest[], int nbElement);
38 
39 /**
40  * create a copy of a stringMatrix which is in the stack
41  */
42 GRAPHICS_IMPEXP char ** createCopyStringMatrixFromStack(void* _pvData, int nbElement);
43 
44 /**
45  * @return TRUE if the given parameter is 'on', %T, 'T', 1, ...
46  *         FALSE if the given parameter is 'off', %F, 'F', 0, ...
47  *         NOT_A_BOOLEAN_VALUE otherwise
48  */
49 GRAPHICS_IMPEXP int tryGetBooleanValueFromStack(void* _pvData, int valueType, int nbRow, int nbCol, const char* propertyName);
50 // with that we are sure to be nether equal to TRUE nor FALSE
51 #define NOT_A_BOOLEAN_VALUE (2*FALSE) - TRUE
52 
53 /*------------------------------------------------------------------------------*/
54 /* Tlist */
55 typedef struct
56 {
57     int iNbItem; /**< number of elements in the tlist */
58     int iCurItem; /**< currently read element */
59     int iRhs; /**< rank of the tlist within the Rhs parameters */
60     int* piList ; /**< pointer of the tlist in the stack */
61 } AssignedList;
62 
63 /**
64  * get the number of element of a tlist stored in the rhs
65  * @param paramNum rank of the list within the Rhs parameters
66  */
67 GRAPHICS_IMPEXP int getStackListNbElement(void* _pvCtx, int _iRhs);
68 
69 /**
70  * create a new instance of an object used to retrieve fields of a tlist
71  * stored on the stack
72  * @param paramNum rank of the list within the Rhs parameters
73  * @param nbElement number of element in the list
74  */
75 GRAPHICS_IMPEXP AssignedList * createAssignedList(void* _pvCtx, int _iRhs, int _iNbItem);
76 
77 /**
78  * destroy the object used to glance through a tlist
79  */
80 GRAPHICS_IMPEXP void destroyAssignedList(AssignedList * list);
81 
82 /**
83  * return the number of element of a tlist
84  */
85 GRAPHICS_IMPEXP int getAssignedListNbElement(AssignedList * list);
86 
87 /**
88  * set the current element to the first
89  */
90 GRAPHICS_IMPEXP void rewindAssignedList(AssignedList * list);
91 
92 /**
93  * Return whether the current element of the list is a double matrix or not.
94  */
95 GRAPHICS_IMPEXP BOOL isListCurrentElementDoubleMatrix(void* _pvCtx, AssignedList* _pList);
96 
97 /**
98 * Return whether the current element of the list is a string matrix or not.
99 */
100 GRAPHICS_IMPEXP BOOL isListCurrentElementStringMatrix(void* _pvCtx, AssignedList* _pList);
101 
102 /**
103 * Return whether the current element of the list is an empty matrix or not.
104 */
105 GRAPHICS_IMPEXP BOOL isListCurrentElementEmptyMatrix(void* _pvCtx, AssignedList* _pList);
106 
107 /**
108  * retrieve a field of a tlist
109  * @param[in]  list object used to retrieve elements
110  * @param      rank position of the element in the list (first, second, ...)
111  *             Note that is it not possible to get the properties names with this function
112  * @param[out] nbRow number of row of the returned matrix
113  * @param[out] nbCol number of column of the returned matrix
114  */
115 GRAPHICS_IMPEXP double* getDoubleMatrixFromList(void* _pvCtx, AssignedList* _pList, int _iItem, int* _piRows, int* _piCols);
116 
117 /**
118 * retrieve a field of a tlist
119 * @param[in]  list object used to retrieve elements
120 * @param      rank position of the element in the list (first, second, ...)
121 *             Note that is it not possible to get the properties names with this function
122 * @param[out] nbRow number of row of the returned matrix
123 * @param[out] nbCol number of column of the returned matrix
124 */
125 GRAPHICS_IMPEXP char ** getStringMatrixFromList(void* _pvCtx, AssignedList* _pList, int _iItem, int* _piRows, int* _piCols);
126 
127 
128 /**
129  * retrieve the current property of a tlist and move to the next
130  * @param[in/out] list object used to retrieve elements
131  * @param[out]    nbRow number of row of the returned matrix
132  * @param[out]    nbCol number of column of the returned matrix
133  */
134 GRAPHICS_IMPEXP double* getCurrentDoubleMatrixFromList(void* _pvCtx, AssignedList* _pList, int* _piRows, int* _piCols);
135 
136 /**
137 * retrieve the current property of a tlist and move to the next
138 * @param[in/out] list object used to retrieve elements
139 * @param[out]    nbRow number of row of the returned matrix
140 * @param[out]    nbCol number of column of the returned matrix
141 */
142 GRAPHICS_IMPEXP char ** getCurrentStringMatrixFromList(void* _pvCtx, AssignedList* _pList, int* _piRows, int* _piCols);
143 
144 /**
145  * create a copy of the current matrix in the tlist
146  * @param[in/out] list object used to retrieve elements
147  * @param[out]    nbRow number of row of the returned matrix or -1 if an error occurred
148  * @param[out]    nbCol number of column of the returned matrix or -1 if an error occurred
149  * @return the created array or NULL if the matrix is empty or an error occurred
150  */
151 GRAPHICS_IMPEXP double* createCopyDoubleMatrixFromList(void* _pvCtx, AssignedList* _pList, int* _piRows, int* _piCols);
152 /*------------------------------------------------------------------------------*/
153 #endif /* _GET_PROPERTY_ASSIGNEMENT_VALUE_H_ */
154