Statistics
| Branch: | Revision:

root / src / org.omnetpp.ide.nativelibs / bigdecimal.i @ 0418c1a0

History | View | Annotate | Download (3.96 KB)

1

    
2
/*--------------------------------------------------------------------------
3
 * use JAVA_MATH_BIGDECIMAL() if you want to map BigDecimals
4
 *                            to java.math.BigDecimal
5
 * WARN: be sure that BigDecimal does not contain NaN/Infinity, because they
6
 *       cannot be mapped to java.math.BigDecimal. (Nil is mapped to null)
7
 * *** THIS IS CURRENTLY UNUSED, WE USE OUR OWN BigDecimal CLASS INSTEAD ***
8
 *--------------------------------------------------------------------------*/
9
%define JAVA_MATH_BIGDECIMAL()
10
%typemap(jni) BigDecimal "jobject";
11
%typemap(jtype) BigDecimal "java.math.BigDecimal";
12
%typemap(jstype) BigDecimal "java.math.BigDecimal";
13
%typemap(javain) BigDecimal "$javainput";
14
%typemap(javaout) BigDecimal {
15
   return $jnicall;
16
}
17

    
18
%typemap(in) BigDecimal {
19
   if ($input)
20
   {
21
      jclass cl = jenv->FindClass("java/math/BigDecimal");
22
      jmethodID methodID = jenv->GetMethodID(cl, "toPlainString", "()Ljava/lang/String;");
23
      jstring javaString = (jstring)jenv->CallObjectMethod($input, methodID);
24
      const char *chars = jenv->GetStringUTFChars(javaString, 0);
25
      $1 = BigDecimal::parse(chars);
26
      jenv->ReleaseStringUTFChars(javaString, chars);
27
   }
28
   else
29
   {
30
      $1 = BigDecimal::Nil;
31
   }
32
}
33

    
34
%typemap(out) BigDecimal {
35
   if ($1.isNil())
36
   {
37
      $result = NULL;
38
   }
39
   else
40
   {
41
      jclass cl = jenv->FindClass("java/math/BigDecimal");
42
      jmethodID methodId = jenv->GetMethodID(cl, "<init>", "(Ljava/lang/String;)V");
43
      $result = (jenv->NewObject(cl, methodId, jenv->NewStringUTF($1.str().c_str())));
44
   }
45
}
46
%enddef // JAVA_MATH_BIGDECIMAL
47

    
48

    
49
/*--------------------------------------------------------------------------
50
 * use COMMON_ENGINE_BIGDECIMAL() if you want to map BigDecimals
51
 *                                to org.omnetpp.common.engine.BigDecimal
52
 * The C++ objects are wrapped by the java object, but BigDecimal::Nil
53
 * mapped to null.
54
 *--------------------------------------------------------------------------*/
55
%define COMMON_ENGINE_BIGDECIMAL()
56
class BigDecimal;
57
%typemap(jstype) BigDecimal "org.omnetpp.common.engine.BigDecimal";
58
%typemap(javain) BigDecimal "org.omnetpp.common.engine.BigDecimal.getCPtr($javainput)"
59
%typemap(javaout) BigDecimal {
60
    long cPtr = $jnicall;
61
    return (cPtr == 0) ? null : new org.omnetpp.common.engine.BigDecimal(cPtr, true);
62
}
63
%typemap(in) BigDecimal ($&1_type argp) %{
64
   argp = *($&1_ltype*)(void *)&$input;
65
   if (!argp) {
66
      $1 = BigDecimal::Nil;
67
   }
68
   else {
69
      $1 = *argp;
70
   }
71
%}
72

    
73
%typemap(out) BigDecimal %{
74
   if ($1.isNil())
75
   {
76
      $result = 0;
77
   }
78
   else
79
   {
80
      {*($&1_ltype*)(void *)&$result = new $1_ltype(($1_ltype &)$1); }
81
   }
82
%}
83

    
84
%typemap(jstype) BigDecimal* "org.omnetpp.common.engine.BigDecimal";
85
%typemap(javain) BigDecimal* "org.omnetpp.common.engine.BigDecimal.getCPtr($javainput)"
86
%typemap(javaout) BigDecimal* {
87
    long cPtr = $jnicall;
88
    return (cPtr == 0) ? null : new org.omnetpp.common.engine.BigDecimal(cPtr, $owner);
89
}
90
%typemap(in) BigDecimal* %{
91
   if (!$input) {
92
      $1 = &BigDecimal::Nil;
93
   }
94
   else {
95
      $1 = *($1_ltype*)(void*)&$input;
96
   }
97
%}
98
%typemap(out) BigDecimal* %{
99
   if (!$1 || $1->isNil())
100
   {
101
      $result = 0;
102
   }
103
   else
104
   {
105
      *($1_ltype*)(void *)&$result = $1;
106
   }
107
%}
108

    
109
%typemap(jstype) BigDecimal& "org.omnetpp.common.engine.BigDecimal";
110
%typemap(javain) BigDecimal& "org.omnetpp.common.engine.BigDecimal.getCPtr($javainput)"
111
%typemap(javaout) BigDecimal& {
112
    long cPtr = $jnicall;
113
    return (cPtr == 0) ? null : new org.omnetpp.common.engine.BigDecimal(cPtr, false);
114
}
115
%typemap(in) BigDecimal& %{
116
   if (!$input) {
117
      $1 = ($1_ltype)(void *)&BigDecimal::Nil;
118
   }
119
   else {
120
      $1 = *($1_ltype*)(void *)&$input;
121
   }
122
%}
123
%typemap(out) BigDecimal& %{
124
   if ($1->isNil())
125
   {
126
      $result = 0;
127
   }
128
   else
129
   {
130
      {*($1_ltype*)(void *)&$result = $1; }
131
   }
132
%}
133
%enddef // COMMON_ENGINE_BIGDECIMAL