@@ -30,45 +30,12 @@ namespace std {
30
30
class string ;
31
31
}
32
32
33
- /* ---- CONST REFERENCE: NATIVE STRING ---- */
34
-
35
- %clear const std::string &;
36
- %typemap(ctype) const std::string & = char *;
37
- %typemap(imtype) const std::string & = char *;
38
- %typemap(ftype) const std::string & = char *;
39
-
40
- // C input translation typemaps: $1 is std::string*, $input is SwigArrayWrapper
41
- %typemap(in, noblock=1 ) const std::string & (std::string tempstr) {
42
- tempstr = std::string (static_cast <char *>($input->data ), $input->size );
43
- $1 = &tempstr;
44
- }
45
-
46
- // C output translation typemaps: $1 is string*, $input is SwigArrayWrapper
47
- %typemap(out, noblock=1 ) const std::string & {
48
- $result.data = ($1 ->empty () ? NULL : &(*$1 ->begin ()));
49
- $result.size = $1 ->size ();
50
- }
51
-
52
- // Fortran proxy translation code: convert from char array to Fortran string
53
- %typemap(fin) const std::string & = char *;
54
- // Unlike char* code, we never delete the return value!
55
- %typemap(fout, noblock=1 , fragment=" SWIG_fout" {char *}) const std::string & {
56
- call %fortrantm (fout, char *)($1 , $result)
57
- }
58
-
59
33
/* ---- VALUE: NATIVE STRING ---- */
60
34
61
35
%clear std::string;
62
- %apply const std::string & { std::string };
63
36
64
- %typemap(globalin) std::string {
65
- $1 = *$input;
66
- }
67
- %typemap(memberin) std::string {
68
- $1 = *$input;
69
- }
37
+ %typemap(ctype) std::string = char *;
70
38
71
- // Copy input data to local string
72
39
%typemap(in, noblock=1 ) std::string {
73
40
$1 .assign (static_cast <char *>($input->data ), $input->size );
74
41
}
@@ -84,9 +51,37 @@ class string;
84
51
}
85
52
}
86
53
54
+ %typemap(imtype) std::string = char *;
55
+ %typemap(ftype) std::string = char *;
56
+
57
+ // Fortran proxy translation code: convert from char array to Fortran string
58
+ %typemap(fin) std::string = char *;
59
+
87
60
// Fortran proxy translation code: convert from char array to Fortran string
88
61
%typemap(fout, noblock=1 ,
89
62
fragment=" SWIG_free_f" , fragment=" SWIG_fout" {char *}) std::string {
90
63
call %fortrantm (fout, char *)($1 , $result)
91
64
call SWIG_free ($1 %data)
92
65
}
66
+
67
+ /* ---- CONST REFERENCE: NATIVE STRING ---- */
68
+
69
+ // Use the same
70
+ %clear const std::string &;
71
+ %apply std::string { const std::string & };
72
+
73
+ // Construct a temporary string from the Fortran character array
74
+ %typemap(in, noblock=1 ) const std::string & (std::string tempstr) {
75
+ tempstr = std::string (static_cast <char *>($input->data ), $input->size );
76
+ $1 = &tempstr;
77
+ }
78
+
79
+ %typemap(out, noblock=1 , fragment=" <stdlib.h>" , fragment=" <string.h>" ) const std::string & {
80
+ $result.size = $1 ->size ();
81
+ if ($result.size > 0 ) {
82
+ $result.data = malloc ($result.size );
83
+ memcpy ($result.data , $1 ->c_str (), $result.size );
84
+ } else {
85
+ $result.data = NULL ;
86
+ }
87
+ }
0 commit comments