Skip to content

Commit

Permalink
[sipify] Add support for abstract classes
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Apr 7, 2017
1 parent cd3528a commit cfeab26
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 3 deletions.
3 changes: 2 additions & 1 deletion cmake_templates/Doxyfile.in
Expand Up @@ -1363,7 +1363,8 @@ EXPAND_AS_DEFINED = "SIP_TRANSFER" \
"SIP_CONVERT_TO_SUBCLASS_CODE" \
"SIP_FEATURE" \
"SIP_IF_FEATURE" \
"SIP_END"
"SIP_END" \
"SIP_ABSTRACT"

# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then
# doxygen's preprocessor will remove all function-like macros that are alone
Expand Down
5 changes: 4 additions & 1 deletion scripts/sipify.pl
Expand Up @@ -227,7 +227,7 @@ sub processDoxygenLine
}

# class declaration started
if ( $line =~ m/^(\s*class)\s*([A-Z]+_EXPORT)?\s+(\w+)(\s*\:.*)?$/ ){
if ( $line =~ m/^(\s*class)\s*([A-Z]+_EXPORT)?\s+(\w+)(\s*\:.*)?(\s*SIP_ABSTRACT)?$/ ){
do {no warnings 'uninitialized';
$classname = $3;
$line =~ m/\b[A-Z]+_EXPORT\b/ or die "Class$classname in $headerfile should be exported with appropriate [LIB]_EXPORT macro. If this should not be available in python, wrap it in a `#ifndef SIP_RUN` block.";
Expand All @@ -241,6 +241,9 @@ sub processDoxygenLine
$m =~ s/(\s*:)?\s*$//;
$line .= $m;
}
if ($5) {
$line .= ' /Abstract/';
}

$line .= "\n{\n";
if ( $comment !~ m/^\s*$/ ){
Expand Down
5 changes: 5 additions & 0 deletions src/core/qgis.h
Expand Up @@ -472,3 +472,8 @@ typedef unsigned long long qgssize;
* Will insert a `%End` directive in sip files
*/
#define SIP_END

/*
* Class level annotation for abstract classes
*/
#define SIP_ABSTRACT
14 changes: 13 additions & 1 deletion tests/scripts/sipifyheader.expected.sip
Expand Up @@ -201,8 +201,20 @@ A constructor with definition in header on several lines

}

QFlags<QgsSipifyHeader::MyEnum> operator|(QgsSipifyHeader::MyEnum f1, QFlags<QgsSipifyHeader::MyEnum> f2);
class AbstractClass /Abstract/

This comment has been minimized.

Copy link
@nyalldawson

nyalldawson Apr 7, 2017

Collaborator

@m-kuhn This commit broke the Q_DECLARE_OPERATORS_FOR_FLAGS handling (and removed the expected output from the test ;) )

This comment has been minimized.

Copy link
@m-kuhn

m-kuhn Apr 8, 2017

Author Member

Fortunately it only broke the test and not the flag - because the header file contained code that wouldn't compile anyway (missing ; after class definition).

{
%Docstring
Documentation goes here
%End

%TypeHeaderCode
#include "sipifyheader.h"
%End
public:
explicit AbstractClass();
%Docstring
A constructor
%End

/************************************************************************
* This file has been generated automatically from *
Expand Down
22 changes: 22 additions & 0 deletions tests/scripts/sipifyheader.h
Expand Up @@ -259,6 +259,28 @@ class CORE_EXPORT ClassWithPrivateInheritanceOnly : private QgsBaseClass

}

/**
* \class AbstractClass
* \ingroup core
* Documentation goes here
*/
class CORE_EXPORT AbstractClass SIP_ABSTRACT
{
public:
//! A constructor
explicit AbstractClass()
{
}

private:

/**
* This method should be overridden by subclasses but not exposed to the public
* or protected API.
*/
virtual QString reason() = 0;
}

Q_DECLARE_OPERATORS_FOR_FLAGS( QgsSipifyHeader::Flags )


Expand Down

0 comments on commit cfeab26

Please sign in to comment.