summaryrefslogtreecommitdiff
path: root/share/swig/2.0.11/chicken/std_string.i
blob: fa77c1533e26af923c5eb5d65393c1aa5ff72027 (plain)
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
/* -----------------------------------------------------------------------------
 * std_string.i
 *
 * SWIG typemaps for std::string
 * ----------------------------------------------------------------------------- */

%{
#include <string>
%}

namespace std {
    %naturalvar string;
  

    %insert(closprefix) %{ (declare (hide <std-string>)) %}
    %nodefault string;
    %rename("std-string") string;
    class string {
      public:
	~string() {}
    };
    %extend string {
      char *str;
    }
    %{
      #define std_string_str_get(s) ((char *)((s)->c_str()))
      #define std_string_str_set(s,v) (s->assign((char *)(v)))
    %}

    %typemap(typecheck) string = char *;
    %typemap(typecheck) const string & = char *;

    %typemap(in) string (char * tempptr) {
      if ($input == C_SCHEME_FALSE) {
	$1.resize(0);
      } else { 
	if (!C_swig_is_string ($input)) {
	  swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, 
		     "Argument #$argnum is not a string");
	}
	tempptr = SWIG_MakeString($input);
	$1.assign(tempptr);
	if (tempptr) SWIG_free(tempptr);
      }
    }

    %typemap(in) const string& ($*1_ltype temp, char *tempptr) {

      if ($input == C_SCHEME_FALSE) {
	temp.resize(0);
	$1 = &temp;
      } else { 
	if (!C_swig_is_string ($input)) {
	  swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, 
		     "Argument #$argnum is not a string");
	}
	tempptr = SWIG_MakeString($input);
	temp.assign(tempptr);
	if (tempptr) SWIG_free(tempptr);
	$1 = &temp;
      }
    }

    %typemap(out) string { 
      int size = $1.size();
      C_word *space = C_alloc (C_SIZEOF_STRING (size));
      $result = C_string (&space, size, (char *) $1.c_str());
    }

    %typemap(out) const string& { 
      int size = $1->size();
      C_word *space = C_alloc (C_SIZEOF_STRING (size));
      $result = C_string (&space, size, (char *) $1->c_str());
    }

    %typemap(varin) string {
      if ($input == C_SCHEME_FALSE) {
	$1.resize(0);
      } else { 
        char *tempptr;
	if (!C_swig_is_string ($input)) {
	  swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, 
		     "Argument #$argnum is not a string");
   	}
	tempptr = SWIG_MakeString($input);
	$1.assign(tempptr);
	if (tempptr) SWIG_free(tempptr);
      }
    }

    %typemap(varout) string { 
      int size = $1.size();
      C_word *space = C_alloc (C_SIZEOF_STRING (size));
      $result = C_string (&space, size, (char *) $1.c_str());
    }
}