PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Examples/test-suite/li_std_string.i

#
Swig | 149 lines | 108 code | 36 blank | 5 comment | 0 complexity | 2a9fa5d31182b238c6843934d2af48f7 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. %module li_std_string
  2. %include <std_string.i>
  3. #if defined(SWIGUTL)
  4. %apply std::string& INPUT { std::string &input }
  5. %apply std::string& INOUT { std::string &inout }
  6. #endif
  7. %inline %{
  8. std::string test_value(std::string x) {
  9. return x;
  10. }
  11. const std::string& test_const_reference(const std::string &x) {
  12. return x;
  13. }
  14. void test_pointer(std::string *x) {
  15. }
  16. std::string *test_pointer_out() {
  17. static std::string x = "x";
  18. return &x;
  19. }
  20. void test_const_pointer(const std::string *x) {
  21. }
  22. const std::string *test_const_pointer_out() {
  23. static std::string x = "x";
  24. return &x;
  25. }
  26. void test_reference(std::string &x) {
  27. }
  28. std::string& test_reference_out() {
  29. static std::string x = "test_reference_out message";
  30. return x;
  31. }
  32. std::string test_reference_input(std::string &input) {
  33. return input;
  34. }
  35. void test_reference_inout(std::string &inout) {
  36. inout += inout;
  37. }
  38. #if defined(_MSC_VER)
  39. #pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
  40. #endif
  41. void test_throw() throw(std::string){
  42. static std::string x = "test_throw message";
  43. throw x;
  44. }
  45. void test_const_reference_throw() throw(const std::string &){
  46. static std::string x = "test_const_reference_throw message";
  47. throw x;
  48. }
  49. void test_pointer_throw() throw(std::string *) {
  50. throw new std::string("foo");
  51. }
  52. void test_const_pointer_throw() throw(const std::string *) {
  53. throw new std::string("foo");
  54. }
  55. #if defined(_MSC_VER)
  56. #pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
  57. #endif
  58. %}
  59. /* Old way, now std::string is a %naturalvar by default
  60. %apply const std::string& { std::string *GlobalString2,
  61. std::string *MemberString2,
  62. std::string *Structure::StaticMemberString2 };
  63. */
  64. %inline %{
  65. std::string GlobalString;
  66. std::string GlobalString2 = "global string 2";
  67. const std::string ConstGlobalString = "const global string";
  68. struct Structure {
  69. std::string MemberString;
  70. std::string MemberString2;
  71. static std::string StaticMemberString;
  72. static std::string StaticMemberString2;
  73. const std::string ConstMemberString;
  74. static const std::string ConstStaticMemberString;
  75. Structure() : MemberString2("member string 2"), ConstMemberString("const member string") {}
  76. };
  77. %}
  78. %{
  79. std::string Structure::StaticMemberString = "static member string";
  80. std::string Structure::StaticMemberString2 = "static member string 2";
  81. const std::string Structure::ConstStaticMemberString = "const static member string";
  82. %}
  83. %inline %{
  84. class Foo {
  85. public:
  86. unsigned long long test(unsigned long long l)
  87. {
  88. return l + 1;
  89. }
  90. std::string test(std::string l)
  91. {
  92. return l + "1";
  93. }
  94. unsigned long long testl(unsigned long long l)
  95. {
  96. return l + 1;
  97. }
  98. };
  99. %}
  100. %inline %{
  101. std::string stdstring_empty() {
  102. return std::string();
  103. }
  104. char *c_empty() {
  105. return (char *)"";
  106. }
  107. char *c_null() {
  108. return 0;
  109. }
  110. const char *get_null(const char *a) {
  111. return a == 0 ? a : "non-null";
  112. }
  113. %}