Skip to content
Permalink
Browse files

[sipify] add macro to explicitely ask for monkey patching

because new scope based enum should not do the monkey patching, it's only done for python API compatibility
  • Loading branch information
3nids committed Mar 8, 2019
1 parent 051ac13 commit 1281bcc256f3b696b0c9b0c9ea8589f5573ac580
Showing with 17 additions and 7 deletions.
  1. +8 −6 scripts/sipify.pl
  2. +8 −0 src/core/qgis_sip.h
  3. +1 −1 src/gui/qgsadvanceddigitizingdockwidget.h
@@ -951,13 +951,15 @@ sub detect_non_method_member{

# Enum declaration
# For scoped and type based enum, the type has to be removed
if ( $LINE =~ m/^(\s*enum\s+(class\s+)?(\w+))(\s*:\s*\w+)?(?<oneliner>.*)$/ ){
if ( $LINE =~ m/^(\s*enum\s+(class\s+)?(\w+))(:?\s+SIP_.*)?(\s*:\s*\w+)?(?<oneliner>.*)$/ ){
write_output("ENU1", "$1");
write_output("ENU1", $+{oneliner}) if defined $+{oneliner};
write_output("ENU1", "\n");
my $enum_qualname = $3;
my $is_scope_based = "0";
$is_scope_based = "1" if defined $2;
my $enum_qualname = $3;
my $monkeypatch = "0";
$monkeypatch = "1" if defined $is_scope_based eq "1" and $LINE =~ m/SIP_MONKEYPATCH_SCOPEENUM/;
if ($LINE =~ m/\{((\s*\w+)(\s*=\s*[\w\s\d<|]+.*?)?(,?))+\s*\}/){
# one line declaration
$LINE !~ m/=/ or exit_with_error("spify.pl does not handle enum one liners with value assignment. Use multiple lines instead.");
@@ -979,12 +981,12 @@ sub detect_non_method_member{
next if ($LINE =~ m/^\s*\w+\s*\|/); # multi line declaration as sum of enums

do {no warnings 'uninitialized';
my $enum_decl = $LINE =~ s/^(\s*(\w+))(\s+SIP_\w+(?:\([^()]+\))?)?(?:\s*=\s*(?:[\w\s\d|+-]|::|<<)+)?(,?)(:?\s*\/\/!<\s*(.*)|.*)$/$1$3$4/r;
my $enum_member = $2;
my $enum_decl = $LINE =~ s/^(\s*(?<em>\w+))(\s+SIP_\w+(?:\([^()]+\))?)?(?:\s*=\s*(?:[\w\s\d|+-]|::|<<)+)?(,?)(:?\s*\/\/!<\s*(?<co>.*)|.*)$/$1$3$4/r;
my $enum_member = $+{em};
push @enum_members_doc, "'* $enum_member: ' + $ACTUAL_CLASS.$enum_qualname.$2.__doc__";
my $comment = $6;
my $comment = $+{co};
push @OUTPUT_PYTHON, "$ACTUAL_CLASS.$enum_qualname.$enum_member.__doc__ = \"$comment\"\n" if $is_scope_based eq "1";
push @OUTPUT_PYTHON, "$ACTUAL_CLASS.$enum_member = $ACTUAL_CLASS.$enum_qualname.$enum_member\n" if $is_scope_based eq "1";
push @OUTPUT_PYTHON, "$ACTUAL_CLASS.$enum_member = $ACTUAL_CLASS.$enum_qualname.$enum_member\n" if $monkeypatch eq "1";
$enum_decl = fix_annotations($enum_decl);
write_output("ENU3", "$enum_decl\n");
};
@@ -232,4 +232,12 @@
#define SIP_PYTHON_SPECIAL_BOOL(method_or_code)
#define SIP_PYTHON_SPECIAL_REPR(method_or_code)

/*
* If one reformat an enum to a scope based enum
* sipify will take care of monkey patching to keep
* API compatibility
*/
#define SIP_MONKEYPATCH_SCOPEENUM


#endif // QGIS_SIP_H
@@ -65,7 +65,7 @@ class GUI_EXPORT QgsAdvancedDigitizingDockWidget : public QgsDockWidget, private
/**
* Additional constraints which can be enabled
*/
enum class AdditionalConstraint : int
enum class AdditionalConstraint SIP_MONKEYPATCH_SCOPEENUM : int
{
NoConstraint, //!< No additional constraint
Perpendicular, //!< Perpendicular

0 comments on commit 1281bcc

Please sign in to comment.
You can’t perform that action at this time.