JIMS: plug extraction
[scilab.git] / scilab / modules / external_objects_java / src / cpp / JIMSwrapunwrap.h
1 /*
2  * JIMS ( http://forge.scilab.org/index.php/p/JIMS/ ) - This file is a part of JIMS
3  * Copyright (C) 2010 - 2011 - Calixte DENIZET <calixte@contrib.scilab.org>
4  *
5  * This file must be used under the terms of the CeCILL.
6  * This source file is licensed as described in the file COPYING, which
7  * you should have received as part of this distribution.  The terms
8  * are also available at
9  * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
10  *
11  */
12 /*--------------------------------------------------------------------------*/
13 /*
14  * Provide several wrappers for Scilab's matrix allocation
15  * Mainly used in unwrap.hpp
16  */
17 /*--------------------------------------------------------------------------*/
18 #ifndef __JIMS__WRAPUNWRAP_H__
19 #define __JIMS__WRAPUNWRAP_H__
20
21 #ifdef _MSC_VER
22 #include <Windows.h>
23 #endif
24
25 #define __JIMS_getmethod__(Kind, Type) static const char * get##Kind##MethodName() \
26     {                                                                   \
27         return "unwrap" #Kind #Type;                                    \
28     };
29
30 #define __JIMS_getsignature__(Kind, Signature) static const char * get##Kind##MethodSignature() \
31     {                                                                   \
32         return "(I)" Signature;                                         \
33     };
34
35 #define __JIMS_getvariableptr__() static T get##Kind##MethodSignature() \
36     {                                                                   \
37         return "(I)" Signature;                                         \
38     };
39
40 /*
41  * Structs defined to make easier the unwrapping
42  */
43 #define __JIMS_wrapToUnwrapObject__(JType, Type, type, Signature) struct __JIMS__Scilab##JType##__ { \
44         static SciErr allocMatrix(void* _pvCtx, int _iVar, int _iRows, int _iCols, void **_pdblReal) \
45             {                                                           \
46                 return allocMatrixOf##Type(_pvCtx, _iVar, _iRows, _iCols, (type**) _pdblReal); \
47             };                                                          \
48         static type getSingleVar(JNIEnv * curEnv, jclass cls, jmethodID id, int javaID) \
49             {                                                           \
50                 return static_cast<type>(curEnv->CallStatic##JType##Method(cls, id, javaID)); \
51             };                                                          \
52         __JIMS_getmethod__(,JType)                                      \
53         __JIMS_getsignature__(,#Signature)                              \
54         __JIMS_getmethod__(Row,JType)                                   \
55         __JIMS_getsignature__(Row,"[" #Signature)                       \
56         __JIMS_getmethod__(Mat,JType)                                   \
57         __JIMS_getsignature__(Mat,"[[" #Signature)                      \
58     };
59
60 __JIMS_wrapToUnwrapObject__(Double, Double, double, D)
61 __JIMS_wrapToUnwrapObject__(Boolean, Boolean, int, Z)
62 __JIMS_wrapToUnwrapObject__(Byte, Integer8, char, B)
63 __JIMS_wrapToUnwrapObject__(Short, Integer16, short, S)
64 __JIMS_wrapToUnwrapObject__(Char, UnsignedInteger16, unsigned short, C)
65 __JIMS_wrapToUnwrapObject__(Int, Integer32, int, I)
66 __JIMS_wrapToUnwrapObject__(Float, Double, double, F)
67
68 #ifdef __SCILAB_INT64__
69 __JIMS_wrapToUnwrapObject__(Long, Integer64, long, J)
70 #else
71 __JIMS_wrapToUnwrapObject__(Long, UnsignedInteger32, unsigned int, J)
72 #endif
73
74 /*
75  * Structs defined to make easier the wrapping
76  */
77 #define __JIMS_wrapToWrapObject__(Type,type) struct __JIMS__ScilabAnOtherWrapper##Type##__ { \
78         static int wrap(JavaVM *vm, type x)                             \
79             {                                                           \
80                 return org_scilab_modules_external_objects_java::ScilabJavaObject::wrap##Type(vm, x); \
81             };                                                          \
82         static int wrap(JavaVM *vm, type *x, int len)                   \
83             {                                                           \
84                 return org_scilab_modules_external_objects_java::ScilabJavaObject::wrap##Type(vm, x, len); \
85             };                                                          \
86         static int wrap(JavaVM *vm, type **xx, int r, int c)            \
87             {                                                           \
88                 return org_scilab_modules_external_objects_java::ScilabJavaObject::wrap##Type(vm, xx, r, c); \
89             };                                                          \
90     };
91
92 __JIMS_wrapToWrapObject__(Double, double)
93 __JIMS_wrapToWrapObject__(Int, int)
94 __JIMS_wrapToWrapObject__(Byte, byte)
95 __JIMS_wrapToWrapObject__(Short, short)
96 __JIMS_wrapToWrapObject__(Char, unsigned short)
97 __JIMS_wrapToWrapObject__(UInt, long long)
98 __JIMS_wrapToWrapObject__(UByte, short)
99 __JIMS_wrapToWrapObject__(UShort, int)
100 __JIMS_wrapToWrapObject__(Boolean, bool)
101 __JIMS_wrapToWrapObject__(Float, float)
102 __JIMS_wrapToWrapObject__(Long, long long)
103
104 #endif //__JIMS__WRAPUNWRAP_H__
105 /*--------------------------------------------------------------------------*/