Skip to content

Commit

Permalink
[sipify] add macro to explicitely ask for monkey patching
Browse files Browse the repository at this point in the history
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 1281bcc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
14 changes: 8 additions & 6 deletions scripts/sipify.pl
Expand Up @@ -951,13 +951,15 @@ sub detect_non_method_member{


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


do {no warnings 'uninitialized'; 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_decl = $LINE =~ s/^(\s*(?<em>\w+))(\s+SIP_\w+(?:\([^()]+\))?)?(?:\s*=\s*(?:[\w\s\d|+-]|::|<<)+)?(,?)(:?\s*\/\/!<\s*(?<co>.*)|.*)$/$1$3$4/r;
my $enum_member = $2; my $enum_member = $+{em};
push @enum_members_doc, "'* $enum_member: ' + $ACTUAL_CLASS.$enum_qualname.$2.__doc__"; 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_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); $enum_decl = fix_annotations($enum_decl);
write_output("ENU3", "$enum_decl\n"); write_output("ENU3", "$enum_decl\n");
}; };
Expand Down
8 changes: 8 additions & 0 deletions src/core/qgis_sip.h
Expand Up @@ -232,4 +232,12 @@
#define SIP_PYTHON_SPECIAL_BOOL(method_or_code) #define SIP_PYTHON_SPECIAL_BOOL(method_or_code)
#define SIP_PYTHON_SPECIAL_REPR(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 #endif // QGIS_SIP_H
2 changes: 1 addition & 1 deletion src/gui/qgsadvanceddigitizingdockwidget.h
Expand Up @@ -65,7 +65,7 @@ class GUI_EXPORT QgsAdvancedDigitizingDockWidget : public QgsDockWidget, private
/** /**
* Additional constraints which can be enabled * Additional constraints which can be enabled
*/ */
enum class AdditionalConstraint : int enum class AdditionalConstraint SIP_MONKEYPATCH_SCOPEENUM : int
{ {
NoConstraint, //!< No additional constraint NoConstraint, //!< No additional constraint
Perpendicular, //!< Perpendicular Perpendicular, //!< Perpendicular
Expand Down

0 comments on commit 1281bcc

Please sign in to comment.