blob: 864cc97eba6512a132e2b1fe7a617aaa5c18b53d (
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
%module cpp17_string_view
#if defined SWIGCSHARP || defined SWIGJAVA || defined SWIGLUA || defined SWIGPHP
%include <std_string_view.i>
// throw is invalid in C++17 and later, only SWIG to use it
#define TESTCASE_THROW1(T1) throw(T1)
%{
#define TESTCASE_THROW1(T1)
%}
%inline %{
std::string_view test_value(std::string_view x) {
return x;
}
const std::string_view& test_const_reference(const std::string_view &x) {
return x;
}
void test_const_reference_returning_void(const std::string_view &) {
}
void test_const_reference_returning_void(const std::string_view &, int) {
}
void test_pointer(std::string_view *x) {
}
std::string_view *test_pointer_out() {
static std::string_view x = "x";
return &x;
}
void test_const_pointer(const std::string_view *x) {
}
const std::string_view *test_const_pointer_out() {
static std::string_view x = "x";
return &x;
}
void test_reference(std::string_view &x) {
}
std::string_view& test_reference_out() {
static std::string_view x = "test_reference_out message";
return x;
}
std::string_view test_reference_input(std::string_view &input) {
return input;
}
void test_throw() TESTCASE_THROW1(std::string_view){
static std::string_view x = "test_throw message";
throw x;
}
void test_const_reference_throw() TESTCASE_THROW1(const std::string_view &){
static const std::string_view x = "test_const_reference_throw message";
throw x;
}
void test_pointer_throw() TESTCASE_THROW1(std::string_view *) {
throw new std::string_view("foo");
}
void test_const_pointer_throw() TESTCASE_THROW1(const std::string_view *) {
throw static_cast<const std::string_view*>(new std::string_view("foo"));
}
%}
#ifdef SWIGSCILAB
%rename(ConstStr) ConstMemberString;
%rename(ConstStaticStr) ConstStaticMemberString;
#endif
%inline %{
const std::string_view ConstGlobalString = "const global string";
struct Structure {
const std::string_view ConstMemberString;
static const std::string_view ConstStaticMemberString;
Structure() : ConstMemberString("const member string") {}
};
%}
%{
const std::string_view Structure::ConstStaticMemberString = "const static member string";
%}
%inline %{
std::string_view stdstring_empty() {
return std::string_view();
}
char *c_empty() {
return (char *)"";
}
char *c_null() {
return 0;
}
const char *get_null(const char *a) {
return a == 0 ? a : "non-null";
}
%}
#endif
|