pdb, libgimp: allow to use external GType-registered enums in the PDB

The enums have to be menually registered in pdb/enums-external.pl.
Currently supports enums from GEGL only.

Add enum GeglDistanceMetric as first external enum.
This commit is contained in:
Michael Natterer 2018-03-17 20:19:58 +01:00
parent c3ef34b496
commit 390ef44481
7 changed files with 45 additions and 6 deletions

View File

@ -445,7 +445,7 @@ CLEANFILES = $(gen_sources)
gimpenums.c: $(srcdir)/gimpenums.h $(srcdir)/gimpenums.c.tail $(GIMP_MKENUMS) Makefile.am gimpenums.c: $(srcdir)/gimpenums.h $(srcdir)/gimpenums.c.tail $(GIMP_MKENUMS) Makefile.am
$(AM_V_GEN) $(GIMP_MKENUMS) \ $(AM_V_GEN) $(GIMP_MKENUMS) \
--fhead "#include \"config.h\"\n#include <gio/gio.h>\n#undef GIMP_DISABLE_DEPRECATED\n#include \"libgimpbase/gimpbase.h\"\n#include \"libgimpbase/gimpbase-private.h\"\n#include \"libgimpconfig/gimpconfigenums.h\"\n#include \"gimpenums.h\"" \ --fhead "#include \"config.h\"\n#include <gio/gio.h>\n#include <gegl.h>\n#undef GIMP_DISABLE_DEPRECATED\n#include \"libgimpbase/gimpbase.h\"\n#include \"libgimpbase/gimpbase-private.h\"\n#include \"libgimpconfig/gimpconfigenums.h\"\n#include \"gimpenums.h\"" \
--fprod "\n/* enumerations from \"@filename@\" */" \ --fprod "\n/* enumerations from \"@filename@\" */" \
--vhead "GType\n@enum_name@_get_type (void)\n{\n static const G@Type@Value values[] =\n {" \ --vhead "GType\n@enum_name@_get_type (void)\n{\n static const G@Type@Value values[] =\n {" \
--vprod " { @VALUENAME@, \"@VALUENAME@\", \"@valuenick@\" }," \ --vprod " { @VALUENAME@, \"@VALUENAME@\", \"@valuenick@\" }," \

View File

