Skip to content
Permalink
Browse files

handle PyName for enums

  • Loading branch information
3nids committed Jun 2, 2017
1 parent 98f653e commit 2d78ef80a9700b9a6274294153f3da07256be46b
@@ -40,13 +40,9 @@ class QgsRasterMinMaxOrigin

enum Limits
{
//! User
None
//! Real
None /PyName=None_/,
MinMax,
//! Range
StdDev,
//! Range
CumulativeCut
};

@@ -79,22 +75,22 @@ class QgsRasterMinMaxOrigin
%End


Limits limits() const;
QgsRasterMinMaxOrigin::Limits limits() const;
%Docstring
Return limits.
:rtype: Limits
:rtype: QgsRasterMinMaxOrigin.Limits
%End

Extent extent() const;
QgsRasterMinMaxOrigin::Extent extent() const;
%Docstring
Return extent.
:rtype: Extent
:rtype: QgsRasterMinMaxOrigin.Extent
%End

StatAccuracy statAccuracy() const;
QgsRasterMinMaxOrigin::StatAccuracy statAccuracy() const;
%Docstring
Return statistic accuracy.
:rtype: StatAccuracy
:rtype: QgsRasterMinMaxOrigin.StatAccuracy
%End

double cumulativeCutLower() const;
@@ -116,17 +112,17 @@ class QgsRasterMinMaxOrigin
%End


void setLimits( Limits limits );
void setLimits( QgsRasterMinMaxOrigin::Limits limits );
%Docstring
Set limits.
%End

void setExtent( Extent extent );
void setExtent( QgsRasterMinMaxOrigin::Extent extent );
%Docstring
Set extent.
%End

void setStatAccuracy( StatAccuracy accuracy );
void setStatAccuracy( QgsRasterMinMaxOrigin::StatAccuracy accuracy );
%Docstring
Set statistics accuracy.
%End
@@ -170,28 +166,28 @@ class QgsRasterMinMaxOrigin
:rtype: Limits
%End

static QString extentString( Extent extent );
static QString extentString( QgsRasterMinMaxOrigin::Extent extent );
%Docstring
Return a string to serialize Extent
:rtype: str
%End

static Extent extentFromString( const QString &extent );
static QgsRasterMinMaxOrigin::Extent extentFromString( const QString &extent );
%Docstring
Deserialize Extent
:rtype: Extent
:rtype: QgsRasterMinMaxOrigin.Extent
%End

static QString statAccuracyString( StatAccuracy accuracy );
static QString statAccuracyString( QgsRasterMinMaxOrigin::StatAccuracy accuracy );
%Docstring
Return a string to serialize StatAccuracy
:rtype: str
%End

static StatAccuracy statAccuracyFromString( const QString &accuracy );
static QgsRasterMinMaxOrigin::StatAccuracy statAccuracyFromString( const QString &accuracy );
%Docstring
Deserialize StatAccuracy
:rtype: StatAccuracy
:rtype: QgsRasterMinMaxOrigin.StatAccuracy
%End

};
@@ -37,7 +37,7 @@ class QgsRasterNuller : QgsRasterInterface
virtual Qgis::DataType dataType( int bandNo ) const;


virtual QgsRasterBlock *block( int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback = 0 );
virtual QgsRasterBlock *block( int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback = 0 ) /Factory/;


void setNoData( int bandNo, const QgsRasterRangeList &noData );
@@ -161,58 +161,60 @@ sub remove_following_body_or_initializerlist {
};
}

