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 // throw is invalid in C++17 and later, only SWIG to use it 10 #define TESTCASE_THROW1(T1) throw(T1) 11 %{ 12 #define TESTCASE_THROW1(T1) 13 %} 14 15 %inline %{ 16 test_value(std::string x)17std::string test_value(std::string x) { 18 return x; 19 } 20 test_const_reference(const std::string & x)21const std::string& test_const_reference(const std::string &x) { 22 return x; 23 } 24 test_const_reference_returning_void(const std::string &)25void test_const_reference_returning_void(const std::string &) { 26 } 27 test_const_reference_returning_void(const std::string &,int)28void test_const_reference_returning_void(const std::string &, int) { 29 } 30 test_pointer(std::string * x)31void test_pointer(std::string *x) { 32 } 33 test_pointer_out()34std::string *test_pointer_out() { 35 static std::string x = "x"; 36 return &x; 37 } 38 test_const_pointer(const std::string * x)39void test_const_pointer(const std::string *x) { 40 } 41 test_const_pointer_out()42const std::string *test_const_pointer_out() { 43 static std::string x = "x"; 44 return &x; 45 } 46 test_reference(std::string & x)47void test_reference(std::string &x) { 48 } 49 test_reference_out()50std::string& test_reference_out() { 51 static std::string x = "test_reference_out message"; 52 return x; 53 } 54 test_reference_input(std::string & input)55std::string test_reference_input(std::string &input) { 56 return input; 57 } 58 test_reference_inout(std::string & inout)59void test_reference_inout(std::string &inout) { 60 inout += inout; 61 } 62 test_throw()63void test_throw() TESTCASE_THROW1(std::string){ 64 static std::string x = "test_throw message"; 65 throw x; 66 } 67 test_const_reference_throw()68void test_const_reference_throw() TESTCASE_THROW1(const std::string &){ 69 static std::string x = "test_const_reference_throw message"; 70 throw x; 71 } 72 test_pointer_throw()73void test_pointer_throw() TESTCASE_THROW1(std::string *) { 74 throw new std::string("foo"); 75 } 76 test_const_pointer_throw()77void test_const_pointer_throw() TESTCASE_THROW1(const std::string *) { 78 throw new std::string("foo"); 79 } 80 %} 81 82 /* Old way, now std::string is a %naturalvar by default 83 %apply const std::string& { std::string *GlobalString2, 84 std::string *MemberString2, 85 std::string *Structure::StaticMemberString2 }; 86 */ 87 88 #ifdef SWIGSCILAB 89 %rename(St) MemberString; 90 %rename(Str) MemberString; 91 %rename(Str2) MemberString2; 92 %rename(StaticStr) StaticMemberString; 93 %rename(StaticStr2) StaticMemberString2; 94 %rename(ConstStr) ConstMemberString; 95 %rename(ConstStaticStr) ConstStaticMemberString; 96 #endif 97 98 %inline %{ 99 std::string GlobalString; 100 std::string GlobalString2 = "global string 2"; 101 const std::string ConstGlobalString = "const global string"; 102 103 struct Structure { 104 std::string MemberString; 105 std::string MemberString2; 106 static std::string StaticMemberString; 107 static std::string StaticMemberString2; 108 109 const std::string ConstMemberString; 110 static const std::string ConstStaticMemberString; 111 StructureStructure112 Structure() : MemberString2("member string 2"), ConstMemberString("const member string") {} 113 }; 114 %} 115 116 %{ 117 std::string Structure::StaticMemberString = "static member string"; 118 std::string Structure::StaticMemberString2 = "static member string 2"; 119 const std::string Structure::ConstStaticMemberString = "const static member string"; 120 %} 121 122 123 %inline %{ 124 class Foo { 125 public: test(unsigned long long l)126 unsigned long long test(unsigned long long l) 127 { 128 return l + 1; 129 } test(std::string l)130 std::string test(std::string l) 131 { 132 return l + "1"; 133 } 134 testl(unsigned long long l)135 unsigned long long testl(unsigned long long l) 136 { 137 return l + 1; 138 } 139 140 }; 141 %} 142 143 %inline %{ stdstring_empty()144 std::string stdstring_empty() { 145 return std::string(); 146 } 147 c_empty()148 char *c_empty() { 149 return (char *)""; 150 } 151 c_null()152 char *c_null() { 153 return 0; 154 } 155 get_null(const char * a)156 const char *get_null(const char *a) { 157 return a == 0 ? a : "non-null"; 158 } 159 %} 160 161