License Header change: Removed the LICENSE_END before beta
[scilab.git] / scilab / modules / api_scilab / help / ja_JP / legacy / low_level_functions / common_getvartype_api.xml
1 <?xml version="1.0" encoding="utf-8"?>
2 <!--
3  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
4  * Copyright (C) 2009  - DIGITEO - Antoine ELIAS
5  * 
6  * Copyright (C) 2012 - 2016 - Scilab Enterprises
7  *
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.
14  *
15  -->
16 <refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns5="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:id="Common_getvartype_API" xml:lang="ja">
17     <refnamediv>
18         <refname>変数の型 (Scilabゲートウェイ)</refname>
19         <refpurpose>
20             ゲートウェイ内で引数または変数の型を取得する方法.
21         </refpurpose>
22     </refnamediv>
23     <refsynopsisdiv>
24         <title>呼び出し手順</title>
25         <para>入力引数プロファイル:</para>
26         <synopsis>SciErr getVarType(void* _pvCtx, int* _piAddress, int* _piType)</synopsis>
27         <para>名前指定変数プロファイル:</para>
28         <synopsis>SciErr getNamedVarType(void* _pvCtx, const char* _pstName, int* _piType)</synopsis>
29     </refsynopsisdiv>
30     <refsection>
31         <title>引数</title>
32         <variablelist>
33             <varlistentry>
34                 <term>_pvCtx</term>
35                 <listitem>
36                     <para>
37                         Scilab環境ポインタ, api_scilab.hで定義される "pvApiCtx" を指定
38                     </para>
39                 </listitem>
40             </varlistentry>
41             <varlistentry>
42                 <term>_piAddress</term>
43                 <listitem>
44                     <para>
45                         変数のアドレス
46                     </para>
47                 </listitem>
48             </varlistentry>
49             <varlistentry>
50                 <term>_pstName</term>
51                 <listitem>
52                     <para>
53                         Scilab変数名.
54                     </para>
55                 </listitem>
56             </varlistentry>
57             <varlistentry>
58                 <term>_piType</term>
59                 <listitem>
60                     <para>
61                         変数のScilab型 (sci_matrix, sci_strings, sci_ints, ...).
62                     </para>
63                     <para>
64                         異なる型のリストがenumとして
65                         <link linkend="sci_types">sci_types.h</link>に定義されている
66                         ことに注意してください.
67                     </para>
68                 </listitem>
69             </varlistentry>
70             <varlistentry>
71                 <term>SciErr</term>
72                 <listitem>
73                     <para>
74                         エラー構造体で,エラーメッセージ履歴と最初のエラー番号を保持します.
75                     </para>
76                 </listitem>
77             </varlistentry>
78         </variablelist>
79     </refsection>
80     <refsection>
81         <title>説明</title>
82         <para>このヘルプはゲートウェイ内で変数のScilab型を取得する方法を示します.</para>
83     </refsection>
84     <refsection>
85         <!--File_gateway: SCI/modules/api_scilab/tests/unit_tests/common_function_api.c-->
86         <!--File_scilab: SCI/modules/api_scilab/tests/unit_tests/common_function.tst-->
87         <!--Lib_name: common_function-->
88         <!--Func_list: common_function-->
89         <title>Gateway Source</title>
90         <programlisting role="code_gateway">
91             <![CDATA[ 
92 #include "api_scilab.h"
93 SciErr printf_info(int _iVar);
94 int common_function(char *fname,void* pvApiCtx)
95 {
96     SciErr sciErr;
97     int i;
98     int *piAddr1    = NULL;
99     int iBool       = 0;
100     for(i = 0 ; i < nbInputArgument(pvApiCtx) ; i++)
101     {
102         sciErr = printf_info(i + 1);
103         if(sciErr.iErr)
104         {
105             printError(&sciErr, 0);
106             break;
107         }
108         sciprint("\n\n");
109     }
110     // trueの場合に1,それ以外は 0
111     iBool = sciErr.iErr == 0 ? 1 : 0;
112     sciErr = createMatrixOfBoolean(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 1, 1, &iBool);
113     if(sciErr.iErr)
114     {
115         printError(&sciErr, 0);
116         return 0;
117     }
118    // 確保された変数を左辺に代入
119     AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
120     return 0;
121 }
122 SciErr printf_info(int _iVar)
123 {
124     SciErr sciErr;
125     int* piAddr     = NULL;
126     int iType       = 0;
127     int iRows       = 0;
128     int iCols       = 0;
129     int iItem       = 0;
130     int iComplex    = 0;
131     sciErr = getVarAddressFromPosition(pvApiCtx, _iVar, &piAddr);
132     if(sciErr.iErr)
133     {
134         return sciErr;
135     }
136     sciprint("Variable %d information:\n", _iVar);
137     sciErr = getVarType(pvApiCtx, piAddr, &iType);
138     if(sciErr.iErr)
139     {
140         return sciErr;
141     }
142     sciprint("\tType: ");
143     switch(iType)
144     {
145         case sci_matrix :
146             sciprint("double\n");
147             break;
148         case sci_poly :
149             sciprint("polynomial\n");
150             break;
151         case sci_boolean :
152             sciprint("boolean\n");
153             break;
154         case sci_sparse :
155             sciprint("sparse\n");
156             break;
157         case sci_boolean_sparse :
158             sciprint("boolean_sparse\n");
159             break;
160         case sci_ints :
161         {
162             char pstSigned[]    = "signed";
163             char pstUnsigned[]  = "unsigned";
164             char* pstSign       = pstSigned;
165             int iPrec           = 0;
166             sciErr = getMatrixOfIntegerPrecision(pvApiCtx, piAddr, &iPrec);
167             if(sciErr.iErr)
168             {
169                 return sciErr;
170             }
171             if(iPrec > 10)
172             {
173                 pstSign = pstUnsigned;
174             }
175             sciprint("%s integer %d bits\n", pstSign, (iPrec % 10) * 8);
176         }
177         break;
178         case sci_strings :
179             sciprint("strings\n");
180             break;
181         case sci_list :
182             sciprint("list\n");
183             break;
184         case sci_tlist :
185             sciprint("tlist\n");
186             break;
187         case sci_mlist :
188             sciprint("mlist\n");
189             break;
190         default :
191             sciprint("Not manage by this function\n");
192             return sciErr;
193     }
194     if(isVarComplex(pvApiCtx, piAddr))
195     {
196         sciprint("\tComplex: Yes\n");
197     }
198     sciprint("\tDimensions: ");
199     if(isVarMatrixType(pvApiCtx, piAddr))
200     {
201         sciErr = getVarDimension(pvApiCtx, piAddr, &iRows, &iCols);
202         if(sciErr.iErr)
203         {
204             return sciErr;
205         }
206         sciprint("%d x %d", iRows, iCols);
207     }
208     else
209     {
210         sciErr = getListItemNumber(pvApiCtx, piAddr, &iItem);
211         if(sciErr.iErr)
212         {
213             return sciErr;
214         }
215         sciprint("%d", iItem);
216     }
217     return sciErr;
218 }
219  ]]>
220         </programlisting>
221     </refsection>
222     <refsection>
223         <title>Scilabテストスクリプト</title>
224         <programlisting role="code_scilab"><![CDATA[ 
225 l1 = [1,2*%i,3;%i,2,3*%i];
226 l2 = ["may","the";"puffin","be";"with","you"];
227 l3 = int8([1,2,3]);
228 l4 = uint16([1000,2000,3000]);
229 l5 = list(l1,l2,l3);
230 l = list(l1,l2,l3,l4,l5);
231 common_function(l(1:$))
232  ]]></programlisting>
233     </refsection>
234     <refsection role="see also">
235         <title>参照</title>
236         <simplelist type="inline">
237             <member>
238                 <link linkend="sci_types">sci_types</link>
239             </member>
240             <member>
241                 <link linkend="isPolyType">isPolyType</link>
242             </member>
243             <member>
244                 <link linkend="isBooleanType">isBooleanType</link>
245             </member>
246             <member>
247                 <link linkend="isListType">isListType</link>
248             </member>
249             <member>
250                 <link linkend="isDoubleType">isDoubleType</link>
251             </member>
252             <member>
253                 <link linkend="isIntegerType">isIntegerType</link>
254             </member>
255             <member>
256                 <link linkend="isSparseType">isSparseType</link>
257             </member>
258             <member>
259                 <link linkend="isBooleanSparseType">isBooleanSparseType</link>
260             </member>
261             <member>
262                 <link linkend="isStringType">isStringType</link>
263             </member>
264         </simplelist>
265     </refsection>
266 </refentry>