~ubuntu-branches/ubuntu/maverick/swig1.3/maverick

« back to all changes in this revision

Viewing changes to Lib/java/stl_string.i

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Landschoff
  • Date: 2002-03-29 01:56:07 UTC
  • Revision ID: james.westby@ubuntu.com-20020329015607-c0wt03xu8oy9ioj7
Tags: upstream-1.3.11
ImportĀ upstreamĀ versionĀ 1.3.11

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Typemaps for standard C++ STL string and wstring
 
3
 * Contributed by: Tal Shalif <tal@slt.atr.co.jp>
 
4
 */
 
5
/* what type to use in java source code */
 
6
%typemap(jni) const string & "jstring"
 
7
%typemap(jtype) const string & "String"
 
8
%typemap(jstype) const string & "String"
 
9
 
 
10
/* how to convert java type to requested c++ type */
 
11
%typemap(in) const string & {
 
12
  $1 = NULL;
 
13
  if($input) {
 
14
    /* get the String from the StringBuffer */
 
15
    char *p = (char *)jenv->GetStringUTFChars($input, 0); 
 
16
    $1 =  new string(p);
 
17
    jenv->ReleaseStringUTFChars($input, p);
 
18
  }
 
19
}
 
20
/* free resource once finished using */
 
21
%typemap(freearg) const string & {
 
22
  delete $1;
 
23
}
 
24
/* how to convert the c++ type to the java type */
 
25
%typemap(out) const string & {
 
26
 $result = jenv->NewStringUTF($1->c_str());
 
27
}
 
28
 
 
29
 
 
30
%typemap(jni) string & = const string &;
 
31
%typemap(jtype) string & = const string &;
 
32
%typemap(jstype) string & = const string &;
 
33
%typemap(in) string & = const string &;
 
34
%typemap(freearg) string & = const string &;
 
35
%typemap(out) string & = const string &;
 
36
 
 
37
%typemap(jni) const wstring & "jstring"
 
38
%typemap(jtype) const wstring & "String"
 
39
%typemap(jstype) const wstring & "String"
 
40
 
 
41
/* how to convert java type to requested c++ type */
 
42
%typemap(in) const wstring & {
 
43
  $1 = NULL;
 
44
  if($input) {
 
45
    /* get the String from the StringBuffer */
 
46
    const jchar *jchar_p = jenv->GetStringChars($input, 0);
 
47
    unsigned int len;
 
48
    for (len = 0; jchar_p[len]; ++len);
 
49
    if (len) {
 
50
      wchar_t *conv_buf = new wchar_t[len];
 
51
      for (unsigned int i = 0; i < len; ++i) {
 
52
         conv_buf[i] = jchar_p[i];
 
53
       }
 
54
       $1 =  new wstring(conv_buf, len);
 
55
       delete [] conv_buf;
 
56
    }
 
57
    jenv->ReleaseStringChars($input, jchar_p);
 
58
  }
 
59
}
 
60
/* how to convert the c++ type to the java type */
 
61
%typemap(out) const wstring & {
 
62
  unsigned int len = $1->length();
 
63
  jchar *conv_buf = new jchar[len];
 
64
  for (unsigned int i = 0; i < len; ++i) {
 
65
    conv_buf[i] = (jchar)(*$1)[i];
 
66
  }
 
67
  $result = jenv->NewString(conv_buf, len);
 
68
  delete [] conv_buf;
 
69
}
 
70
 
 
71
 
 
72
%typemap(jni) wstring & = const wstring &;
 
73
%typemap(jtype) wstring & = const wstring &;
 
74
%typemap(jstype) wstring & = const wstring &;
 
75
%typemap(in) wstring & = const wstring &;
 
76
%typemap(out) wstring & = const wstring &;
 
77