File: plmodule.i

package info (click to toggle)
mapserver 7.2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 16,620 kB
  • sloc: ansic: 176,974; cpp: 58,161; python: 2,969; xml: 1,676; cs: 997; yacc: 856; lex: 766; java: 588; perl: 428; makefile: 374; sh: 184; tcl: 158; ruby: 55
file content (200 lines) | stat: -rw-r--r-- 5,295 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/******************************************************************************
 * $Id$
 *
 * Project:  MapServer
 * Purpose:  Perl-specific enhancements to MapScript
 * Author:   SDL based on Sean's Python conventions
 *
 ******************************************************************************
 *
 * Perl-specific mapscript code has been moved into this 
 * SWIG interface file to improve the readibility of the main
 * interface file.  The main mapscript.i file includes this
 * file when SWIGPERL is defined (via 'swig -perl5 ...').
 *
 *****************************************************************************/

/******************************************************************************
 * Simple Typemaps
 *****************************************************************************/

%init %{
  if(msSetup() != MS_SUCCESS) {
    msSetError(MS_MISCERR, "Error initializing MapServer/Mapscript.", "msSetup()");
  }
%}

/* Translate Perl's built-in file object to FILE * */
%typemap(in) FILE * {
  $1 = PerlIO_exportFILE (IoIFP (sv_2io ($input)), NULL);
}

/* To support imageObj::getBytes */
%typemap(out) gdBuffer {
        SV *mysv;
        mysv = sv_newmortal();
        if ($1.data == NULL)
            sv_setpv(mysv,"");
        else
            sv_setpvn(mysv,(const char*)$1.data,$1.size);
        $result = newRV(mysv);
        sv_2mortal($result);
        argvi++;
        if( $1.owns_data )
            msFree($1.data);
}

%typemap(out) char[ANY] {
        $result = newSVpvn($1, strlen($1));
        argvi++;
}

/*
===============================================================================
RFC-24 implementation follows
===============================================================================
   Modified constructor according to:
   - cache population and sync, item 3.2
   - reference counter since Perl does not obey %newobject
*/
%allowexception;

%exception layer {
	/* Accessing layer */
	$action;
	MS_REFCNT_INCR(result);
}
%exception map {
	/* Accessing map */
	$action;
	MS_REFCNT_INCR(result);
}

%feature("shadow") layerObj(mapObj *map)
%{
sub new {
        my $pkg = shift;
        my $self = mapscriptc::new_layerObj(@_);
        bless $self, $pkg if defined($self);
        if (defined($_[0])) {
                # parent reference
                mapscript::RFC24_ADD_PARENT_REF( tied(%$self), $_[0]);
        }
        return $self;
}
%}

%feature("shadow") getLayer(int i)
%{
sub getLayer {
        my $layer = mapscriptc::mapObj_getLayer(@_);
        if (defined($layer)) {
                # parent reference
                #print "l=$layer,m=$_[0]\n";
                mapscript::RFC24_ADD_PARENT_REF( tied(%$layer) , $_[0]);
        }
        return $layer;
}
%}

%feature("shadow") getLayerByName(char* name)
%{
sub getLayerByName {
        my $layer = mapscriptc::mapObj_getLayerByName(@_);
        if (defined($layer)) {
                # parent reference
                #print "l=$layer,m=$_[0]\n";
                mapscript::RFC24_ADD_PARENT_REF( tied(%$layer) , $_[0]);
        }
        return $layer;
}
%}

%feature("shadow") insertLayer
%{
sub insertLayer {
        my $idx = mapscriptc::mapObj_insertLayer(@_);
        my $layer=$_[1];
        # parent reference
        mapscript::RFC24_ADD_PARENT_REF(tied(%$layer), $_[0]);
        return $idx;
}
%}

%feature("shadow") ~layerObj()
%{
sub DESTROY {
        return unless $_[0]->isa('HASH');
        my $self = tied(%{$_[0]});
        return unless defined $self;
        delete $ITERATORS{$self};
        mapscriptc::delete_layerObj($self);
        # remove parent reference
        mapscript::RFC24_DEL_PARENT_REF($self);
}
%}

%feature("shadow") classObj(layerObj *layer)
%{
sub new {
        my $pkg = shift;
        my $self = mapscriptc::new_classObj(@_);
        bless $self, $pkg if defined($self);
        if (defined($_[0])) {
                # parent reference
                mapscript::RFC24_ADD_PARENT_REF( tied(%$self), $_[0]);
        }
        return $self;
}
%}

%feature("shadow") getClass(int i)
%{
sub getClass {
        my $clazz = mapscriptc::layerObj_getClass(@_);
        if (defined($clazz)) {
                # parent reference
                mapscript::RFC24_ADD_PARENT_REF( tied(%$clazz) , $_[0]);
        }
        return $clazz;
}
%}
%feature("shadow") insertClass
%{
sub insertClass {
        my $idx = mapscriptc::layerObj_insertClass(@_);
        my $clazz=$_[1];
        # parent reference
        mapscript::RFC24_ADD_PARENT_REF(tied(%$clazz), $_[0]);
        return $idx;
}
%}

%feature("shadow") ~classObj()
%{
sub DESTROY {
        return unless $_[0]->isa('HASH');
        my $self = tied(%{$_[0]});
        return unless defined $self;
        delete $ITERATORS{$self};
        mapscriptc::delete_classObj($self);
        # remove parent reference
        mapscript::RFC24_DEL_PARENT_REF($self);
}
%}
%perlcode %{
        %PARENT_PTRS=();
        sub RFC24_ADD_PARENT_REF {
                my ($child, $parent)=@_;
                $PARENT_PTRS{ $$child }=$parent;
        }
        sub RFC24_DEL_PARENT_REF {
                my ($child)=@_;
                delete $PARENT_PTRS{ $$child };
        }

        # USE THIS function only for debugging!
        sub getPARENT_PTRS {
                return \%PARENT_PTRS;
        }
%}