@ -3,6 +3,7 @@ typedef GType (* GimpGetTypeFunc) (void);
static const GimpGetTypeFunc get_type_funcs[] = static const GimpGetTypeFunc get_type_funcs[] =
{ {
gegl_distance_metric_get_type,
gimp_add_mask_type_get_type, gimp_add_mask_type_get_type,
gimp_blend_mode_get_type, gimp_blend_mode_get_type,
gimp_brush_application_mode_get_type, gimp_brush_application_mode_get_type,
@ -69,6 +70,7 @@ static const GimpGetTypeFunc get_type_funcs[] =
static const gchar * const type_names[] = static const gchar * const type_names[] =
{ {
"GeglDistanceMetric",
"GimpAddMaskType", "GimpAddMaskType",
"GimpBlendMode", "GimpBlendMode",
"GimpBrushApplicationMode", "GimpBrushApplicationMode",

View File

@ -66,6 +66,7 @@ EXTRA_DIST = \
enumcode.pl \ enumcode.pl \
enumgen.pl \ enumgen.pl \
enums.pl \ enums.pl \
enums-external.pl \
groups.pl \ groups.pl \
lib.pl \ lib.pl \
pdb.pl \ pdb.pl \
@ -112,7 +113,7 @@ DISTCLEANFILES = $(stamp_files)
$(srcdir)/enums.pl: stamp-enums $(srcdir)/enums.pl: stamp-enums
@: @:
stamp-enums: $(srcdir)/enumgen.pl $(enum_headers) Makefile.am stamp-enums: $(srcdir)/enumgen.pl $(enum_headers) enums-external.pl Makefile.am
rootme=`pwd`; \ rootme=`pwd`; \
destdir=`cd $(top_srcdir) && pwd`; export destdir; \ destdir=`cd $(top_srcdir) && pwd`; export destdir; \
builddir=`cd $(top_builddir) && pwd`; export builddir; \ builddir=`cd $(top_builddir) && pwd`; export builddir; \

View File

@ -68,7 +68,8 @@ G_BEGIN_DECLS
HEADER HEADER
foreach (sort keys %enums) { foreach (sort keys %enums) {
if (! ($enums{$_}->{header} =~ /libgimp/)) { if (! ($enums{$_}->{header} =~ /libgimp/) &&
! $enums{$_}->{external}) {
my $gtype = $func = $_; my $gtype = $func = $_;
for ($gtype) { s/Gimp//; s/([A-Z][^A-Z]+)/\U$1\E_/g; s/_$// } for ($gtype) { s/Gimp//; s/([A-Z][^A-Z]+)/\U$1\E_/g; s/_$// }
@ -125,11 +126,18 @@ foreach (sort keys %enums) {
if (! ($_ =~ /GimpUnit/)) { if (! ($_ =~ /GimpUnit/)) {
my $enum = $enums{$_}; my $enum = $enums{$_};
my $func = $_; my $func = $_;
my $gegl_enum = ($func =~ /Gegl/);
for ($func) { s/Gimp//; s/PDB/Pdb/; s/([A-Z][^A-Z]+)/\L$1\E_/g; s/_$// } for ($func) { s/Gimp//; s/Gegl//; s/PDB/Pdb/;
s/([A-Z][^A-Z]+)/\L$1\E_/g; s/_$// }
print ENUMFILE ",\n" unless $first; print ENUMFILE ",\n" unless $first;
print ENUMFILE " gimp_$func\_get_type";
if ($gegl_enum) {
print ENUMFILE " gegl_$func\_get_type";
} else {
print ENUMFILE " gimp_$func\_get_type";
}
$first = 0; $first = 0;
} }

View File

@ -57,6 +57,14 @@ my $header = <<'HEADER';
:%enums = ( :%enums = (
HEADER HEADER
my $external;
open my $EXTERNAL, "enums-external.pl";
{
local $/;
$external = <$EXTERNAL>;
}
close $EXTERNAL;
my $footer = <<'FOOTER'; my $footer = <<'FOOTER';
:); :);
: :
@ -255,6 +263,6 @@ foreach ($header, $code, $footer) { s/^://mg }
$outfile = "$builddir/pdb/enums.pl$FILE_EXT"; $outfile = "$builddir/pdb/enums.pl$FILE_EXT";
open OUTFILE, "> $outfile"; open OUTFILE, "> $outfile";
print OUTFILE $header, $code, $footer; print OUTFILE $header, $external, $code, $footer;
close OUTFILE; close OUTFILE;
&write_file($outfile, "$destdir/pdb"); &write_file($outfile, "$destdir/pdb");

10
pdb/enums-external.pl Normal file
View File

@ -0,0 +1,10 @@
GeglDistanceMetric =>
{ contig => 1,
external => 1,
symbols => [ qw(GEGL_DISTANCE_METRIC_EUCLIDEAN
GEGL_DISTANCE_METRIC_MANHATTAN
GEGL_DISTANCE_METRIC_CHEBYSHEV) ],
mapping => { GEGL_DISTANCE_METRIC_EUCLIDEAN => '0',
GEGL_DISTANCE_METRIC_MANHATTAN => '1',
GEGL_DISTANCE_METRIC_CHEBYSHEV => '2' }
},

View File

@ -19,6 +19,16 @@
package Gimp::CodeGen::enums; package Gimp::CodeGen::enums;
%enums = ( %enums = (
GeglDistanceMetric =>
{ contig => 1,
external => 1,
symbols => [ qw(GEGL_DISTANCE_METRIC_EUCLIDEAN
GEGL_DISTANCE_METRIC_MANHATTAN
GEGL_DISTANCE_METRIC_CHEBYSHEV) ],
mapping => { GEGL_DISTANCE_METRIC_EUCLIDEAN => '0',
GEGL_DISTANCE_METRIC_MANHATTAN => '1',
GEGL_DISTANCE_METRIC_CHEBYSHEV => '2' }
},
GimpAddMaskType => GimpAddMaskType =>
{ contig => 1, { contig => 1,
header => 'libgimpbase/gimpbaseenums.h', header => 'libgimpbase/gimpbaseenums.h',