sub fix_annotations(){
# printed annotations
$LINE =~ s/\bSIP_ABSTRACT\b/\/Abstract\//;
$LINE =~ s/\bSIP_ALLOWNONE\b/\/AllowNone\//;
$LINE =~ s/\bSIP_ARRAY\b/\/Array\//g;
$LINE =~ s/\bSIP_ARRAYSIZE\b/\/ArraySize\//g;
$LINE =~ s/\bSIP_DEPRECATED\b/\/Deprecated\//g;
$LINE =~ s/\bSIP_CONSTRAINED\b/\/Constrained\//g;
$LINE =~ s/\bSIP_EXTERNAL\b/\/External\//g;
$LINE =~ s/\bSIP_FACTORY\b/\/Factory\//;
$LINE =~ s/\bSIP_IN\b/\/In\//g;
$LINE =~ s/\bSIP_INOUT\b/\/In,Out\//g;
$LINE =~ s/\bSIP_KEEPREFERENCE\b/\/KeepReference\//;
$LINE =~ s/\bSIP_NODEFAULTCTORS\b/\/NoDefaultCtors\//;
$LINE =~ s/\bSIP_OUT\b/\/Out\//g;
$LINE =~ s/\bSIP_RELEASEGIL\b/\/ReleaseGIL\//;
$LINE =~ s/\bSIP_TRANSFER\b/\/Transfer\//g;
$LINE =~ s/\bSIP_TRANSFERBACK\b/\/TransferBack\//;
$LINE =~ s/\bSIP_TRANSFERTHIS\b/\/TransferThis\//;

$LINE =~ s/SIP_PYNAME\(\s*(\w+)\s*\)/\/PyName=$1\//;

# combine multiple annotations
# https://regex101.com/r/uvCt4M/3
do {no warnings 'uninitialized';
$LINE =~ s/\/(\w+(=\w+)?)\/\s*\/(\w+(=\w+)?)\//\/$1,$3\//;
(! $3) or dbg_info("combine multiple annotations -- works only for 2");
};

# unprinted annotations
$LINE =~ s/(\w+)(\<(?>[^<>]|(?2))*\>)?\s+SIP_PYALTERNATIVETYPE\(\s*\'?([^()']+)(\(\s*(?:[^()]++|(?2))*\s*\))?\'?\s*\)/$3/g;
$LINE =~ s/=\s+[^=]*?\s+SIP_PYARGDEFAULT\(\s*\'?([^()']+)(\(\s*(?:[^()]++|(?2))*\s*\))?\'?\s*\)/= $1/g;
# remove argument
if ($LINE =~ m/SIP_PYARGREMOVE/){
dbg_info("remove arg");
if ( $MULTILINE_DEFINITION == 1 ){
my $prev_line = pop(@OUTPUT) =~ s/\n$//r;
# update multi line status
my $parenthesis_balance = 0;
$parenthesis_balance += $prev_line =~ tr/\(//;
$parenthesis_balance -= $prev_line =~ tr/\)//;
if ($parenthesis_balance == 1){
$MULTILINE_DEFINITION = 0;
}
# concat with above line to bring previous commas
$LINE =~ s/^\s+//;
$LINE = "$prev_line $LINE\n";
}
# see https://regex101.com/r/5iNptO/4
$LINE =~ s/(?<coma>, +)?(const )?(\w+)(\<(?>[^<>]|(?4))*\>)?\s+[\w&*]+\s+SIP_PYARGREMOVE( = [^()]*(\(\s*(?:[^()]++|(?6))*\s*\))?)?(?(<coma>)|,?)//g;
}
$LINE =~ s/SIP_FORCE//;
sub fix_annotations {
my $line = $_[0];
# printed annotations
$line =~ s/\bSIP_ABSTRACT\b/\/Abstract\//;
$line =~ s/\bSIP_ALLOWNONE\b/\/AllowNone\//;
$line =~ s/\bSIP_ARRAY\b/\/Array\//g;
$line =~ s/\bSIP_ARRAYSIZE\b/\/ArraySize\//g;
$line =~ s/\bSIP_DEPRECATED\b/\/Deprecated\//g;
$line =~ s/\bSIP_CONSTRAINED\b/\/Constrained\//g;
$line =~ s/\bSIP_EXTERNAL\b/\/External\//g;
$line =~ s/\bSIP_FACTORY\b/\/Factory\//;
$line =~ s/\bSIP_IN\b/\/In\//g;
$line =~ s/\bSIP_INOUT\b/\/In,Out\//g;
$line =~ s/\bSIP_KEEPREFERENCE\b/\/KeepReference\//;
$line =~ s/\bSIP_NODEFAULTCTORS\b/\/NoDefaultCtors\//;
$line =~ s/\bSIP_OUT\b/\/Out\//g;
$line =~ s/\bSIP_RELEASEGIL\b/\/ReleaseGIL\//;
$line =~ s/\bSIP_TRANSFER\b/\/Transfer\//g;
$line =~ s/\bSIP_TRANSFERBACK\b/\/TransferBack\//;
$line =~ s/\bSIP_TRANSFERTHIS\b/\/TransferThis\//;

$line =~ s/SIP_PYNAME\(\s*(\w+)\s*\)/\/PyName=$1\//;

# combine multiple annotations
# https://regex101.com/r/uvCt4M/3
do {no warnings 'uninitialized';
$line =~ s/\/(\w+(=\w+)?)\/\s*\/(\w+(=\w+)?)\//\/$1,$3\//;
(! $3) or dbg_info("combine multiple annotations -- works only for 2");
};

# unprinted annotations
$line =~ s/(\w+)(\<(?>[^<>]|(?2))*\>)?\s+SIP_PYALTERNATIVETYPE\(\s*\'?([^()']+)(\(\s*(?:[^()]++|(?2))*\s*\))?\'?\s*\)/$3/g;
$line =~ s/=\s+[^=]*?\s+SIP_PYARGDEFAULT\(\s*\'?([^()']+)(\(\s*(?:[^()]++|(?2))*\s*\))?\'?\s*\)/= $1/g;
# remove argument
if ($line =~ m/SIP_PYARGREMOVE/){
dbg_info("remove arg");
if ( $MULTILINE_DEFINITION == 1 ){
my $prev_line = pop(@OUTPUT) =~ s/\n$//r;
# update multi line status
my $parenthesis_balance = 0;
$parenthesis_balance += $prev_line =~ tr/\(//;
$parenthesis_balance -= $prev_line =~ tr/\)//;
if ($parenthesis_balance == 1){
$MULTILINE_DEFINITION = 0;
}
# concat with above line to bring previous commas
$line =~ s/^\s+//;
$line = "$prev_line $line\n";
}
# see https://regex101.com/r/5iNptO/4
$line =~ s/(?<coma>, +)?(const )?(\w+)(\<(?>[^<>]|(?4))*\>)?\s+[\w&*]+\s+SIP_PYARGREMOVE( = [^()]*(\(\s*(?:[^()]++|(?6))*\s*\))?)?(?(<coma>)|,?)//g;
}
$line =~ s/SIP_FORCE//;
return $line;
}

