diff --git a/cppwg/input/base_info.py b/cppwg/input/base_info.py index d5783ce..87a3513 100644 --- a/cppwg/input/base_info.py +++ b/cppwg/input/base_info.py @@ -38,12 +38,14 @@ class BaseInfo: Do not include these methods. excluded_variables : List[str] Do not include these variables. + arg_type_excludes : List[str] + List of exclude patterns for arg types in methods. constructor_arg_type_excludes : List[str] - List of exclude patterns for ctors. + List of exclude patterns for arg types in constructors. + constructor_signature_excludes : List[List[str]] + List of exclude patterns for constructor signatures. return_type_excludes : List[str] List of exclude patterns for return types. - arg_type_excludes : List[str] - List of exclude patterns for arg types. name_replacements : Dict[str, str] A dictionary of name replacements e.g. {"double":"Double", "unsigned int":"Unsigned"} @@ -62,9 +64,10 @@ def __init__(self, name): self.custom_generator: Optional[str] = None self.excluded_methods: List[str] = [] self.excluded_variables: List[str] = [] + self.arg_type_excludes: List[str] = [] self.constructor_arg_type_excludes: List[str] = [] + self.constructor_signature_excludes: List[List[str]] = [] self.return_type_excludes: List[str] = [] - self.arg_type_excludes: List[str] = [] self.name_replacements: Dict[str, str] = { "double": "Double", "unsigned int": "Unsigned", diff --git a/cppwg/parsers/package_info_parser.py b/cppwg/parsers/package_info_parser.py index 552c404..876d178 100644 --- a/cppwg/parsers/package_info_parser.py +++ b/cppwg/parsers/package_info_parser.py @@ -123,6 +123,7 @@ def parse(self) -> PackageInfo: "pointer_call_policy": None, "reference_call_policy": None, "constructor_arg_type_excludes": None, + "constructor_signature_excludes": None, "excluded_methods": [], "excluded_variables": [], "custom_generator": None, diff --git a/cppwg/writers/constructor_writer.py b/cppwg/writers/constructor_writer.py index 1e95b8c..d8b4281 100644 --- a/cppwg/writers/constructor_writer.py +++ b/cppwg/writers/constructor_writer.py @@ -94,36 +94,53 @@ def exclude(self) -> bool: ): return True - # Check for excluded argument patterns + # Get arg type strings with spaces removed + # e.g. ::std::vector const & -> ::std::vectorconst& + arg_types = [ + x.decl_string.replace(" ", "") for x in self.ctor_decl.argument_types + ] + + # Exclude constructors with "iterator" in args + for arg_type in arg_types: + if "iterator" in arg_type.lower(): + return True + + # Exclude constructors with args matching patterns in calldef_excludes calldef_excludes = [ x.replace(" ", "") for x in self.class_info.hierarchy_attribute_gather("calldef_excludes") ] + for arg_type in arg_types: + if arg_type in calldef_excludes: + return True + # Exclude constructors with args matching patterns in constructor_arg_type_excludes ctor_arg_type_excludes = [ x.replace(" ", "") for x in self.class_info.hierarchy_attribute_gather( "constructor_arg_type_excludes" ) ] + for exclude_type in ctor_arg_type_excludes: + for arg_type in arg_types: + if exclude_type in arg_type: + return True - for arg_type in self.ctor_decl.argument_types: - # e.g. ::std::vector const & -> ::std::vectorconst& - arg_type_str = arg_type.decl_string.replace(" ", "") + # Exclude constructors matching a signature in constructor_signature_excludes + ctor_signature_excludes = self.class_info.hierarchy_attribute_gather( + "constructor_signature_excludes" + ) - # Exclude constructors with "iterator" in args - if "iterator" in arg_type_str.lower(): - return True + for exclude_types in ctor_signature_excludes: + if len(exclude_types) != len(arg_types): + continue - # Exclude constructors with args matching calldef_excludes - if arg_type_str in calldef_excludes: + if all( + exclude_type in arg_type + for arg_type, exclude_type in zip(arg_types, exclude_types) + ): return True - # Exclude constructurs with args matching constructor_arg_type_excludes - for excluded_type in ctor_arg_type_excludes: - if excluded_type in arg_type_str: - return True - return False def generate_wrapper(self) -> str: diff --git a/examples/shapes/src/geometry/Point.cpp b/examples/shapes/src/geometry/Point.cpp index 87630e1..49191fc 100644 --- a/examples/shapes/src/geometry/Point.cpp +++ b/examples/shapes/src/geometry/Point.cpp @@ -18,6 +18,14 @@ Point::Point(double x, double y, double z) } } +template +Point::Point(int x, int y, int z) + : Point(static_cast(x), + static_cast(y), + static_cast(z)) +{ +} + template Point::~Point() { diff --git a/examples/shapes/src/geometry/Point.hpp b/examples/shapes/src/geometry/Point.hpp index fe93805..7eae659 100644 --- a/examples/shapes/src/geometry/Point.hpp +++ b/examples/shapes/src/geometry/Point.hpp @@ -31,6 +31,11 @@ class Point */ Point(double x, double y, double z = (DIM - DIM)); + /** + * Constructor to exclude from wrapping + */ + Point(int x, int y, int z = 0); + /** * Destructor */ diff --git a/examples/shapes/wrapper/package_info.yaml b/examples/shapes/wrapper/package_info.yaml index 51efc20..e9d8cc9 100644 --- a/examples/shapes/wrapper/package_info.yaml +++ b/examples/shapes/wrapper/package_info.yaml @@ -16,14 +16,6 @@ source_includes: # Exclude default arguments from wrapped methods. exclude_default_args: False -# Exclude any methods that have these arg types. -# arg_type_excludes: -# - double - -# Exclude any constructors that have these arg types. -# constructor_arg_type_excludes: -# - double - # Signature/replacement settings for explicit template instantiations. template_substitutions: - signature: @@ -53,6 +45,18 @@ modules: excluded_methods: - ExcludedMethod + # Exclude any methods that have these arg types. + # arg_type_excludes: + # - double + + # Exclude any constructors that have these arg types. + # constructor_arg_type_excludes: + # - double + + # Exclude any constructors that have these signatures. + constructor_signature_excludes: + - [int, int, int] + # Path to a custom script for generating wrappers for this class. # CPPWG_SOURCEROOT points to the supplied source root directory. # custom_generator: "CPPWG_SOURCEROOT/point_generator.py"