Represent enums as enums, not int, if possible

Use enum types instead of int for the enum-valued parameters and
function return values, this is more type-safe and clear for the users
of the library.

Change cpp_enum unit test to use C++ to check that C++ enum wrappers
can at least be compiled, but still use C API in it.

Note that enum whose underlying type is bigger than int still don't
work, but this is no different from what it was before, so just document
this limitation but don't do anything else about it for now.

This commit is best viewed ignoring whitespace-only changes.
This commit is contained in:
Vadim Zeitlin 2021-11-29 21:12:53 +01:00
commit 579c343d5f
4 changed files with 198 additions and 96 deletions

View file

@ -122,8 +122,12 @@ same_macro_all_primitive_types_but_void(cref_as_value,ctype);
%typemap(ctype) SWIGTYPE & "$*resolved_type*"
%typemap(ctype) SWIGTYPE [ANY] "$resolved_type*"
%typemap(ctype) SWIGTYPE * [ANY] "$resolved_type**"
%typemap(ctype) enum SWIGTYPE "int"
%typemap(ctype) enum SWIGTYPE &, enum SWIGTYPE * "int *"
// enums
%typemap(ctype) enum SWIGTYPE "$resolved_type"
%typemap(ctype) enum SWIGTYPE * "$resolved_type*"
%typemap(ctype) enum SWIGTYPE & "$*resolved_type*"
%typemap(ctype) enum SWIGTYPE [ANY] "$resolved_type*"
%typemap(ctype, fragment="stdbool_inc") bool, const bool, const bool & "bool"
%typemap(ctype, fragment="stdbool_inc") bool *, const bool *, bool & "bool *"