/trunk/Examples/test-suite/li_std_string.i
Swig | 149 lines | 108 code | 36 blank | 5 comment | 0 complexity | 2a9fa5d31182b238c6843934d2af48f7 MD5 | raw file
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 12std::string test_value(std::string x) { 13 return x; 14} 15 16const std::string& test_const_reference(const std::string &x) { 17 return x; 18} 19 20void test_pointer(std::string *x) { 21} 22 23std::string *test_pointer_out() { 24 static std::string x = "x"; 25 return &x; 26} 27 28void test_const_pointer(const std::string *x) { 29} 30 31const std::string *test_const_pointer_out() { 32 static std::string x = "x"; 33 return &x; 34} 35 36void test_reference(std::string &x) { 37} 38 39std::string& test_reference_out() { 40 static std::string x = "test_reference_out message"; 41 return x; 42} 43 44std::string test_reference_input(std::string &input) { 45 return input; 46} 47 48void 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 56void test_throw() throw(std::string){ 57 static std::string x = "test_throw message"; 58 throw x; 59} 60 61void test_const_reference_throw() throw(const std::string &){ 62 static std::string x = "test_const_reference_throw message"; 63 throw x; 64} 65 66void test_pointer_throw() throw(std::string *) { 67 throw new std::string("foo"); 68} 69 70void 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 %{ 87std::string GlobalString; 88std::string GlobalString2 = "global string 2"; 89const std::string ConstGlobalString = "const global string"; 90 91struct 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 %{ 112class Foo { 113public: 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%}