Merge branch 'master' into gsoc2017-php7-classes-via-c-api
This commit is contained in:
commit
8ded9d8dae
1906 changed files with 50934 additions and 30001 deletions
|
|
@ -79,5 +79,9 @@ protected:
|
|||
};
|
||||
int ProtectedBase::staticMemberVariable = 10;
|
||||
|
||||
class ProtectedDerived : public ProtectedBase {
|
||||
public:
|
||||
ProtectedDerived(const char *s) : ProtectedBase(s) {}
|
||||
};
|
||||
%}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
%module(docstring="hello.") autodoc
|
||||
|
||||
%warnfilter(SWIGWARN_PARSE_KEYWORD) inout;
|
||||
|
||||
%feature("autodoc");
|
||||
|
||||
// special typemap and its docs
|
||||
|
|
@ -74,6 +76,10 @@
|
|||
%feature("autodoc","1") D::D(int a, int b, Hola h); // names + types
|
||||
%feature("autodoc","2") E::E(int a, int b, Hola h); // extended
|
||||
%feature("autodoc","3") F::F(int a, int b, Hola h); // extended + types
|
||||
%feature("autodoc","0") C::~C(); // names
|
||||
%feature("autodoc","1") D::~D(); // names + types
|
||||
%feature("autodoc","2") E::~E(); // extended
|
||||
%feature("autodoc","3") F::~F(); // extended + types
|
||||
|
||||
%inline {
|
||||
|
||||
|
|
@ -148,3 +154,41 @@ bool is_python_builtin() { return true; }
|
|||
bool is_python_builtin() { return false; }
|
||||
#endif
|
||||
%}
|
||||
|
||||
// Autodoc language keywords
|
||||
%feature(autodoc,1) process;
|
||||
%feature(autodoc,1) process2;
|
||||
%feature("compactdefaultargs") process;
|
||||
%feature("compactdefaultargs") process2;
|
||||
%inline %{
|
||||
int process(int from, int in, int var) { return from; }
|
||||
int process2(int from = 0, int _in = 1, int var = 2) { return from; }
|
||||
%}
|
||||
|
||||
%feature(autodoc,1) process3;
|
||||
%feature(autodoc,1) process4;
|
||||
%feature("kwargs") process3;
|
||||
%feature("kwargs") process4;
|
||||
%inline %{
|
||||
int process3(int from, int _in, int var) { return from; }
|
||||
int process4(int from = 0, int _in = 1, int var = 2) { return from; }
|
||||
%}
|
||||
|
||||
// Autodoc for methods with default arguments not directly representable in
|
||||
// target language.
|
||||
%feature(autodoc,0) process_complex_defval;
|
||||
%feature("compactdefaultargs") process_complex_defval;
|
||||
%inline %{
|
||||
const int PROCESS_DEFAULT_VALUE = 17;
|
||||
typedef long int some_type;
|
||||
int process_complex_defval(int val = PROCESS_DEFAULT_VALUE, int factor = some_type(-1)) { return val*factor; }
|
||||
%}
|
||||
|
||||
// Test for empty docstring, which should be ignored.
|
||||
%feature("docstring") ""
|
||||
|
||||
%inline %{
|
||||
struct a_structure{
|
||||
char my_array[1];
|
||||
};
|
||||
%}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,9 @@
|
|||
%module catches
|
||||
|
||||
// throw is invalid in C++17 and later, only SWIG to use it
|
||||
#define TESTCASE_THROW3(T1, T2, T3) throw(T1, T2, T3)
|
||||
%{
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
|
||||
#endif
|
||||
#if __GNUC__ >= 7
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated" // dynamic exception specifications are deprecated in C++11
|
||||
#endif
|
||||
#define TESTCASE_THROW3(T1, T2, T3)
|
||||
%}
|
||||
|
||||
%include <exception.i> // for throws(...) typemap
|
||||
|
|
@ -27,7 +23,7 @@ void test_catches(int i) {
|
|||
throw ThreeException();
|
||||
}
|
||||
}
|
||||
void test_exception_specification(int i) throw(int, const char *, const ThreeException&) {
|
||||
void test_exception_specification(int i) TESTCASE_THROW3(int, const char *, const ThreeException&) {
|
||||
test_catches(i);
|
||||
}
|
||||
void test_catches_all(int i) {
|
||||
|
|
@ -35,11 +31,3 @@ void test_catches_all(int i) {
|
|||
}
|
||||
%}
|
||||
|
||||
%{
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
|
||||
#endif
|
||||
#if __GNUC__ >= 7
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
%}
|
||||
|
|
|
|||
81
Examples/test-suite/ccomplextest.i
Normal file
81
Examples/test-suite/ccomplextest.i
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
%module ccomplextest
|
||||
|
||||
%include <complex.i>
|
||||
|
||||
%{
|
||||
#include <complex.h>
|
||||
|
||||
#if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199001L
|
||||
#define HAS_C99_COMPLEX_FOR_TESTING 1
|
||||
#else
|
||||
/* c99 complex not supported - super hack tests to just test plain floating point numbers */
|
||||
/* some pre c99 compilers (gcc-4.x) don't define _Complex but do define complex */
|
||||
#define _Complex
|
||||
#if !defined(complex)
|
||||
# define complex
|
||||
#endif
|
||||
#define conj
|
||||
#define conjf
|
||||
#define creal
|
||||
#define cimag
|
||||
#if defined(I)
|
||||
# undef I
|
||||
# define I 1
|
||||
#endif
|
||||
#define HAS_C99_COMPLEX_FOR_TESTING 0
|
||||
#endif
|
||||
%}
|
||||
|
||||
%inline
|
||||
{
|
||||
int has_c99_complex(void) {
|
||||
return HAS_C99_COMPLEX_FOR_TESTING;
|
||||
}
|
||||
|
||||
complex double Conj(complex double a)
|
||||
{
|
||||
return conj(a);
|
||||
}
|
||||
|
||||
|
||||
complex float Conjf(complex float a)
|
||||
{
|
||||
return conjf(a);
|
||||
}
|
||||
|
||||
|
||||
double complex Conj1(double complex a)
|
||||
{
|
||||
return conj(a);
|
||||
}
|
||||
|
||||
|
||||
float complex Conjf1(float complex a)
|
||||
{
|
||||
return conjf(a);
|
||||
}
|
||||
|
||||
|
||||
_Complex double Conj2(_Complex double a)
|
||||
{
|
||||
return conj(a);
|
||||
}
|
||||
|
||||
|
||||
_Complex float Conjf2(_Complex float a)
|
||||
{
|
||||
return conjf(a);
|
||||
}
|
||||
|
||||
|
||||
double _Complex Conj3(double _Complex a)
|
||||
{
|
||||
return conj(a);
|
||||
}
|
||||
|
||||
|
||||
float _Complex Conjf3(float _Complex a)
|
||||
{
|
||||
return conjf(a);
|
||||
}
|
||||
}
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
%module class_scope_namespace
|
||||
|
||||
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) H::HH;
|
||||
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Space8::I::II;
|
||||
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Space8::I_::II;
|
||||
|
||||
%inline %{
|
||||
struct A;
|
||||
|
|
@ -107,12 +107,12 @@ void hhh(H::HH) {}
|
|||
|
||||
namespace Space8 {
|
||||
struct II;
|
||||
struct I {
|
||||
struct I_ {
|
||||
struct II {
|
||||
void ii(Space8::I::II, I::II) {}
|
||||
void ii(Space8::I_::II, I_::II) {}
|
||||
};
|
||||
};
|
||||
void iii(Space8::I::II, I::II) {}
|
||||
void iii(Space8::I_::II, I_::II) {}
|
||||
}
|
||||
|
||||
struct J;
|
||||
|
|
|
|||
|
|
@ -83,13 +83,11 @@ Makefile: $(srcdir)/Makefile.in ../../../config.status
|
|||
# Broken C++ test cases. (Can be run individually using: make testcase.cpptest)
|
||||
CPP_TEST_BROKEN += \
|
||||
constants \
|
||||
cpp_broken \
|
||||
director_nested_class \
|
||||
exception_partial_info \
|
||||
extend_variable \
|
||||
li_boost_shared_ptr_template \
|
||||
nested_private \
|
||||
overload_complicated \
|
||||
rename_camel \
|
||||
template_default_pointer \
|
||||
template_private_assignment \
|
||||
|
|
@ -161,15 +159,23 @@ CPP_TEST_CASES += \
|
|||
cpp_enum \
|
||||
cpp_namespace \
|
||||
cpp_nodefault \
|
||||
cpp_parameters \
|
||||
cpp_static \
|
||||
cpp_typedef \
|
||||
cpp14_binary_integer_literals \
|
||||
cpp17_hex_floating_literals \
|
||||
cpp17_nested_namespaces \
|
||||
cpp17_nspace_nested_namespaces \
|
||||
cpp17_u8_char_literals \
|
||||
curiously_recurring_template_pattern \
|
||||
default_args \
|
||||
default_arg_expressions \
|
||||
default_arg_values \
|
||||
default_constructor \
|
||||
defvalue_constructor \
|
||||
derived_byvalue \
|
||||
derived_nested \
|
||||
destructor_methodmodifiers \
|
||||
destructor_reprotected \
|
||||
director_abstract \
|
||||
director_alternating \
|
||||
|
|
@ -178,10 +184,14 @@ CPP_TEST_CASES += \
|
|||
director_classes \
|
||||
director_classic \
|
||||
director_constructor \
|
||||
director_comparison_operators \
|
||||
director_conversion_operators \
|
||||
director_default \
|
||||
director_detect \
|
||||
director_enum \
|
||||
director_exception \
|
||||
director_exception_catches \
|
||||
director_exception_nothrow \
|
||||
director_extend \
|
||||
director_finalizer \
|
||||
director_frob \
|
||||
|
|
@ -193,6 +203,7 @@ CPP_TEST_CASES += \
|
|||
director_nspace_director_name_collision \
|
||||
director_overload \
|
||||
director_overload2 \
|
||||
director_ownership \
|
||||
director_pass_by_value \
|
||||
director_primitives \
|
||||
director_property \
|
||||
|
|
@ -240,7 +251,9 @@ CPP_TEST_CASES += \
|
|||
friends \
|
||||
friends_template \
|
||||
funcptr_cpp \
|
||||
functors \
|
||||
fvirtual \
|
||||
global_immutable_vars_cpp \
|
||||
global_namespace \
|
||||
global_ns_arg \
|
||||
global_scope_types \
|
||||
|
|
@ -264,9 +277,10 @@ CPP_TEST_CASES += \
|
|||
li_attribute \
|
||||
li_attribute_template \
|
||||
li_boost_shared_ptr \
|
||||
li_boost_shared_ptr_bits \
|
||||
li_boost_shared_ptr_template \
|
||||
li_boost_shared_ptr_attribute \
|
||||
li_boost_shared_ptr_bits \
|
||||
li_boost_shared_ptr_director \
|
||||
li_boost_shared_ptr_template \
|
||||
li_carrays_cpp \
|
||||
li_cdata_cpp \
|
||||
li_cpointer_cpp \
|
||||
|
|
@ -306,6 +320,7 @@ CPP_TEST_CASES += \
|
|||
namespace_virtual_method \
|
||||
nspace \
|
||||
nspace_extend \
|
||||
native_directive \
|
||||
naturalvar \
|
||||
naturalvar_more \
|
||||
naturalvar_onoff \
|
||||
|
|
@ -313,10 +328,13 @@ CPP_TEST_CASES += \
|
|||
nested_directors \
|
||||
nested_comment \
|
||||
nested_ignore \
|
||||
nested_scope \
|
||||
nested_inheritance_interface \
|
||||
nested_in_template \
|
||||
nested_scope_flat \
|
||||
nested_template_base \
|
||||
nested_workaround \
|
||||
newobject1 \
|
||||
newobject3 \
|
||||
null_pointer \
|
||||
operator_overload \
|
||||
operator_overload_break \
|
||||
|
|
@ -325,10 +343,12 @@ CPP_TEST_CASES += \
|
|||
ordering \
|
||||
overload_arrays \
|
||||
overload_bool \
|
||||
overload_complicated \
|
||||
overload_copy \
|
||||
overload_extend \
|
||||
overload_method \
|
||||
overload_numeric \
|
||||
overload_null \
|
||||
overload_polymorphic \
|
||||
overload_rename \
|
||||
overload_return_type \
|
||||
|
|
@ -347,7 +367,6 @@ CPP_TEST_CASES += \
|
|||
redefined_not \
|
||||
refcount \
|
||||
reference_global_vars \
|
||||
register_par \
|
||||
rename1 \
|
||||
rename2 \
|
||||
rename3 \
|
||||
|
|
@ -393,6 +412,7 @@ CPP_TEST_CASES += \
|
|||
static_array_member \
|
||||
static_const_member \
|
||||
static_const_member_2 \
|
||||
stl_no_default_constructor \
|
||||
string_constants \
|
||||
struct_initialization_cpp \
|
||||
struct_value \
|
||||
|
|
@ -405,6 +425,7 @@ CPP_TEST_CASES += \
|
|||
template_basic \
|
||||
template_base_template \
|
||||
template_classes \
|
||||
template_class_reuse_name \
|
||||
template_const_ref \
|
||||
template_construct \
|
||||
template_templated_constructors \
|
||||
|
|
@ -439,6 +460,7 @@ CPP_TEST_CASES += \
|
|||
template_using_directive_and_declaration_forward \
|
||||
template_using_directive_typedef \
|
||||
template_nested \
|
||||
template_nested_flat \
|
||||
template_nested_typemaps \
|
||||
template_ns \
|
||||
template_ns2 \
|
||||
|
|
@ -486,6 +508,7 @@ CPP_TEST_CASES += \
|
|||
throw_exception \
|
||||
typedef_array_member \
|
||||
typedef_class \
|
||||
typedef_classforward_same_name \
|
||||
typedef_funcptr \
|
||||
typedef_inherit \
|
||||
typedef_mptr \
|
||||
|
|
@ -506,6 +529,8 @@ CPP_TEST_CASES += \
|
|||
typemap_numinputs \
|
||||
typemap_template \
|
||||
typemap_template_parm_typedef \
|
||||
typemap_template_parms \
|
||||
typemap_template_typedef \
|
||||
typemap_out_optimal \
|
||||
typemap_qualifier_strip \
|
||||
typemap_variables \
|
||||
|
|
@ -534,6 +559,7 @@ CPP_TEST_CASES += \
|
|||
varargs_overload \
|
||||
variable_replacement \
|
||||
virtual_destructor \
|
||||
virtual_derivation \
|
||||
virtual_poly \
|
||||
virtual_vs_nonvirtual_base \
|
||||
voidtest \
|
||||
|
|
@ -542,6 +568,7 @@ CPP_TEST_CASES += \
|
|||
|
||||
# C++11 test cases.
|
||||
CPP11_TEST_CASES += \
|
||||
cpp11_alias_nested_template_scoping \
|
||||
cpp11_alignment \
|
||||
cpp11_alternate_function_syntax \
|
||||
cpp11_constexpr \
|
||||
|
|
@ -551,22 +578,26 @@ CPP11_TEST_CASES += \
|
|||
cpp11_director_enums \
|
||||
cpp11_directors \
|
||||
cpp11_explicit_conversion_operators \
|
||||
cpp11_final_directors \
|
||||
cpp11_final_override \
|
||||
cpp11_function_objects \
|
||||
cpp11_inheriting_constructors \
|
||||
cpp11_initializer_list \
|
||||
cpp11_initializer_list_extend \
|
||||
cpp11_lambda_functions \
|
||||
cpp11_li_std_array \
|
||||
cpp11_noexcept \
|
||||
cpp11_null_pointer_constant \
|
||||
cpp11_raw_string_literals \
|
||||
cpp11_ref_qualifiers \
|
||||
cpp11_ref_qualifiers_rvalue_unignore \
|
||||
cpp11_ref_qualifiers_typemaps \
|
||||
cpp11_result_of \
|
||||
cpp11_rvalue_reference \
|
||||
cpp11_rvalue_reference2 \
|
||||
cpp11_rvalue_reference3 \
|
||||
cpp11_sizeof_object \
|
||||
cpp11_static_assert \
|
||||
cpp11_std_array \
|
||||
cpp11_strongly_typed_enumerations \
|
||||
cpp11_thread_local \
|
||||
cpp11_template_double_brackets \
|
||||
|
|
@ -583,6 +614,37 @@ CPP11_TEST_BROKEN = \
|
|||
# cpp11_variadic_templates \ # Broken for some languages (such as Java)
|
||||
# cpp11_reference_wrapper \ # No typemaps
|
||||
|
||||
# Doxygen support test cases: can only be used with languages supporting
|
||||
# Doxygen comment translation (currently Python and Java) and only if not
|
||||
# disabled by configure via SKIP_DOXYGEN_TEST_CASES.
|
||||
ifneq ($(SKIP_DOXYGEN_TEST_CASES),1)
|
||||
python_HAS_DOXYGEN := 1
|
||||
java_HAS_DOXYGEN := 1
|
||||
|
||||
$(eval HAS_DOXYGEN := $($(LANGUAGE)_HAS_DOXYGEN))
|
||||
endif
|
||||
|
||||
ifdef HAS_DOXYGEN
|
||||
DOXYGEN_TEST_CASES += \
|
||||
doxygen_alias \
|
||||
doxygen_basic_notranslate \
|
||||
doxygen_basic_translate \
|
||||
doxygen_basic_translate_style2 \
|
||||
doxygen_basic_translate_style3 \
|
||||
doxygen_code_blocks \
|
||||
doxygen_ignore \
|
||||
doxygen_misc_constructs \
|
||||
doxygen_nested_class \
|
||||
doxygen_parsing \
|
||||
doxygen_parsing_enums \
|
||||
doxygen_translate \
|
||||
doxygen_translate_all_tags \
|
||||
doxygen_translate_links \
|
||||
|
||||
$(DOXYGEN_TEST_CASES:=.cpptest): SWIGOPT += -doxygen
|
||||
|
||||
CPP_TEST_CASES += $(DOXYGEN_TEST_CASES)
|
||||
endif
|
||||
|
||||
#
|
||||
# Put all the heavy STD/STL cases here, where they can be skipped if needed
|
||||
|
|
@ -591,6 +653,7 @@ CPP_STD_TEST_CASES += \
|
|||
director_string \
|
||||
ignore_template_constructor \
|
||||
li_std_combinations \
|
||||
li_std_containers_overload \
|
||||
li_std_deque \
|
||||
li_std_except \
|
||||
li_std_except_as_class \
|
||||
|
|
@ -599,9 +662,11 @@ CPP_STD_TEST_CASES += \
|
|||
li_std_pair_using \
|
||||
li_std_string \
|
||||
li_std_vector \
|
||||
li_std_vector_back_reference \
|
||||
li_std_vector_enum \
|
||||
li_std_vector_member_var\
|
||||
li_std_vector_ptr \
|
||||
li_std_wstring \
|
||||
smart_pointer_inherit \
|
||||
template_typedef_fnc \
|
||||
template_type_namespace \
|
||||
|
|
@ -611,7 +676,7 @@ ifndef SKIP_CPP_STD_CASES
|
|||
CPP_TEST_CASES += ${CPP_STD_TEST_CASES}
|
||||
endif
|
||||
|
||||
ifneq (,$(HAVE_CXX11_COMPILER))
|
||||
ifneq (,$(HAVE_CXX11))
|
||||
CPP_TEST_CASES += $(CPP11_TEST_CASES)
|
||||
endif
|
||||
|
||||
|
|
@ -624,6 +689,7 @@ C_TEST_CASES += \
|
|||
char_constant \
|
||||
const_const \
|
||||
constant_expr \
|
||||
default_args_c \
|
||||
empty_c \
|
||||
enums \
|
||||
enum_forward \
|
||||
|
|
@ -633,6 +699,7 @@ C_TEST_CASES += \
|
|||
funcptr \
|
||||
function_typedef \
|
||||
global_functions \
|
||||
global_immutable_vars \
|
||||
immutable_values \
|
||||
inctest \
|
||||
infinity \
|
||||
|
|
@ -652,13 +719,16 @@ C_TEST_CASES += \
|
|||
nested_extend_c \
|
||||
nested_structs \
|
||||
newobject2 \
|
||||
not_c_keywords \
|
||||
overload_extend_c \
|
||||
overload_extend2 \
|
||||
preproc \
|
||||
preproc_constants_c \
|
||||
preproc_defined \
|
||||
preproc_gcc_output \
|
||||
preproc_include \
|
||||
preproc_line_file \
|
||||
register_par \
|
||||
ret_by_value \
|
||||
simple_array \
|
||||
sizeof_pointer \
|
||||
|
|
@ -666,6 +736,7 @@ C_TEST_CASES += \
|
|||
string_simple \
|
||||
struct_rename \
|
||||
struct_initialization \
|
||||
typedef_classforward_same_name \
|
||||
typedef_struct \
|
||||
typemap_subst \
|
||||
union_parameter \
|
||||
|
|
@ -675,12 +746,12 @@ C_TEST_CASES += \
|
|||
# Multi-module C++ test cases . (Can be run individually using make testcase.multicpptest)
|
||||
MULTI_CPP_TEST_CASES += \
|
||||
clientdata_prop \
|
||||
imports \
|
||||
import_stl \
|
||||
packageoption \
|
||||
imports \
|
||||
mod \
|
||||
template_typedef_import \
|
||||
multi_import \
|
||||
packageoption \
|
||||
template_typedef_import \
|
||||
|
||||
# Custom tests - tests with additional commandline options
|
||||
wallkw.cpptest: SWIGOPT += -Wallkw
|
||||
|
|
@ -729,6 +800,10 @@ check-cpp: $(CPP_TEST_CASES:=.cpptest)
|
|||
|
||||
check-cpp11: $(CPP11_TEST_CASES:=.cpptest)
|
||||
|
||||
ifdef HAS_DOXYGEN
|
||||
check-doxygen: $(DOXYGEN_TEST_CASES:=.cpptest)
|
||||
endif
|
||||
|
||||
check-failing-test = \
|
||||
$(MAKE) -s $1.$2 >/dev/null 2>/dev/null && echo "Failing test $1 passed."
|
||||
|
||||
|
|
@ -785,8 +860,6 @@ setup = \
|
|||
echo "$(ACTION)ing $(LANGUAGE) testcase $*" ; \
|
||||
fi
|
||||
|
||||
|
||||
|
||||
#######################################################################
|
||||
# Clean
|
||||
#######################################################################
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
%include <complex.i>
|
||||
|
||||
#ifdef __cplusplus
|
||||
%{
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
|
|
@ -10,57 +9,54 @@
|
|||
%}
|
||||
%include <std_vector.i>
|
||||
|
||||
#if 1
|
||||
%template(VectorStdCplx) std::vector<std::complex<double> >;
|
||||
#endif
|
||||
|
||||
%inline
|
||||
%inline
|
||||
{
|
||||
std::complex<double> Conj(const std::complex<double>& a)
|
||||
std::complex<double> Conj(std::complex<double> a)
|
||||
{
|
||||
return std::conj(a);
|
||||
}
|
||||
}
|
||||
|
||||
std::complex<float> Conjf(const std::complex<float>& a)
|
||||
std::complex<float> Conjf(std::complex<float> a)
|
||||
{
|
||||
return std::conj(a);
|
||||
}
|
||||
}
|
||||
|
||||
#if 1
|
||||
std::vector<std::complex<double> > Copy_h(const std::vector<std::complex<double> >& a)
|
||||
std::vector<std::complex<double> > CopyHalf(std::vector<std::complex<double> > a)
|
||||
{
|
||||
std::vector<std::complex<double> > b(a.size()/2);
|
||||
std::copy(a.begin(), a.begin()+a.size()/2, b.begin());
|
||||
return b;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
using namespace std;
|
||||
|
||||
struct ComplexPair
|
||||
{
|
||||
std::complex<double> z1, z2;
|
||||
std::complex<double> z1;
|
||||
complex<double> z2;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
|
||||
|
||||
%{
|
||||
%}
|
||||
|
||||
%inline
|
||||
{
|
||||
complex Conj(complex a)
|
||||
const complex<double>& Conj2(const complex<double>& a)
|
||||
{
|
||||
return conj(a);
|
||||
static complex<double> ret;
|
||||
ret = std::conj(a);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
complex float Conjf(float complex a)
|
||||
const complex<float>& Conjf2(const complex<float>& a)
|
||||
{
|
||||
return conj(a);
|
||||
static complex<float> ret;
|
||||
ret = std::conj(a);
|
||||
return ret;
|
||||
}
|
||||
|
||||
const vector<complex<double> >& CopyHalfRef(const vector<complex<double> >& a)
|
||||
{
|
||||
static vector<complex<double> > b;
|
||||
b = CopyHalf(a);
|
||||
return b;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -2,6 +2,10 @@
|
|||
|
||||
// %constant and struct
|
||||
|
||||
#ifdef SWIGOCAML
|
||||
%warnfilter(SWIGWARN_PARSE_KEYWORD) val;
|
||||
#endif
|
||||
|
||||
%inline %{
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(disable : 4190) // warning C4190: 'result' has C-linkage specified, but returns UDT 'Type1' which is incompatible with C
|
||||
|
|
@ -10,6 +14,11 @@ struct Type1 {
|
|||
Type1(int val = 0) : val(val) {}
|
||||
int val;
|
||||
};
|
||||
enum EnumType
|
||||
{
|
||||
EnumValue
|
||||
};
|
||||
EnumType enumValue = EnumValue;
|
||||
/* Typedefs for const Type and its pointer */
|
||||
typedef const Type1 Type1Const;
|
||||
typedef const Type1* Type1Cptr;
|
||||
|
|
@ -42,3 +51,4 @@ Type1 getType1Instance() { return Type1(111); }
|
|||
%constant Type1Cfptr TYPE1CFPTR1DEF_CONSTANT1 = getType1Instance;
|
||||
/* Regular constant */
|
||||
%constant int TYPE_INT = 0;
|
||||
%constant enum EnumType newValue = enumValue;
|
||||
|
|
|
|||
|
|
@ -5,14 +5,10 @@
|
|||
|
||||
%module cplusplus_throw
|
||||
|
||||
// throw is invalid in C++17 and later, only SWIG to use it
|
||||
#define TESTCASE_THROW1(T1) throw(T1)
|
||||
%{
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
|
||||
#endif
|
||||
#if __GNUC__ >= 7
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated" // dynamic exception specifications are deprecated in C++11
|
||||
#endif
|
||||
#define TESTCASE_THROW1(T1)
|
||||
%}
|
||||
|
||||
%nodefaultctor;
|
||||
|
|
@ -24,17 +20,9 @@ class Foo { };
|
|||
class Bar {
|
||||
public:
|
||||
void baz() const { };
|
||||
void foo() throw (Foo) { };
|
||||
void bazfoo() const throw (int) { };
|
||||
void foo() TESTCASE_THROW1(Foo) { };
|
||||
void bazfoo() const TESTCASE_THROW1(int) { };
|
||||
};
|
||||
|
||||
%}
|
||||
|
||||
%{
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
|
||||
#endif
|
||||
#if __GNUC__ >= 7
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
%}
|
||||
|
|
|
|||
45
Examples/test-suite/cpp11_alias_nested_template_scoping.i
Normal file
45
Examples/test-suite/cpp11_alias_nested_template_scoping.i
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
%module cpp11_alias_nested_template_scoping
|
||||
|
||||
// Test to check a template parameter type is expanded when the template parameter
|
||||
// is used twice in a type name. Expansion was
|
||||
// Y< short >::YYY< T >::value_type >
|
||||
// instead of
|
||||
// Y< short >::YYY< short >::value_type >
|
||||
|
||||
#if !defined(SWIGCSHARP) && !defined(SWIGJAVA)
|
||||
%feature("flatnested") ZZZ;
|
||||
#endif
|
||||
|
||||
%inline %{
|
||||
template<typename T> struct Y {
|
||||
typedef T value_type;
|
||||
typedef Y YY;
|
||||
template<typename T2> using YYY = Y<T2>;
|
||||
template<typename T2> struct ZZZ {
|
||||
typedef T2 another_type;
|
||||
};
|
||||
value_type create1() const { return T(); }
|
||||
typename Y::value_type create2() const { return T(); }
|
||||
typename Y<T>::value_type create3() const { return T(); }
|
||||
typename YY::value_type create4() const { return T(); }
|
||||
typename Y<T>::YY::value_type create5() const { return T(); }
|
||||
Y<T>::YYY<T>::value_type create6() const { return T(); }
|
||||
typename Y<T>::template ZZZ<T>::another_type create7() const { return T(); }
|
||||
|
||||
// With global scope prefix
|
||||
typename ::Y<T>::value_type create13() const { return T(); }
|
||||
|
||||
typename ::Y<T>::YY::value_type create15() const { return T(); }
|
||||
::Y<T>::YYY<T>::value_type create16() const { return T(); }
|
||||
typename ::Y<T>::template ZZZ<T>::another_type create17() const { return T(); }
|
||||
};
|
||||
%}
|
||||
|
||||
%extend Y {
|
||||
%template() YYY<short>;
|
||||
%template() ZZZ<short>;
|
||||
};
|
||||
// Use above workaround instead of below (which currently gives syntax error)
|
||||
// %template() Y<short>::YYY<short>;
|
||||
|
||||
%template(Yshort) Y<short>;
|
||||
|
|
@ -4,7 +4,8 @@
|
|||
struct A {
|
||||
int member;
|
||||
};
|
||||
const int align1 = alignof(A::member);
|
||||
const int align1 = alignof(int);
|
||||
const int align2 = alignof(int *);
|
||||
%}
|
||||
|
||||
%{
|
||||
|
|
|
|||
|
|
@ -4,6 +4,15 @@
|
|||
%module cpp11_constexpr
|
||||
|
||||
|
||||
%{
|
||||
#if defined(__clang__)
|
||||
#pragma clang diagnostic push
|
||||
// Suppress: 'constexpr' non-static member function will not be implicitly 'const' in C++14; add 'const' to avoid a change in behavior
|
||||
// For MMM() and NNN()
|
||||
#pragma clang diagnostic ignored "-Wconstexpr-not-const"
|
||||
#endif
|
||||
%}
|
||||
|
||||
%inline %{
|
||||
#ifdef SWIG
|
||||
#define SWIGTESTCONST const
|
||||
|
|
|
|||
|
|
@ -28,7 +28,13 @@ A1::A1(const A1&) = default;
|
|||
|
||||
struct A2 {
|
||||
void funk(int i) {}
|
||||
|
||||
// Workaround clang 10.0.1 -std=c++17 linker error (oddly for Java and not Python):
|
||||
// Undefined symbols for architecture x86_64:"___cxa_deleted_virtual", referenced from: vtable for A2
|
||||
#if !(defined(__clang__) && __cplusplus >= 201703L)
|
||||
virtual void fff(int) = delete;
|
||||
#endif
|
||||
|
||||
virtual ~A2() = default;
|
||||
template<class T> void funk(T) = delete;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,20 +1,16 @@
|
|||
%module(directors="1") cpp11_directors
|
||||
%feature("director");
|
||||
|
||||
%{
|
||||
%inline %{
|
||||
|
||||
class Foo {
|
||||
public:
|
||||
virtual ~Foo() noexcept {}
|
||||
virtual int ping() noexcept = 0;
|
||||
virtual int pong() noexcept = 0;
|
||||
virtual int pang() const& noexcept = 0;
|
||||
virtual int peng() & noexcept = 0;
|
||||
virtual int pung() & = 0;
|
||||
};
|
||||
|
||||
%}
|
||||
|
||||
class Foo {
|
||||
public:
|
||||
virtual ~Foo() noexcept {}
|
||||
virtual int ping() noexcept = 0;
|
||||
virtual int pong() noexcept = 0;
|
||||
};
|
||||
33
Examples/test-suite/cpp11_final_directors.i
Normal file
33
Examples/test-suite/cpp11_final_directors.i
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
%module(directors="1") cpp11_final_directors
|
||||
|
||||
%director Derived;
|
||||
|
||||
// Check SWIG will not wrap these classes as directors where the destructors are final
|
||||
%director BaseFinalDestructor;
|
||||
%director BaseFinalDestructor2;
|
||||
|
||||
%warnfilter(SWIGWARN_LANG_DIRECTOR_FINAL) BaseFinalDestructor::~BaseFinalDestructor;
|
||||
%warnfilter(SWIGWARN_LANG_DIRECTOR_FINAL) BaseFinalDestructor2::~BaseFinalDestructor2;
|
||||
|
||||
%inline %{
|
||||
struct Base {
|
||||
virtual void basemeth() final {}
|
||||
virtual ~Base() {}
|
||||
};
|
||||
|
||||
struct Derived : Base {
|
||||
virtual int derivedmeth() final { return 1; }
|
||||
virtual int meth() { return 2; }
|
||||
virtual ~Derived() {}
|
||||
};
|
||||
|
||||
struct BaseFinalDestructor {
|
||||
virtual void basefinalmeth() final {}
|
||||
virtual ~BaseFinalDestructor() final {}
|
||||
};
|
||||
|
||||
struct BaseFinalDestructor2 {
|
||||
virtual void basefinalmeth() {}
|
||||
virtual ~BaseFinalDestructor2() final {}
|
||||
};
|
||||
%}
|
||||
|
|
@ -6,6 +6,12 @@
|
|||
%warnfilter(SWIGWARN_PARSE_KEYWORD) final; // 'final' is a java keyword, renaming to '_final'
|
||||
%warnfilter(SWIGWARN_PARSE_KEYWORD) override; // 'override' is a C# keyword, renaming to '_override'
|
||||
|
||||
// throw is invalid in C++17 and later, only SWIG to use it
|
||||
#define TESTCASE_THROW1(T1) throw(T1)
|
||||
%{
|
||||
#define TESTCASE_THROW1(T1)
|
||||
%}
|
||||
|
||||
%inline %{
|
||||
|
||||
struct Base {
|
||||
|
|
@ -33,8 +39,8 @@ struct Derived /*final*/ : Base {
|
|||
virtual void finaloverride2() override final {}
|
||||
virtual void finaloverride3() noexcept override final {}
|
||||
virtual void finaloverride4() const noexcept override final {}
|
||||
virtual void finaloverride5() throw(int) override final {}
|
||||
virtual void finaloverride6() const throw(int) override final {}
|
||||
virtual void finaloverride5() TESTCASE_THROW1(int) override final {}
|
||||
virtual void finaloverride6() const TESTCASE_THROW1(int) override final {}
|
||||
virtual ~Derived() override final {}
|
||||
};
|
||||
void Derived::override2() const noexcept {}
|
||||
|
|
@ -131,3 +137,32 @@ void DerivedNoVirtualStruct::cd() {}
|
|||
void DerivedNoVirtualStruct::ef() {}
|
||||
DerivedNoVirtualStruct::~DerivedNoVirtualStruct() {}
|
||||
%}
|
||||
|
||||
%inline %{
|
||||
namespace Outer {
|
||||
namespace final {
|
||||
template <typename T> struct smart_ptr {
|
||||
typedef T type;
|
||||
};
|
||||
}
|
||||
namespace override {
|
||||
template <typename T> struct dumb_ptr {
|
||||
typedef T type;
|
||||
};
|
||||
}
|
||||
}
|
||||
%}
|
||||
|
||||
%template(SmartPtrBaseStruct) Outer::final::smart_ptr<DerivedStruct>;
|
||||
|
||||
%inline %{
|
||||
class ObjectDB
|
||||
{
|
||||
public:
|
||||
static void smart1(typename Outer::final::smart_ptr<DerivedStruct>::type *objectT) {}
|
||||
static void smart2(Outer::final::smart_ptr<DerivedStruct>::type *objectT) {}
|
||||
static void dumb1(typename Outer::override::dumb_ptr<DerivedStruct>::type *objectT) {}
|
||||
static void dumb2(Outer::override::dumb_ptr<DerivedStruct>::type *objectT) {}
|
||||
static Outer::final::smart_ptr<DerivedStruct>::type get() { return DerivedStruct(); }
|
||||
};
|
||||
%}
|
||||
|
|
|
|||
|
|
@ -6,12 +6,21 @@
|
|||
%ignore A::A(std::initializer_list<int>);
|
||||
%ignore B::method;
|
||||
|
||||
%typemap(in) std::initializer_list<const char *> {
|
||||
%typemap(in) std::initializer_list<const char *> %{
|
||||
$1 = {"Ab", "Fab"};
|
||||
}
|
||||
%}
|
||||
|
||||
%begin %{
|
||||
#if __GNUC__ >= 9
|
||||
/* warning: ‘new’ of initializer_list does not extend the lifetime of the underlying array [-Winit-list-lifetime] */
|
||||
/* incorrect warning for C::C(std::initializer_list<const char *>) */
|
||||
#pragma GCC diagnostic ignored "-Winit-list-lifetime"
|
||||
#endif
|
||||
%}
|
||||
|
||||
%inline %{
|
||||
#include <initializer_list>
|
||||
#include <string>
|
||||
|
||||
class A {
|
||||
public:
|
||||
|
|
@ -26,9 +35,16 @@ public:
|
|||
void method(std::initializer_list<int> init) {}
|
||||
};
|
||||
class C {
|
||||
std::string joined;
|
||||
public:
|
||||
C(std::initializer_list<const char *>) {}
|
||||
C(std::initializer_list<const char *> init) {
|
||||
for (auto& val : init)
|
||||
joined += val;
|
||||
}
|
||||
C() {}
|
||||
const char * get_joined_string() {
|
||||
return joined.c_str();
|
||||
}
|
||||
};
|
||||
%}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,14 @@
|
|||
%warnfilter(SWIGWARN_CPP11_LAMBDA) Space1::lambda19;
|
||||
%warnfilter(SWIGWARN_CPP11_LAMBDA) Space1::Space2::lambda20;
|
||||
|
||||
// throw is invalid in C++17 and later, only SWIG to use it
|
||||
#define TESTCASE_THROW0() throw()
|
||||
#define TESTCASE_THROW1(T1) throw(T1)
|
||||
%{
|
||||
#define TESTCASE_THROW0()
|
||||
#define TESTCASE_THROW1(T1)
|
||||
%}
|
||||
|
||||
%inline %{
|
||||
/* Defined lambda function with return value. */
|
||||
auto lambda1 = [](int x, int y) -> int { return x+y; };
|
||||
|
|
@ -54,22 +62,27 @@ void fn() {
|
|||
}
|
||||
auto lambda6 = [] (int a, int b) mutable { return a + b; };
|
||||
auto lambda7 = [] (int x, int y) -> int { return x+y; };
|
||||
auto lambda8 = [] (int x, int y) throw() -> int { return x+y; };
|
||||
auto lambda9 = [] (int x, int y) mutable throw() -> int { return x+y; };
|
||||
auto lambda10 = [] (int x, int y) throw(int) { return x+y; };
|
||||
auto lambda11 = [] (int x, int y) mutable throw(int) { return x+y; };
|
||||
auto lambda8 = [] (int x, int y) TESTCASE_THROW0() -> int { return x+y; };
|
||||
auto lambda9 = [] (int x, int y) mutable TESTCASE_THROW0() -> int { return x+y; };
|
||||
auto lambda10 = [] (int x, int y) TESTCASE_THROW1(int) { return x+y; };
|
||||
auto lambda11 = [] (int x, int y) mutable TESTCASE_THROW1(int) { return x+y; };
|
||||
auto lambda12 = [] (int a, int b) { return a + b; }(1, 2);
|
||||
auto lambda13 = [] (int a, int b) mutable { return a + b; }(1, 2);
|
||||
auto lambda14 = [] () throw () {};
|
||||
auto lambda15 = [] () mutable throw () {};
|
||||
auto lambda14 = [] () TESTCASE_THROW0() {};
|
||||
auto lambda15 = [] () mutable TESTCASE_THROW0() {};
|
||||
auto lambda16 = [] { return thing; };
|
||||
auto lambda17 = [] { return thing; }();
|
||||
constexpr auto lambda18 = [] (int x, int y) mutable throw(int) { return x+y; };
|
||||
#if defined(SWIG) || (defined(__cplusplus) && __cplusplus >= 201703L)
|
||||
#define CONSTEXPR constexpr
|
||||
#else
|
||||
#define CONSTEXPR
|
||||
#endif
|
||||
CONSTEXPR auto lambda18 = [] (int x, int y) mutable TESTCASE_THROW1(int) { return x+y; };
|
||||
|
||||
namespace Space1 {
|
||||
constexpr auto lambda19 = [] (int x, int y) mutable throw(int) { return x+y; };
|
||||
CONSTEXPR auto lambda19 = [] (int x, int y) mutable TESTCASE_THROW1(int) { return x+y; };
|
||||
namespace Space2 {
|
||||
constexpr auto lambda20 = [] (int x, int y) mutable throw(int) { return x+y; };
|
||||
CONSTEXPR auto lambda20 = [] (int x, int y) mutable TESTCASE_THROW1(int) { return x+y; };
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,8 +31,13 @@ struct NoExceptClass {
|
|||
void noo1() const noexcept {}
|
||||
static void noo2() noexcept {}
|
||||
virtual void noo3() const noexcept {}
|
||||
|
||||
// Workaround clang 10.0.1 -std=c++17 linker error (oddly for Java and not Python):
|
||||
// Undefined symbols for architecture x86_64: "___cxa_deleted_virtual", referenced from: vtable for NoExceptClass
|
||||
#if !(defined(__clang__) && __cplusplus >= 201703L)
|
||||
virtual void noo4() const noexcept = delete;
|
||||
virtual void noo5() const throw() = delete;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct NoExceptAbstract {
|
||||
|
|
|
|||
|
|
@ -47,6 +47,9 @@ wstring aa = L"Wide string";
|
|||
const char *bb = u8"UTF-8 string";
|
||||
const char16_t *cc = u"UTF-16 string";
|
||||
const char32_t *dd = U"UTF-32 string";
|
||||
// New char literals
|
||||
char16_t char16_t_char = u'a';
|
||||
char32_t char32_t_char = U'b';
|
||||
%}
|
||||
|
||||
/* Raw string literals */
|
||||
|
|
@ -59,3 +62,43 @@ const char16_t *hh = uR"XXX(I'm a "raw UTF-16" \ string.)XXX";
|
|||
const char32_t *ii = UR"XXX(I'm a "raw UTF-32" \ string.)XXX";
|
||||
%}
|
||||
|
||||
// Constants
|
||||
#if defined(SWIGJAVA)
|
||||
%javaconst(1);
|
||||
#elif SWIGCSHARP
|
||||
%csconst(1);
|
||||
#elif SWIGD
|
||||
%dmanifestconst;
|
||||
#endif
|
||||
|
||||
%inline %{
|
||||
#define jj ")I'm an \"ascii\" \\ string constant."
|
||||
#define kk R"XXX()I'm an "ascii" \ string constant.)XXX";
|
||||
%}
|
||||
|
||||
%constant mm = R"XXX()I'm an "ascii" \ string constant with multiple
|
||||
|
||||
lines.)XXX";
|
||||
|
||||
// docstring feature
|
||||
%feature("docstring") RawStringDoc::WW "Single line documentation comment"
|
||||
%feature("docstring") RawStringDoc::XX %{
|
||||
Multi-line
|
||||
documentation
|
||||
comment
|
||||
%}
|
||||
%feature("docstring") RawStringDoc::YY R"RRR(Single line "raw string" documentation comment)RRR"
|
||||
%feature("docstring") RawStringDoc::ZZ R"FOO(Documentation comment
|
||||
|
||||
as a "raw string"
|
||||
on multiple lines including a \ backslash)FOO"
|
||||
|
||||
%inline %{
|
||||
struct RawStringDoc {
|
||||
void WW() {}
|
||||
void XX() {}
|
||||
void YY() {}
|
||||
void ZZ() {}
|
||||
};
|
||||
%}
|
||||
|
||||
|
|
|
|||
226
Examples/test-suite/cpp11_ref_qualifiers.i
Normal file
226
Examples/test-suite/cpp11_ref_qualifiers.i
Normal file
|
|
@ -0,0 +1,226 @@
|
|||
%module cpp11_ref_qualifiers
|
||||
|
||||
%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) ccextra2;
|
||||
%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) ccextra3;
|
||||
%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) cc2;
|
||||
%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) cc3;
|
||||
%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) cc5;
|
||||
|
||||
%include <std_string.i>
|
||||
|
||||
%ignore Host::h() const &;
|
||||
|
||||
// Basic testing
|
||||
%inline %{
|
||||
using std::string;
|
||||
class Host {
|
||||
string s;
|
||||
public:
|
||||
string h1() & { return string(); }
|
||||
string h2() const & { return string(); }
|
||||
string h3() && { return std::move(string()); }
|
||||
string h4() const && { return std::move(string()); }
|
||||
string h5() const { return string(); }
|
||||
string h6() volatile const & { return string(); }
|
||||
string h7() const volatile & { return string(); }
|
||||
string h8() volatile const && { return std::move(string()); }
|
||||
string h9() const volatile && { return std::move(string()); }
|
||||
|
||||
string h() & { return string(); }
|
||||
string h() const & { return string(); }
|
||||
string h() && { return std::move(string()); }
|
||||
string h() const && { return std::move(string()); }
|
||||
};
|
||||
%}
|
||||
|
||||
// %feature testing
|
||||
%feature("except") F1() & %{ result = "F1"; %}
|
||||
%feature("except") F2 %{ result = "F2"; %}
|
||||
%feature("except") F3 %{ result = "F3"; %}
|
||||
%feature("except") F3() %{ _should_not_be_used_ %}
|
||||
|
||||
%feature("except") C1(int i) const & %{ result = "C1"; %}
|
||||
%feature("except") C2 %{ result = "C2"; %}
|
||||
%feature("except") C3 %{ result = "C3"; %}
|
||||
%feature("except") C3(int i) %{ _should_not_be_used_ %}
|
||||
|
||||
%inline %{
|
||||
struct Features {
|
||||
string F1() & { return string(); }
|
||||
string F2() & { return string(); }
|
||||
string F3() & { return string(); }
|
||||
|
||||
string C1(int i) const & { return string(); }
|
||||
string C2(int i) const & { return string(); }
|
||||
string C3(int i) const & { return string(); }
|
||||
};
|
||||
%}
|
||||
|
||||
// %rename testing
|
||||
%rename(RR1) R1;
|
||||
%rename(RR2) R2() &;
|
||||
%rename(RR3) R3;
|
||||
%rename(RR3Bad) R3();
|
||||
|
||||
%rename(SS1) S1;
|
||||
%rename(SS2) S2(int i) const &;
|
||||
%rename(SS3) S3;
|
||||
%rename(SS3Bad) S3(int i);
|
||||
%rename(SS3BadConst) S3(int i) const;
|
||||
%rename(SS3BadLValue) S3(int i) &;
|
||||
|
||||
%inline %{
|
||||
struct Renames {
|
||||
string R1() & { return string(); }
|
||||
string R2() & { return string(); }
|
||||
string R3() & { return string(); }
|
||||
|
||||
string S1(int i) const & { return string(); }
|
||||
string S2(int i) const & { return string(); }
|
||||
string S3(int i) const & { return string(); }
|
||||
};
|
||||
%}
|
||||
|
||||
// Conversion operators
|
||||
%rename(StringConvertCopy) operator string() &;
|
||||
%rename(StringConvertMove) operator string() &&;
|
||||
%feature("ignore", "0") operator string() &&; // unignore as it is ignored by default
|
||||
|
||||
%inline %{
|
||||
struct ConversionOperators {
|
||||
virtual operator string() & { return string(); }
|
||||
virtual operator string() && { return std::move(string()); }
|
||||
virtual ~ConversionOperators() {}
|
||||
};
|
||||
struct ConversionOperators2 {
|
||||
virtual operator string() && { return std::move(string()); }
|
||||
virtual ~ConversionOperators2() {}
|
||||
};
|
||||
%}
|
||||
|
||||
%inline %{
|
||||
struct Funcs {
|
||||
short FF(bool) { return 0; }
|
||||
short CC(bool) const & { return 0; }
|
||||
};
|
||||
|
||||
class MemberFuncPtrs
|
||||
{
|
||||
public:
|
||||
// member ref-qualified function pointers, unnamed parameters
|
||||
int aaa1(short (Funcs::*)(bool) &) const;
|
||||
int aaa2(short (Funcs::* const *&)(bool) &) const;
|
||||
int aaa3(short (Funcs::* *&)(bool) &) const;
|
||||
int aaa4(short (Funcs::* *const&)(bool) &) const;
|
||||
int aaa5(short (Funcs::* &)(bool) &) const;
|
||||
int aaa6(short (Funcs::* const)(bool) &) const;
|
||||
int aaa7(short (Funcs::* const&)(bool) &) const;
|
||||
|
||||
int aaa8(short (Funcs::* const&)(bool) &&) const;
|
||||
|
||||
// member cv-qualified and ref-qualified function pointers, unnamed parameters
|
||||
int bbb1(short (Funcs::*)(bool) const &) const;
|
||||
int bbb2(short (Funcs::* const *&)(bool) const &) const;
|
||||
int bbb3(short (Funcs::* *&)(bool) const &) const;
|
||||
int bbb4(short (Funcs::* *const&)(bool) const &) const;
|
||||
int bbb5(short (Funcs::* &)(bool) const &) const;
|
||||
int bbb6(short (Funcs::* const)(bool) const &) const;
|
||||
int bbb7(short (Funcs::* const&)(bool) const &) const;
|
||||
|
||||
int bbb8(short (Funcs::*)(bool) const &&) const;
|
||||
|
||||
// member ref-qualified function pointers, named parameters
|
||||
int qqq1(short (Funcs::* qq1)(bool) &) const;
|
||||
int qqq2(short (Funcs::* const *& qq2)(bool) &) const;
|
||||
int qqq3(short (Funcs::* *& qq3)(bool) &) const;
|
||||
int qqq4(short (Funcs::* *const& qq4)(bool) &) const;
|
||||
int qqq5(short (Funcs::* & qq5)(bool) &) const;
|
||||
int qqq6(short (Funcs::* const qq6)(bool) &) const;
|
||||
int qqq7(short (Funcs::* const& qq7)(bool) &) const;
|
||||
|
||||
int qqq8(short (Funcs::* const& qq8)(bool) &&) const;
|
||||
|
||||
// member cv-qualified and ref-qualified function pointers, named parameters
|
||||
int rrr1(short (Funcs::* rr1)(bool) const &) const;
|
||||
int rrr2(short (Funcs::* const *& rr2)(bool) const &) const;
|
||||
int rrr3(short (Funcs::* *& rr3)(bool) const &) const;
|
||||
int rrr4(short (Funcs::* *const& rr4)(bool) const &) const;
|
||||
int rrr5(short (Funcs::* & rr5)(bool) const &) const;
|
||||
int rrr6(short (Funcs::* const rr6)(bool) const &) const;
|
||||
int rrr7(short (Funcs::* const& rr7)(bool) const &) const;
|
||||
|
||||
int rrr8(short (Funcs::* rr1)(bool) const &&) const;
|
||||
};
|
||||
|
||||
// member ref-qualified function pointers, unnamed parameters
|
||||
int MemberFuncPtrs::aaa1(short (Funcs::*)(bool) &) const { return 0; }
|
||||
int MemberFuncPtrs::aaa2(short (Funcs::* const *&)(bool) &) const { return 0; }
|
||||
int MemberFuncPtrs::aaa3(short (Funcs::* *&)(bool) &) const { return 0; }
|
||||
int MemberFuncPtrs::aaa4(short (Funcs::* *const&)(bool) &) const { return 0; }
|
||||
int MemberFuncPtrs::aaa5(short (Funcs::* &)(bool) &) const { return 0; }
|
||||
int MemberFuncPtrs::aaa6(short (Funcs::* const)(bool) &) const { return 0; }
|
||||
int MemberFuncPtrs::aaa7(short (Funcs::* const&)(bool) &) const { return 0; }
|
||||
|
||||
int MemberFuncPtrs::aaa8(short (Funcs::* const&)(bool) &&) const { return 0; }
|
||||
|
||||
// member cv-qualified and ref-qualified function pointers, unnamed parameters
|
||||
int MemberFuncPtrs::bbb1(short (Funcs::*)(bool) const &) const { return 0; }
|
||||
int MemberFuncPtrs::bbb2(short (Funcs::* const *&)(bool) const &) const { return 0; }
|
||||
int MemberFuncPtrs::bbb3(short (Funcs::* *&)(bool) const &) const { return 0; }
|
||||
int MemberFuncPtrs::bbb4(short (Funcs::* *const&)(bool) const &) const { return 0; }
|
||||
int MemberFuncPtrs::bbb5(short (Funcs::* &)(bool) const &) const { return 0; }
|
||||
int MemberFuncPtrs::bbb6(short (Funcs::* const)(bool) const &) const { return 0; }
|
||||
int MemberFuncPtrs::bbb7(short (Funcs::* const&)(bool) const &) const { return 0; }
|
||||
|
||||
int MemberFuncPtrs::bbb8(short (Funcs::*)(bool) const &&) const { return 0; }
|
||||
|
||||
// member ref-qualified function pointers, named parameters
|
||||
int MemberFuncPtrs::qqq1(short (Funcs::* qq1)(bool) &) const { return 0; }
|
||||
int MemberFuncPtrs::qqq2(short (Funcs::* const *& qq2)(bool) &) const { return 0; }
|
||||
int MemberFuncPtrs::qqq3(short (Funcs::* *& qq3)(bool) &) const { return 0; }
|
||||
int MemberFuncPtrs::qqq4(short (Funcs::* *const& qq4)(bool) &) const { return 0; }
|
||||
int MemberFuncPtrs::qqq5(short (Funcs::* & qq5)(bool) &) const { return 0; }
|
||||
int MemberFuncPtrs::qqq6(short (Funcs::* const qq6)(bool) &) const { return 0; }
|
||||
int MemberFuncPtrs::qqq7(short (Funcs::* const& qq7)(bool) &) const { return 0; }
|
||||
|
||||
int MemberFuncPtrs::qqq8(short (Funcs::* const& qq8)(bool) &&) const { return 0; }
|
||||
|
||||
// member cv-qualified and ref-qualified function pointers, named parameters
|
||||
int MemberFuncPtrs::rrr1(short (Funcs::* rr1)(bool) const &) const { return 0; }
|
||||
int MemberFuncPtrs::rrr2(short (Funcs::* const *& rr2)(bool) const &) const { return 0; }
|
||||
int MemberFuncPtrs::rrr3(short (Funcs::* *& rr3)(bool) const &) const { return 0; }
|
||||
int MemberFuncPtrs::rrr4(short (Funcs::* *const& rr4)(bool) const &) const { return 0; }
|
||||
int MemberFuncPtrs::rrr5(short (Funcs::* & rr5)(bool) const &) const { return 0; }
|
||||
int MemberFuncPtrs::rrr6(short (Funcs::* const rr6)(bool) const &) const { return 0; }
|
||||
int MemberFuncPtrs::rrr7(short (Funcs::* const& rr7)(bool) const &) const { return 0; }
|
||||
|
||||
int MemberFuncPtrs::rrr8(short (Funcs::* rr1)(bool) const &&) const { return 0; }
|
||||
|
||||
// member cv-qualified and ref-qualified pointer variables
|
||||
short (Funcs::* cc1)(bool) const & = &Funcs::CC;
|
||||
|
||||
short (Funcs::* const * ccextra2)(bool) const & = &cc1;
|
||||
short (Funcs::* * ccextra3)(bool) const & = &cc1;
|
||||
short (Funcs::* *const ccextra4)(bool) const & = &cc1;
|
||||
|
||||
short (Funcs::* const *& cc2)(bool) const & = ccextra2;
|
||||
short (Funcs::* *& cc3)(bool) const & = ccextra3;
|
||||
short (Funcs::* *const& cc4)(bool) const & = ccextra4;
|
||||
short (Funcs::* & cc5)(bool) const & = cc1;
|
||||
short (Funcs::* const cc6)(bool) const & = &Funcs::CC;
|
||||
short (Funcs::* const& cc7)(bool) const & = cc1;
|
||||
%}
|
||||
|
||||
%inline %{
|
||||
|
||||
struct Funktions {
|
||||
int addByValue(const int &a, int b) const & { return a+b; }
|
||||
int * addByPointer(const int &a, int b) const & { static int val; val = a+b; return &val; }
|
||||
int & addByReference(const int &a, int b) const & { static int val; val = a+b; return val; }
|
||||
};
|
||||
|
||||
int call1(int (Funktions::*d)(const int &, int) const &, int a, int b) { Funktions f; return (f.*d)(a, b); }
|
||||
//int call2(int * (Funktions::*d)(const int &, int) const &, int a, int b) { Funktions f; return *(f.*d)(a, b); }
|
||||
//int call3(int & (Funktions::*d)(const int &, int) const &, int a, int b) { Funktions f; return (f.*d)(a, b); }
|
||||
%}
|
||||
%constant int (Funktions::*ADD_BY_VALUE)(const int &, int) const & = &Funktions::addByValue;
|
||||
15
Examples/test-suite/cpp11_ref_qualifiers_rvalue_unignore.i
Normal file
15
Examples/test-suite/cpp11_ref_qualifiers_rvalue_unignore.i
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
%module cpp11_ref_qualifiers_rvalue_unignore
|
||||
|
||||
// This is a minimal test that does not include any C++ headers to make sure the required
|
||||
// <memory> header is generated from a fragment for the generated std::move call
|
||||
|
||||
// m1 and m2 are ignored by default, unignore them
|
||||
%feature("ignore", "0") RefQualifier::m1() &&;
|
||||
%feature("ignore", "0") RefQualifier::m2() const &&;
|
||||
|
||||
%inline %{
|
||||
struct RefQualifier {
|
||||
void m1() && {}
|
||||
void m2() const && {}
|
||||
};
|
||||
%}
|
||||
74
Examples/test-suite/cpp11_ref_qualifiers_typemaps.i
Normal file
74
Examples/test-suite/cpp11_ref_qualifiers_typemaps.i
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
%module cpp11_ref_qualifiers_typemaps
|
||||
|
||||
%typemap(in) SWIGTYPE (CLASS::*) %{
|
||||
_this_will_fail_to_compile_if_used_
|
||||
%}
|
||||
|
||||
// typemaps to completely ignore the input parm and override it
|
||||
%typemap(in) short (Funcs::*ff)(bool) const %{ $1 = &Funcs::FFF2; %}
|
||||
%typemap(in) short (Funcs::*cc)(bool) & %{ $1 = &Funcs::CCC5; %}
|
||||
%typemap(in) short (Funcs::*gg)(bool) const & %{ $1 = &Funcs::GGG8; %}
|
||||
%typemap(in) short (Funcs::*hh)(bool) && %{ $1 = &Funcs::HHH11; %}
|
||||
|
||||
%typemap(in) short (Funcs::*)(bool) const %{ $1 = &Funcs::FFF3; %}
|
||||
%typemap(in) short (Funcs::*)(bool) & %{ $1 = &Funcs::CCC6; %}
|
||||
%typemap(in) short (Funcs::*)(bool) const & %{ $1 = &Funcs::GGG9; %}
|
||||
%typemap(in) short (Funcs::*)(bool) && %{ $1 = &Funcs::HHH12; %}
|
||||
|
||||
%inline %{
|
||||
struct Funcs {
|
||||
short FFF1(bool) const { return 1; }
|
||||
short FFF2(bool) const { return 2; }
|
||||
short FFF3(bool) const { return 3; }
|
||||
short CCC4(bool) & { return 4; }
|
||||
short CCC5(bool) & { return 5; }
|
||||
short CCC6(bool) & { return 6; }
|
||||
short GGG7(bool) const & { return 7; }
|
||||
short GGG8(bool) const & { return 8; }
|
||||
short GGG9(bool) const & { return 9; }
|
||||
short HHH10(bool) && { return 10; }
|
||||
short HHH11(bool) && { return 11; }
|
||||
short HHH12(bool) && { return 12; }
|
||||
};
|
||||
struct TypemapsNamedParms
|
||||
{
|
||||
short fff(short (Funcs::*ff)(bool) const) {
|
||||
Funcs funcs;
|
||||
return (funcs.*ff)(true);
|
||||
}
|
||||
short ccc(short (Funcs::*cc)(bool) &) {
|
||||
Funcs funcs;
|
||||
return (funcs.*cc)(true);
|
||||
}
|
||||
short ggg(short (Funcs::*gg)(bool) const &) {
|
||||
Funcs funcs;
|
||||
return (funcs.*gg)(true);
|
||||
}
|
||||
short hhh(short (Funcs::*hh)(bool) &&) {
|
||||
return (Funcs().*hh)(true);
|
||||
}
|
||||
};
|
||||
struct TypemapsUnnamedParms
|
||||
{
|
||||
short fff(short (Funcs::*f)(bool) const) {
|
||||
Funcs funcs;
|
||||
return (funcs.*f)(true);
|
||||
}
|
||||
short ccc(short (Funcs::*c)(bool) &) {
|
||||
Funcs funcs;
|
||||
return (funcs.*c)(true);
|
||||
}
|
||||
short ggg(short (Funcs::*g)(bool) const &) {
|
||||
Funcs funcs;
|
||||
return (funcs.*g)(true);
|
||||
}
|
||||
short hhh(short (Funcs::*h)(bool) &&) {
|
||||
return (Funcs().*h)(true);
|
||||
}
|
||||
};
|
||||
%}
|
||||
|
||||
%constant short (Funcs::*FF1_MFP)(bool) const = &Funcs::FFF1;
|
||||
%constant short (Funcs::*CC4_MFP)(bool) & = &Funcs::CCC4;
|
||||
%constant short (Funcs::*GG7_MFP)(bool) const & = &Funcs::GGG7;
|
||||
%constant short (Funcs::*HH10_MFP)(bool) && = &Funcs::HHH10;
|
||||
|
|
@ -31,7 +31,7 @@ struct Thingy {
|
|||
// test both primitive and user defined rvalue reference default arguments and compactdefaultargs
|
||||
void compactDefaultArgs(const bool &&b = (const bool &&)PublicGlobalTrue, const UserDef &&u = (const UserDef &&)PublicUserDef) {}
|
||||
void privateDefaultArgs(const bool &&b = (const bool &&)PrivateTrue) {}
|
||||
operator int &&() { return std::move(0); }
|
||||
operator int &&() { return std::move(val); }
|
||||
Thingy(const Thingy& rhs) : val(rhs.val), lvalref(rhs.lvalref), rvalref(std::move(rhs.rvalref)) {}
|
||||
Thingy& operator=(const Thingy& rhs) {
|
||||
val = rhs.val;
|
||||
|
|
|
|||
|
|
@ -26,10 +26,10 @@ void takeit5(Thing const*const&& t) {}
|
|||
|
||||
struct Containing {
|
||||
Thing && member_rvalue_ref;
|
||||
Thing *&& member_rvalue_ref_ptr1 = 0;
|
||||
Thing const*&& member_rvalue_ref_ptr2 = 0;
|
||||
Thing *const&& member_rvalue_ref_ptr3 = 0;
|
||||
Thing const*const &&member_rvalue_ref_ptr4 = 0;
|
||||
Thing *&& member_rvalue_ref_ptr1;
|
||||
Thing const*&& member_rvalue_ref_ptr2;
|
||||
Thing *const&& member_rvalue_ref_ptr3;
|
||||
Thing const*const &&member_rvalue_ref_ptr4;
|
||||
|
||||
Containing(Thing&&r, Thing*&& r1, Thing const*&& r2, Thing *const&& r3, Thing const*const && r4) :
|
||||
member_rvalue_ref(std::move(r)),
|
||||
|
|
@ -63,10 +63,10 @@ void int_takeit5(int const*const&& t) {}
|
|||
|
||||
struct IntContaining {
|
||||
int && member_rvalue_ref;
|
||||
int *&& member_rvalue_ref_ptr1 = 0;
|
||||
int const*&& member_rvalue_ref_ptr2 = 0;
|
||||
int *const&& member_rvalue_ref_ptr3 = 0;
|
||||
int const*const &&member_rvalue_ref_ptr4 = 0;
|
||||
int *&& member_rvalue_ref_ptr1;
|
||||
int const*&& member_rvalue_ref_ptr2;
|
||||
int *const&& member_rvalue_ref_ptr3;
|
||||
int const*const &&member_rvalue_ref_ptr4;
|
||||
|
||||
IntContaining(int&& r, int*&& r1, int const*&& r2, int *const&& r3, int const*const && r4) :
|
||||
member_rvalue_ref(std::move(r)),
|
||||
|
|
|
|||
|
|
@ -7,10 +7,10 @@
|
|||
|
||||
class Foo
|
||||
{
|
||||
int m;
|
||||
public:
|
||||
Foo(int i) : m(i) {}
|
||||
int get_m() { return m;}
|
||||
int m;
|
||||
};
|
||||
|
||||
std::shared_ptr<Foo> foo(Foo v) {
|
||||
|
|
@ -45,10 +45,10 @@ std::vector<std::shared_ptr<const Foo> > const_foo_vec(Foo v) {
|
|||
|
||||
class Foo
|
||||
{
|
||||
int m;
|
||||
public:
|
||||
Foo(int i);
|
||||
int get_m();
|
||||
int m;
|
||||
};
|
||||
std::shared_ptr<Foo> foo(Foo v);
|
||||
std::shared_ptr<const Foo> const_foo(Foo v);
|
||||
|
|
|
|||
|
|
@ -15,11 +15,11 @@ class C;
|
|||
%inline %{
|
||||
|
||||
class C {
|
||||
int m;
|
||||
public:
|
||||
C() : m(-1) {}
|
||||
C(int i) : m(i) {}
|
||||
int get_m() { return m; }
|
||||
int m;
|
||||
};
|
||||
|
||||
%}
|
||||
|
|
|
|||
89
Examples/test-suite/cpp11_shared_ptr_overload.i
Normal file
89
Examples/test-suite/cpp11_shared_ptr_overload.i
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
%module cpp11_shared_ptr_overload
|
||||
|
||||
// Tests to ensure valid overloading in C++ between shared_ptr and other types result in code that compiles
|
||||
// and all but the 1st overloaded method are automatically ignored/shadowed.
|
||||
// Tests the 'equivalent' attribute in the 'typecheck' typemap.
|
||||
|
||||
%include <std_string.i>
|
||||
%include <std_shared_ptr.i>
|
||||
|
||||
%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED,SWIGWARN_LANG_OVERLOAD_SHADOW) UseA(std::shared_ptr<MyType> mytype);
|
||||
%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED,SWIGWARN_LANG_OVERLOAD_SHADOW) UseB(int, std::shared_ptr<MyType> mytype);
|
||||
%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED,SWIGWARN_LANG_OVERLOAD_SHADOW) UseC(int, std::shared_ptr<MyType> mytype, std::shared_ptr<MyType>);
|
||||
|
||||
%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED,SWIGWARN_LANG_OVERLOAD_SHADOW) UseX(MyType &mytype);
|
||||
%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED,SWIGWARN_LANG_OVERLOAD_SHADOW) UseY(int, MyType &mytype);
|
||||
%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED,SWIGWARN_LANG_OVERLOAD_SHADOW) UseZ(int, MyType &mytype, std::shared_ptr<MyType>);
|
||||
|
||||
%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED,SWIGWARN_LANG_OVERLOAD_SHADOW) Combo1;
|
||||
%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED,SWIGWARN_LANG_OVERLOAD_SHADOW) Combo2;
|
||||
%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED,SWIGWARN_LANG_OVERLOAD_SHADOW) Combo3;
|
||||
%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED,SWIGWARN_LANG_OVERLOAD_SHADOW) Combo4;
|
||||
%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED,SWIGWARN_LANG_OVERLOAD_SHADOW) Combo5;
|
||||
%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED,SWIGWARN_LANG_OVERLOAD_SHADOW) Combo6;
|
||||
%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED,SWIGWARN_LANG_OVERLOAD_SHADOW) Combo7;
|
||||
|
||||
%shared_ptr(MyType);
|
||||
|
||||
%inline %{
|
||||
#include <memory>
|
||||
#include <string>
|
||||
struct MyType {
|
||||
std::string val;
|
||||
MyType(std::string val = std::string()) : val(val) {}
|
||||
};
|
||||
|
||||
// ref
|
||||
std::string UseA(MyType &mytype) { return mytype.val + " ref"; }
|
||||
std::string UseA(std::shared_ptr<MyType> mytype) { return mytype->val + " sharedptr"; }
|
||||
|
||||
std::string UseB(int, MyType &mytype) { return mytype.val + " ref"; }
|
||||
std::string UseB(int, std::shared_ptr<MyType> mytype) { return mytype->val + " sharedptr"; }
|
||||
|
||||
std::string UseC(int, MyType &mytype, std::shared_ptr<MyType>) { return mytype.val + " ref"; }
|
||||
std::string UseC(int, std::shared_ptr<MyType> mytype, std::shared_ptr<MyType>) { return mytype->val + " sharedptr"; }
|
||||
|
||||
// sharedptr
|
||||
std::string UseX(std::shared_ptr<MyType> mytype) { return mytype->val + " sharedptr"; }
|
||||
std::string UseX(MyType &mytype) { return mytype.val + " ref"; }
|
||||
|
||||
std::string UseY(int, std::shared_ptr<MyType> mytype) { return mytype->val + " sharedptr"; }
|
||||
std::string UseY(int, MyType &mytype) { return mytype.val + " ref"; }
|
||||
|
||||
std::string UseZ(int, std::shared_ptr<MyType> mytype, std::shared_ptr<MyType>) { return mytype->val + " sharedptr"; }
|
||||
std::string UseZ(int, MyType &mytype, std::shared_ptr<MyType>) { return mytype.val + " ref"; }
|
||||
|
||||
// Combo1-4
|
||||
std::string Combo1(MyType mytype) { return mytype.val + "Combo1"; }
|
||||
std::string Combo1(MyType *mytype) { return ""; }
|
||||
std::string Combo1(std::shared_ptr<MyType> mytype) { return ""; }
|
||||
std::string Combo1(std::shared_ptr<MyType>* mytype) { return ""; }
|
||||
|
||||
std::string Combo2(MyType *mytype) { return mytype->val + "Combo2"; }
|
||||
std::string Combo2(std::shared_ptr<MyType> mytype) { return ""; }
|
||||
std::string Combo2(std::shared_ptr<MyType>* mytype) { return ""; }
|
||||
std::string Combo2(MyType mytype) { return ""; }
|
||||
|
||||
std::string Combo3(std::shared_ptr<MyType> mytype) { return mytype->val + "Combo3"; }
|
||||
std::string Combo3(std::shared_ptr<MyType>* mytype) { return ""; }
|
||||
std::string Combo3(MyType mytype) { return ""; }
|
||||
std::string Combo3(MyType *mytype) { return ""; }
|
||||
|
||||
std::string Combo4(std::shared_ptr<MyType>* mytype) { return (*mytype)->val + "Combo4"; }
|
||||
std::string Combo4(MyType mytype) { return ""; }
|
||||
std::string Combo4(MyType *mytype) { return ""; }
|
||||
std::string Combo4(std::shared_ptr<MyType> mytype) { return ""; }
|
||||
|
||||
// Combo5-7
|
||||
std::string Combo5(MyType &mytype) { return mytype.val + "Combo5"; }
|
||||
std::string Combo5(MyType *mytype) { return ""; }
|
||||
std::string Combo5(std::shared_ptr<MyType> mytype) { return ""; }
|
||||
|
||||
std::string Combo6(MyType *mytype) { return mytype->val + "Combo6"; }
|
||||
std::string Combo6(std::shared_ptr<MyType> mytype) { return ""; }
|
||||
std::string Combo6(MyType &mytype) { return ""; }
|
||||
|
||||
std::string Combo7(std::shared_ptr<MyType> mytype) { return mytype->val + "Combo7"; }
|
||||
std::string Combo7(MyType &mytype) { return ""; }
|
||||
std::string Combo7(MyType *mytype) { return ""; }
|
||||
%}
|
||||
88
Examples/test-suite/cpp11_shared_ptr_template_upcast.i
Normal file
88
Examples/test-suite/cpp11_shared_ptr_template_upcast.i
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
%module cpp11_shared_ptr_template_upcast
|
||||
|
||||
%{
|
||||
#include <memory>
|
||||
#include <string>
|
||||
%}
|
||||
|
||||
%include <std_shared_ptr.i>
|
||||
%include <std_string.i>
|
||||
|
||||
%{
|
||||
class Base {
|
||||
public:
|
||||
Base() : value(0) {}
|
||||
Base(int v) : value(v) {}
|
||||
virtual ~Base() {}
|
||||
|
||||
virtual int GetResult() = 0;
|
||||
|
||||
int value;
|
||||
};
|
||||
|
||||
class Derived : public Base {
|
||||
public:
|
||||
Derived() : Base() {}
|
||||
Derived(int v) : Base(v) {}
|
||||
virtual ~Derived() {}
|
||||
|
||||
int GetResult() { return value*2; }
|
||||
};
|
||||
|
||||
template <class T> class Printable : virtual public T {
|
||||
public:
|
||||
Printable(int param) : T(param) {}
|
||||
~Printable() {}
|
||||
|
||||
std::string GetFormatted() { return std::string("The formatted result is: ").append(std::to_string(this->GetResult())); }
|
||||
};
|
||||
|
||||
std::shared_ptr<Printable<Derived> > MakePrintableDerived(int param) {
|
||||
return std::make_shared<Printable<Derived> >(param);
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
%shared_ptr(Base);
|
||||
%shared_ptr(Derived);
|
||||
%shared_ptr(Printable<Derived>)
|
||||
|
||||
class Base {
|
||||
public:
|
||||
Base();
|
||||
Base(int v);
|
||||
virtual ~Base();
|
||||
|
||||
virtual int GetResult() = 0;
|
||||
|
||||
int value;
|
||||
};
|
||||
|
||||
class Derived : public Base {
|
||||
public:
|
||||
Derived();
|
||||
Derived(int v);
|
||||
virtual ~Derived();
|
||||
|
||||
int GetResult();
|
||||
};
|
||||
|
||||
/*
|
||||
Virtual inheritance is contrived for this case, but exposes whether SWIGSmartPtrUpcast generated a correctly typed shared pointer of the upcasted class type -
|
||||
if the pointer type is incorrect, this will result in a segmentation fault (on Windows, this could manifest as undefined behavior) when trying to access members
|
||||
inherited from T through a shared_ptr<Printable<T> >.
|
||||
*/
|
||||
template <class T> class Printable : virtual public T {
|
||||
public:
|
||||
Printable(int param);
|
||||
~Printable();
|
||||
|
||||
std::string GetFormatted();
|
||||
};
|
||||
|
||||
std::shared_ptr<Printable<Derived> > MakePrintableDerived(int param);
|
||||
|
||||
|
||||
%template(PrintableDerived) Printable<Derived>;
|
||||
|
||||
|
||||
|
|
@ -16,19 +16,19 @@
|
|||
%{
|
||||
|
||||
class Base {
|
||||
int m;
|
||||
public:
|
||||
Base() : m(-1) {}
|
||||
Base(int i) : m(i) {}
|
||||
int get_m() { return m; }
|
||||
int m;
|
||||
};
|
||||
|
||||
class Derived : public Base {
|
||||
int n;
|
||||
public:
|
||||
Derived() : n(-2) {}
|
||||
Derived(int i) : n(i) {}
|
||||
int get_n() { return n; }
|
||||
int n;
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<Base> BasePtr;
|
||||
|
|
@ -96,18 +96,18 @@ int base_num(std::map<int, BasePtr > v) {
|
|||
%template(DerivedMap) std::map<int, std::shared_ptr<Derived> >;
|
||||
|
||||
class Base {
|
||||
int m;
|
||||
public:
|
||||
Base();
|
||||
int get_m();
|
||||
int m;
|
||||
};
|
||||
|
||||
class Derived : public Base {
|
||||
int n;
|
||||
public:
|
||||
Derived();
|
||||
Derived(int i);
|
||||
int get_n();
|
||||
int n;
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<Base> BasePtr;
|
||||
|
|
@ -135,20 +135,20 @@ int base_num(std::map<int, BasePtr > v);
|
|||
|
||||
%inline %{
|
||||
class Base2 {
|
||||
int m;
|
||||
public:
|
||||
Base2() : m(-1) {}
|
||||
Base2(int i) : m(i) {}
|
||||
int get_m() { return m; }
|
||||
int m;
|
||||
};
|
||||
|
||||
|
||||
class Derived2 : public Base2 {
|
||||
int n;
|
||||
public:
|
||||
Derived2() : n(0) {}
|
||||
Derived2(int i) : n(i) {}
|
||||
int get_n_2() { return n; }
|
||||
int n;
|
||||
};
|
||||
%}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
%module cpp11_li_std_array
|
||||
%module cpp11_std_array
|
||||
|
||||
#if defined(SWIGPYTHON) || defined(SWIGRUBY) || defined(SWIGJAVA) || defined(SWIGCSHARP)
|
||||
|
||||
|
|
@ -1,5 +1,11 @@
|
|||
%module cpp11_std_unordered_map
|
||||
|
||||
%include <std_string.i>
|
||||
%include <std_unordered_map.i>
|
||||
|
||||
%template(UnorderedMapIntInt) std::unordered_map<int, int>;
|
||||
%template(UnorderedMapStringInt) std::unordered_map<std::string, int>;
|
||||
|
||||
%inline %{
|
||||
std::unordered_map<std::string, int, std::hash< std::string >,std::equal_to< std::string >,std::allocator< std::pair< std::string const,int > > > inout(std::unordered_map<std::string, int> m) { return m; }
|
||||
%}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
%module cpp11_std_unordered_set
|
||||
|
||||
%include <std_string.i>
|
||||
%include <std_unordered_set.i>
|
||||
|
||||
%template(UnorderedSetInt) std::unordered_set<int>;
|
||||
%template(UnorderedSetString) std::unordered_set<std::string>;
|
||||
|
|
|
|||
|
|
@ -8,7 +8,8 @@
|
|||
|
||||
%inline %{
|
||||
|
||||
template<typename T> struct Temper {
|
||||
template<typename T> class Temper {
|
||||
public:
|
||||
T val;
|
||||
};
|
||||
|
||||
|
|
@ -18,14 +19,20 @@ public:
|
|||
int memberFunction() { return 100; }
|
||||
};
|
||||
|
||||
class B {
|
||||
public:
|
||||
short member;
|
||||
short memberFunction() { return 100; }
|
||||
};
|
||||
|
||||
template class Temper<A>;
|
||||
extern template class Temper<A>;
|
||||
extern template class Temper<B>;
|
||||
|
||||
template class Temper<A*>;
|
||||
extern template class Temper<A*>;
|
||||
extern template class Temper<B*>;
|
||||
|
||||
template class Temper<int>;
|
||||
extern template class Temper<int>;
|
||||
extern template class Temper<short>;
|
||||
%}
|
||||
|
||||
%template(TemperInt) Temper<int>;
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ public:
|
|||
using type2_t = T2;
|
||||
T1 a;
|
||||
T2 b;
|
||||
constexpr int get_n() { return N; }
|
||||
constexpr int get_n() const { return N; }
|
||||
};
|
||||
|
||||
// Specialization for T1=const char*, T2=bool
|
||||
|
|
@ -26,7 +26,7 @@ public:
|
|||
using type2_t = bool;
|
||||
type1_t a;
|
||||
type2_t b;
|
||||
constexpr int get_n() { return 3 * N; }
|
||||
constexpr int get_n() const { return 3 * N; }
|
||||
};
|
||||
|
||||
// alias templates
|
||||
|
|
|
|||
|
|
@ -20,8 +20,10 @@ extern "C++" thread_local int ecpptval;
|
|||
|
||||
thread_local int ThreadLocals::stval = 11;
|
||||
thread_local int ThreadLocals::tsval = 22;
|
||||
#if !defined(_MSC_VER)
|
||||
thread_local const int ThreadLocals::stcval88;
|
||||
thread_local const int ThreadLocals::tscval99;
|
||||
#endif
|
||||
%}
|
||||
|
||||
%{
|
||||
|
|
|
|||
31
Examples/test-suite/cpp14_binary_integer_literals.i
Normal file
31
Examples/test-suite/cpp14_binary_integer_literals.i
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
%module cpp14_binary_integer_literals
|
||||
|
||||
// Tests are designed so that code compiles with C++98 compilers
|
||||
|
||||
%{
|
||||
#if __cplusplus >= 201402L
|
||||
#define CPP14 1
|
||||
#endif
|
||||
%}
|
||||
|
||||
int b1 = 0b1;
|
||||
int b2 = 0b10;
|
||||
long b3 = 0b11l;
|
||||
unsigned long b4 = 0b100ul;
|
||||
unsigned long b5 = 0B101UL;
|
||||
|
||||
%{
|
||||
#if defined(CPP14)
|
||||
int b1 = 0b1;
|
||||
int b2 = 0b10;
|
||||
long b3 = 0b11l;
|
||||
unsigned long b4 = 0b100ul;
|
||||
unsigned long b5 = 0B101UL;
|
||||
#else
|
||||
int b1 = 1;
|
||||
int b2 = 2;
|
||||
long b3 = 3;
|
||||
unsigned long b4 = 4;
|
||||
unsigned long b5 = 5;
|
||||
#endif
|
||||
%}
|
||||
43
Examples/test-suite/cpp17_hex_floating_literals.i
Normal file
43
Examples/test-suite/cpp17_hex_floating_literals.i
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
%module cpp17_hex_floating_literals
|
||||
|
||||
// Tests are designed so that code compiles with C++98 compilers
|
||||
|
||||
%{
|
||||
#if __cplusplus >= 201703L
|
||||
#define CPP17 1
|
||||
#endif
|
||||
%}
|
||||
|
||||
double f1 = 0x.0p1;
|
||||
double f2 = 0x0.p1;
|
||||
double f3 = 0x0.0p-1;
|
||||
double f4 = 0xf.p-1;
|
||||
double f5 = 0xA.0p1;
|
||||
double f6 = 0x0.10P+10;
|
||||
double f7 = 0xb2F.p2;
|
||||
float f8 = 0x1234AP1F;
|
||||
float f9 = 0x45A1.D1A2p+10f;
|
||||
|
||||
%{
|
||||
#if defined(CPP17)
|
||||
double f1 = 0x.0p1;
|
||||
double f2 = 0x0.p1;
|
||||
double f3 = 0x0.0p-1;
|
||||
double f4 = 0xf.p-1;
|
||||
double f5 = 0xA.0p1;
|
||||
double f6 = 0x0.10P+10;
|
||||
double f7 = 0xb2F.p2;
|
||||
float f8 = 0x1234AP1F;
|
||||
float f9 = 0x45A1.D1A2p+10f;
|
||||
#else
|
||||
double f1 = 0.;
|
||||
double f2 = 0.;
|
||||
double f3 = 0.;
|
||||
double f4 = 7.5;
|
||||
double f5 = 20.;
|
||||
double f6 = 64.;
|
||||
double f7 = 11452.;
|
||||
float f8 = 149140.f;
|
||||
float f9 = 18253638.f;
|
||||
#endif
|
||||
%}
|
||||
199
Examples/test-suite/cpp17_nested_namespaces.i
Normal file
199
Examples/test-suite/cpp17_nested_namespaces.i
Normal file
|
|
@ -0,0 +1,199 @@
|
|||
%module cpp17_nested_namespaces
|
||||
// Tests c++17 style nested namespaces
|
||||
// Tests are designed so that code compiles with C++98 compilers
|
||||
|
||||
#define CPP17 1
|
||||
%{
|
||||
#if __cplusplus >= 201703L
|
||||
#define CPP17 1
|
||||
#endif
|
||||
%}
|
||||
|
||||
%inline %{
|
||||
// Tests with namespaces already defined using C++98 style (non-nested) namespaces
|
||||
namespace A1 {
|
||||
struct A1Struct {
|
||||
void A1Method() {}
|
||||
};
|
||||
namespace B1 {
|
||||
struct B1Struct {
|
||||
void B1Method() {}
|
||||
};
|
||||
}
|
||||
}
|
||||
#if defined(CPP17)
|
||||
namespace A1::B1 {
|
||||
#else
|
||||
namespace A1 {
|
||||
namespace B1 {
|
||||
#endif
|
||||
A1Struct createA1Struct() { return ::A1::A1Struct(); }
|
||||
B1Struct createB1Struct() { return ::A1::B1::B1Struct(); }
|
||||
#if !defined(CPP17)
|
||||
}
|
||||
}
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace A1 {
|
||||
namespace B1 {
|
||||
namespace C1 {
|
||||
struct C1Struct {
|
||||
void C1Method() {}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(CPP17)
|
||||
namespace A1::B1::C1 {
|
||||
#else
|
||||
namespace A1 {
|
||||
namespace B1 {
|
||||
namespace C1 {
|
||||
#endif
|
||||
C1Struct createC1Struct() { return ::A1::B1::C1::C1Struct(); }
|
||||
#if !defined(CPP17)
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
%}
|
||||
|
||||
%inline %{
|
||||
// Tests with namespaces already defined using C++17 style (nested) namespaces
|
||||
#if defined(CPP17)
|
||||
namespace A2::B2 {
|
||||
#else
|
||||
namespace A2 {
|
||||
namespace B2 {
|
||||
#endif
|
||||
struct B2Struct {
|
||||
void B2Method() {}
|
||||
};
|
||||
#if !defined(CPP17)
|
||||
}
|
||||
}
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(CPP17)
|
||||
namespace A2::B2 {
|
||||
#else
|
||||
namespace A2 {
|
||||
namespace B2 {
|
||||
#endif
|
||||
B2Struct createB2Struct() { return ::A2::B2::B2Struct(); }
|
||||
#if !defined(CPP17)
|
||||
}
|
||||
}
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(CPP17)
|
||||
namespace A2::B2::C2 {
|
||||
#else
|
||||
namespace A2 {
|
||||
namespace B2 {
|
||||
namespace C2 {
|
||||
#endif
|
||||
struct C2Struct {
|
||||
void C2Method() {}
|
||||
};
|
||||
#if !defined(CPP17)
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(CPP17)
|
||||
namespace A2::B2::C2 {
|
||||
#else
|
||||
namespace A2 {
|
||||
namespace B2 {
|
||||
namespace C2 {
|
||||
#endif
|
||||
C2Struct createC2Struct() { return ::A2::B2::C2::C2Struct(); }
|
||||
#if !defined(CPP17)
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
%}
|
||||
|
||||
|
||||
%inline %{
|
||||
// Tests with namespaces already defined using C++17 style (nested) namespaces to 3 levels
|
||||
#if defined(CPP17)
|
||||
namespace A3::B3::C3 {
|
||||
#else
|
||||
namespace A3 {
|
||||
namespace B3 {
|
||||
namespace C3 {
|
||||
#endif
|
||||
struct C3Struct {
|
||||
void C3Method() {}
|
||||
};
|
||||
#if !defined(CPP17)
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(CPP17)
|
||||
namespace A3::B3::C3 {
|
||||
#else
|
||||
namespace A3 {
|
||||
namespace B3 {
|
||||
namespace C3 {
|
||||
#endif
|
||||
C3Struct createC3Struct() { return ::A3::B3::C3::C3Struct(); }
|
||||
#if !defined(CPP17)
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(CPP17)
|
||||
namespace A3::B3 {
|
||||
#else
|
||||
namespace A3 {
|
||||
namespace B3 {
|
||||
#endif
|
||||
struct B3Struct {
|
||||
void B3Method() {}
|
||||
};
|
||||
#if !defined(CPP17)
|
||||
}
|
||||
}
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(CPP17)
|
||||
namespace A3::B3 {
|
||||
#else
|
||||
namespace A3 {
|
||||
namespace B3 {
|
||||
#endif
|
||||
B3Struct createB3Struct() { return ::A3::B3::B3Struct(); }
|
||||
#if !defined(CPP17)
|
||||
}
|
||||
}
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
%}
|
||||
13
Examples/test-suite/cpp17_nspace_nested_namespaces.i
Normal file
13
Examples/test-suite/cpp17_nspace_nested_namespaces.i
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
%module cpp17_nspace_nested_namespaces
|
||||
|
||||
#if defined(SWIGJAVA)
|
||||
SWIG_JAVABODY_PROXY(public, public, SWIGTYPE)
|
||||
#endif
|
||||
|
||||
// nspace feature only supported by these languages
|
||||
#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGD) || defined(SWIGLUA) || defined(SWIGJAVASCRIPT)
|
||||
%nspace;
|
||||
#endif
|
||||
|
||||
|
||||
%include "cpp17_nested_namespaces.i"
|
||||
26
Examples/test-suite/cpp17_u8_char_literals.i
Normal file
26
Examples/test-suite/cpp17_u8_char_literals.i
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
%module cpp17_u8_char_literals
|
||||
|
||||
// Tests are designed so that code compiles with C++98 compilers
|
||||
|
||||
%{
|
||||
#if __cplusplus >= 201703L
|
||||
#define CPP17 1
|
||||
#endif
|
||||
%}
|
||||
|
||||
// UTF-8 character literals will (apparently) have type char8_t in C++20.
|
||||
char a = u8'a';
|
||||
char u = u8'u';
|
||||
char u8 = u8'8';
|
||||
|
||||
%{
|
||||
#if defined(CPP17)
|
||||
char a = u8'a';
|
||||
char u = u8'u';
|
||||
char u8 = u8'8';
|
||||
#else
|
||||
char a = 'a';
|
||||
char u = 'u';
|
||||
char u8 = '8';
|
||||
#endif
|
||||
%}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
%module cpp_broken
|
||||
|
||||
|
||||
// bug #940318
|
||||
%inline %{
|
||||
typedef enum {
|
||||
eZero = 0
|
||||
#define ONE 1
|
||||
} EFoo;
|
||||
%}
|
||||
|
||||
|
||||
|
|
@ -2,6 +2,10 @@
|
|||
|
||||
%module cpp_namespace
|
||||
|
||||
#ifdef SWIGOCAML
|
||||
%warnfilter(SWIGWARN_PARSE_KEYWORD) method;
|
||||
#endif
|
||||
|
||||
%inline %{
|
||||
typedef int Bad;
|
||||
|
||||
|
|
|
|||
46
Examples/test-suite/cpp_parameters.i
Normal file
46
Examples/test-suite/cpp_parameters.i
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
%module cpp_parameters
|
||||
|
||||
%{
|
||||
// For Perl
|
||||
#ifdef Zero
|
||||
#undef Zero
|
||||
#endif
|
||||
%}
|
||||
%inline %{
|
||||
|
||||
// Zero arguments
|
||||
struct Zero {
|
||||
Zero() {}
|
||||
int zero() { return 0; }
|
||||
static int stat_zero() { return 0; }
|
||||
};
|
||||
// One mandatory argument
|
||||
struct One {
|
||||
One(int a) {}
|
||||
int one(int a) { return a; }
|
||||
static int stat_one(int a) { return a; }
|
||||
};
|
||||
// Two mandatory arguments
|
||||
struct Two {
|
||||
Two(int a, int b) {}
|
||||
int two(int a, int b) { return a + b; }
|
||||
static int stat_two(int a, int b) { return a + b; }
|
||||
};
|
||||
// Single optional argument
|
||||
struct Single {
|
||||
Single(int a=0) {}
|
||||
int single(int a=0) { return a; }
|
||||
static int stat_single(int a=0) { return a; }
|
||||
};
|
||||
|
||||
int global_zero() { return 0; }
|
||||
int global_one(int a) { return a; }
|
||||
int global_two(int a, int b) { return a + b; }
|
||||
int global_single(int a=0) { return a; }
|
||||
|
||||
#ifdef SWIGPYTHON_BUILTIN
|
||||
bool is_python_builtin() { return true; }
|
||||
#else
|
||||
bool is_python_builtin() { return false; }
|
||||
#endif
|
||||
%}
|
||||
|
|
@ -10,6 +10,7 @@ Tests Sourceforge bug #444748.
|
|||
class StaticMemberTest {
|
||||
public:
|
||||
static int static_int;
|
||||
static int grab_int() { return static_int; }
|
||||
};
|
||||
|
||||
class StaticFunctionTest {
|
||||
|
|
@ -28,10 +29,12 @@ int StaticMemberTest::static_int = 99;
|
|||
%inline %{
|
||||
struct StaticBase {
|
||||
static int statty;
|
||||
static int grab_statty_base() { return statty; }
|
||||
virtual ~StaticBase() {}
|
||||
};
|
||||
struct StaticDerived : StaticBase {
|
||||
static int statty;
|
||||
static int grab_statty_derived() { return statty; }
|
||||
};
|
||||
%}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@
|
|||
%module cpp_typedef
|
||||
|
||||
%{
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning( disable : 5208) // warning C5208: unnamed class used in typedef name cannot declare members other than non-static data members, member enumerations, or member classes
|
||||
#endif
|
||||
|
||||
class Bar {
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -16,9 +16,11 @@ CPP_TEST_CASES = \
|
|||
complextest \
|
||||
csharp_attributes \
|
||||
csharp_swig2_compatibility \
|
||||
csharp_director_typemaps \
|
||||
csharp_exceptions \
|
||||
csharp_features \
|
||||
csharp_lib_arrays \
|
||||
csharp_lib_arrays_bool \
|
||||
csharp_namespace_system_collision \
|
||||
csharp_prepost \
|
||||
csharp_typemaps \
|
||||
|
|
@ -26,9 +28,16 @@ CPP_TEST_CASES = \
|
|||
enum_thorough_typesafe \
|
||||
exception_partial_info \
|
||||
intermediary_classname \
|
||||
li_boost_intrusive_ptr
|
||||
nested_scope \
|
||||
li_boost_intrusive_ptr \
|
||||
li_std_list \
|
||||
|
||||
CPP11_TEST_CASES = \
|
||||
cpp11_shared_ptr_const \
|
||||
cpp11_shared_ptr_nullptr_in_containers \
|
||||
cpp11_shared_ptr_overload \
|
||||
cpp11_shared_ptr_template_upcast \
|
||||
cpp11_shared_ptr_upcast \
|
||||
cpp11_strongly_typed_enumerations_simple \
|
||||
|
||||
include $(srcdir)/../common.mk
|
||||
|
|
@ -43,6 +52,7 @@ CSHARPFLAGSSPECIAL =
|
|||
intermediary_classname.cpptest: SWIGOPT += -dllimport intermediary_classname
|
||||
complextest.cpptest: CSHARPFLAGSSPECIAL = -r:System.Numerics.dll
|
||||
csharp_lib_arrays.cpptest: CSHARPFLAGSSPECIAL = -unsafe
|
||||
csharp_lib_arrays_bool.cpptest: CSHARPFLAGSSPECIAL = -unsafe
|
||||
csharp_swig2_compatibility.cpptest: SWIGOPT += -DSWIG2_CSHARP
|
||||
|
||||
# Rules for the different types of tests
|
||||
|
|
|
|||
|
|
@ -13,6 +13,20 @@ public class runme
|
|||
{
|
||||
MyProtectedBase mpb = new MyProtectedBase("MyProtectedBase");
|
||||
mpb.accessProtected();
|
||||
try {
|
||||
// C++ destructor is protected
|
||||
mpb.Dispose();
|
||||
throw new Exception("failed to catch MethodAccessException");
|
||||
} catch (MethodAccessException) {
|
||||
// Exception message: C++ destructor does not have public access
|
||||
}
|
||||
ProtectedDerived pd = new ProtectedDerived("ProtectedDerived");
|
||||
// Destroying via the ProtectedDerived's destructor should work
|
||||
pd.Dispose();
|
||||
|
||||
ProtectedBase pb = new ProtectedDerived("ProtectedDerived");
|
||||
// ProtectedDerived's destructor should be called via the Dispose(disposing) virtual call
|
||||
pb.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,14 +16,23 @@ public class complextest_runme {
|
|||
if ( complextest.Conjf(a) != Complex.Conjugate(a) )
|
||||
throw new Exception("std::complex<float> test failed");
|
||||
|
||||
if ( complextest.Conj2(a) != Complex.Conjugate(a) )
|
||||
throw new Exception("std::complex<double> test failed");
|
||||
|
||||
if ( complextest.Conjf2(a) != Complex.Conjugate(a) )
|
||||
throw new Exception("std::complex<float> test failed");
|
||||
|
||||
var vec = new VectorStdCplx();
|
||||
vec.Add(new Complex(1, 2));
|
||||
vec.Add(new Complex(2, 3));
|
||||
vec.Add(new Complex(4, 3));
|
||||
vec.Add(new Complex(1, 0));
|
||||
|
||||
if ( complextest.Copy_h(vec).Count != 2 )
|
||||
throw new Exception("vector<complex> test failed");
|
||||
if ( complextest.CopyHalf(vec).Count != 2 )
|
||||
throw new Exception("CopyHalf test failed");
|
||||
|
||||
if ( complextest.CopyHalfRef(vec).Count != 2 )
|
||||
throw new Exception("CopyHalfRef test failed");
|
||||
|
||||
var p = new ComplexPair();
|
||||
p.z1 = new Complex(0, 1);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
// This is the cpp11_shared_ptr_template_upcast runtime testcase. It checks that SWIG generates the appropriate upcasted shared_ptr type for a template instantiation deriving from a base class.
|
||||
// For this case, the expected behavior is: given a cptr with underlying type shared_ptr<Printable<Derived> >, PrintableDerived_SWIGSmartPtrUpcast returns a cptr with
|
||||
// underlying type std::shared_ptr< Derived >, where Printable<Derived> inherits from Derived.
|
||||
using System;
|
||||
using cpp11_shared_ptr_template_upcastNamespace;
|
||||
|
||||
public class cpp11_shared_ptr_template_upcast_runme
|
||||
{
|
||||
static void Main()
|
||||
{
|
||||
PrintableDerived pd = cpp11_shared_ptr_template_upcast.MakePrintableDerived(20);
|
||||
pd.GetResult();
|
||||
pd.GetFormatted();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
// This test tests all the methods in the C# collection wrapper
|
||||
using System;
|
||||
using cpp11_li_std_arrayNamespace;
|
||||
using cpp11_std_arrayNamespace;
|
||||
|
||||
public class cpp11_li_std_array_runme
|
||||
public class cpp11_std_array_runme
|
||||
{
|
||||
private static ArrayInt6 ToArray6(int[] a)
|
||||
{
|
||||
|
|
@ -37,24 +37,24 @@ public class cpp11_li_std_array_runme
|
|||
compareContainers(ai, vals);
|
||||
|
||||
// Check return
|
||||
compareContainers(cpp11_li_std_array.arrayOutVal(), new int[] { -2, -1, 0, 0, 1, 2 });
|
||||
compareContainers(cpp11_li_std_array.arrayOutConstRef(), new int[] { -2, -1, 0, 0, 1, 2 });
|
||||
compareContainers(cpp11_li_std_array.arrayOutRef(), new int[] { -2, -1, 0, 0, 1, 2 });
|
||||
compareContainers(cpp11_li_std_array.arrayOutPtr(), new int[] { -2, -1, 0, 0, 1, 2 });
|
||||
compareContainers(cpp11_std_array.arrayOutVal(), new int[] { -2, -1, 0, 0, 1, 2 });
|
||||
compareContainers(cpp11_std_array.arrayOutConstRef(), new int[] { -2, -1, 0, 0, 1, 2 });
|
||||
compareContainers(cpp11_std_array.arrayOutRef(), new int[] { -2, -1, 0, 0, 1, 2 });
|
||||
compareContainers(cpp11_std_array.arrayOutPtr(), new int[] { -2, -1, 0, 0, 1, 2 });
|
||||
|
||||
// Check passing arguments
|
||||
ai = cpp11_li_std_array.arrayInVal(ToArray6(new int[] { 9, 8, 7, 6, 5, 4 }));
|
||||
ai = cpp11_std_array.arrayInVal(ToArray6(new int[] { 9, 8, 7, 6, 5, 4 }));
|
||||
compareContainers(ai, new int[] { 90, 80, 70, 60, 50, 40 });
|
||||
|
||||
ai = cpp11_li_std_array.arrayInConstRef(ToArray6(new int[] { 9, 8, 7, 6, 5, 4 }));
|
||||
ai = cpp11_std_array.arrayInConstRef(ToArray6(new int[] { 9, 8, 7, 6, 5, 4 }));
|
||||
compareContainers(ai, new int[] { 90, 80, 70, 60, 50, 40 });
|
||||
|
||||
ai = new ArrayInt6(ToArray6(new int[] { 9, 8, 7, 6, 5, 4 }));
|
||||
cpp11_li_std_array.arrayInRef(ai);
|
||||
cpp11_std_array.arrayInRef(ai);
|
||||
compareContainers(ai, new int[] { 90, 80, 70, 60, 50, 40 });
|
||||
|
||||
ai = new ArrayInt6(ToArray6(new int[] { 9, 8, 7, 6, 5, 4 }));
|
||||
cpp11_li_std_array.arrayInPtr(ai);
|
||||
cpp11_std_array.arrayInPtr(ai);
|
||||
compareContainers(ai, new int[] { 90, 80, 70, 60, 50, 40 });
|
||||
|
||||
// fill
|
||||
25
Examples/test-suite/csharp/cpp17_nested_namespaces_runme.cs
Normal file
25
Examples/test-suite/csharp/cpp17_nested_namespaces_runme.cs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
using System;
|
||||
using cpp17_nested_namespacesNamespace;
|
||||
|
||||
public class cpp17_nested_namespaces_runme
|
||||
{
|
||||
static void Main()
|
||||
{
|
||||
new A1Struct().A1Method();
|
||||
new B1Struct().B1Method();
|
||||
new C1Struct().C1Method();
|
||||
cpp17_nested_namespaces.createA1Struct().A1Method();
|
||||
cpp17_nested_namespaces.createB1Struct().B1Method();
|
||||
cpp17_nested_namespaces.createC1Struct().C1Method();
|
||||
|
||||
new B2Struct().B2Method();
|
||||
new C2Struct().C2Method();
|
||||
cpp17_nested_namespaces.createB2Struct().B2Method();
|
||||
cpp17_nested_namespaces.createC2Struct().C2Method();
|
||||
|
||||
new B3Struct().B3Method();
|
||||
new C3Struct().C3Method();
|
||||
cpp17_nested_namespaces.createB3Struct().B3Method();
|
||||
cpp17_nested_namespaces.createC3Struct().C3Method();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
using System;
|
||||
using cpp17_nspace_nested_namespacesNamespace;
|
||||
|
||||
public class cpp17_nspace_nested_namespaces_runme
|
||||
{
|
||||
static void Main()
|
||||
{
|
||||
new cpp17_nspace_nested_namespacesNamespace.A1.A1Struct().A1Method();
|
||||
new cpp17_nspace_nested_namespacesNamespace.A1.B1.B1Struct().B1Method();
|
||||
new cpp17_nspace_nested_namespacesNamespace.A1.B1.C1.C1Struct().C1Method();
|
||||
cpp17_nspace_nested_namespaces.createA1Struct().A1Method();
|
||||
cpp17_nspace_nested_namespaces.createB1Struct().B1Method();
|
||||
cpp17_nspace_nested_namespaces.createC1Struct().C1Method();
|
||||
|
||||
new cpp17_nspace_nested_namespacesNamespace.A2.B2.B2Struct().B2Method();
|
||||
new cpp17_nspace_nested_namespacesNamespace.A2.B2.C2.C2Struct().C2Method();
|
||||
cpp17_nspace_nested_namespaces.createB2Struct().B2Method();
|
||||
cpp17_nspace_nested_namespaces.createC2Struct().C2Method();
|
||||
|
||||
new cpp17_nspace_nested_namespacesNamespace.A3.B3.B3Struct().B3Method();
|
||||
new cpp17_nspace_nested_namespacesNamespace.A3.B3.C3.C3Struct().C3Method();
|
||||
cpp17_nspace_nested_namespaces.createB3Struct().B3Method();
|
||||
cpp17_nspace_nested_namespaces.createC3Struct().C3Method();
|
||||
}
|
||||
}
|
||||
53
Examples/test-suite/csharp/csharp_director_typemaps_runme.cs
Normal file
53
Examples/test-suite/csharp/csharp_director_typemaps_runme.cs
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using csharp_director_typemapsNamespace;
|
||||
|
||||
public class csharp_director_typemaps_runme {
|
||||
|
||||
class CSharpDirectorTypemaps_InStreamDerived : InStream
|
||||
{
|
||||
private int constant;
|
||||
public CSharpDirectorTypemaps_InStreamDerived(int constant) { this.constant = constant; }
|
||||
public override int Read(global::System.IntPtr buf, int len, out int readLen) {
|
||||
readLen = (buf == global::System.IntPtr.Zero) ? -len - constant : len + constant;
|
||||
return readLen;
|
||||
}
|
||||
public override int Write(global::System.IntPtr buf, int len, out int writeLen) {
|
||||
writeLen = (buf == global::System.IntPtr.Zero) ? -len - constant : len + constant;
|
||||
return writeLen;
|
||||
}
|
||||
}
|
||||
public static void Main() {
|
||||
int outLen = -1;
|
||||
int k = 100;
|
||||
int j = 23;
|
||||
InStream instream = new CSharpDirectorTypemaps_InStreamDerived(k);
|
||||
|
||||
{
|
||||
int ret = csharp_director_typemaps.callRead(instream, InStream.getCPtr(instream).Handle, j, out outLen);
|
||||
Assert(outLen, j + k);
|
||||
Assert(ret, j + k);
|
||||
}
|
||||
{
|
||||
int ret = csharp_director_typemaps.callRead(instream, global::System.IntPtr.Zero, j, out outLen);
|
||||
Assert(outLen, -j - k);
|
||||
Assert(ret, -j - k);
|
||||
}
|
||||
|
||||
{
|
||||
int ret = csharp_director_typemaps.callWrite(instream, InStream.getCPtr(instream).Handle, j, out outLen);
|
||||
Assert(outLen, j + k);
|
||||
Assert(ret, j + k);
|
||||
}
|
||||
{
|
||||
int ret = csharp_director_typemaps.callWrite(instream, global::System.IntPtr.Zero, j, out outLen);
|
||||
Assert(outLen, -j - k);
|
||||
Assert(ret, -j - k);
|
||||
}
|
||||
}
|
||||
private static void Assert(int i1, int i2) {
|
||||
if (i1 != i2)
|
||||
throw new Exception("assertion failure. " + i1 + " != " + i2);
|
||||
}
|
||||
}
|
||||
90
Examples/test-suite/csharp/csharp_lib_arrays_bool_runme.cs
Normal file
90
Examples/test-suite/csharp/csharp_lib_arrays_bool_runme.cs
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
using System;
|
||||
using csharp_lib_arrays_boolNamespace;
|
||||
|
||||
public class runme
|
||||
{
|
||||
static void Main()
|
||||
{
|
||||
{
|
||||
bool[] source = { true, false, false, true, false, true, true, false };
|
||||
bool[] target = new bool[ source.Length ];
|
||||
|
||||
csharp_lib_arrays_bool.myArrayCopyUsingFixedArraysBool( source, target, target.Length );
|
||||
CompareArrays(source, target, "bool[] INPUT/OUTPUT Fixed");
|
||||
}
|
||||
|
||||
{
|
||||
bool[] source = { true, false, false, true, false, true, true, false };
|
||||
bool[] target = { false, true, true, false, true, false, false, true };
|
||||
|
||||
csharp_lib_arrays_bool.myArraySwapUsingFixedArraysBool( source, target, target.Length );
|
||||
|
||||
for (int i=0; i<target.Length; ++i)
|
||||
target[i] = !target[i];
|
||||
|
||||
CompareArrays(source, target, "bool[] INOUT");
|
||||
}
|
||||
|
||||
if( runtimeIsMono() )
|
||||
{
|
||||
// Console.Error.WriteLine("Tests are running on mono, failing bool[] tests skipped");
|
||||
// See Mono bug report https://github.com/mono/mono/issues/15592
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
bool[] source = { true, false, false, true, false, true, true, false };
|
||||
bool[] target = new bool[ source.Length ];
|
||||
|
||||
if( !csharp_lib_arrays_bool.checkBoolArrayCorrect( source, source.Length ) )
|
||||
{
|
||||
throw new Exception("bool[] INPUT incorrect");
|
||||
}
|
||||
|
||||
csharp_lib_arrays_bool.myArrayCopyBool( source, target, target.Length );
|
||||
CompareArrays(source, target, "bool[] INPUT/OUTPUT");
|
||||
}
|
||||
|
||||
{
|
||||
bool[] source = { true, false, false, true, false, true, true, false };
|
||||
bool[] target = { false, true, true, false, true, false, false, true };
|
||||
|
||||
csharp_lib_arrays_bool.myArraySwapBool( source, target, target.Length );
|
||||
|
||||
for (int i=0; i<target.Length; ++i)
|
||||
target[i] = !target[i];
|
||||
|
||||
CompareArrays(source, target, "bool[] INOUT");
|
||||
}
|
||||
}
|
||||
|
||||
static void CompareArrays<T>( T[] a, T[] b, string testName )
|
||||
{
|
||||
if (a.Length != b.Length)
|
||||
throw new Exception("size mismatch");
|
||||
|
||||
for(int i=0; i<a.Length; ++i) {
|
||||
if (a[i].Equals(b[i]) == false) {
|
||||
Console.Error.WriteLine("C# Array mismatch: " + testName);
|
||||
Console.Error.WriteLine("a:");
|
||||
PrintArray(a);
|
||||
Console.Error.WriteLine("b:");
|
||||
PrintArray(b);
|
||||
throw new Exception("element mismatch");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void PrintArray<T>( T[] a )
|
||||
{
|
||||
foreach ( T i in a )
|
||||
Console.Error.Write( "{0} ", i );
|
||||
Console.Error.WriteLine();
|
||||
}
|
||||
|
||||
static bool runtimeIsMono()
|
||||
{
|
||||
return Type.GetType ("Mono.Runtime") != null;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -48,6 +48,36 @@ public class runme
|
|||
if (myNewBar == null)
|
||||
throw new Exception("non-null pointer marshalling problem");
|
||||
myNewBar.x = 10;
|
||||
|
||||
// Low level implementation check
|
||||
// my.testSwigDerivedClassHasMethod();
|
||||
|
||||
// These should not call the C# implementations as they are not overridden
|
||||
int v;
|
||||
v = MyClass.call_nonVirtual(my);
|
||||
if (v != 100) throw new Exception("call_nonVirtual broken() " + v);
|
||||
|
||||
v = MyClass.call_nonOverride(my);
|
||||
if (v != 101) throw new Exception("call_nonOverride broken() " + v);
|
||||
|
||||
// A mix of overridden and non-overridden
|
||||
MyClassEnd myend = new MyClassEnd();
|
||||
MyClass mc = myend;
|
||||
|
||||
v = mc.nonVirtual();
|
||||
if (v != 202) throw new Exception("mc.nonVirtual() broken " + v);
|
||||
|
||||
v = MyClass.call_nonVirtual(mc);
|
||||
if (v != 202) throw new Exception("call_nonVirtual(mc) broken " + v);
|
||||
|
||||
v = MyClass.call_nonVirtual(myend);
|
||||
if (v != 202) throw new Exception("call_nonVirtual(myend) broken" + v);
|
||||
|
||||
v = MyClass.call_nonOverride(mc);
|
||||
if (v != 101) throw new Exception("call_nonOverride(mc) broken" + v);
|
||||
|
||||
v = MyClass.call_nonOverride(myend);
|
||||
if (v != 101) throw new Exception("call_nonOverride(myend) broken" + v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -69,6 +99,30 @@ class MyOverriddenClass : MyClass {
|
|||
throw new Exception("null not received as expected");
|
||||
return b;
|
||||
}
|
||||
|
||||
public new bool nonVirtual() {
|
||||
throw new Exception("non-virtual overrides virtual method");
|
||||
}
|
||||
|
||||
public new virtual bool nonOverride() {
|
||||
throw new Exception("non-override overrides virtual method");
|
||||
}
|
||||
}
|
||||
|
||||
class MyClassMiddle : MyClass {
|
||||
public override int nonVirtual() {
|
||||
return 202;
|
||||
}
|
||||
}
|
||||
|
||||
class MyClassEnd : MyClassMiddle {
|
||||
public new bool nonVirtual() {
|
||||
throw new Exception("non-virtual overrides virtual method");
|
||||
}
|
||||
|
||||
public new virtual bool nonOverride() {
|
||||
throw new Exception("non-override overrides virtual method");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ Expected output if PrintDebug enabled:
|
|||
Base - Val(444.555)
|
||||
Base - Ref(444.555)
|
||||
Base - Ptr(444.555)
|
||||
Base - ConstPtrRef(444.555)
|
||||
Base - FullyOverloaded(int 10)
|
||||
Base - FullyOverloaded(bool 1)
|
||||
Base - SemiOverloaded(int -678)
|
||||
|
|
@ -26,6 +27,7 @@ Base - DefaultParms(10, 1.1)
|
|||
Derived - Val(444.555)
|
||||
Derived - Ref(444.555)
|
||||
Derived - Ptr(444.555)
|
||||
Derived - ConstPtrRef(444.555)
|
||||
Derived - FullyOverloaded(int 10)
|
||||
Derived - FullyOverloaded(bool 1)
|
||||
Derived - SemiOverloaded(int -678)
|
||||
|
|
@ -36,6 +38,7 @@ Derived - DefaultParms(10, 1.1)
|
|||
CSharpDerived - Val(444.555)
|
||||
CSharpDerived - Ref(444.555)
|
||||
CSharpDerived - Ptr(444.555)
|
||||
CSharpDerived - ConstPtrRef(444.555)
|
||||
CSharpDerived - FullyOverloaded(int 10)
|
||||
CSharpDerived - FullyOverloaded(bool True)
|
||||
CSharpDerived - SemiOverloaded(-678)
|
||||
|
|
@ -59,7 +62,7 @@ public class runme
|
|||
|
||||
void run()
|
||||
{
|
||||
if (director_classes.PrintDebug) Console.WriteLine("------------ Start ------------ ");
|
||||
if (director_classes.PrintDebug) Console.WriteLine("------------ Start ------------");
|
||||
|
||||
Caller myCaller = new Caller();
|
||||
|
||||
|
|
@ -85,7 +88,7 @@ public class runme
|
|||
makeCalls(myCaller, myBase);
|
||||
}
|
||||
|
||||
if (director_classes.PrintDebug) Console.WriteLine("------------ Finish ------------ ");
|
||||
if (director_classes.PrintDebug) Console.WriteLine("------------ Finish ------------");
|
||||
}
|
||||
|
||||
void makeCalls(Caller myCaller, Base myBase)
|
||||
|
|
@ -99,6 +102,7 @@ public class runme
|
|||
if (myCaller.ValCall(dh).val != dh.val) throw new Exception("failed");
|
||||
if (myCaller.RefCall(dh).val != dh.val) throw new Exception("failed");
|
||||
if (myCaller.PtrCall(dh).val != dh.val) throw new Exception("failed");
|
||||
if (myCaller.ConstPtrRefCall(dh).val != dh.val) throw new Exception("failed");
|
||||
|
||||
// Fully overloaded method test (all methods in base class are overloaded)
|
||||
if (NAMESPACE + myCaller.FullyOverloadedCall(10) != myBase.GetType() + "::FullyOverloaded(int)") throw new Exception("failed");
|
||||
|
|
@ -142,6 +146,11 @@ public class CSharpDerived : Base
|
|||
if (director_classes.PrintDebug) Console.WriteLine("CSharpDerived - Ptr({0})", x.val);
|
||||
return x;
|
||||
}
|
||||
public override DoubleHolder ConstPtrRef(DoubleHolder x)
|
||||
{
|
||||
if (director_classes.PrintDebug) Console.WriteLine("CSharpDerived - ConstPtrRef({0})", x.val);
|
||||
return x;
|
||||
}
|
||||
public override String FullyOverloaded(int x)
|
||||
{
|
||||
if (director_classes.PrintDebug) Console.WriteLine("CSharpDerived - FullyOverloaded(int {0})", x);
|
||||
|
|
|
|||
|
|
@ -67,6 +67,12 @@ public class runme
|
|||
if (x != 1334)
|
||||
throw new Exception("Bad4 should be 1334, got " + x);
|
||||
}
|
||||
{
|
||||
MemberVoid mv = new MemberVoid();
|
||||
global::System.IntPtr zero = global::System.IntPtr.Zero;
|
||||
mv.memberVariable = zero;
|
||||
zero = mv.memberVariable;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
111
Examples/test-suite/csharp/li_boost_shared_ptr_director_runme.cs
Normal file
111
Examples/test-suite/csharp/li_boost_shared_ptr_director_runme.cs
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
using System;
|
||||
using li_boost_shared_ptr_directorNamespace;
|
||||
|
||||
public class li_boost_shared_ptr_director_runme {
|
||||
|
||||
private static void check(int got, int expected) {
|
||||
if (got != expected)
|
||||
throw new Exception("Failed, got: " + got + " expected: " + expected);
|
||||
}
|
||||
|
||||
public static void Main() {
|
||||
Derived a = new Derived(false);
|
||||
Derived b = new Derived(true);
|
||||
|
||||
check(li_boost_shared_ptr_director.call_ret_c_shared_ptr(a), 1);
|
||||
check(li_boost_shared_ptr_director.call_ret_c_shared_ptr(b), -1);
|
||||
check(li_boost_shared_ptr_director.call_ret_c_by_value(a), 1);
|
||||
|
||||
check(li_boost_shared_ptr_director.call_ret_c_shared_ptr(a), 1);
|
||||
check(li_boost_shared_ptr_director.call_ret_c_shared_ptr(b), -1);
|
||||
check(li_boost_shared_ptr_director.call_ret_c_by_value(a), 1);
|
||||
|
||||
check(li_boost_shared_ptr_director.call_take_c_by_value(a), 5);
|
||||
check(li_boost_shared_ptr_director.call_take_c_by_ref(a), 6);
|
||||
check(li_boost_shared_ptr_director.call_take_c_by_pointer(a), 7);
|
||||
check(li_boost_shared_ptr_director.call_take_c_by_pointer_ref(a), 8);
|
||||
check(li_boost_shared_ptr_director.call_take_c_shared_ptr_by_value(a), 9);
|
||||
check(li_boost_shared_ptr_director.call_take_c_shared_ptr_by_ref(a), 10);
|
||||
check(li_boost_shared_ptr_director.call_take_c_shared_ptr_by_pointer(a), 11);
|
||||
check(li_boost_shared_ptr_director.call_take_c_shared_ptr_by_pointer_ref(a), 12);
|
||||
|
||||
check(li_boost_shared_ptr_director.call_take_c_by_pointer_with_null(a), -2);
|
||||
check(li_boost_shared_ptr_director.call_take_c_by_pointer_ref_with_null(a), -3);
|
||||
check(li_boost_shared_ptr_director.call_take_c_shared_ptr_by_value_with_null(a), -4);
|
||||
check(li_boost_shared_ptr_director.call_take_c_shared_ptr_by_ref_with_null(a), -5);
|
||||
check(li_boost_shared_ptr_director.call_take_c_shared_ptr_by_pointer_with_null(a), -6);
|
||||
check(li_boost_shared_ptr_director.call_take_c_shared_ptr_by_pointer_ref_with_null(a), -7);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Derived : Base {
|
||||
|
||||
private bool return_none;
|
||||
|
||||
public Derived(bool flag) : base() {
|
||||
this.return_none = flag;
|
||||
}
|
||||
|
||||
public override C ret_c_shared_ptr() {
|
||||
if (this.return_none)
|
||||
return null;
|
||||
else
|
||||
return new C();
|
||||
}
|
||||
|
||||
public override C ret_c_by_value() {
|
||||
return new C();
|
||||
}
|
||||
|
||||
public override int take_c_by_value(C c) {
|
||||
return c.get_m();
|
||||
}
|
||||
|
||||
public override int take_c_by_ref(C c) {
|
||||
return c.get_m();
|
||||
}
|
||||
|
||||
public override int take_c_by_pointer(C c) {
|
||||
if (c != null)
|
||||
return c.get_m();
|
||||
else
|
||||
return -2;
|
||||
}
|
||||
|
||||
public override int take_c_by_pointer_ref(C c) {
|
||||
if (c != null)
|
||||
return c.get_m();
|
||||
else
|
||||
return -3;
|
||||
}
|
||||
|
||||
public override int take_c_shared_ptr_by_value(C c) {
|
||||
if (c != null)
|
||||
return c.get_m();
|
||||
else
|
||||
return -4;
|
||||
}
|
||||
|
||||
public override int take_c_shared_ptr_by_ref(C c) {
|
||||
if (c != null)
|
||||
return c.get_m();
|
||||
else
|
||||
return -5;
|
||||
}
|
||||
|
||||
public override int take_c_shared_ptr_by_pointer(C c) {
|
||||
if (c != null)
|
||||
return c.get_m();
|
||||
else
|
||||
return -6;
|
||||
}
|
||||
|
||||
public override int take_c_shared_ptr_by_pointer_ref(C c) {
|
||||
if (c != null)
|
||||
return c.get_m();
|
||||
else
|
||||
return -7;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -19,6 +19,13 @@ public class li_std_auto_ptr_runme {
|
|||
if (Klass.getTotal_count() != 2)
|
||||
throw new Exception("number of objects should be 2");
|
||||
|
||||
using (Klass k3 = li_std_auto_ptr.makeKlassAutoPtr("second")) {
|
||||
if (Klass.getTotal_count() != 3)
|
||||
throw new Exception("number of objects should be 3");
|
||||
}
|
||||
if (Klass.getTotal_count() != 2)
|
||||
throw new Exception("number of objects should be 2");
|
||||
|
||||
k1 = null;
|
||||
{
|
||||
int countdown = 500;
|
||||
|
|
|
|||
402
Examples/test-suite/csharp/li_std_list_runme.cs
Normal file
402
Examples/test-suite/csharp/li_std_list_runme.cs
Normal file
|
|
@ -0,0 +1,402 @@
|
|||
using System;
|
||||
using li_std_listNamespace;
|
||||
|
||||
public class li_std_list_runme {
|
||||
private static readonly int collectionSize = 20;
|
||||
|
||||
public static void Main() {
|
||||
// Setup a list of int
|
||||
IntList list = new IntList();
|
||||
IntList.IntListNode node;
|
||||
|
||||
for (int i = 0; i < 20; i++) {
|
||||
int nb = i * 10;
|
||||
list.Add(nb);
|
||||
}
|
||||
|
||||
// Count property test
|
||||
if (list.Count != collectionSize)
|
||||
throw new Exception("Count test failed");
|
||||
|
||||
// IsReadOnly property test
|
||||
if (list.IsReadOnly)
|
||||
throw new Exception("IsReadOnly test failed");
|
||||
|
||||
// Contains method test
|
||||
if (!list.Contains(0))
|
||||
throw new Exception("Contains method test 1 failed");
|
||||
if (!list.Contains(2 * 10))
|
||||
throw new Exception("Contains method test 2 failed");
|
||||
if (!list.Contains(19 * 10))
|
||||
throw new Exception("Contains method test 3 failed");
|
||||
if (list.Contains(20 * 10))
|
||||
throw new Exception("Contains method test 4 failed");
|
||||
|
||||
// Nodes comparison method overload
|
||||
{
|
||||
IntList.IntListNode temp = new IntList.IntListNode(3);
|
||||
if (list.First == temp)
|
||||
throw new Exception("== overload method test (1) failed");
|
||||
temp = new IntList.IntListNode(0);
|
||||
if (list.First == temp)
|
||||
throw new Exception("== overload method test (2) failed");
|
||||
IntList.IntListNode temp2 = new IntList.IntListNode(0);
|
||||
if (temp == temp2)
|
||||
throw new Exception("== overload method test (3) failed");
|
||||
if (!(list.First == list.First))
|
||||
throw new Exception("== overload method test (4) failed");
|
||||
if (list.First != list.First)
|
||||
throw new Exception("!= overload method test (1) failed");
|
||||
if (!(temp != temp2))
|
||||
throw new Exception("!= overload method test (2) failed");
|
||||
if (list.First.Equals(temp))
|
||||
throw new Exception("Equals method test failed");
|
||||
if (list.First.GetHashCode() == temp.GetHashCode())
|
||||
throw new Exception("GetHashCode method test (1) failed");
|
||||
if (list.First.GetHashCode() == list.First.GetHashCode())
|
||||
throw new Exception("GetHashCode method test (2) failed");
|
||||
|
||||
}
|
||||
|
||||
// Getter test
|
||||
{
|
||||
if (list.First == null)
|
||||
throw new Exception("First getter test (1) failed");
|
||||
if (list.Last == null)
|
||||
throw new Exception("Last getter test (1) failed");
|
||||
if (list.Last.Next != null)
|
||||
throw new Exception("Next getter test (1) failed");
|
||||
if (list.First.Next == null)
|
||||
throw new Exception("Next getter test (2) failed");
|
||||
if (list.First.Previous != null)
|
||||
throw new Exception("Previous getter test (1) failed");
|
||||
if (list.Last.Previous == null)
|
||||
throw new Exception("Previous getter test (2) failed");
|
||||
}
|
||||
|
||||
// AddFirst method test
|
||||
node = list.AddFirst(34);
|
||||
if (list.First.Value != 34 || node.Value != 34 || node != list.First)
|
||||
throw new Exception("AddFirst method test failed");
|
||||
try {
|
||||
list.AddFirst(null);
|
||||
} catch (ArgumentNullException) {
|
||||
try {
|
||||
list.AddFirst(list.First);
|
||||
} catch (InvalidOperationException) {
|
||||
}
|
||||
}
|
||||
|
||||
// RemoveFirst method test
|
||||
int tmp = list.First.Value;
|
||||
list.RemoveFirst();
|
||||
if (list.First.Value == tmp || list.First.Value != 0 * 10)
|
||||
throw new Exception("RemoveFirst method test failed");
|
||||
|
||||
// AddLast method test
|
||||
node = list.AddLast(8);
|
||||
if (list.Last.Value != 8 || node.Value != 8 || node != list.Last)
|
||||
throw new Exception("AddLast method test failed");
|
||||
try {
|
||||
list.AddLast(null);
|
||||
} catch (ArgumentNullException) {
|
||||
try {
|
||||
list.AddLast(list.First);
|
||||
} catch (InvalidOperationException) {
|
||||
}
|
||||
}
|
||||
|
||||
// RemoveLast method test
|
||||
int tmp2 = list.Last.Value;
|
||||
list.RemoveLast();
|
||||
if (list.Last.Value == tmp2 || list.Last.Value != (list.Count - 1) * 10)
|
||||
throw new Exception("RemoveLast method test failed");
|
||||
|
||||
// AddBefore method test
|
||||
node = list.AddBefore(list.Last, 17);
|
||||
if (list.Last.Previous.Value != 17 || node.Value != 17 || node != list.Last.Previous)
|
||||
throw new Exception("AddBefore method test (1) failed");
|
||||
try {
|
||||
node = null;
|
||||
list.AddBefore(list.Last, node);
|
||||
throw new Exception("AddBefore method test (2) failed");
|
||||
} catch (ArgumentNullException) {
|
||||
try {
|
||||
node = new IntList.IntListNode(1);
|
||||
list.AddBefore(null, node);
|
||||
throw new Exception("AddBefore method test (3) failed");
|
||||
} catch (ArgumentNullException) {
|
||||
try {
|
||||
list.AddBefore(list.Last, list.First);
|
||||
} catch (InvalidOperationException) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// AddAfter method test
|
||||
node = list.AddAfter(list.First, 47);
|
||||
if (list.First.Next.Value != 47 || node.Value != 47 || node != list.First.Next)
|
||||
throw new Exception("AddAfter method test (1) failed");
|
||||
try {
|
||||
node = null;
|
||||
list.AddAfter(list.First.Next, node);
|
||||
throw new Exception("AddAfter method test (2) failed");
|
||||
} catch (ArgumentNullException) {
|
||||
try {
|
||||
list.AddAfter(list.First, list.Last);
|
||||
} catch (InvalidOperationException) {
|
||||
}
|
||||
}
|
||||
|
||||
// Find method test
|
||||
node = list.Find(0);
|
||||
if (node == null || node.Value != 0)
|
||||
throw new Exception("Find method test (1) failed");
|
||||
node = list.Find(47);
|
||||
if (node == null || node.Value != 47)
|
||||
throw new Exception("Find method test (2) failed");
|
||||
node = list.Find(190);
|
||||
if (node == null || node.Value != 190)
|
||||
throw new Exception("Find method test (3) failed");
|
||||
node = list.Find(-3);
|
||||
if (node != null)
|
||||
throw new Exception("Find method test (4) failed");
|
||||
|
||||
// Remove method test
|
||||
if (!list.Remove(17) || list.Contains(17) || list.Last.Previous.Value == 17)
|
||||
throw new Exception("Remove method test (1) failed");
|
||||
if (!list.Remove(47) || list.Contains(47) || list.First.Next.Value == 47)
|
||||
throw new Exception("Remove method test (2) failed");
|
||||
if (!list.Remove(0) || list.Contains(0) || list.First.Value == 0)
|
||||
throw new Exception("Remove method test (3) failed");
|
||||
if (!list.Remove(190) || list.Contains(190) || list.Last.Value == 190)
|
||||
throw new Exception("Remove method test (4) failed");
|
||||
try {
|
||||
node = null;
|
||||
list.Remove(node);
|
||||
throw new Exception("Remove method test (5) failed");
|
||||
} catch (ArgumentNullException) {
|
||||
try {
|
||||
node = new IntList.IntListNode(4);
|
||||
list.Remove(node);
|
||||
throw new Exception("Remove method test (5) failed");
|
||||
} catch (InvalidOperationException) {
|
||||
}
|
||||
}
|
||||
|
||||
// ICollection constructor test
|
||||
{
|
||||
int[] intArray = new int[] { 0, 11, 22, 33, 44, 55, 33 };
|
||||
IntList il = new IntList(intArray);
|
||||
if (intArray.Length != il.Count)
|
||||
throw new Exception("ICollection constructor length check failed: " + intArray.Length + "-" + il.Count);
|
||||
node = il.First;
|
||||
for (int i = 0; i < intArray.Length; i++) {
|
||||
if (intArray[i] != node.Value)
|
||||
throw new Exception("ICollection constructor failed, index:" + i);
|
||||
node = node.Next;
|
||||
}
|
||||
try {
|
||||
new IntList((System.Collections.ICollection)null);
|
||||
throw new Exception("ICollection constructor null test failed");
|
||||
} catch (ArgumentNullException) {
|
||||
}
|
||||
}
|
||||
|
||||
// Enumerator test
|
||||
{
|
||||
node = list.First;
|
||||
System.Collections.IEnumerator myEnumerator = list.GetEnumerator();
|
||||
while (myEnumerator.MoveNext()) {
|
||||
if ((int)myEnumerator.Current != node.Value)
|
||||
throw new Exception("Enumerator (1) test failed");
|
||||
node = node.Next;
|
||||
}
|
||||
}
|
||||
{
|
||||
node = list.First;
|
||||
System.Collections.Generic.IEnumerator<int> myEnumerator = list.GetEnumerator();
|
||||
while (myEnumerator.MoveNext()) {
|
||||
if (myEnumerator.Current != node.Value)
|
||||
throw new Exception("Enumerator (2) test failed");
|
||||
node = node.Next;
|
||||
}
|
||||
}
|
||||
{
|
||||
node = list.First;
|
||||
IntList.IntListEnumerator myEnumerator = list.GetEnumerator();
|
||||
while (myEnumerator.MoveNext()) {
|
||||
if (myEnumerator.Current != node.Value)
|
||||
throw new Exception("Enumerator (3) test failed");
|
||||
node = node.Next;
|
||||
}
|
||||
}
|
||||
{
|
||||
node = list.First;
|
||||
foreach (var elem in list) {
|
||||
if (elem != node.Value)
|
||||
throw new Exception("Enumerator (4) test failed");
|
||||
node = node.Next;
|
||||
}
|
||||
}
|
||||
|
||||
// CopyTo method test
|
||||
{
|
||||
int[] outputarray = new int[collectionSize - 2];
|
||||
list.CopyTo(outputarray, 0);
|
||||
int index = 0;
|
||||
IntList.IntListNode temp = list.First;
|
||||
foreach (int val in outputarray) {
|
||||
if (temp.Value != val) {
|
||||
throw new Exception("CopyTo method test (1) failed, index:" + index);
|
||||
}
|
||||
index++;
|
||||
temp = temp.Next;
|
||||
}
|
||||
}
|
||||
{
|
||||
DoubleList inputlist = new DoubleList();
|
||||
int arrayLen = 10;
|
||||
for (int i = 0; i < arrayLen; i++) {
|
||||
double num = i * 10.1;
|
||||
inputlist.Add(num);
|
||||
}
|
||||
double[] outputarray = new double[arrayLen];
|
||||
inputlist.CopyTo(outputarray, 0);
|
||||
DoubleList.DoubleListNode temp = inputlist.First;
|
||||
for (int i = 0; i < arrayLen; i++) {
|
||||
if (outputarray[i] != temp.Value)
|
||||
throw new Exception("CopyTo method test (2) failed, index:" + i);
|
||||
temp = temp.Next;
|
||||
}
|
||||
}
|
||||
{
|
||||
StructList inputlist = new StructList();
|
||||
int arrayLen = 10;
|
||||
for (int i = 0; i < arrayLen; i++)
|
||||
inputlist.Add(new Struct(i / 10.0));
|
||||
Struct[] outputarray = new Struct[arrayLen];
|
||||
inputlist.CopyTo(outputarray, 0);
|
||||
StructList.StructListNode temp = inputlist.First;
|
||||
for (int i = 0; i < arrayLen; i++) {
|
||||
if (outputarray[i].num != temp.Value.num)
|
||||
throw new Exception("CopyTo method test (3) failed, index:" + i);
|
||||
temp = temp.Next;
|
||||
}
|
||||
foreach (Struct s in inputlist) {
|
||||
s.num += 20.0;
|
||||
}
|
||||
temp = inputlist.First;
|
||||
for (int i = 0; i < arrayLen; i++) {
|
||||
if (outputarray[i].num != temp.Value.num)
|
||||
throw new Exception("CopyTo method test (4) failed, index:" + i);
|
||||
temp = temp.Next;
|
||||
}
|
||||
}
|
||||
try {
|
||||
list.CopyTo(null, 0);
|
||||
throw new Exception("CopyTo method test (5) failed");
|
||||
} catch (ArgumentNullException) {
|
||||
}
|
||||
|
||||
// Clear() test
|
||||
list.Clear();
|
||||
if (list.Count != 0)
|
||||
throw new Exception("Clear method failed");
|
||||
|
||||
// Finally test the methods being wrapped
|
||||
{
|
||||
IntList il = new IntList();
|
||||
for (int i = 0; i < 4; i++) {
|
||||
il.Add(i);
|
||||
}
|
||||
|
||||
double x = li_std_list.average(il);
|
||||
x += li_std_list.average(new IntList(new int[] { 1, 2, 3, 4 }));
|
||||
|
||||
DoubleList dlist = new DoubleList();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
dlist.Add(i / 2.0);
|
||||
}
|
||||
li_std_list.halve_in_place(dlist);
|
||||
}
|
||||
|
||||
// Dispose()
|
||||
{
|
||||
using (StructList ls = new StructList(new Struct[] { new Struct(0.0), new Struct(11.1) }))
|
||||
using (DoubleList ld = new DoubleList(new double[] { 0.0, 11.1 })) { }
|
||||
}
|
||||
|
||||
// More wrapped methods
|
||||
{
|
||||
FloatList l0 = li_std_list.listreal(new FloatList());
|
||||
float flo = 123.456f;
|
||||
l0.Add(flo);
|
||||
flo = l0.First.Value;
|
||||
|
||||
IntList l1 = li_std_list.listint(new IntList());
|
||||
IntPtrList l2 = li_std_list.listintptr(new IntPtrList());
|
||||
IntConstPtrList l3 = li_std_list.listintconstptr(new IntConstPtrList());
|
||||
|
||||
l1.Add(123);
|
||||
l2.Clear();
|
||||
l3.Clear();
|
||||
|
||||
StructList l4 = li_std_list.liststruct(new StructList());
|
||||
StructPtrList l5 = li_std_list.liststructptr(new StructPtrList());
|
||||
StructConstPtrList l6 = li_std_list.liststructconstptr(new StructConstPtrList());
|
||||
|
||||
l4.Add(new Struct(123));
|
||||
l5.Add(new Struct(123));
|
||||
l6.Add(new Struct(123));
|
||||
}
|
||||
|
||||
// Test lists of pointers
|
||||
{
|
||||
StructPtrList inputlist = new StructPtrList();
|
||||
int arrayLen = 10;
|
||||
for (int i = 0; i < arrayLen; i++) {
|
||||
inputlist.Add(new Struct(i / 10.0));
|
||||
}
|
||||
Struct[] outputarray = new Struct[arrayLen];
|
||||
inputlist.CopyTo(outputarray, 0);
|
||||
StructPtrList.StructPtrListNode temp = inputlist.First;
|
||||
for (int i = 0; i < arrayLen; i++) {
|
||||
if (outputarray[i].num != temp.Value.num)
|
||||
throw new Exception("StructPtrList test (1) failed, i:" + i);
|
||||
temp = temp.Next;
|
||||
}
|
||||
foreach (Struct s in inputlist) {
|
||||
s.num += 20.0;
|
||||
}
|
||||
for (int i = 0; i < arrayLen; i++) {
|
||||
if (outputarray[i].num != 20.0 + i / 10.0)
|
||||
throw new Exception("StructPtrList test (2) failed (a deep copy was incorrectly made), i:" + i);
|
||||
}
|
||||
}
|
||||
|
||||
// Test lists of const pointers
|
||||
{
|
||||
StructConstPtrList inputlist = new StructConstPtrList();
|
||||
int arrayLen = 10;
|
||||
for (int i = 0; i < arrayLen; i++) {
|
||||
inputlist.Add(new Struct(i / 10.0));
|
||||
}
|
||||
Struct[] outputarray = new Struct[arrayLen];
|
||||
inputlist.CopyTo(outputarray, 0);
|
||||
StructConstPtrList.StructConstPtrListNode temp = inputlist.First;
|
||||
for (int i = 0; i < arrayLen; i++) {
|
||||
if (outputarray[i].num != temp.Value.num)
|
||||
throw new Exception("StructConstPtrList test (1) failed, i:" + i);
|
||||
temp = temp.Next;
|
||||
}
|
||||
foreach (Struct s in inputlist) {
|
||||
s.num += 20.0;
|
||||
}
|
||||
for (int i = 0; i < arrayLen; i++) {
|
||||
if (outputarray[i].num != 20.0 + i / 10.0)
|
||||
throw new Exception("StructConstPtrList test (2) failed (a deep copy was incorrectly made), i:" + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -240,6 +240,20 @@ public class li_std_map_runme {
|
|||
throw new Exception("Key test (2) on complex key map failed");
|
||||
}
|
||||
|
||||
// Custom compare function
|
||||
{
|
||||
StringLengthNumberMap slmap = new StringLengthNumberMap();
|
||||
li_std_map.populate(slmap);
|
||||
|
||||
string keys = string.Join(" ", new List<string>(slmap.Keys));
|
||||
if (keys != "a aa zzz xxxx aaaaa")
|
||||
throw new Exception("Keys are wrong or in wrong order: " + keys);
|
||||
|
||||
string values = string.Join(" ", new List<int>(slmap.Values));
|
||||
if (values != "1 2 3 4 5")
|
||||
throw new Exception("Values are wrong or in wrong order: " + values);
|
||||
}
|
||||
|
||||
// All done
|
||||
}
|
||||
}
|
||||
|
|
|
|||
105
Examples/test-suite/csharp/li_std_set_runme.cs
Normal file
105
Examples/test-suite/csharp/li_std_set_runme.cs
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using li_std_setNamespace;
|
||||
|
||||
public class runme
|
||||
{
|
||||
static void checkThat(bool mustBeTrue, string message)
|
||||
{
|
||||
if (!mustBeTrue)
|
||||
throw new Exception("Test that the set " + message + " failed");
|
||||
}
|
||||
|
||||
static void Main()
|
||||
{
|
||||
StringSet ss = new StringSet();
|
||||
|
||||
// Check the interface methods first.
|
||||
ISet<string> s = ss;
|
||||
|
||||
checkThat(s.Count == 0, "is initially empty");
|
||||
checkThat(!s.Contains("key"), "doesn't contain inexistent element");
|
||||
checkThat(!s.Remove("key"), "returns false when removing inexistent element");
|
||||
|
||||
checkThat(s.Add("key"), "returns true when adding a new element");
|
||||
checkThat(!s.Add("key"), "returns false when adding an existing element");
|
||||
checkThat(s.Contains("key"), "contains the just added element");
|
||||
checkThat(s.Remove("key"), "returns true when removing an existing element");
|
||||
checkThat(s.Count == 0, "is empty again");
|
||||
|
||||
checkThat(s.Add("key1"), "Add(key1) returns true");
|
||||
checkThat(s.Add("key2"), "Add(key2) returns true");
|
||||
checkThat(s.Add("key3"), "Add(key3) returns true");
|
||||
|
||||
// Also check a different interface, providing a different Add() (sic!).
|
||||
ICollection<string> coll = ss;
|
||||
coll.Add("key");
|
||||
checkThat(ss.Count == 4, "contains 4 elements");
|
||||
|
||||
// Now use object-specific methods, mimicking HashSet<>.
|
||||
string val;
|
||||
checkThat(ss.TryGetValue("key1", out val), "could retrieve existing item");
|
||||
checkThat(val.Equals("key1"), "value was returned correctly by TryGetValue()");
|
||||
checkThat(!ss.TryGetValue("no-such-key", out val), "couldn't retrieve inexistent item");
|
||||
checkThat(val == null, "value was reset after failed TryGetValue()");
|
||||
|
||||
IList<string> list = new List<string>();
|
||||
foreach (string str in ss) {
|
||||
list.Add(str);
|
||||
}
|
||||
checkThat(list.Count == 4, "copy contains 4 elements");
|
||||
|
||||
ss.Clear();
|
||||
checkThat(ss.Count == 0, "is empty after Clear()");
|
||||
|
||||
// Check set-theoretic methods.
|
||||
checkThat(new StringSet().SetEquals(new StringSet()), "SetEquals() works for empty sets");
|
||||
checkThat(new StringSet{"foo"}.SetEquals(new StringSet{"foo"}), "SetEquals() works for non-empty sets");
|
||||
checkThat(!new StringSet{"foo"}.SetEquals(new[] {"bar"}), "SetEquals() doesn't always return true");
|
||||
|
||||
ss = new StringSet{"foo", "bar", "baz"};
|
||||
ss.ExceptWith(new[] {"baz", "quux"});
|
||||
checkThat(ss.SetEquals(new[] {"foo", "bar"}), "ExceptWith works");
|
||||
|
||||
ss = new StringSet{"foo", "bar", "baz"};
|
||||
ss.IntersectWith(new[] {"baz", "quux"});
|
||||
checkThat(ss.SetEquals(new[] {"baz"}), "IntersectWith works");
|
||||
|
||||
checkThat(ss.IsProperSubsetOf(new[] {"bar", "baz"}), "IsProperSubsetOf works");
|
||||
checkThat(!ss.IsProperSubsetOf(new[] {"baz"}), "!IsProperSubsetOf works");
|
||||
checkThat(ss.IsSubsetOf(new[] {"bar", "baz"}), "IsSubsetOf works");
|
||||
checkThat(!ss.IsSubsetOf(new[] {"bar"}), "!IsSubsetOf works");
|
||||
|
||||
ss = new StringSet{"foo", "bar", "baz"};
|
||||
checkThat(ss.IsProperSupersetOf(new[] {"bar"}), "IsProperSupersetOf works");
|
||||
checkThat(!ss.IsProperSupersetOf(new[] {"quux"}), "IsProperSupersetOf works");
|
||||
checkThat(ss.IsSupersetOf(new[] {"foo", "bar", "baz"}), "IsProperSupersetOf works");
|
||||
checkThat(!ss.IsSupersetOf(new[] {"foo", "bar", "baz", "quux"}), "IsProperSupersetOf works");
|
||||
|
||||
checkThat(ss.Overlaps(new[] {"foo"}), "Overlaps works");
|
||||
checkThat(!ss.Overlaps(new[] {"moo"}), "!Overlaps works");
|
||||
|
||||
ss.SymmetricExceptWith(new[] {"baz", "quux"});
|
||||
checkThat(ss.SetEquals(new[] {"foo", "bar", "quux"}), "SymmetricExceptWith works");
|
||||
|
||||
ss = new StringSet{"foo", "bar", "baz"};
|
||||
ss.UnionWith(new[] {"baz", "quux"});
|
||||
checkThat(ss.SetEquals(new[] {"foo", "bar", "baz", "quux"}), "UnionWith works");
|
||||
|
||||
// Check a set of another type.
|
||||
FooSet fooSet = new FooSet();
|
||||
ISet<Foo> fooISet = fooSet;
|
||||
checkThat(fooISet.Count == 0, "is initially empty");
|
||||
checkThat(fooISet.Add(new Foo(17)), "added successfully");
|
||||
checkThat(fooISet.Count == 1, "is not empty any more");
|
||||
|
||||
// And a set of primitive type.
|
||||
IntSet intSet = new IntSet();
|
||||
checkThat(intSet.Count == 0, "is initially empty");
|
||||
checkThat(intSet.Add(17), "17 added successfully");
|
||||
checkThat(!intSet.Add(17), "17 not added again");
|
||||
checkThat(intSet.Count == 1, "not empty any more");
|
||||
checkThat(intSet.Add(289), "289 added successfully");
|
||||
checkThat(intSet.Count == 2, "even less empty now");
|
||||
}
|
||||
}
|
||||
|
|
@ -177,6 +177,17 @@ public class li_std_vector_runme {
|
|||
if (doubleArray[i] != dvCopy[i])
|
||||
throw new Exception("Copy constructor failed, index:" + i);
|
||||
}
|
||||
if (dvCopy.Count != doubleArray.Length)
|
||||
throw new Exception("Copy constructor lengths mismatch");
|
||||
|
||||
// ToArray test
|
||||
double[] dvArray = dv.ToArray();
|
||||
for (int i=0; i<doubleArray.Length; i++) {
|
||||
if (doubleArray[i] != dvArray[i])
|
||||
throw new Exception("ToArray failed, index:" + i);
|
||||
}
|
||||
if (dvArray.Length != doubleArray.Length)
|
||||
throw new Exception("ToArray lengths mismatch");
|
||||
}
|
||||
{
|
||||
// Repeat() test
|
||||
|
|
|
|||
|
|
@ -3,74 +3,130 @@ using li_std_wstringNamespace;
|
|||
|
||||
public class runme
|
||||
{
|
||||
static private void check_equal(char a, char b)
|
||||
{
|
||||
if (a != b)
|
||||
throw new Exception("char failed '" + a + "' != '" + b + "'");
|
||||
}
|
||||
|
||||
static private void check_equal(string a, string b)
|
||||
{
|
||||
if (a != b)
|
||||
throw new Exception("string failed '" + a + "' != '" + b + "'");
|
||||
}
|
||||
|
||||
static void Main()
|
||||
{
|
||||
char y='h';
|
||||
char h = 'h';
|
||||
check_equal(li_std_wstring.test_wcvalue(h), h);
|
||||
|
||||
if (li_std_wstring.test_wcvalue(y) != y)
|
||||
throw new Exception("bad string mapping:" + li_std_wstring.test_wcvalue(y));
|
||||
string x = "abc";
|
||||
check_equal(li_std_wstring.test_ccvalue(x), x);
|
||||
check_equal(li_std_wstring.test_cvalue(x), x);
|
||||
|
||||
if (li_std_wstring.test_wcvalue_w() != 'W')
|
||||
throw new Exception("bad string mapping:" + li_std_wstring.test_wcvalue_w());
|
||||
check_equal(li_std_wstring.test_wchar_overload(x), x);
|
||||
check_equal(li_std_wstring.test_wchar_overload(), null);
|
||||
|
||||
string x="hello";
|
||||
li_std_wstring.test_pointer(null);
|
||||
li_std_wstring.test_const_pointer(null);
|
||||
|
||||
if (li_std_wstring.test_ccvalue(x) != x)
|
||||
throw new Exception("bad string mapping");
|
||||
try {
|
||||
li_std_wstring.test_value(null);
|
||||
throw new Exception("NULL check failed");
|
||||
} catch (ArgumentNullException) {
|
||||
}
|
||||
|
||||
if (li_std_wstring.test_cvalue(x) != x)
|
||||
throw new Exception("bad string mapping");
|
||||
try {
|
||||
li_std_wstring.test_reference(null);
|
||||
throw new Exception("NULL check failed");
|
||||
} catch (ArgumentNullException e) {
|
||||
if (!e.Message.Contains("type is null"))
|
||||
throw new Exception("Missing text " + e);
|
||||
}
|
||||
try {
|
||||
li_std_wstring.test_const_reference(null);
|
||||
throw new Exception("NULL check failed");
|
||||
} catch (ArgumentNullException e) {
|
||||
if (!e.Message.Contains("null wstring"))
|
||||
throw new Exception("Missing text " + e);
|
||||
}
|
||||
|
||||
x = "hello";
|
||||
check_equal(li_std_wstring.test_const_reference(x), x);
|
||||
|
||||
if (li_std_wstring.test_value(x) != x)
|
||||
throw new Exception("bad string mapping: " + x + li_std_wstring.test_value(x));
|
||||
/* Postpone, tricky, std::wstring portability problem.
|
||||
* std::wstring is 2 bytes on Windows, 4 bytes on Linux, LPWSTR is 2 bytes.
|
||||
* .NET marshalling should work on Windows but not Linux.
|
||||
string s = "abc";
|
||||
if (!li_std_wstring.test_equal_abc(s))
|
||||
throw new Exception("Not equal " + s);
|
||||
*/
|
||||
|
||||
if (li_std_wstring.test_const_reference(x) != x)
|
||||
throw new Exception("bad string mapping");
|
||||
try {
|
||||
li_std_wstring.test_throw();
|
||||
} catch (Exception e) {
|
||||
check_equal(e.Message, "throwing test_throw");
|
||||
}
|
||||
|
||||
x = "abc\0def";
|
||||
// Unlike other languages, embedded NULL in std::string not supported
|
||||
// check_equal(li_std_wstring.test_value(x), x);
|
||||
check_equal(li_std_wstring.test_value(x), "abc");
|
||||
check_equal(li_std_wstring.test_ccvalue(x), "abc");
|
||||
check_equal(li_std_wstring.test_wchar_overload(x), "abc");
|
||||
|
||||
string s = "he";
|
||||
s = s + "llo";
|
||||
// Member variables
|
||||
var s = new wchar_test_struct();
|
||||
s.wchar_t_member = h;
|
||||
check_equal(s.wchar_t_member, h);
|
||||
s.wchar_t_ptr_member = x;
|
||||
check_equal(s.wchar_t_ptr_member, "abc");
|
||||
|
||||
if (s != x)
|
||||
throw new Exception("bad string mapping: " + s + x);
|
||||
{
|
||||
// Unicode strings
|
||||
string[] test_strings = {
|
||||
"JP: 日本語", "DE: Kröpeliner Straße" , "RU: Война и мир", "EN: War and Peace"
|
||||
};
|
||||
|
||||
if (li_std_wstring.test_value(s) != x)
|
||||
throw new Exception("bad string mapping");
|
||||
foreach (string expected in test_strings)
|
||||
{
|
||||
string received = li_std_wstring.test_value(expected);
|
||||
check_equal(received, expected);
|
||||
}
|
||||
|
||||
if (li_std_wstring.test_const_reference(s) != x)
|
||||
throw new Exception("bad string mapping");
|
||||
foreach (string expected in test_strings)
|
||||
{
|
||||
string received = li_std_wstring.test_const_reference(expected);
|
||||
check_equal(received, expected);
|
||||
}
|
||||
|
||||
string a = s;
|
||||
foreach (string expected in test_strings)
|
||||
{
|
||||
string received = li_std_wstring.test_ccvalue(expected);
|
||||
check_equal(received, expected);
|
||||
}
|
||||
|
||||
if (li_std_wstring.test_value(a) != x)
|
||||
throw new Exception("bad string mapping");
|
||||
foreach (string expected in test_strings)
|
||||
{
|
||||
s.wchar_t_ptr_member = expected;
|
||||
string received = s.wchar_t_ptr_member;
|
||||
check_equal(received, expected);
|
||||
}
|
||||
|
||||
if (li_std_wstring.test_const_reference(a) != x)
|
||||
throw new Exception("bad string mapping");
|
||||
|
||||
string b = " world";
|
||||
|
||||
if (a + b != "hello world")
|
||||
throw new Exception("bad string mapping");
|
||||
|
||||
if (a + " world" != "hello world")
|
||||
throw new Exception("bad string mapping");
|
||||
|
||||
if ("hello" + b != "hello world")
|
||||
throw new Exception("bad string mapping");
|
||||
|
||||
s = "hello world";
|
||||
|
||||
B myB = new B("hi");
|
||||
|
||||
myB.name = "hello";
|
||||
if (myB.name != "hello")
|
||||
throw new Exception("bad string mapping");
|
||||
|
||||
myB.a = "hello";
|
||||
if (myB.a != "hello")
|
||||
throw new Exception("bad string mapping");
|
||||
/* Not working for Japanese and Russian characters on Windows, okay on Linux
|
||||
* Is fixed by adding CharSet=CharSet.Unicode to the DllImport, so change to:
|
||||
* [global::System.Runtime.InteropServices.DllImport("li_std_wstring", CharSet=global::System.Runtime.InteropServices.CharSet.Unicode, EntryPoint="CSharp_li_std_wstringNamespace_test_wcvalue")]
|
||||
* Needs a SWIG code change to support this
|
||||
foreach (string test_string in test_strings)
|
||||
{
|
||||
foreach (char expected in test_string)
|
||||
{
|
||||
char received = li_std_wstring.test_wcvalue(expected);
|
||||
check_equal(received, expected);
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
10
Examples/test-suite/csharp/nested_in_template_runme.cs
Normal file
10
Examples/test-suite/csharp/nested_in_template_runme.cs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
using System;
|
||||
using nested_in_templateNamespace;
|
||||
|
||||
public class runme {
|
||||
static void Main() {
|
||||
var cd = new OuterTemplate1.ConcreteDerived(88);
|
||||
if (cd.m_value != 88)
|
||||
throw new Exception("ConcreteDerived not created correctly");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using nested_inheritance_interfaceNamespace;
|
||||
|
||||
public class nested_inheritance_interface_runme {
|
||||
|
||||
static string SortArrayToString(string[] types) {
|
||||
Array.Sort<string>(types);
|
||||
return string.Join(" ", types);
|
||||
}
|
||||
|
||||
static string SortArrayToString(Type[] types) {
|
||||
List<string> stypes = new List<string>();
|
||||
foreach (Type t in types)
|
||||
stypes.Add(t.Name);
|
||||
return SortArrayToString(stypes.ToArray());
|
||||
}
|
||||
|
||||
private static void takeIA(IASwigInterface ia) {
|
||||
}
|
||||
|
||||
public static void Main() {
|
||||
Type[] BNInterfaces = typeof(B.N).GetInterfaces();
|
||||
string expectedInterfacesString = "IASwigInterface IDisposable";
|
||||
string actualInterfacesString = SortArrayToString(BNInterfaces);
|
||||
if (expectedInterfacesString != actualInterfacesString)
|
||||
throw new Exception("Expected interfaces for " + typeof(B.N).Name + ": \n" + expectedInterfacesString + "\n" + "Actual interfaces: \n" + actualInterfacesString);
|
||||
|
||||
if (!typeof(IASwigInterface).IsInterface)
|
||||
throw new Exception(typeof(IASwigInterface).Name + " should be an interface but is not");
|
||||
|
||||
// overloaded methods check
|
||||
B.N d = new B.N();
|
||||
takeIA(d);
|
||||
}
|
||||
}
|
||||
|
|
@ -36,7 +36,7 @@ public class runme {
|
|||
assert( typeof(string) == preproc_constants_c.CONST_STRING2.GetType() );
|
||||
|
||||
assert( typeof(int) == preproc_constants_c.INT_AND_BOOL.GetType() );
|
||||
// assert( typeof(int) == preproc_constants_c.INT_AND_CHAR.GetType() );
|
||||
assert( typeof(int) == preproc_constants_c.INT_AND_CHAR.GetType() );
|
||||
assert( typeof(int) == preproc_constants_c.INT_AND_INT.GetType() );
|
||||
assert( typeof(uint) == preproc_constants_c.INT_AND_UINT.GetType() );
|
||||
assert( typeof(int) == preproc_constants_c.INT_AND_LONG.GetType() );
|
||||
|
|
@ -61,7 +61,9 @@ public class runme {
|
|||
assert( typeof(int) == preproc_constants_c.EXPR_LAND.GetType() );
|
||||
assert( typeof(int) == preproc_constants_c.EXPR_LOR.GetType() );
|
||||
assert( typeof(double) == preproc_constants_c.EXPR_CONDITIONAL.GetType() );
|
||||
|
||||
assert( typeof(double) == preproc_constants_c.EXPR_MIXED1.GetType() );
|
||||
assert( typeof(int) == preproc_constants_c.EXPR_WCHAR_MAX.GetType() );
|
||||
assert( typeof(int) == preproc_constants_c.EXPR_WCHAR_MIN.GetType() );
|
||||
}
|
||||
static void assert(bool assertion) {
|
||||
if (!assertion)
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ public class runme {
|
|||
assert( typeof(string) == preproc_constants.CONST_STRING2.GetType() );
|
||||
|
||||
assert( typeof(int) == preproc_constants.INT_AND_BOOL.GetType() );
|
||||
// assert( typeof(int) == preproc_constants.INT_AND_CHAR.GetType() );
|
||||
assert( typeof(int) == preproc_constants.INT_AND_CHAR.GetType() );
|
||||
assert( typeof(int) == preproc_constants.INT_AND_INT.GetType() );
|
||||
assert( typeof(uint) == preproc_constants.INT_AND_UINT.GetType() );
|
||||
assert( typeof(int) == preproc_constants.INT_AND_LONG.GetType() );
|
||||
|
|
@ -60,6 +60,9 @@ public class runme {
|
|||
assert( typeof(bool) == preproc_constants.EXPR_LAND.GetType() );
|
||||
assert( typeof(bool) == preproc_constants.EXPR_LOR.GetType() );
|
||||
assert( typeof(double) == preproc_constants.EXPR_CONDITIONAL.GetType() );
|
||||
assert( typeof(double) == preproc_constants.EXPR_MIXED1.GetType() );
|
||||
assert( typeof(int) == preproc_constants.EXPR_WCHAR_MAX.GetType() );
|
||||
assert( typeof(int) == preproc_constants.EXPR_WCHAR_MIN.GetType() );
|
||||
|
||||
}
|
||||
static void assert(bool assertion) {
|
||||
|
|
|
|||
25
Examples/test-suite/csharp/template_nested_flat_runme.cs
Normal file
25
Examples/test-suite/csharp/template_nested_flat_runme.cs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
using System;
|
||||
using template_nested_flatNamespace;
|
||||
#pragma warning disable 219
|
||||
|
||||
public class runme {
|
||||
static void Main() {
|
||||
new T_NormalTemplateNormalClass().tmethod(new NormalClass());
|
||||
new OuterClass().T_OuterTMethodNormalClass(new NormalClass());
|
||||
|
||||
TemplateFuncs tf = new TemplateFuncs();
|
||||
if (tf.T_TemplateFuncs1Int(-10) != -10)
|
||||
throw new Exception("it failed");
|
||||
if (tf.T_TemplateFuncs2Double(-12.3) != -12.3)
|
||||
throw new Exception("it failed");
|
||||
|
||||
T_NestedOuterTemplateDouble tn = new T_NestedOuterTemplateDouble();
|
||||
if (tn.hohum(-12.3) != -12.3)
|
||||
throw new Exception("it failed");
|
||||
T_OuterClassInner1Int inner1 = new OuterClass().useInner1(new T_OuterClassInner1Int());
|
||||
T_OuterClassInner2NormalClass inner2 = new T_OuterClassInner2NormalClass();
|
||||
inner2.embeddedVar = 2;
|
||||
T_OuterClassInner2NormalClass inner22 = new OuterClass().useInner2Again(inner2);
|
||||
}
|
||||
}
|
||||
|
||||
37
Examples/test-suite/csharp_director_typemaps.i
Normal file
37
Examples/test-suite/csharp_director_typemaps.i
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
%module (directors="1") csharp_director_typemaps
|
||||
|
||||
// This tests that the csout typemap is handled correctly in the director code.
|
||||
// The 'out' needs stripping in some parts of the generated director code.
|
||||
|
||||
%feature("director") InStream;
|
||||
|
||||
%apply void *VOID_INT_PTR { void * }
|
||||
|
||||
%typemap(ctype) int* readLen, int* writeLen "/*ctype*/ int*"
|
||||
%typemap(imtype) int* readLen, int* writeLen "/*imtype*/ out int"
|
||||
%typemap(cstype) int* readLen "/*cstype*/ out int"
|
||||
// Note for below: 'out' used in typemap comment
|
||||
%typemap(cstype) int* writeLen "/*out cstype out*/ out int"
|
||||
%typemap(csin) int* readLen, int* writeLen "/*csin*/ out $csinput"
|
||||
%typemap(in) int* readLen, int* writeLen %{/*in*/ $1 = ($1_ltype)$input; %}
|
||||
%typemap(out) int* readLen, int* writeLen %{/*out*/ $result = (void *)$1; %}
|
||||
%typemap(csdirectorin) int* readLen, int* writeLen "/*csdirectorin*/ out $iminput"
|
||||
%typemap(csdirectorout) int* readLen, int* writeLen "/*csdirectorout*/ $cscall"
|
||||
%typemap(directorin) int* readLen, int* writeLen "/*directorin*/ $input = $1;"
|
||||
%typemap(directorout) int* readLen, int* writeLen %{/*directorout*/ $result = ($1_ltype)$input; %}
|
||||
|
||||
%inline %{
|
||||
class InStream
|
||||
{
|
||||
public:
|
||||
virtual int Read(void* buf, int len, int* readLen) = 0;
|
||||
virtual int Write(void* buf, int len, int* writeLen) = 0;
|
||||
virtual ~InStream() {}
|
||||
};
|
||||
int callRead(InStream* stream, void* buf, int len, int* readLen) {
|
||||
return stream->Read(buf, len, readLen);
|
||||
}
|
||||
int callWrite(InStream* stream, void* buf, int len, int* writeLen) {
|
||||
return stream->Write(buf, len, writeLen);
|
||||
}
|
||||
%}
|
||||
|
|
@ -1,5 +1,11 @@
|
|||
%module csharp_exceptions
|
||||
|
||||
// throw is invalid in C++17 and later, only SWIG to use it
|
||||
#define TESTCASE_THROW1(T1) throw(T1)
|
||||
%{
|
||||
#define TESTCASE_THROW1(T1)
|
||||
%}
|
||||
|
||||
%include <exception.i>
|
||||
|
||||
%inline %{
|
||||
|
|
@ -36,25 +42,16 @@
|
|||
}
|
||||
|
||||
%inline %{
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
|
||||
#endif
|
||||
#if __GNUC__ >= 7
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated" // dynamic exception specifications are deprecated in C++11
|
||||
#endif
|
||||
|
||||
// %exception tests
|
||||
void ThrowByValue() { throw Ex("ThrowByValue"); }
|
||||
void ThrowByReference() { throw Ex("ThrowByReference"); }
|
||||
// %csnothrowexception
|
||||
void NoThrowException() { throw Ex("NoThrowException"); }
|
||||
// exception specifications
|
||||
void ExceptionSpecificationValue() throw(Ex) { throw Ex("ExceptionSpecificationValue"); }
|
||||
void ExceptionSpecificationReference() throw(Ex&) { throw Ex("ExceptionSpecificationReference"); }
|
||||
void ExceptionSpecificationString() throw(const char *) { throw "ExceptionSpecificationString"; }
|
||||
void ExceptionSpecificationInteger() throw(int) { throw 20; }
|
||||
void ExceptionSpecificationValue() TESTCASE_THROW1(Ex) { throw Ex("ExceptionSpecificationValue"); }
|
||||
void ExceptionSpecificationReference() TESTCASE_THROW1(Ex&) { throw Ex("ExceptionSpecificationReference"); }
|
||||
void ExceptionSpecificationString() TESTCASE_THROW1(const char *) { throw "ExceptionSpecificationString"; }
|
||||
void ExceptionSpecificationInteger() TESTCASE_THROW1(int) { throw 20; }
|
||||
%}
|
||||
|
||||
// test exceptions in the default typemaps
|
||||
|
|
@ -68,15 +65,15 @@ void NullValue(Ex e) {}
|
|||
// enums
|
||||
%inline %{
|
||||
enum TestEnum {TestEnumItem};
|
||||
void ExceptionSpecificationEnumValue() throw(TestEnum) { throw TestEnumItem; }
|
||||
void ExceptionSpecificationEnumReference() throw(TestEnum&) { throw TestEnumItem; }
|
||||
void ExceptionSpecificationEnumValue() TESTCASE_THROW1(TestEnum) { throw TestEnumItem; }
|
||||
void ExceptionSpecificationEnumReference() TESTCASE_THROW1(TestEnum&) { throw TestEnumItem; }
|
||||
%}
|
||||
|
||||
// std::string
|
||||
%include <std_string.i>
|
||||
%inline %{
|
||||
void ExceptionSpecificationStdStringValue() throw(std::string) { throw std::string("ExceptionSpecificationStdStringValue"); }
|
||||
void ExceptionSpecificationStdStringReference() throw(const std::string&) { throw std::string("ExceptionSpecificationStdStringReference"); }
|
||||
void ExceptionSpecificationStdStringValue() TESTCASE_THROW1(std::string) { throw std::string("ExceptionSpecificationStdStringValue"); }
|
||||
void ExceptionSpecificationStdStringReference() TESTCASE_THROW1(const std::string&) { throw std::string("ExceptionSpecificationStdStringReference"); }
|
||||
void NullStdStringValue(std::string s) {}
|
||||
void NullStdStringReference(std::string &s) {}
|
||||
%}
|
||||
|
|
@ -108,12 +105,8 @@ void MemoryLeakCheck() {
|
|||
%inline %{
|
||||
struct constructor {
|
||||
constructor(std::string s) {}
|
||||
constructor() throw(int) { throw 10; }
|
||||
constructor() TESTCASE_THROW1(int) { throw 10; }
|
||||
};
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
|
||||
#endif
|
||||
%}
|
||||
|
||||
// test exception pending in the csout typemaps
|
||||
|
|
@ -244,11 +237,3 @@ struct ThrowsClass {
|
|||
void InnerExceptionTest() { throw Ex("My InnerException message"); }
|
||||
%}
|
||||
|
||||
%{
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
|
||||
#endif
|
||||
#if __GNUC__ >= 7
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
%}
|
||||
|
|
|
|||
78
Examples/test-suite/csharp_lib_arrays_bool.i
Normal file
78
Examples/test-suite/csharp_lib_arrays_bool.i
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
%module csharp_lib_arrays_bool
|
||||
|
||||
%include "arrays_csharp.i"
|
||||
|
||||
%apply bool INPUT[] { bool* sourceArray }
|
||||
%apply bool OUTPUT[] { bool* targetArray }
|
||||
|
||||
%apply bool INOUT[] { bool* array1 }
|
||||
%apply bool INOUT[] { bool* array2 }
|
||||
|
||||
%inline %{
|
||||
#include <iostream>
|
||||
|
||||
/* copy the contents of the first array to the second */
|
||||
void myArrayCopyBool( bool* sourceArray, bool* targetArray, int nitems ) {
|
||||
int i;
|
||||
for ( i = 0; i < nitems; i++ ) {
|
||||
targetArray[ i ] = sourceArray[ i ];
|
||||
}
|
||||
}
|
||||
|
||||
/* swap the contents of the two arrays */
|
||||
void myArraySwapBool( bool* array1, bool* array2, int nitems ) {
|
||||
int i;
|
||||
bool temp;
|
||||
for ( i = 0; i < nitems; i++ ) {
|
||||
temp = array1[ i ];
|
||||
array1[ i ] = array2[ i ];
|
||||
array2[ i ] = temp;
|
||||
}
|
||||
}
|
||||
|
||||
bool checkBoolArrayCorrect( bool* sourceArray, int sourceArraySize ) {
|
||||
if( sourceArraySize != 8 ) {
|
||||
std::cout << "checkBoolArrayCorrect: Expected array with 8 elements" << std::endl;
|
||||
return false;
|
||||
}
|
||||
return sourceArray[0] == true &&
|
||||
sourceArray[1] == false &&
|
||||
sourceArray[2] == false &&
|
||||
sourceArray[3] == true &&
|
||||
sourceArray[4] == false &&
|
||||
sourceArray[5] == true &&
|
||||
sourceArray[6] == true &&
|
||||
sourceArray[7] == false;
|
||||
}
|
||||
%}
|
||||
|
||||
%clear bool* sourceArray;
|
||||
%clear bool* targetArray;
|
||||
|
||||
%clear bool* array1;
|
||||
%clear bool* array2;
|
||||
|
||||
// Below replicates the above array handling but this time using the pinned (fixed) array typemaps
|
||||
%csmethodmodifiers myArrayCopyUsingFixedArraysBool "public unsafe";
|
||||
%csmethodmodifiers myArraySwapUsingFixedArraysBool "public unsafe";
|
||||
|
||||
%apply bool FIXED[] { bool* sourceArray }
|
||||
%apply bool FIXED[] { bool* targetArray }
|
||||
|
||||
%inline %{
|
||||
void myArrayCopyUsingFixedArraysBool( bool *sourceArray, bool* targetArray, int nitems ) {
|
||||
myArrayCopyBool(sourceArray, targetArray, nitems);
|
||||
}
|
||||
%}
|
||||
|
||||
%apply bool FIXED[] { bool* array1 }
|
||||
%apply bool FIXED[] { bool* array2 }
|
||||
|
||||
%inline %{
|
||||
void myArraySwapUsingFixedArraysBool( bool* array1, bool* array2, int nitems ) {
|
||||
myArraySwapBool(array1, array2, nitems);
|
||||
}
|
||||
%}
|
||||
|
||||
|
||||
|
||||
|
|
@ -24,6 +24,12 @@ CPP_TEST_CASES = \
|
|||
d_nativepointers \
|
||||
exception_partial_info
|
||||
|
||||
CPP11_TEST_CASES = \
|
||||
cpp11_shared_ptr_const \
|
||||
cpp11_shared_ptr_nullptr_in_containers \
|
||||
cpp11_shared_ptr_overload \
|
||||
cpp11_shared_ptr_upcast \
|
||||
|
||||
include $(srcdir)/../common.mk
|
||||
|
||||
# Overridden variables here
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
* Base - Val(444.555)
|
||||
* Base - Ref(444.555)
|
||||
* Base - Ptr(444.555)
|
||||
* Base - ConstPtrRef(444.555)
|
||||
* Base - FullyOverloaded(int 10)
|
||||
* Base - FullyOverloaded(bool 1)
|
||||
* Base - SemiOverloaded(int -678)
|
||||
|
|
@ -28,6 +29,7 @@
|
|||
* Derived - Val(444.555)
|
||||
* Derived - Ref(444.555)
|
||||
* Derived - Ptr(444.555)
|
||||
* Derived - ConstPtrRef(444.555)
|
||||
* Derived - FullyOverloaded(int 10)
|
||||
* Derived - FullyOverloaded(bool 1)
|
||||
* Derived - SemiOverloaded(int -678)
|
||||
|
|
@ -38,6 +40,7 @@
|
|||
* DDerived - Val(444.555)
|
||||
* DDerived - Ref(444.555)
|
||||
* DDerived - Ptr(444.555)
|
||||
* DDerived - ConstPtrRef(444.555)
|
||||
* DDerived - FullyOverloaded(int 10)
|
||||
* DDerived - FullyOverloaded(bool True)
|
||||
* DDerived - SemiOverloaded(-678)
|
||||
|
|
@ -57,7 +60,7 @@ import director_classes.Derived;
|
|||
import director_classes.DoubleHolder;
|
||||
|
||||
void main() {
|
||||
if (PrintDebug) Stdout.formatln("------------ Start ------------ ");
|
||||
if (PrintDebug) Stdout.formatln("------------ Start ------------");
|
||||
|
||||
auto myCaller = new Caller();
|
||||
|
||||
|
|
@ -83,7 +86,7 @@ void main() {
|
|||
makeCalls(myCaller, myBase);
|
||||
}
|
||||
|
||||
if (PrintDebug) Stdout.formatln("------------ Finish ------------ ");
|
||||
if (PrintDebug) Stdout.formatln("------------ Finish ------------");
|
||||
}
|
||||
|
||||
void makeCalls(Caller myCaller, Base myBase) {
|
||||
|
|
@ -96,6 +99,7 @@ void makeCalls(Caller myCaller, Base myBase) {
|
|||
if (myCaller.ValCall(dh).val != dh.val) throw new Exception("[1] failed");
|
||||
if (myCaller.RefCall(dh).val != dh.val) throw new Exception("[2] failed");
|
||||
if (myCaller.PtrCall(dh).val != dh.val) throw new Exception("[3] failed");
|
||||
if (myCaller.ConstPtrRefCall(dh).val != dh.val) throw new Exception("[3] failed");
|
||||
|
||||
// Fully overloaded method test (all methods in base class are overloaded)
|
||||
if (myCaller.FullyOverloadedCall(10) != myBaseType ~ "::FullyOverloaded(int)") throw new Exception("[4] failed");
|
||||
|
|
@ -136,6 +140,11 @@ public class DDerived : Base {
|
|||
return x;
|
||||
}
|
||||
|
||||
public override DoubleHolder ConstPtrRef(DoubleHolder x) {
|
||||
if (PrintDebug) Stdout.formatln("DDerived - ConstPtrRef({0:d3})", x.val);
|
||||
return x;
|
||||
}
|
||||
|
||||
public override char[] FullyOverloaded(int x) {
|
||||
if (PrintDebug) Stdout.formatln("DDerived - FullyOverloaded(int {0})", x);
|
||||
return "DDerived::FullyOverloaded(int)";
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
* Base - Val(444.555)
|
||||
* Base - Ref(444.555)
|
||||
* Base - Ptr(444.555)
|
||||
* Base - ConstPtrRef(444.555)
|
||||
* Base - FullyOverloaded(int 10)
|
||||
* Base - FullyOverloaded(bool 1)
|
||||
* Base - SemiOverloaded(int -678)
|
||||
|
|
@ -28,6 +29,7 @@
|
|||
* Derived - Val(444.555)
|
||||
* Derived - Ref(444.555)
|
||||
* Derived - Ptr(444.555)
|
||||
* Derived - ConstPtrRef(444.555)
|
||||
* Derived - FullyOverloaded(int 10)
|
||||
* Derived - FullyOverloaded(bool 1)
|
||||
* Derived - SemiOverloaded(int -678)
|
||||
|
|
@ -38,6 +40,7 @@
|
|||
* DDerived - Val(444.555)
|
||||
* DDerived - Ref(444.555)
|
||||
* DDerived - Ptr(444.555)
|
||||
* DDerived - ConstPtrRef(444.555)
|
||||
* DDerived - FullyOverloaded(int 10)
|
||||
* DDerived - FullyOverloaded(bool true)
|
||||
* DDerived - SemiOverloaded(-678)
|
||||
|
|
@ -58,7 +61,7 @@ import director_classes.Derived;
|
|||
import director_classes.DoubleHolder;
|
||||
|
||||
void main() {
|
||||
if (PrintDebug) writeln("------------ Start ------------ ");
|
||||
if (PrintDebug) writeln("------------ Start ------------");
|
||||
|
||||
auto myCaller = new Caller();
|
||||
|
||||
|
|
@ -84,7 +87,7 @@ void main() {
|
|||
makeCalls(myCaller, myBase);
|
||||
}
|
||||
|
||||
if (PrintDebug) writeln("------------ Finish ------------ ");
|
||||
if (PrintDebug) writeln("------------ Finish ------------");
|
||||
}
|
||||
|
||||
void makeCalls(Caller myCaller, Base myBase) {
|
||||
|
|
@ -97,6 +100,7 @@ void makeCalls(Caller myCaller, Base myBase) {
|
|||
enforce(myCaller.ValCall(dh).val == dh.val, "[1] failed");
|
||||
enforce(myCaller.RefCall(dh).val == dh.val, "[2] failed");
|
||||
enforce(myCaller.PtrCall(dh).val == dh.val, "[3] failed");
|
||||
enforce(myCaller.ConstPtrRefCall(dh).val == dh.val, "[3] failed");
|
||||
|
||||
// Fully overloaded method test (all methods in base class are overloaded)
|
||||
enforce(myCaller.FullyOverloadedCall(10) == myBaseType ~ "::FullyOverloaded(int)", "[4] failed");
|
||||
|
|
@ -137,6 +141,11 @@ public class DDerived : Base {
|
|||
return x;
|
||||
}
|
||||
|
||||
public override DoubleHolder ConstPtrRef(DoubleHolder x) {
|
||||
if (PrintDebug) writefln("DDerived - ConstPtrRef(%s)", x.val);
|
||||
return x;
|
||||
}
|
||||
|
||||
public override string FullyOverloaded(int x) {
|
||||
if (PrintDebug) writefln("DDerived - FullyOverloaded(int %s)", x);
|
||||
return "DDerived::FullyOverloaded(int)";
|
||||
|
|
|
|||
114
Examples/test-suite/d/li_boost_shared_ptr_director_runme.2.d
Normal file
114
Examples/test-suite/d/li_boost_shared_ptr_director_runme.2.d
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
module li_boost_shared_ptr_director_runme;
|
||||
|
||||
import std.conv;
|
||||
import std.exception;
|
||||
import std.stdio;
|
||||
import std.string;
|
||||
import li_boost_shared_ptr_director.li_boost_shared_ptr_director;
|
||||
import li_boost_shared_ptr_director.Base;
|
||||
import li_boost_shared_ptr_director.C;
|
||||
|
||||
void check(int got, int expected) {
|
||||
enforce(got == expected, "Failed. got: " ~ to!string(got) ~ " Expected: " ~ to!string(expected));
|
||||
}
|
||||
|
||||
void main() {
|
||||
Derived a = new Derived(false);
|
||||
Derived b = new Derived(true);
|
||||
|
||||
check(call_ret_c_shared_ptr(a), 1);
|
||||
check(call_ret_c_shared_ptr(b), -1);
|
||||
check(call_ret_c_by_value(a), 1);
|
||||
|
||||
check(call_ret_c_shared_ptr(a), 1);
|
||||
check(call_ret_c_shared_ptr(b), -1);
|
||||
check(call_ret_c_by_value(a), 1);
|
||||
|
||||
check(call_take_c_by_value(a), 5);
|
||||
check(call_take_c_by_ref(a), 6);
|
||||
check(call_take_c_by_pointer(a), 7);
|
||||
check(call_take_c_by_pointer_ref(a), 8);
|
||||
check(call_take_c_shared_ptr_by_value(a), 9);
|
||||
check(call_take_c_shared_ptr_by_ref(a), 10);
|
||||
check(call_take_c_shared_ptr_by_pointer(a), 11);
|
||||
check(call_take_c_shared_ptr_by_pointer_ref(a), 12);
|
||||
|
||||
check(call_take_c_by_pointer_with_null(a), -2);
|
||||
check(call_take_c_by_pointer_ref_with_null(a), -3);
|
||||
check(call_take_c_shared_ptr_by_value_with_null(a), -4);
|
||||
check(call_take_c_shared_ptr_by_ref_with_null(a), -5);
|
||||
check(call_take_c_shared_ptr_by_pointer_with_null(a), -6);
|
||||
check(call_take_c_shared_ptr_by_pointer_ref_with_null(a), -7);
|
||||
}
|
||||
|
||||
public class Derived : Base {
|
||||
|
||||
private bool return_none;
|
||||
|
||||
public this(bool flag) {
|
||||
super();
|
||||
this.return_none = flag;
|
||||
}
|
||||
|
||||
public override C ret_c_shared_ptr() {
|
||||
if (this.return_none)
|
||||
return null;
|
||||
else
|
||||
return new C();
|
||||
}
|
||||
|
||||
public override C ret_c_by_value() {
|
||||
return new C();
|
||||
}
|
||||
|
||||
public override int take_c_by_value(C c) {
|
||||
return c.get_m();
|
||||
}
|
||||
|
||||
public override int take_c_by_ref(C c) {
|
||||
return c.get_m();
|
||||
}
|
||||
|
||||
public override int take_c_by_pointer(C c) {
|
||||
if (c !is null)
|
||||
return c.get_m();
|
||||
else
|
||||
return -2;
|
||||
}
|
||||
|
||||
public override int take_c_by_pointer_ref(C c) {
|
||||
if (c !is null)
|
||||
return c.get_m();
|
||||
else
|
||||
return -3;
|
||||
}
|
||||
|
||||
public override int take_c_shared_ptr_by_value(C c) {
|
||||
if (c !is null)
|
||||
return c.get_m();
|
||||
else
|
||||
return -4;
|
||||
}
|
||||
|
||||
public override int take_c_shared_ptr_by_ref(C c) {
|
||||
if (c !is null)
|
||||
return c.get_m();
|
||||
else
|
||||
return -5;
|
||||
}
|
||||
|
||||
public override int take_c_shared_ptr_by_pointer(C c) {
|
||||
if (c !is null)
|
||||
return c.get_m();
|
||||
else
|
||||
return -6;
|
||||
}
|
||||
|
||||
public override int take_c_shared_ptr_by_pointer_ref(C c) {
|
||||
if (c !is null)
|
||||
return c.get_m();
|
||||
else
|
||||
return -7;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -36,7 +36,7 @@ void main() {
|
|||
static assert(is(char[] == typeof(CONST_STRING2())));
|
||||
|
||||
static assert(is(int == typeof(INT_AND_BOOL())));
|
||||
// static assert(is(int == typeof(INT_AND_CHAR())));
|
||||
static assert(is(int == typeof(INT_AND_CHAR())));
|
||||
static assert(is(int == typeof(INT_AND_INT())));
|
||||
static assert(is(uint == typeof(INT_AND_UINT())));
|
||||
static assert(is(c_long == typeof(INT_AND_LONG())));
|
||||
|
|
@ -61,4 +61,7 @@ void main() {
|
|||
static assert(is(int == typeof(EXPR_LAND())));
|
||||
static assert(is(int == typeof(EXPR_LOR())));
|
||||
static assert(is(double == typeof(EXPR_CONDITIONAL())));
|
||||
static assert(is(double == typeof(EXPR_MIXED1())));
|
||||
static assert(is(int == typeof(EXPR_WCHAR_MAX())));
|
||||
static assert(is(int == typeof(EXPR_WCHAR_MIN())));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ void main() {
|
|||
static assert(is(string == typeof(CONST_STRING2())));
|
||||
|
||||
static assert(is(int == typeof(INT_AND_BOOL())));
|
||||
// static assert(is(int == typeof(INT_AND_CHAR())));
|
||||
static assert(is(int == typeof(INT_AND_CHAR())));
|
||||
static assert(is(int == typeof(INT_AND_INT())));
|
||||
static assert(is(uint == typeof(INT_AND_UINT())));
|
||||
static assert(is(c_long == typeof(INT_AND_LONG())));
|
||||
|
|
@ -61,4 +61,7 @@ void main() {
|
|||
static assert(is(int == typeof(EXPR_LAND())));
|
||||
static assert(is(int == typeof(EXPR_LOR())));
|
||||
static assert(is(double == typeof(EXPR_CONDITIONAL())));
|
||||
static assert(is(double == typeof(EXPR_MIXED1())));
|
||||
static assert(is(int == typeof(EXPR_WCHAR_MAX())));
|
||||
static assert(is(int == typeof(EXPR_WCHAR_MIN())));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ void main() {
|
|||
static assert(is(char[] == typeof(CONST_STRING2())));
|
||||
|
||||
static assert(is(int == typeof(INT_AND_BOOL())));
|
||||
// static assert(is(int == typeof(INT_AND_CHAR())));
|
||||
static assert(is(int == typeof(INT_AND_CHAR())));
|
||||
static assert(is(int == typeof(INT_AND_INT())));
|
||||
static assert(is(uint == typeof(INT_AND_UINT())));
|
||||
static assert(is(c_long == typeof(INT_AND_LONG())));
|
||||
|
|
@ -60,4 +60,7 @@ void main() {
|
|||
static assert(is(bool == typeof(EXPR_LAND())));
|
||||
static assert(is(bool == typeof(EXPR_LOR())));
|
||||
static assert(is(double == typeof(EXPR_CONDITIONAL())));
|
||||
static assert(is(double == typeof(EXPR_MIXED1())));
|
||||
static assert(is(int == typeof(EXPR_WCHAR_MAX())));
|
||||
static assert(is(int == typeof(EXPR_WCHAR_MIN())));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ void main() {
|
|||
static assert(is(string == typeof(CONST_STRING2())));
|
||||
|
||||
static assert(is(int == typeof(INT_AND_BOOL())));
|
||||
// static assert(is(int == typeof(INT_AND_CHAR())));
|
||||
static assert(is(int == typeof(INT_AND_CHAR())));
|
||||
static assert(is(int == typeof(INT_AND_INT())));
|
||||
static assert(is(uint == typeof(INT_AND_UINT())));
|
||||
static assert(is(c_long == typeof(INT_AND_LONG())));
|
||||
|
|
@ -60,4 +60,7 @@ void main() {
|
|||
static assert(is(bool == typeof(EXPR_LAND())));
|
||||
static assert(is(bool == typeof(EXPR_LOR())));
|
||||
static assert(is(double == typeof(EXPR_CONDITIONAL())));
|
||||
static assert(is(double == typeof(EXPR_MIXED1())));
|
||||
static assert(is(int == typeof(EXPR_WCHAR_MAX())));
|
||||
static assert(is(int == typeof(EXPR_WCHAR_MIN())));
|
||||
}
|
||||
|
|
|
|||
34
Examples/test-suite/default_arg_expressions.i
Normal file
34
Examples/test-suite/default_arg_expressions.i
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
%module default_arg_expressions
|
||||
|
||||
#ifdef SWIGOCAML
|
||||
%warnfilter(SWIGWARN_PARSE_KEYWORD) val;
|
||||
#endif
|
||||
|
||||
%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) ptr;
|
||||
%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) UsdGeomTokensPtr;
|
||||
%immutable UsdGeomTokens;
|
||||
|
||||
%inline %{
|
||||
struct Numbers {
|
||||
int val;
|
||||
int *ptr;
|
||||
Numbers() : val(), ptr(&val) {}
|
||||
};
|
||||
struct TfToken {
|
||||
Numbers val;
|
||||
Numbers *ptr;
|
||||
TfToken() : val(), ptr(&val) {}
|
||||
};
|
||||
struct Tokens {
|
||||
const TfToken face;
|
||||
const TfToken *pface;
|
||||
Tokens() : face(), pface(&face) {}
|
||||
};
|
||||
static Tokens UsdGeomTokens;
|
||||
static Tokens *UsdGeomTokensPtr = &UsdGeomTokens;
|
||||
void CreateMaterialBindSubset1(const Tokens &elementType = UsdGeomTokens) {}
|
||||
void CreateMaterialBindSubset2(int num = UsdGeomTokensPtr->pface->val.val) {}
|
||||
void CreateMaterialBindSubset3(int num = UsdGeomTokensPtr->pface->ptr->val) {}
|
||||
void CreateMaterialBindSubset4(int num = UsdGeomTokensPtr->face.val.val) {}
|
||||
//void CreateMaterialBindSubset5(int num = UsdGeomTokens.face.val.val) {}
|
||||
%}
|
||||
|
|
@ -2,15 +2,22 @@
|
|||
|
||||
%module default_args
|
||||
|
||||
#ifdef SWIGOCAML
|
||||
%warnfilter(SWIGWARN_PARSE_KEYWORD) val;
|
||||
#endif
|
||||
|
||||
%{
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
|
||||
#pragma warning(disable: 4146) // unary minus operator applied to unsigned type, result still unsigned
|
||||
#endif
|
||||
#if __GNUC__ >= 7
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated" // dynamic exception specifications are deprecated in C++11
|
||||
#endif
|
||||
%}
|
||||
|
||||
// throw is invalid in C++17 and later, only SWIG to use it
|
||||
#define TESTCASE_THROW1(T1) throw(T1)
|
||||
#define TESTCASE_THROW2(T1, T2) throw(T1, T2)
|
||||
%{
|
||||
#define TESTCASE_THROW1(T1)
|
||||
#define TESTCASE_THROW2(T1, T2)
|
||||
%}
|
||||
|
||||
%include <std_string.i>
|
||||
|
|
@ -28,6 +35,13 @@
|
|||
int value_perm(int first, int mode = 0640 | 0004) { return mode; }
|
||||
int value_m01(int first, int val = -01) { return val; }
|
||||
bool booltest2(bool x = 0 | 1) { return x; }
|
||||
int max_32bit_int1(int a = 0x7FFFFFFF) { return a; }
|
||||
int max_32bit_int2(int a = 2147483647) { return a; }
|
||||
int min_32bit_int1(int a = -0x80000000) { return a; }
|
||||
long long too_big_32bit_int1(long long a = 0x80000000) { return a; }
|
||||
long long too_big_32bit_int2(long long a = 2147483648LL) { return a; }
|
||||
long long too_small_32bit_int1(long long a = -0x80000001) { return a; }
|
||||
long long too_small_32bit_int2(long long a = -2147483649LL) { return a; }
|
||||
};
|
||||
|
||||
void doublevalue1(int first, double num = 0.0e-1) {}
|
||||
|
|
@ -196,18 +210,18 @@
|
|||
|
||||
// Default parameters with exception specifications
|
||||
%inline %{
|
||||
void exceptionspec(int a = -1) throw (int, const char*) {
|
||||
void exceptionspec(int a = -1) TESTCASE_THROW2(int, const char*) {
|
||||
if (a == -1)
|
||||
throw "ciao";
|
||||
else
|
||||
throw a;
|
||||
}
|
||||
struct Except {
|
||||
Except(bool throwException, int a = -1) throw (int) {
|
||||
Except(bool throwException, int a = -1) TESTCASE_THROW1(int) {
|
||||
if (throwException)
|
||||
throw a;
|
||||
}
|
||||
void exspec(int a = 0) throw (int, const char*) {
|
||||
void exspec(int a = 0) TESTCASE_THROW2(int, const char*) {
|
||||
::exceptionspec(a);
|
||||
}
|
||||
};
|
||||
|
|
@ -319,11 +333,3 @@ struct CDA {
|
|||
};
|
||||
%}
|
||||
|
||||
%{
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
|
||||
#endif
|
||||
#if __GNUC__ >= 7
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
%}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,13 @@
|
|||
%module default_args_c
|
||||
|
||||
%{
|
||||
#if defined(__clang__)
|
||||
#pragma clang diagnostic push
|
||||
// Suppress: use of logical '||' with constant operand
|
||||
#pragma clang diagnostic ignored "-Wconstant-logical-operand"
|
||||
#endif
|
||||
%}
|
||||
|
||||
/* Default arguments for C code */
|
||||
int foo1(int x = 42 || 3);
|
||||
int foo43(int x = 42 | 3);
|
||||
|
|
@ -12,3 +20,34 @@ int foo43(int x) {
|
|||
return x;
|
||||
}
|
||||
%}
|
||||
|
||||
%inline %{
|
||||
struct FooStruct {
|
||||
int num;
|
||||
};
|
||||
%}
|
||||
%extend FooStruct {
|
||||
void no_arg() {}
|
||||
void one_req(int *required) {}
|
||||
void one_opt(int *optional = NULL) {}
|
||||
void two_arg(int *required, int *optional = NULL) {}
|
||||
}
|
||||
|
||||
%inline %{
|
||||
struct StaticStruct {
|
||||
int snum;
|
||||
};
|
||||
%}
|
||||
%extend StaticStruct {
|
||||
static void no_arg() {}
|
||||
static void one_req(int *required) {}
|
||||
static void one_opt(int *optional = NULL) {}
|
||||
static void two_arg(int *required, int *optional = NULL) {}
|
||||
}
|
||||
|
||||
%{
|
||||
void global_opts1(int *optional) {}
|
||||
void global_opts2(int *required, int *optional) {}
|
||||
%}
|
||||
void global_opts1(int *optional = NULL) {}
|
||||
void global_opts2(int *required, int *optional = NULL) {}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,9 @@
|
|||
%module derived_byvalue
|
||||
|
||||
#ifdef SWIGOCAML
|
||||
%warnfilter(SWIGWARN_PARSE_KEYWORD) method;
|
||||
#endif
|
||||
|
||||
%inline %{
|
||||
|
||||
struct Foo {
|
||||
|
|
|
|||
61
Examples/test-suite/destructor_methodmodifiers.i
Normal file
61
Examples/test-suite/destructor_methodmodifiers.i
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
%module destructor_methodmodifiers
|
||||
|
||||
// This test changes the proxy classes so that they cannot be inherited from in the target language
|
||||
// Previously the %csmethodmodifiers, %dmethodmodifiers, %javamethodmodifiers on destructors were ignored
|
||||
// Now they can control the dispose/Dispose/delete method modifiers
|
||||
|
||||
#if defined(SWIGCSHARP)
|
||||
|
||||
// remove all use of protected and virtual keywords
|
||||
%typemap(csclassmodifiers) NotForDeriving1, NotForDeriving2 "public sealed class"
|
||||
%csmethodmodifiers NotForDeriving1::~NotForDeriving1 "public /*not virtual nor override*/";
|
||||
%csmethodmodifiers NotForDeriving2::~NotForDeriving2 "public /*not virtual nor override*/";
|
||||
|
||||
// remove protected keyword to remove compiler warning
|
||||
%typemap(csbody) NotForDeriving1, NotForDeriving2 %{
|
||||
private global::System.Runtime.InteropServices.HandleRef swigCPtr;
|
||||
private /*protected*/ bool swigCMemOwn;
|
||||
|
||||
internal $csclassname(global::System.IntPtr cPtr, bool cMemoryOwn) {
|
||||
swigCMemOwn = cMemoryOwn;
|
||||
swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
|
||||
}
|
||||
|
||||
internal static global::System.Runtime.InteropServices.HandleRef getCPtr($csclassname obj) {
|
||||
return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
|
||||
}
|
||||
%}
|
||||
|
||||
#elif defined(SWIGD)
|
||||
|
||||
%typemap(dclassmodifiers) NotForDeriving1, NotForDeriving2 "final class"
|
||||
%dmethodmodifiers NotForDeriving1::~NotForDeriving1 "public final";
|
||||
%dmethodmodifiers NotForDeriving2::~NotForDeriving2 "public final";
|
||||
|
||||
#elif defined(SWIGJAVA)
|
||||
|
||||
%typemap(javaclassmodifiers) NotForDeriving1, NotForDeriving2 "public final class"
|
||||
%javamethodmodifiers NotForDeriving1::~NotForDeriving1 "public synchronized final";
|
||||
%javamethodmodifiers NotForDeriving2::~NotForDeriving2 "public synchronized final";
|
||||
|
||||
#endif
|
||||
|
||||
%inline %{
|
||||
//#include <iostream>
|
||||
struct NotForDeriving1 {
|
||||
void notvirtual() {}
|
||||
~NotForDeriving1() {
|
||||
// std::cout << "~NotForDeriving1 called" << std::endl;
|
||||
}
|
||||
};
|
||||
struct NotForDeriving2 {
|
||||
void notvirtual() {}
|
||||
#if defined(SWIG)
|
||||
%extend {
|
||||
~NotForDeriving2() {
|
||||
// std::cout << "~NotForDeriving2 called" << std::endl;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
};
|
||||
%}
|
||||
|
|
@ -1,6 +1,11 @@
|
|||
%module(directors="1") director_basic
|
||||
|
||||
#ifdef SWIGOCAML
|
||||
%warnfilter(SWIGWARN_PARSE_KEYWORD) method;
|
||||
#endif
|
||||
|
||||
%warnfilter(SWIGWARN_TYPEMAP_THREAD_UNSAFE,SWIGWARN_TYPEMAP_DIRECTOROUT_PTR) MyClass::pmethod;
|
||||
%warnfilter(SWIGWARN_TYPEMAP_DIRECTOROUT_PTR) ConstPtrClass::getConstPtr;
|
||||
|
||||
%{
|
||||
#include <string>
|
||||
|
|
@ -65,6 +70,14 @@
|
|||
|
||||
%}
|
||||
|
||||
%typemap(cscode) MyClass %{
|
||||
public void testSwigDerivedClassHasMethod() {
|
||||
if (SwigDerivedClassHasMethod("nonVirtual", swigMethodTypes3))
|
||||
throw new global::System.Exception("non-overriding non-virtual method would be when connecting director");
|
||||
if (SwigDerivedClassHasMethod("nonOverride", swigMethodTypes4))
|
||||
throw new global::System.Exception("non-overriding virtual method would be when connecting director");
|
||||
}
|
||||
%}
|
||||
|
||||
%feature("director") MyClass;
|
||||
|
||||
|
|
@ -121,6 +134,29 @@ public:
|
|||
static Bar * call_pmethod(MyClass *myclass, Bar *b) {
|
||||
return myclass->pmethod(b);
|
||||
}
|
||||
|
||||
virtual int nonVirtual()
|
||||
{
|
||||
return 100;
|
||||
}
|
||||
|
||||
virtual int nonOverride()
|
||||
{
|
||||
return 101;
|
||||
}
|
||||
|
||||
static int call_nonVirtual(MyClass *myclass)
|
||||
{
|
||||
return myclass->nonVirtual();
|
||||
}
|
||||
|
||||
static int call_nonOverride(MyClass *myclass)
|
||||
{
|
||||
return myclass->nonOverride();
|
||||
}
|
||||
|
||||
// Collisions with generated method names
|
||||
virtual void Connect() { }
|
||||
};
|
||||
|
||||
template<class T>
|
||||
|
|
@ -139,7 +175,19 @@ public:
|
|||
}
|
||||
|
||||
};
|
||||
|
||||
%}
|
||||
%}
|
||||
|
||||
%template(MyClassT_i) MyClassT<int>;
|
||||
|
||||
%feature("director") ConstPtrClass;
|
||||
|
||||
%inline %{
|
||||
|
||||
class ConstPtrClass {
|
||||
public:
|
||||
virtual ~ConstPtrClass() {}
|
||||
virtual int *const getConstPtr() = 0;
|
||||
};
|
||||
|
||||
%}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,11 @@
|
|||
|
||||
%warnfilter(SWIGWARN_TYPEMAP_THREAD_UNSAFE,SWIGWARN_TYPEMAP_DIRECTOROUT_PTR) Base::Ref;
|
||||
%warnfilter(SWIGWARN_TYPEMAP_THREAD_UNSAFE,SWIGWARN_TYPEMAP_DIRECTOROUT_PTR) Base::Ptr;
|
||||
%warnfilter(SWIGWARN_TYPEMAP_THREAD_UNSAFE,SWIGWARN_TYPEMAP_DIRECTOROUT_PTR) Base::ConstPtrRef;
|
||||
|
||||
#ifdef SWIGOCAML
|
||||
%warnfilter(SWIGWARN_PARSE_KEYWORD) val;
|
||||
#endif
|
||||
|
||||
%module(directors="1") director_classes
|
||||
|
||||
|
|
@ -43,6 +48,7 @@ public:
|
|||
virtual DoubleHolder Val(DoubleHolder x) { if (PrintDebug) std::cout << "Base - Val(" << x.val << ")" << std::endl; return x; }
|
||||
virtual DoubleHolder& Ref(DoubleHolder& x) { if (PrintDebug) std::cout << "Base - Ref(" << x.val << ")" << std::endl; return x; }
|
||||
virtual DoubleHolder* Ptr(DoubleHolder* x) { if (PrintDebug) std::cout << "Base - Ptr(" << x->val << ")" << std::endl; return x; }
|
||||
virtual DoubleHolder *const& ConstPtrRef(DoubleHolder *const& cprx) { if (PrintDebug) std::cout << "Base - ConstPtrRef(" << cprx->val << ")" << std::endl; return cprx; }
|
||||
|
||||
virtual std::string FullyOverloaded(int x) { if (PrintDebug) std::cout << "Base - FullyOverloaded(int " << x << ")" << std::endl; return "Base::FullyOverloaded(int)"; }
|
||||
virtual std::string FullyOverloaded(bool x) { if (PrintDebug) std::cout << "Base - FullyOverloaded(bool " << x << ")" << std::endl; return "Base::FullyOverloaded(bool)"; }
|
||||
|
|
@ -68,6 +74,7 @@ public:
|
|||
virtual DoubleHolder Val(DoubleHolder x) { if (PrintDebug) std::cout << "Derived - Val(" << x.val << ")" << std::endl; return x; }
|
||||
virtual DoubleHolder& Ref(DoubleHolder& x) { if (PrintDebug) std::cout << "Derived - Ref(" << x.val << ")" << std::endl; return x; }
|
||||
virtual DoubleHolder* Ptr(DoubleHolder* x) { if (PrintDebug) std::cout << "Derived - Ptr(" << x->val << ")" << std::endl; return x; }
|
||||
virtual DoubleHolder *const& ConstPtrRef(DoubleHolder *const& cprx) { if (PrintDebug) std::cout << "Derived - ConstPtrRef(" << cprx->val << ")" << std::endl; return cprx; }
|
||||
|
||||
virtual std::string FullyOverloaded(int x) { if (PrintDebug) std::cout << "Derived - FullyOverloaded(int " << x << ")" << std::endl; return "Derived::FullyOverloaded(int)"; }
|
||||
virtual std::string FullyOverloaded(bool x) { if (PrintDebug) std::cout << "Derived - FullyOverloaded(bool " << x << ")" << std::endl; return "Derived::FullyOverloaded(bool)"; }
|
||||
|
|
@ -99,6 +106,7 @@ public:
|
|||
DoubleHolder ValCall(DoubleHolder x) { return m_base->Val(x); }
|
||||
DoubleHolder& RefCall(DoubleHolder& x) { return m_base->Ref(x); }
|
||||
DoubleHolder* PtrCall(DoubleHolder* x) { return m_base->Ptr(x); }
|
||||
DoubleHolder *const& ConstPtrRefCall(DoubleHolder *const& cprx) { return m_base->ConstPtrRef(cprx); }
|
||||
std::string FullyOverloadedCall(int x) { return m_base->FullyOverloaded(x); }
|
||||
std::string FullyOverloadedCall(bool x) { return m_base->FullyOverloaded(x); }
|
||||
std::string SemiOverloadedCall(int x) { return m_base->SemiOverloaded(x); }
|
||||
|
|
|
|||
23
Examples/test-suite/director_comparison_operators.i
Normal file
23
Examples/test-suite/director_comparison_operators.i
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
%module(directors="1") director_comparison_operators
|
||||
|
||||
%include "std_string.i"
|
||||
%feature("director");
|
||||
|
||||
#if !defined(SWIGLUA) && !defined(SWIGR)
|
||||
%rename(EqualEqual) operator ==;
|
||||
%rename(NotEqual) operator !=;
|
||||
%rename(LessThanEqual) operator <=;
|
||||
%rename(GreaterThanEqual) operator >=;
|
||||
#endif
|
||||
|
||||
%inline %{
|
||||
class Foo {
|
||||
public:
|
||||
virtual ~Foo() { }
|
||||
virtual bool operator==(const Foo&) const = 0;
|
||||
virtual bool operator>=(const Foo&) const = 0;
|
||||
virtual bool operator<=(const Foo&) const = 0;
|
||||
virtual bool operator!=(const Foo&) const = 0;
|
||||
virtual std::string test(const char *foo="a=1,b=2") { return foo; }
|
||||
};
|
||||
%}
|
||||
35
Examples/test-suite/director_conversion_operators.i
Normal file
35
Examples/test-suite/director_conversion_operators.i
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
%module(directors="1") director_conversion_operators
|
||||
|
||||
%feature("director");
|
||||
|
||||
%warnfilter(SWIGWARN_TYPEMAP_DIRECTOROUT_PTR) Bar;
|
||||
|
||||
%rename(toFoo) Bar::operator Foo();
|
||||
%rename(toFooPtr) Bar::operator Foo *();
|
||||
%rename(toFooRef) Bar::operator Foo &();
|
||||
%rename(toFooPtrRef) Bar::operator Foo *&();
|
||||
|
||||
%rename(toOtherFoo) Bar::operator OtherFoo();
|
||||
%rename(toOtherFooPtr) Bar::operator OtherFoo *();
|
||||
%rename(toOtherFooRef) Bar::operator OtherFoo &();
|
||||
%rename(toOtherFooPtrRef) Bar::operator OtherFoo *&();
|
||||
|
||||
%inline %{
|
||||
struct Foo {
|
||||
};
|
||||
struct OtherFoo {
|
||||
};
|
||||
struct Bar {
|
||||
Foo myFoo;
|
||||
Foo *myFooPtr;
|
||||
virtual ~Bar() { }
|
||||
virtual operator Foo () { return Foo(); }
|
||||
virtual operator Foo *() { return &myFoo; }
|
||||
virtual operator Foo &() { return myFoo; }
|
||||
virtual operator Foo *&() { return myFooPtr; }
|
||||
virtual operator OtherFoo () = 0;
|
||||
virtual operator OtherFoo *() = 0;
|
||||
virtual operator OtherFoo &() = 0;
|
||||
virtual operator OtherFoo *&() = 0;
|
||||
};
|
||||
%}
|
||||
|
|
@ -3,31 +3,17 @@
|
|||
%warnfilter(SWIGWARN_TYPEMAP_DIRECTOROUT_PTR) return_const_char_star;
|
||||
|
||||
%{
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
|
||||
#endif
|
||||
#if __GNUC__ >= 7
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated" // dynamic exception specifications are deprecated in C++11
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
|
||||
|
||||
// define dummy director exception classes to prevent spurious errors
|
||||
// in target languages that do not support directors.
|
||||
|
||||
#ifndef SWIG_DIRECTORS
|
||||
namespace Swig {
|
||||
class DirectorException {};
|
||||
class DirectorMethodException: public Swig::DirectorException {};
|
||||
class DirectorException {};
|
||||
class DirectorMethodException: public Swig::DirectorException {};
|
||||
}
|
||||
#ifndef SWIG_fail
|
||||
#define SWIG_fail
|
||||
#endif
|
||||
#endif /* !SWIG_DIRECTORS */
|
||||
|
||||
%}
|
||||
|
||||
%include "std_string.i"
|
||||
|
|
@ -41,8 +27,8 @@ class DirectorMethodException: public Swig::DirectorException {};
|
|||
}
|
||||
|
||||
%exception {
|
||||
try { $action }
|
||||
catch (Swig::DirectorException &) { SWIG_fail; }
|
||||
try { $action }
|
||||
catch (Swig::DirectorException &) { SWIG_fail; }
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -56,8 +42,8 @@ class DirectorMethodException: public Swig::DirectorException {};
|
|||
}
|
||||
|
||||
%exception {
|
||||
try { $action }
|
||||
catch (Swig::DirectorException &) { SWIG_fail; }
|
||||
try { $action }
|
||||
catch (Swig::DirectorException &) { SWIG_fail; }
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -75,12 +61,12 @@ class DirectorMethodException: public Swig::DirectorException {};
|
|||
// Change back to old 2.0 default behavior
|
||||
|
||||
%feature("director:except") {
|
||||
jthrowable $error = jenv->ExceptionOccurred();
|
||||
if ($error) {
|
||||
// Dont clear exception, still be active when return to java execution
|
||||
// Essentially ignore exception occurred -- old behavior.
|
||||
return $null;
|
||||
}
|
||||
jthrowable $error = jenv->ExceptionOccurred();
|
||||
if ($error) {
|
||||
// Dont clear exception, still be active when return to java execution
|
||||
// Essentially ignore exception occurred -- old behavior.
|
||||
return $null;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -129,6 +115,18 @@ Foo *launder(Foo *f) {
|
|||
%feature("director") Bar;
|
||||
%feature("director") ReturnAllTypes;
|
||||
|
||||
%{
|
||||
// throw is deprecated in C++11 and invalid in C++17 and later
|
||||
#if defined(__cplusplus) && __cplusplus >= 201103L
|
||||
#define throw(TYPE1, TYPE2, TYPE3)
|
||||
#else
|
||||
#define throw(TYPE1, TYPE2, TYPE3) throw(TYPE1, TYPE2, TYPE3)
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
|
||||
#endif
|
||||
#endif
|
||||
%}
|
||||
|
||||
%inline %{
|
||||
struct Exception1
|
||||
{
|
||||
|
|
@ -141,16 +139,15 @@ Foo *launder(Foo *f) {
|
|||
class Base
|
||||
{
|
||||
public:
|
||||
virtual ~Base() throw () {}
|
||||
virtual ~Base() {}
|
||||
};
|
||||
|
||||
|
||||
class Bar : public Base
|
||||
{
|
||||
public:
|
||||
virtual std::string ping() throw (Exception1, Exception2&) { return "Bar::ping()"; }
|
||||
virtual std::string pong() throw (Unknown1, int, Unknown2&) { return "Bar::pong();" + ping(); }
|
||||
virtual std::string pang() throw () { return "Bar::pang()"; }
|
||||
virtual std::string ping() throw(Exception1, Exception2&, double) { return "Bar::ping()"; }
|
||||
virtual std::string pong() throw(Unknown1, int, Unknown2&) { return "Bar::pong();" + ping(); }
|
||||
};
|
||||
|
||||
// Class to allow regression testing SWIG/PHP not checking if an exception
|
||||
|
|
|
|||
25
Examples/test-suite/director_exception_catches.i
Normal file
25
Examples/test-suite/director_exception_catches.i
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
%module(directors="1") director_exception_catches
|
||||
|
||||
%include <std_string.i>
|
||||
%feature("director") BaseClass;
|
||||
|
||||
%{
|
||||
// define dummy director exception classes to prevent spurious errors
|
||||
// in target languages that do not support directors.
|
||||
|
||||
#ifndef SWIG_DIRECTORS
|
||||
namespace Swig {
|
||||
class DirectorException {};
|
||||
}
|
||||
#endif /* !SWIG_DIRECTORS */
|
||||
%}
|
||||
|
||||
%catches(Swig::DirectorException) BaseClass::call_description;
|
||||
|
||||
%inline %{
|
||||
struct BaseClass {
|
||||
virtual std::string description() const = 0;
|
||||
static std::string call_description(BaseClass& bc) { return bc.description(); }
|
||||
virtual ~BaseClass() {}
|
||||
};
|
||||
%}
|
||||
28
Examples/test-suite/director_exception_nothrow.i
Normal file
28
Examples/test-suite/director_exception_nothrow.i
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
%module(directors="1") director_exception_nothrow
|
||||
|
||||
%include "std_string.i"
|
||||
|
||||
%feature("director") Bar;
|
||||
|
||||
%{
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
|
||||
#endif
|
||||
%}
|
||||
|
||||
%inline %{
|
||||
#include <string>
|
||||
|
||||
class Base
|
||||
{
|
||||
public:
|
||||
virtual ~Base() throw() {}
|
||||
};
|
||||
|
||||
|
||||
class Bar : public Base
|
||||
{
|
||||
public:
|
||||
virtual std::string pang() throw() { return "Bar::pang()"; }
|
||||
};
|
||||
%}
|
||||
|
|
@ -1,5 +1,9 @@
|
|||
%module(directors="1") director_overload
|
||||
|
||||
#ifdef SWIGOCAML
|
||||
%warnfilter(SWIGWARN_PARSE_KEYWORD) method;
|
||||
#endif
|
||||
|
||||
%feature("director");
|
||||
|
||||
#ifdef SWIGPYTHON
|
||||
|
|
@ -43,5 +47,14 @@ public:
|
|||
virtual void notover(int *p) const {}
|
||||
};
|
||||
|
||||
%}
|
||||
class OverloadedGetSet
|
||||
{
|
||||
int v;
|
||||
public:
|
||||
OverloadedGetSet() : v(42) { }
|
||||
virtual ~OverloadedGetSet() { }
|
||||
virtual int rw() const { return v; }
|
||||
virtual void rw(int new_v) { v = new_v; }
|
||||
};
|
||||
|
||||
%}
|
||||
|
|
|
|||
|
|
@ -14,11 +14,15 @@ struct OverloadDerived1 : OverloadBase {
|
|||
virtual void nnn(int vvv) {}
|
||||
#if defined(__SUNPRO_CC)
|
||||
virtual void nnn() {}
|
||||
#elif defined(SWIGPHP) // FIXME: Hack to stop director_overload2 failing for PHP8
|
||||
virtual void nnn() {}
|
||||
#endif
|
||||
};
|
||||
struct OverloadDerived2 : OverloadBase {
|
||||
#if defined(__SUNPRO_CC)
|
||||
virtual void nnn(int vvv) {}
|
||||
#elif defined(SWIGPHP) // FIXME: Hack to stop director_overload2 failing for PHP8
|
||||
virtual void nnn(int vvv) {}
|
||||
#endif
|
||||
virtual void nnn() {}
|
||||
};
|
||||
|
|
|
|||
72
Examples/test-suite/director_ownership.i
Normal file
72
Examples/test-suite/director_ownership.i
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
%module(directors="1") director_ownership
|
||||
|
||||
// Github issue #1184
|
||||
|
||||
%include "std_string.i"
|
||||
|
||||
%feature("director") example::ContentBase;
|
||||
%feature("director") example::ContentDerived;
|
||||
|
||||
%newobject example::make_content;
|
||||
|
||||
%inline %{
|
||||
#include <string>
|
||||
|
||||
namespace example
|
||||
{
|
||||
|
||||
class ContentBase
|
||||
{
|
||||
public:
|
||||
ContentBase() {}
|
||||
virtual ~ContentBase() {}
|
||||
virtual std::string get_name() const = 0;
|
||||
};
|
||||
|
||||
|
||||
class ContentDerived: public ContentBase
|
||||
{
|
||||
public:
|
||||
ContentDerived():ContentBase() { m_name = "ContentDerived"; }
|
||||
virtual ~ContentDerived() {}
|
||||
virtual std::string get_name() const { return m_name; }
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
};
|
||||
|
||||
|
||||
class Container
|
||||
{
|
||||
public:
|
||||
Container() { m_content = 0; }
|
||||
~Container()
|
||||
{
|
||||
clear_content();
|
||||
}
|
||||
// the container takes the ownership of the content
|
||||
void set_content(ContentBase* content)
|
||||
{
|
||||
clear_content();
|
||||
m_content = content;
|
||||
}
|
||||
ContentBase* get_content() { return m_content; }
|
||||
|
||||
private:
|
||||
void clear_content()
|
||||
{
|
||||
if(m_content)
|
||||
{
|
||||
delete m_content;
|
||||
m_content = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
ContentBase* m_content;
|
||||
};
|
||||
|
||||
static ContentBase* make_content() { return new ContentDerived(); }
|
||||
|
||||
} // namespace example
|
||||
%}
|
||||
|
|
@ -2,6 +2,10 @@
|
|||
|
||||
%warnfilter(SWIGWARN_TYPEMAP_THREAD_UNSAFE,SWIGWARN_TYPEMAP_DIRECTOROUT_PTR) MyClass::pmethod;
|
||||
|
||||
#ifdef SWIGOCAML
|
||||
%warnfilter(SWIGWARN_PARSE_KEYWORD) method;
|
||||
#endif
|
||||
|
||||
%{
|
||||
#include <string>
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,15 @@
|
|||
%module(directors="1") director_thread
|
||||
#endif
|
||||
|
||||
#ifdef SWIGOCAML
|
||||
%warnfilter(SWIGWARN_PARSE_KEYWORD) val;
|
||||
#endif
|
||||
|
||||
%begin %{
|
||||
#define SWIG_JAVA_USE_THREAD_NAME
|
||||
//#define DEBUG_DIRECTOR_THREAD_NAME
|
||||
%}
|
||||
|
||||
%{
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
|
|
@ -14,6 +23,8 @@
|
|||
#include <stdio.h>
|
||||
#else
|
||||
#include <pthread.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
|
@ -86,13 +97,40 @@ extern "C" {
|
|||
%#else
|
||||
int create = pthread_create(&thread,NULL,working,this);
|
||||
if (create != 0) {
|
||||
fprintf(stderr, "pthread_create failed in run()\n");
|
||||
errno = create;
|
||||
perror("pthread_create in run()");
|
||||
assert(0);
|
||||
}
|
||||
%#endif
|
||||
MilliSecondSleep(500);
|
||||
}
|
||||
|
||||
|
||||
void setThreadName() {
|
||||
%#ifdef _WIN32
|
||||
%#else
|
||||
|
||||
%#ifdef __APPLE__
|
||||
int setname = pthread_setname_np("MyThreadName");
|
||||
%#else
|
||||
int setname = pthread_setname_np(pthread_self(), "MyThreadName");
|
||||
%#endif
|
||||
|
||||
if (setname != 0) {
|
||||
errno = setname;
|
||||
perror("calling pthread_setname_np in setThreadName()");
|
||||
assert(0);
|
||||
}
|
||||
%#endif
|
||||
}
|
||||
|
||||
static bool namedThread() {
|
||||
%#ifdef _WIN32
|
||||
return false;
|
||||
%#else
|
||||
return true;
|
||||
%#endif
|
||||
}
|
||||
|
||||
virtual void do_foo() {
|
||||
val += 1;
|
||||
}
|
||||
|
|
@ -108,6 +146,7 @@ extern "C" {
|
|||
#endif
|
||||
{
|
||||
Foo* f = static_cast<Foo*>(t);
|
||||
f->setThreadName();
|
||||
while (!get_thread_terminate()) {
|
||||
MilliSecondSleep(50);
|
||||
f->do_foo();
|
||||
|
|
|
|||
|
|
@ -43,5 +43,9 @@ struct Caller {
|
|||
return *(int *)p;
|
||||
}
|
||||
};
|
||||
|
||||
struct MemberVoid {
|
||||
void *memberVariable;
|
||||
};
|
||||
%}
|
||||
|
||||
|
|
|
|||
22
Examples/test-suite/doxygen_alias.i
Normal file
22
Examples/test-suite/doxygen_alias.i
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
%module doxygen_alias
|
||||
|
||||
#ifdef SWIGJAVA
|
||||
%feature("doxygen:alias:nullptr") "null"
|
||||
#elif defined(SWIGPYTHON)
|
||||
%feature("doxygen:alias:nullptr") "None"
|
||||
#else
|
||||
%feature("doxygen:alias:nullptr") "NULL"
|
||||
#endif
|
||||
|
||||
%inline %{
|
||||
|
||||
class Something {};
|
||||
|
||||
/**
|
||||
A function returning something.
|
||||
|
||||
@returns A new object which may be @nullptr.
|
||||
*/
|
||||
Something* make_something() { return 0; }
|
||||
|
||||
%}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue