import source from 1.3.40
[external/swig.git] / Examples / test-suite / li_std_string.i
1 %module li_std_string
2 %include <std_string.i>
3
4 #if defined(SWIGUTL)
5 %apply std::string& INPUT { std::string &input }
6 %apply std::string& INOUT { std::string &inout }
7 #endif
8
9
10 %inline %{
11
12 std::string test_value(std::string x) {
13    return x;
14 }
15
16 const std::string& test_const_reference(const std::string &x) {
17    return x;
18 }
19
20 void test_pointer(std::string *x) {
21 }
22
23 std::string *test_pointer_out() {
24    static std::string x = "x";
25    return &x;
26 }
27
28 void test_const_pointer(const std::string *x) {
29 }
30
31 const std::string *test_const_pointer_out() {
32    static std::string x = "x";
33    return &x;
34 }
35
36 void test_reference(std::string &x) {
37 }
38
39 std::string& test_reference_out() {
40    static std::string x = "test_reference_out message";
41    return x;
42 }
43
44 std::string test_reference_input(std::string &input) {
45   return input;
46 }
47
48 void test_reference_inout(std::string &inout) {
49   inout += inout;
50 }
51
52 #if defined(_MSC_VER)
53   #pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
54 #endif
55
56 void test_throw() throw(std::string){
57   static std::string x = "test_throw message";
58   throw x;
59 }
60
61 void test_const_reference_throw() throw(const std::string &){
62   static std::string x = "test_const_reference_throw message";
63   throw x;
64 }
65
66 void test_pointer_throw() throw(std::string *) {
67   throw new std::string("foo");
68 }
69
70 void test_const_pointer_throw() throw(const std::string *) {
71   throw new std::string("foo");
72 }
73
74 #if defined(_MSC_VER)
75   #pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
76 #endif
77
78 %}
79
80 /* Old way, now std::string is a %naturalvar by default
81 %apply const std::string& { std::string *GlobalString2, 
82                             std::string *MemberString2, 
83                             std::string *Structure::StaticMemberString2 };
84 */
85
86 %inline %{
87 std::string GlobalString;
88 std::string GlobalString2 = "global string 2";
89 const std::string ConstGlobalString = "const global string";
90
91 struct Structure {
92   std::string MemberString;
93   std::string MemberString2;
94   static std::string StaticMemberString;
95   static std::string StaticMemberString2;
96
97   const std::string ConstMemberString;
98   static const std::string ConstStaticMemberString;
99
100   Structure() : MemberString2("member string 2"), ConstMemberString("const member string") {}
101 };
102 %}
103
104 %{
105   std::string Structure::StaticMemberString = "static member string";
106   std::string Structure::StaticMemberString2 = "static member string 2";
107   const std::string Structure::ConstStaticMemberString = "const static member string";
108 %}
109
110
111 %inline %{
112 class Foo {
113 public:
114    unsigned long long  test(unsigned long long l)
115    {
116        return l + 1;
117    }
118    std::string test(std::string l)
119    {
120        return l + "1";
121    }
122
123    unsigned long long  testl(unsigned long long l)
124    {
125        return l + 1;
126    }
127
128 }; 
129 %}
130
131 %inline %{
132   std::string stdstring_empty() {
133     return std::string();
134   }
135
136   char *c_empty() {
137     return (char *)"";
138   }
139
140   char *c_null() {
141     return 0;
142   }
143
144   const char *get_null(const char *a) {
145     return a == 0 ? a : "non-null";
146   }
147
148
149 %}