Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions cppwg/input/base_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand All @@ -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",
Expand Down
1 change: 1 addition & 0 deletions cppwg/parsers/package_info_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
45 changes: 31 additions & 14 deletions cppwg/writers/constructor_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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<unsigned int> const & -> ::std::vector<unsignedint>const&
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<unsigned int> const & -> ::std::vector<unsignedint>const&
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:
Expand Down
8 changes: 8 additions & 0 deletions examples/shapes/src/geometry/Point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ Point<DIM>::Point(double x, double y, double z)
}
}

template <unsigned DIM>
Point<DIM>::Point(int x, int y, int z)
: Point(static_cast<double>(x),
static_cast<double>(y),
static_cast<double>(z))
{
}

template <unsigned DIM>
Point<DIM>::~Point()
{
Expand Down
5 changes: 5 additions & 0 deletions examples/shapes/src/geometry/Point.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
20 changes: 12 additions & 8 deletions examples/shapes/wrapper/package_info.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: <unsigned DIM>
Expand Down Expand Up @@ -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"
Expand Down