aboutsummaryrefslogtreecommitdiff
path: root/devel/swig20/files/patch-Lib::guile::typemaps.i
blob: 0826663f96e227c39ff0c800818ca600ee6397ae (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
diff -urN ../SWIG1.3a5/Lib/guile/typemaps.i ./Lib/guile/typemaps.i
--- ../SWIG1.3a5/Lib/guile/typemaps.i	Thu Sep 21 16:06:17 2000
+++ ./Lib/guile/typemaps.i	Tue Feb 27 06:17:46 2001
@@ -49,6 +49,150 @@
  SIMPLE_MAP(char *, GSWIG_scm2str, gh_str02scm, string);
  SIMPLE_MAP(const char *, GSWIG_scm2str, gh_str02scm, string);
 
+
+
+
+%define SIMPLE_MAP_STR(C_NAME, SCM_TO_C, C_TO_SCM, SCM_NAME)
+ %typemap (guile, in)          C_NAME { char* x; x=SCM_TO_C($source); $target = new string(x); scm_must_free(x);};
+ %typemap (guile, varin)       C_NAME { char* x; x=SCM_TO_C($source); $target = new string(x); scm_must_free(x);};
+ %typemap (guile, out)         C_NAME "$target = C_TO_SCM($source->c_str());";
+ %typemap (guile, varout)      C_NAME "$target = C_TO_SCM($source->c_str());";
+%enddef
+ 
+SIMPLE_MAP_STR(string , GSWIG_scm2str, gh_str02scm, string);
+SIMPLE_MAP_STR(string&, GSWIG_scm2str, gh_str02scm, string);
+SIMPLE_MAP_STR(const string , GSWIG_scm2str, gh_str02scm, string);
+SIMPLE_MAP_STR(const string&, GSWIG_scm2str, gh_str02scm, string);
+
+%typemap (guile, freearg) string, string&, const string, const string& "if ($target) delete $target;";
+
+
+
+
+%typemap (guile, in) vector<string> (vector<string> temp) { 
+
+  SCM v = gh_list_to_vector( $source );
+  unsigned long len = gh_vector_length (v);
+  unsigned long i=0;
+
+  $target = new vector<string>();
+
+  for( i=0; i<len; i++) 
+    {
+      //      cerr << " copying i:" << i << endl;
+      SCM scm_i = gh_ulong2scm(i);
+      SCM scm_str = gh_vector_ref( v, scm_i );
+      char* x = GSWIG_scm2str(scm_str); 
+      $target->push_back(string(x));
+      scm_must_free(x);
+    }
+
+};
+%typemap (guile, freearg) vector<string> "if ($target) delete $target;";
+
+
+%typemap (guile, out) vector<string> {
+
+  int i=0;
+  int count = $source->size();
+
+  cerr << " convert vector<> to scheme world" << endl;
+
+  if( !count ) 
+    {
+      $target = gh_list( SCM_UNDEFINED );
+    }
+  else
+    {
+      const string& s = (*$source)[count-1];
+      cerr << " convert vector<> to scheme world 2... s: " << s << endl;
+      $target = gh_list( gh_str02scm( s.c_str()),  SCM_UNDEFINED );
+      cerr << " convert vector<> to scheme world 3 " << endl;
+
+      for( i=count-2; i>=0; i-- )
+	{
+	  cerr << " convert vector<> to scheme world i:" << i << endl;
+	  const string& s = (*$source)[i];
+	  $target = gh_cons( gh_str02scm( s.c_str()), $target );
+	}
+    }
+};
+
+
+%typemap (guile, out) vector<foo*> {
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+
+  swig_type_info *element_type_mangled_name = SWIGTYPE_p_foo;
+  typedef  foo*  element_type;
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+
+  int i=0;
+  int count = $source->size();
+
+  if( !count ) 
+    {
+      $target = gh_list( SCM_UNDEFINED );
+    }
+  else 
+    {
+      element_type s = (*$source)[count-1];  
+      SCM s_scm = SWIG_Guile_MakePtr( s, element_type_mangled_name );
+      $target = gh_list( s_scm,  SCM_UNDEFINED );
+
+      for( i=count-2; i>=0; i-- )
+	{
+	  element_type s = (*$source)[i];
+	  s_scm = SWIG_Guile_MakePtr( s, element_type_mangled_name );
+	  $target = gh_cons( s_scm , $target );
+	}
+    }
+
+};
+
+
+
+
+
+%typemap (guile, out) vector<Witme_DirItem*> {
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+
+  swig_type_info *element_type_mangled_name = SWIGTYPE_p_Witme_DirItem;
+  typedef  Witme_DirItem*  element_type;
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+
+  int i=0;
+  int count = $source->size();
+
+  if( !count ) 
+    {
+      $target = gh_list( SCM_UNDEFINED );
+    }
+  else 
+    {
+      element_type s = (*$source)[count-1];  
+      SCM s_scm = SWIG_Guile_MakePtr( s, element_type_mangled_name );
+      $target = gh_list( s_scm,  SCM_UNDEFINED );
+
+      for( i=count-2; i>=0; i-- )
+	{
+	  element_type s = (*$source)[i];
+	  s_scm = SWIG_Guile_MakePtr( s, element_type_mangled_name );
+	  $target = gh_cons( s_scm , $target );
+	}
+    }
+
+};
+
+
+
 /* GSWIG_scm2str makes a malloc'ed copy of the string, so get rid of it after
    the function call. */