# detect a comment block, return 1 if found
@@ -464,7 +466,7 @@ sub detect_comment_block{
if (defined $+{annot})
{
$LINE .= "$+{annot}";
fix_annotations();
$LINE = fix_annotations($LINE);
}

$LINE .= "\n{\n";
@@ -606,8 +608,11 @@ sub detect_comment_block{
if ($LINE =~ m/\};/){
last;
}
my $enum_val = $LINE =~ s/(\s*\w+)(\s*=\s*[\w\s\d<|]+.*?)?(,?).*$/$1$3/r;
write_output("ENU3", "$enum_val\n");
do {no warnings 'uninitialized';
my $enum_decl = $LINE =~ s/(\s*\w+)(\s+SIP_\w+(?:\([^()]+\))?)?(?:\s*=\s*[\w\s\d<|]+.*?)?(,?).*$/$1$2$3/r;
$enum_decl = fix_annotations($enum_decl);
write_output("ENU3", "$enum_decl\n");
};
detect_comment_block(strict_mode => UNSTRICT);
}
write_output("ENU4", "$LINE\n");
@@ -739,7 +744,7 @@ sub detect_comment_block{
# remove export macro from struct definition
$LINE =~ s/^(\s*struct )\w+_EXPORT (.+)$/$1$2/;

fix_annotations();
$LINE = fix_annotations($LINE);

# fix astyle placing space after % character
$LINE =~ s/\s*% (MappedType|Type(Header)?Code|Module(Header)?Code|Convert(From|To)TypeCode|MethodCode|End)/%$1/;
@@ -319,7 +319,7 @@ class CORE_EXPORT QgsRasterInterface
*/
#ifndef SIP_RUN
virtual bool hasHistogram( int bandNo,
int binCount = 0,
int binCount,
double minimum = std::numeric_limits<double>::quiet_NaN(),
double maximum = std::numeric_limits<double>::quiet_NaN(),
const QgsRectangle &extent = QgsRectangle(),
@@ -384,7 +384,7 @@ class CORE_EXPORT QgsRasterInterface
#ifndef SIP_RUN
void initHistogram( QgsRasterHistogram &histogram,
int bandNo,
int binCount = 0,
int binCount,
double minimum = std::numeric_limits<double>::quiet_NaN(),
double maximum = std::numeric_limits<double>::quiet_NaN(),
const QgsRectangle &boundingBox = QgsRectangle(),
@@ -46,14 +46,10 @@ class CORE_EXPORT QgsRasterMinMaxOrigin
//! \brief This enumerator describes the limits used to compute min/max values
enum Limits
{
//! User defined.
None SIP_PYNAME( None_ ),
//! Real min-max values
MinMax,
//! Range is [ mean - stdDevFactor() * stddev, mean + stdDevFactor() * stddev ]
StdDev,
//! Range is [ min + cumulativeCutLower() * (max - min), min + cumulativeCutUpper() * (max - min) ]
CumulativeCut
None SIP_PYNAME( None_ ), //!< User defined.
MinMax, //!< Real min-max values
StdDev, //!< Range is [ mean - stdDevFactor() * stddev, mean + stdDevFactor() * stddev ]
CumulativeCut //!< Range is [ min + cumulativeCutLower() * (max - min), min + cumulativeCutUpper() * (max - min) ]
};

//! \brief This enumerator describes the extent used to compute min/max values
@@ -85,13 +81,13 @@ class CORE_EXPORT QgsRasterMinMaxOrigin
//////// Getter methods /////////////////////

//! \brief Return limits.
Limits limits() const { return mLimits; }
QgsRasterMinMaxOrigin::Limits limits() const { return mLimits; }

//! \brief Return extent.
Extent extent() const { return mExtent; }
QgsRasterMinMaxOrigin::Extent extent() const { return mExtent; }

//! \brief Return statistic accuracy.
StatAccuracy statAccuracy() const { return mAccuracy; }
QgsRasterMinMaxOrigin::StatAccuracy statAccuracy() const { return mAccuracy; }

//! \brief Return lower bound of cumulative cut method (between 0 and 1).
double cumulativeCutLower() const { return mCumulativeCutLower; }
@@ -105,13 +101,13 @@ class CORE_EXPORT QgsRasterMinMaxOrigin
//////// Setter methods /////////////////////

//! \brief Set limits.
void setLimits( Limits limits ) { mLimits = limits; }
void setLimits( QgsRasterMinMaxOrigin::Limits limits ) { mLimits = limits; }

//! \brief Set extent.
void setExtent( Extent extent ) { mExtent = extent; }
void setExtent( QgsRasterMinMaxOrigin::Extent extent ) { mExtent = extent; }

//! \brief Set statistics accuracy.
void setStatAccuracy( StatAccuracy accuracy ) { mAccuracy = accuracy; }
void setStatAccuracy( QgsRasterMinMaxOrigin::StatAccuracy accuracy ) { mAccuracy = accuracy; }

//! \brief Set lower bound of cumulative cut method (between 0 and 1).
void setCumulativeCutLower( double val ) { mCumulativeCutLower = val; }
@@ -139,16 +135,16 @@ class CORE_EXPORT QgsRasterMinMaxOrigin
static Limits limitsFromString( const QString &limits );

//! \brief Return a string to serialize Extent
static QString extentString( Extent extent );
static QString extentString( QgsRasterMinMaxOrigin::Extent extent );

//! \brief Deserialize Extent
static Extent extentFromString( const QString &extent );
static QgsRasterMinMaxOrigin::Extent extentFromString( const QString &extent );

//! \brief Return a string to serialize StatAccuracy
static QString statAccuracyString( StatAccuracy accuracy );
static QString statAccuracyString( QgsRasterMinMaxOrigin::StatAccuracy accuracy );

//! \brief Deserialize StatAccuracy
static StatAccuracy statAccuracyFromString( const QString &accuracy );
static QgsRasterMinMaxOrigin::StatAccuracy statAccuracyFromString( const QString &accuracy );

private:

@@ -45,7 +45,7 @@ class CORE_EXPORT QgsRasterNuller : public QgsRasterInterface

Qgis::DataType dataType( int bandNo ) const override;

QgsRasterBlock *block( int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback = nullptr ) override;
QgsRasterBlock *block( int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback = nullptr ) override SIP_FACTORY;

void setNoData( int bandNo, const QgsRasterRangeList &noData );

@@ -8,7 +8,6 @@




%ModuleHeaderCode
#include <qgsnetworkspeedstrategy.h>
#include <qgsnetworkdistancestrategy.h>
@@ -79,6 +78,7 @@ typedef QtClass<QVariant> QtClassQVariantBase;
ImaginarySuccess,
RecursiveSuccess,
SuccessCombination,
PythonName /PyName=DifferentName/,
};
typedef QFlags<QgsSipifyHeader::MyEnum> Flags;

@@ -16,7 +16,6 @@ email : denis.rouzaud@gmail.com
#ifndef SIPIFYHEADER_H
#define SIPIFYHEADER_H


#include "qgis_core.h"
#include <QtClass>

@@ -113,6 +112,7 @@ class CORE_EXPORT QgsSipifyHeader : public QtClass<QVariant>, private Ui::QgsBas
ImaginarySuccess = 1 << 3, //!< Edit operation resulted in an imaginary geometry
RecursiveSuccess = 1 << 4, //!< Edit operation resulted in an n-dimensional wormhole
SuccessCombination = Success | ImaginarySuccess, //!< Holy Graal
PythonName SIP_PYNAME( DifferentName ), //!< Different python name
};
Q_DECLARE_FLAGS( Flags, MyEnum )

0 comments on commit 2d78ef8

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