/src/MapServer/src/mapcopy.c
Line | Count | Source (jump to first uncovered line) |
1 | | /****************************************************************************** |
2 | | * $Id$ |
3 | | * |
4 | | * Project: MapServer |
5 | | * Purpose: Functions to allow copying/cloning of maps |
6 | | * Author: Sean Gillies, sgillies@frii.com |
7 | | * |
8 | | * Notes: |
9 | | * These functions are not in mapfile.c because that file is |
10 | | * cumbersome enough as it is. There is agreement that this code and |
11 | | * that in mapfile.c should eventually be split up by object into |
12 | | * mapobj.c, layerobj.c, etc. Or something like that. |
13 | | * |
14 | | * Unit tests are written in Python using PyUnit and are in |
15 | | * mapscript/python/tests/testCopyMap.py. The tests can be |
16 | | * executed from the python directory as |
17 | | * |
18 | | * python2 tests/testCopyMap.py |
19 | | * |
20 | | * I just find Python to be very handy for unit testing, that's all. |
21 | | * |
22 | | ****************************************************************************** |
23 | | * Copyright (c) 1996-2005 Regents of the University of Minnesota. |
24 | | * |
25 | | * Permission is hereby granted, free of charge, to any person obtaining a |
26 | | * copy of this software and associated documentation files (the "Software"), |
27 | | * to deal in the Software without restriction, including without limitation |
28 | | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
29 | | * and/or sell copies of the Software, and to permit persons to whom the |
30 | | * Software is furnished to do so, subject to the following conditions: |
31 | | * |
32 | | * The above copyright notice and this permission notice shall be included in |
33 | | * all copies of this Software or works derived from this Software. |
34 | | * |
35 | | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
36 | | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
37 | | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
38 | | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
39 | | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
40 | | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
41 | | * DEALINGS IN THE SOFTWARE. |
42 | | ****************************************************************************/ |
43 | | |
44 | | #include <assert.h> |
45 | | #include "mapserver.h" |
46 | | #include "mapsymbol.h" |
47 | | |
48 | | #include "mapcopy.h" |
49 | | |
50 | | #include "cpl_string.h" |
51 | | |
52 | | /*********************************************************************** |
53 | | * msCopyProjectionExtended() * |
54 | | * * |
55 | | * Copy a projectionObj while adding additional arguments * |
56 | | **********************************************************************/ |
57 | | |
58 | | int msCopyProjectionExtended(projectionObj *dst, const projectionObj *src, |
59 | 0 | char **args, int num_args) { |
60 | 0 | MS_COPYSTELEM(numargs); |
61 | 0 | MS_COPYSTELEM(gt); |
62 | |
|
63 | 0 | for (int i = 0; i < dst->numargs; i++) { |
64 | | /* Our destination consists of unallocated pointers */ |
65 | 0 | dst->args[i] = msStrdup(src->args[i]); |
66 | 0 | } |
67 | 0 | if (args) { |
68 | 0 | for (int i = 0; i < num_args; i++) { |
69 | 0 | dst->args[dst->numargs++] = msStrdup(args[i]); |
70 | 0 | } |
71 | 0 | } |
72 | 0 | msProjectionInheritContextFrom(dst, src); |
73 | 0 | if (dst->numargs != 0) { |
74 | 0 | if (msProcessProjection(dst) != MS_SUCCESS) |
75 | 0 | return MS_FAILURE; |
76 | 0 | } |
77 | 0 | MS_COPYSTELEM(wellknownprojection); |
78 | 0 | return MS_SUCCESS; |
79 | 0 | } |
80 | | |
81 | | /*********************************************************************** |
82 | | * msCopyProjection() * |
83 | | * * |
84 | | * Copy a projectionObj * |
85 | | **********************************************************************/ |
86 | | |
87 | 0 | int msCopyProjection(projectionObj *dst, const projectionObj *src) { |
88 | 0 | return msCopyProjectionExtended(dst, src, NULL, 0); |
89 | 0 | } |
90 | | |
91 | | /*********************************************************************** |
92 | | * msCopyLine() * |
93 | | * * |
94 | | * Copy a lineObj, using msCopyPoint() * |
95 | | **********************************************************************/ |
96 | 0 | int msCopyLine(lineObj *dst, const lineObj *src) { |
97 | |
|
98 | 0 | int i; |
99 | |
|
100 | 0 | dst->numpoints = src->numpoints; |
101 | 0 | for (i = 0; i < dst->numpoints; i++) { |
102 | 0 | MS_COPYPOINT(&(dst->point[i]), &(src->point[i])); |
103 | 0 | } |
104 | |
|
105 | 0 | return MS_SUCCESS; |
106 | 0 | } |
107 | | |
108 | | /*********************************************************************** |
109 | | * msCopyShape() * |
110 | | * * |
111 | | * Copy a shapeObj, using msCopyLine(), msCopyRect() * |
112 | | * Not completely implemented or tested. * |
113 | | **********************************************************************/ |
114 | | /* |
115 | | int msCopyShapeObj(shapeObj *dst, shapeObj *src) { |
116 | | int i; |
117 | | copyProperty(&(dst->numlines), &(src->numlines), sizeof(int)); |
118 | | for (i = 0; i < dst->numlines; i++) { |
119 | | msCopyLine(&(dst->line[i]), &(src->line[i])); |
120 | | } |
121 | | msCopyRect(&(dst->bounds), &(src->bounds)); |
122 | | copyProperty(&(dst->type), &(src->type), sizeof(int)); |
123 | | copyProperty(&(dst->index), &(src->index), sizeof(long)); |
124 | | copyProperty(&(dst->tileindex), &(src->tileindex), sizeof(int)); |
125 | | copyProperty(&(dst->classindex), &(src->classindex), sizeof(int)); |
126 | | copyStringPropertyRealloc(&(dst->text), src->text); |
127 | | copyProperty(&(dst->numvalues), &(src->numvalues), sizeof(int)); |
128 | | for (i = 0; i < dst->numvalues; i++) { |
129 | | copyStringPropertyRealloc(&(dst->values[i]), src->values[i]); |
130 | | } |
131 | | |
132 | | return(0); |
133 | | } |
134 | | */ |
135 | | |
136 | | /********************************************************************** |
137 | | * msCopyItem() * |
138 | | * * |
139 | | * Copy an itemObj * |
140 | | **********************************************************************/ |
141 | | |
142 | 0 | int msCopyItem(itemObj *dst, const itemObj *src) { |
143 | |
|
144 | 0 | MS_COPYSTRING(dst->name, src->name); |
145 | 0 | MS_COPYSTELEM(type); |
146 | 0 | MS_COPYSTELEM(index); |
147 | 0 | MS_COPYSTELEM(size); |
148 | 0 | MS_COPYSTELEM(numdecimals); |
149 | |
|
150 | 0 | return MS_SUCCESS; |
151 | 0 | } |
152 | | |
153 | | /*********************************************************************** |
154 | | * msCopyHashTable() * |
155 | | * * |
156 | | * Copy a hashTableObj, using msInsertHashTable() * |
157 | | **********************************************************************/ |
158 | | |
159 | 0 | int msCopyHashTable(hashTableObj *dst, const hashTableObj *src) { |
160 | 0 | const char *key = NULL; |
161 | 0 | while (1) { |
162 | 0 | key = msNextKeyFromHashTable(src, key); |
163 | 0 | if (!key) |
164 | 0 | break; |
165 | 0 | else |
166 | 0 | msInsertHashTable(dst, key, msLookupHashTable(src, key)); |
167 | 0 | } |
168 | 0 | return MS_SUCCESS; |
169 | 0 | } |
170 | | |
171 | | /*********************************************************************** |
172 | | * msCopyFontSet() * |
173 | | * * |
174 | | * Copy a fontSetObj, using msCreateHashTable() and msCopyHashTable() * |
175 | | **********************************************************************/ |
176 | | |
177 | 0 | int msCopyFontSet(fontSetObj *dst, const fontSetObj *src, mapObj *map) { |
178 | |
|
179 | 0 | MS_COPYSTRING(dst->filename, src->filename); |
180 | 0 | MS_COPYSTELEM(numfonts); |
181 | 0 | if (msCopyHashTable(&(dst->fonts), &(src->fonts)) != MS_SUCCESS) |
182 | 0 | return MS_FAILURE; |
183 | | |
184 | 0 | dst->map = map; |
185 | |
|
186 | 0 | return MS_SUCCESS; |
187 | 0 | } |
188 | | |
189 | | /*********************************************************************** |
190 | | * msCopyExpression() * |
191 | | * * |
192 | | * Copy an expressionObj, but only its string, type and flags * |
193 | | **********************************************************************/ |
194 | | |
195 | 0 | int msCopyExpression(expressionObj *dst, const expressionObj *src) { |
196 | 0 | if ((dst->type == MS_REGEX) && dst->compiled) |
197 | 0 | ms_regfree(&(dst->regex)); |
198 | 0 | dst->compiled = MS_FALSE; |
199 | |
|
200 | 0 | MS_COPYSTRING(dst->string, src->string); |
201 | 0 | MS_COPYSTELEM(type); |
202 | 0 | MS_COPYSTELEM(flags); |
203 | |
|
204 | 0 | return MS_SUCCESS; |
205 | 0 | } |
206 | | |
207 | | /*********************************************************************** |
208 | | * msCopyJoin() * |
209 | | * * |
210 | | * Copy a joinObj * |
211 | | **********************************************************************/ |
212 | | |
213 | 0 | int msCopyJoin(joinObj *dst, const joinObj *src) { |
214 | 0 | MS_COPYSTRING(dst->name, src->name); |
215 | | |
216 | | /* makes no sense to copy the items or values |
217 | | since they are runtime additions to the mapfile */ |
218 | |
|
219 | 0 | MS_COPYSTRING(dst->table, src->table); |
220 | 0 | MS_COPYSTRING(dst->from, src->from); |
221 | 0 | MS_COPYSTRING(dst->to, src->to); |
222 | 0 | MS_COPYSTRING(dst->header, src->header); |
223 | 0 | #ifndef __cplusplus |
224 | 0 | MS_COPYSTRING(dst->template, src->template); |
225 | | #else |
226 | | MS_COPYSTRING(dst->_template, src->_template); |
227 | | #endif |
228 | 0 | MS_COPYSTRING(dst->footer, src->footer); |
229 | 0 | dst->type = src->type; |
230 | 0 | MS_COPYSTRING(dst->connection, src->connection); |
231 | |
|
232 | 0 | MS_COPYSTELEM(connectiontype); |
233 | | |
234 | | /* TODO: need to handle joininfo (probably should be just set to NULL) */ |
235 | 0 | dst->joininfo = NULL; |
236 | |
|
237 | 0 | return MS_SUCCESS; |
238 | 0 | } |
239 | | |
240 | | /*********************************************************************** |
241 | | * msCopyQueryMap() * |
242 | | * * |
243 | | * Copy a queryMapObj, using msCopyColor() * |
244 | | **********************************************************************/ |
245 | | |
246 | 0 | int msCopyQueryMap(queryMapObj *dst, const queryMapObj *src) { |
247 | 0 | MS_COPYSTELEM(height); |
248 | 0 | MS_COPYSTELEM(width); |
249 | 0 | MS_COPYSTELEM(status); |
250 | 0 | MS_COPYSTELEM(style); |
251 | 0 | MS_COPYCOLOR(&(dst->color), &(src->color)); |
252 | |
|
253 | 0 | return MS_SUCCESS; |
254 | 0 | } |
255 | | |
256 | | /*********************************************************************** |
257 | | * msCopyLeader() * |
258 | | * * |
259 | | * Copy a labelLeaderObj, using msCopyStyle() * |
260 | | **********************************************************************/ |
261 | | |
262 | 0 | int msCopyLabelLeader(labelLeaderObj *dst, const labelLeaderObj *src) { |
263 | 0 | int i; |
264 | 0 | assert(dst && src); |
265 | 0 | MS_COPYSTELEM(gridstep); |
266 | 0 | MS_COPYSTELEM(maxdistance); |
267 | | /* |
268 | | ** now the styles |
269 | | */ |
270 | | |
271 | | /* free any previous styles on the dst label */ |
272 | 0 | for (i = 0; i < dst->numstyles; i++) { /* each style */ |
273 | 0 | if (dst->styles[i] != NULL) { |
274 | 0 | if (freeStyle(dst->styles[i]) == MS_SUCCESS) |
275 | 0 | msFree(dst->styles[i]); |
276 | 0 | } |
277 | 0 | } |
278 | 0 | dst->numstyles = 0; |
279 | |
|
280 | 0 | for (i = 0; i < src->numstyles; i++) { |
281 | 0 | if (msGrowLeaderStyles(dst) == NULL) |
282 | 0 | return MS_FAILURE; |
283 | 0 | if (initStyle(dst->styles[i]) != MS_SUCCESS) { |
284 | 0 | msSetError(MS_MEMERR, "Failed to init style.", "msCopyLabel()"); |
285 | 0 | return MS_FAILURE; |
286 | 0 | } |
287 | 0 | if (msCopyStyle(dst->styles[i], src->styles[i]) != MS_SUCCESS) { |
288 | 0 | msSetError(MS_MEMERR, "Failed to copy style.", "msCopyLabel()"); |
289 | 0 | return MS_FAILURE; |
290 | 0 | } |
291 | 0 | dst->numstyles++; |
292 | 0 | } |
293 | 0 | return MS_SUCCESS; |
294 | 0 | } |
295 | | |
296 | | /*********************************************************************** |
297 | | * msCopyLabel() * |
298 | | * * |
299 | | * Copy a labelObj, using msCopyColor() and msCopyStyle() * |
300 | | **********************************************************************/ |
301 | | |
302 | 0 | int msCopyLabel(labelObj *dst, const labelObj *src) { |
303 | 0 | int i; |
304 | |
|
305 | 0 | for (i = 0; i < MS_LABEL_BINDING_LENGTH; i++) { |
306 | 0 | MS_COPYSTRING(dst->bindings[i].item, src->bindings[i].item); |
307 | 0 | dst->bindings[i].index = |
308 | 0 | src->bindings[i].index; /* no way to use the macros */ |
309 | 0 | MS_COPYSTRING(dst->exprBindings[i].string, src->exprBindings[i].string); |
310 | 0 | dst->exprBindings[i].type = src->exprBindings[i].type; |
311 | 0 | } |
312 | 0 | MS_COPYSTELEM(numbindings); |
313 | 0 | MS_COPYSTELEM(nexprbindings); |
314 | |
|
315 | 0 | MS_COPYSTRING(dst->font, src->font); |
316 | |
|
317 | 0 | MS_COPYCOLOR(&(dst->color), &(src->color)); |
318 | 0 | MS_COPYCOLOR(&(dst->outlinecolor), &(src->outlinecolor)); |
319 | 0 | MS_COPYCOLOR(&(dst->shadowcolor), &(src->shadowcolor)); |
320 | |
|
321 | 0 | MS_COPYSTELEM(shadowsizex); |
322 | 0 | MS_COPYSTELEM(shadowsizey); |
323 | |
|
324 | 0 | MS_COPYSTELEM(size); |
325 | 0 | MS_COPYSTELEM(minsize); |
326 | 0 | MS_COPYSTELEM(maxsize); |
327 | 0 | MS_COPYSTELEM(position); |
328 | 0 | MS_COPYSTELEM(offsetx); |
329 | 0 | MS_COPYSTELEM(offsety); |
330 | 0 | MS_COPYSTELEM(angle); |
331 | 0 | MS_COPYSTELEM(anglemode); |
332 | 0 | MS_COPYSTELEM(buffer); |
333 | 0 | MS_COPYSTELEM(wrap); |
334 | 0 | MS_COPYSTELEM(align); |
335 | 0 | MS_COPYSTELEM(maxlength); |
336 | 0 | MS_COPYSTELEM(minfeaturesize); |
337 | |
|
338 | 0 | MS_COPYSTELEM(minscaledenom); |
339 | 0 | MS_COPYSTELEM(maxscaledenom); |
340 | |
|
341 | 0 | MS_COPYSTELEM(autominfeaturesize); |
342 | |
|
343 | 0 | MS_COPYSTELEM(mindistance); |
344 | 0 | MS_COPYSTELEM(partials); |
345 | 0 | MS_COPYSTELEM(force); |
346 | 0 | MS_COPYSTELEM(priority); |
347 | |
|
348 | 0 | MS_COPYSTELEM(repeatdistance); |
349 | 0 | MS_COPYSTELEM(maxoverlapangle); |
350 | |
|
351 | 0 | MS_COPYSTRING(dst->encoding, src->encoding); |
352 | |
|
353 | 0 | MS_COPYSTELEM(outlinewidth); |
354 | 0 | MS_COPYSTELEM(space_size_10); |
355 | |
|
356 | 0 | if (msCopyExpression(&(dst->expression), &(src->expression)) != MS_SUCCESS) { |
357 | 0 | msSetError(MS_MEMERR, "Failed to copy expression.", "msCopyLabel()"); |
358 | 0 | return MS_FAILURE; |
359 | 0 | } |
360 | | |
361 | 0 | if (msCopyExpression(&(dst->text), &(src->text)) != MS_SUCCESS) { |
362 | 0 | msSetError(MS_MEMERR, "Failed to copy text.", "msCopyLabel()"); |
363 | 0 | return MS_FAILURE; |
364 | 0 | } |
365 | | |
366 | | /* |
367 | | ** now the styles |
368 | | */ |
369 | | |
370 | | /* free any previous styles on the dst label */ |
371 | 0 | for (i = 0; i < dst->numstyles; i++) { /* each style */ |
372 | 0 | if (dst->styles[i] != NULL) { |
373 | 0 | if (freeStyle(dst->styles[i]) == MS_SUCCESS) |
374 | 0 | msFree(dst->styles[i]); |
375 | 0 | } |
376 | 0 | } |
377 | 0 | dst->numstyles = 0; |
378 | |
|
379 | 0 | for (i = 0; i < src->numstyles; i++) { |
380 | 0 | if (msGrowLabelStyles(dst) == NULL) |
381 | 0 | return MS_FAILURE; |
382 | 0 | if (initStyle(dst->styles[i]) != MS_SUCCESS) { |
383 | 0 | msSetError(MS_MEMERR, "Failed to init style.", "msCopyLabel()"); |
384 | 0 | return MS_FAILURE; |
385 | 0 | } |
386 | 0 | if (msCopyStyle(dst->styles[i], src->styles[i]) != MS_SUCCESS) { |
387 | 0 | msSetError(MS_MEMERR, "Failed to copy style.", "msCopyLabel()"); |
388 | 0 | return MS_FAILURE; |
389 | 0 | } |
390 | 0 | dst->numstyles++; |
391 | 0 | } |
392 | | |
393 | 0 | if (src->leader) { |
394 | 0 | dst->leader = msSmallMalloc(sizeof(labelLeaderObj)); |
395 | 0 | initLeader(dst->leader); |
396 | 0 | msCopyLabelLeader(dst->leader, src->leader); |
397 | 0 | } else { |
398 | 0 | if (dst->leader) { |
399 | 0 | freeLabelLeader(dst->leader); |
400 | 0 | msFree(dst->leader); |
401 | 0 | } |
402 | 0 | dst->leader = NULL; |
403 | 0 | } |
404 | |
|
405 | 0 | MS_COPYSTELEM(sizeunits); |
406 | 0 | MS_COPYSTELEM(scalefactor); |
407 | |
|
408 | 0 | return MS_SUCCESS; |
409 | 0 | } |
410 | | |
411 | | /*********************************************************************** |
412 | | * msCopyWeb() * |
413 | | * * |
414 | | * Copy webObj, using msCopyRect(), msCreateHashTable(), and * |
415 | | * msCopyHashTable() * |
416 | | **********************************************************************/ |
417 | | |
418 | 0 | int msCopyWeb(webObj *dst, const webObj *src, mapObj *map) { |
419 | |
|
420 | 0 | MS_COPYSTRING(dst->imagepath, src->imagepath); |
421 | 0 | MS_COPYSTRING(dst->imageurl, src->imageurl); |
422 | 0 | dst->map = map; |
423 | 0 | #ifndef __cplusplus |
424 | 0 | MS_COPYSTRING(dst->template, src->template); |
425 | | #else |
426 | | MS_COPYSTRING(dst->_template, src->_template); |
427 | | #endif |
428 | 0 | MS_COPYSTRING(dst->header, src->header); |
429 | 0 | MS_COPYSTRING(dst->footer, src->footer); |
430 | 0 | MS_COPYSTRING(dst->empty, src->empty); |
431 | 0 | MS_COPYSTRING(dst->error, src->error); |
432 | |
|
433 | 0 | MS_COPYSTELEM(minscaledenom); |
434 | 0 | MS_COPYSTELEM(maxscaledenom); |
435 | 0 | MS_COPYSTRING(dst->mintemplate, src->mintemplate); |
436 | 0 | MS_COPYSTRING(dst->maxtemplate, src->maxtemplate); |
437 | |
|
438 | 0 | if (msCopyHashTable(&(dst->metadata), &(src->metadata)) != MS_SUCCESS) |
439 | 0 | return MS_FAILURE; |
440 | 0 | msCopyHashTable(&dst->validation, &src->validation); |
441 | |
|
442 | 0 | MS_COPYSTRING(dst->queryformat, src->queryformat); |
443 | 0 | MS_COPYSTRING(dst->legendformat, src->legendformat); |
444 | 0 | MS_COPYSTRING(dst->browseformat, src->browseformat); |
445 | |
|
446 | 0 | return MS_SUCCESS; |
447 | 0 | } |
448 | | |
449 | | /*********************************************************************** |
450 | | * msCopyStyle() * |
451 | | * * |
452 | | * Copy a styleObj, using msCopyColor() * |
453 | | **********************************************************************/ |
454 | | |
455 | 0 | int msCopyStyle(styleObj *dst, const styleObj *src) { |
456 | 0 | int i; |
457 | |
|
458 | 0 | for (i = 0; i < MS_STYLE_BINDING_LENGTH; i++) { |
459 | 0 | MS_COPYSTRING(dst->bindings[i].item, src->bindings[i].item); |
460 | 0 | dst->bindings[i].index = |
461 | 0 | src->bindings[i].index; /* no way to use the macros */ |
462 | 0 | MS_COPYSTRING(dst->exprBindings[i].string, src->exprBindings[i].string); |
463 | 0 | dst->exprBindings[i].type = src->exprBindings[i].type; |
464 | 0 | } |
465 | 0 | MS_COPYSTELEM(numbindings); |
466 | 0 | MS_COPYSTELEM(nexprbindings); |
467 | |
|
468 | 0 | MS_COPYCOLOR(&(dst->color), &(src->color)); |
469 | 0 | MS_COPYCOLOR(&(dst->outlinecolor), &(src->outlinecolor)); |
470 | |
|
471 | 0 | MS_COPYCOLOR(&(dst->mincolor), &(src->mincolor)); |
472 | 0 | MS_COPYCOLOR(&(dst->maxcolor), &(src->maxcolor)); |
473 | |
|
474 | 0 | MS_COPYSTRING(dst->symbolname, src->symbolname); |
475 | 0 | MS_COPYSTELEM(patternlength); |
476 | 0 | for (i = 0; i < src->patternlength; i++) |
477 | 0 | dst->pattern[i] = src->pattern[i]; |
478 | 0 | MS_COPYSTELEM(initialgap); |
479 | 0 | MS_COPYSTELEM(gap); |
480 | 0 | MS_COPYSTELEM(linejoin); |
481 | 0 | MS_COPYSTELEM(linejoinmaxsize); |
482 | 0 | MS_COPYSTELEM(antialiased); |
483 | 0 | MS_COPYSTELEM(linecap); |
484 | 0 | MS_COPYSTELEM(symbol); |
485 | 0 | MS_COPYSTELEM(size); |
486 | 0 | MS_COPYSTELEM(minsize); |
487 | 0 | MS_COPYSTELEM(maxsize); |
488 | 0 | MS_COPYSTELEM(width); |
489 | 0 | MS_COPYSTELEM(minwidth); |
490 | 0 | MS_COPYSTELEM(maxwidth); |
491 | 0 | MS_COPYSTELEM(offsetx); |
492 | 0 | MS_COPYSTELEM(offsety); |
493 | 0 | MS_COPYSTELEM(angle); |
494 | 0 | MS_COPYSTELEM(autoangle); |
495 | 0 | MS_COPYSTELEM(minvalue); |
496 | 0 | MS_COPYSTELEM(maxvalue); |
497 | 0 | MS_COPYSTELEM(opacity); |
498 | 0 | MS_COPYSTRING(dst->_geomtransform.string, src->_geomtransform.string); |
499 | 0 | MS_COPYSTELEM(_geomtransform.type); |
500 | 0 | MS_COPYSTRING(dst->rangeitem, src->rangeitem); |
501 | 0 | MS_COPYSTELEM(rangeitemindex); |
502 | 0 | MS_COPYSTELEM(outlinewidth); |
503 | 0 | MS_COPYSTELEM(minscaledenom); |
504 | 0 | MS_COPYSTELEM(maxscaledenom); |
505 | | /* TODO: add copy for bindings */ |
506 | |
|
507 | 0 | MS_COPYSTELEM(sizeunits); |
508 | 0 | MS_COPYSTELEM(scalefactor); |
509 | |
|
510 | 0 | return MS_SUCCESS; |
511 | 0 | } |
512 | | |
513 | | /*********************************************************************** |
514 | | * msCopyClass() * |
515 | | * * |
516 | | * Copy a classObj, using msCopyExpression(), msCopyStyle(), * |
517 | | * msCopyLabel(), msCreateHashTable(), msCopyHashTable() * |
518 | | **********************************************************************/ |
519 | | |
520 | 0 | int msCopyClass(classObj *dst, const classObj *src, layerObj *layer_unused) { |
521 | 0 | int i, return_value; |
522 | 0 | (void)layer_unused; |
523 | |
|
524 | 0 | return_value = msCopyExpression(&(dst->expression), &(src->expression)); |
525 | 0 | if (return_value != MS_SUCCESS) { |
526 | 0 | msSetError(MS_MEMERR, "Failed to copy expression.", "msCopyClass()"); |
527 | 0 | return MS_FAILURE; |
528 | 0 | } |
529 | | |
530 | 0 | MS_COPYSTELEM(status); |
531 | 0 | MS_COPYSTELEM(isfallback); |
532 | | |
533 | | /* free any previous styles on the dst layer */ |
534 | 0 | for (i = 0; i < dst->numstyles; i++) { /* each style */ |
535 | 0 | if (dst->styles[i] != NULL) { |
536 | 0 | if (freeStyle(dst->styles[i]) == MS_SUCCESS) { |
537 | 0 | msFree(dst->styles[i]); |
538 | 0 | } |
539 | 0 | } |
540 | 0 | } |
541 | 0 | dst->numstyles = 0; |
542 | |
|
543 | 0 | for (i = 0; i < src->numstyles; i++) { |
544 | 0 | if (msGrowClassStyles(dst) == NULL) |
545 | 0 | return MS_FAILURE; |
546 | 0 | if (initStyle(dst->styles[i]) != MS_SUCCESS) { |
547 | 0 | msSetError(MS_MEMERR, "Failed to init style.", "msCopyClass()"); |
548 | 0 | return MS_FAILURE; |
549 | 0 | } |
550 | 0 | if (msCopyStyle(dst->styles[i], src->styles[i]) != MS_SUCCESS) { |
551 | 0 | msSetError(MS_MEMERR, "Failed to copy style.", "msCopyClass()"); |
552 | 0 | return MS_FAILURE; |
553 | 0 | } |
554 | | |
555 | 0 | dst->numstyles++; |
556 | 0 | } |
557 | | |
558 | 0 | for (i = 0; i < src->numlabels; i++) { |
559 | 0 | if (msGrowClassLabels(dst) == NULL) |
560 | 0 | return MS_FAILURE; |
561 | 0 | initLabel(dst->labels[i]); |
562 | 0 | if (msCopyLabel(dst->labels[i], src->labels[i]) != MS_SUCCESS) { |
563 | 0 | msSetError(MS_MEMERR, "Failed to copy label.", "msCopyClass()"); |
564 | 0 | return MS_FAILURE; |
565 | 0 | } |
566 | | |
567 | 0 | dst->numlabels++; |
568 | 0 | } |
569 | 0 | MS_COPYSTELEM(numlabels); |
570 | |
|
571 | 0 | if (src->leader) { |
572 | 0 | if (dst->leader) { |
573 | 0 | freeLabelLeader(dst->leader); |
574 | 0 | } |
575 | 0 | if (!dst->leader) { |
576 | 0 | dst->leader = msSmallMalloc(sizeof(labelLeaderObj)); |
577 | 0 | initLeader(dst->leader); |
578 | 0 | } |
579 | 0 | msCopyLabelLeader(dst->leader, src->leader); |
580 | 0 | } |
581 | |
|
582 | 0 | MS_COPYSTRING(dst->keyimage, src->keyimage); |
583 | 0 | MS_COPYSTRING(dst->name, src->name); |
584 | 0 | MS_COPYSTRING(dst->title, src->title); |
585 | 0 | MS_COPYSTRING(dst->group, src->group); |
586 | |
|
587 | 0 | if (msCopyExpression(&(dst->text), &(src->text)) != MS_SUCCESS) { |
588 | 0 | msSetError(MS_MEMERR, "Failed to copy text.", "msCopyClass()"); |
589 | 0 | return MS_FAILURE; |
590 | 0 | } |
591 | | |
592 | 0 | #ifndef __cplusplus |
593 | 0 | MS_COPYSTRING(dst->template, src->template); |
594 | | #else |
595 | | MS_COPYSTRING(dst->_template, src->_template); |
596 | | #endif |
597 | |
|
598 | 0 | msCopyHashTable(&(dst->metadata), &(src->metadata)); |
599 | 0 | msCopyHashTable(&dst->validation, &src->validation); |
600 | |
|
601 | 0 | MS_COPYSTELEM(minscaledenom); |
602 | 0 | MS_COPYSTELEM(maxscaledenom); |
603 | 0 | MS_COPYSTELEM(layer); |
604 | 0 | MS_COPYSTELEM(debug); |
605 | |
|
606 | 0 | MS_COPYSTELEM(sizeunits); |
607 | 0 | MS_COPYSTELEM(scalefactor); |
608 | |
|
609 | 0 | return MS_SUCCESS; |
610 | 0 | } |
611 | | |
612 | 0 | int msCopyCluster(clusterObj *dst, const clusterObj *src) { |
613 | 0 | int return_value; |
614 | |
|
615 | 0 | MS_COPYSTELEM(maxdistance); |
616 | 0 | MS_COPYSTELEM(buffer); |
617 | 0 | MS_COPYSTRING(dst->region, src->region); |
618 | |
|
619 | 0 | return_value = msCopyExpression(&(dst->group), &(src->group)); |
620 | 0 | if (return_value != MS_SUCCESS) { |
621 | 0 | msSetError(MS_MEMERR, "Failed to copy cluster group.", "msCopyCluster()"); |
622 | 0 | return MS_FAILURE; |
623 | 0 | } |
624 | | |
625 | 0 | return_value = msCopyExpression(&(dst->filter), &(src->filter)); |
626 | 0 | if (return_value != MS_SUCCESS) { |
627 | 0 | msSetError(MS_MEMERR, "Failed to copy cluster filter.", "msCopyCluster()"); |
628 | 0 | return MS_FAILURE; |
629 | 0 | } |
630 | | |
631 | 0 | return MS_SUCCESS; |
632 | 0 | } |
633 | | |
634 | | /*********************************************************************** |
635 | | * msCopyGrid() * |
636 | | **********************************************************************/ |
637 | | |
638 | 0 | int msCopyGrid(graticuleObj *dst, const graticuleObj *src) { |
639 | 0 | MS_COPYSTELEM(dwhichlatitude); |
640 | 0 | MS_COPYSTELEM(dwhichlongitude); |
641 | 0 | MS_COPYSTELEM(dstartlatitude); |
642 | 0 | MS_COPYSTELEM(dstartlongitude); |
643 | 0 | MS_COPYSTELEM(dendlatitude); |
644 | 0 | MS_COPYSTELEM(dendlongitude); |
645 | 0 | MS_COPYSTELEM(dincrementlatitude); |
646 | 0 | MS_COPYSTELEM(dincrementlongitude); |
647 | 0 | MS_COPYSTELEM(minarcs); |
648 | 0 | MS_COPYSTELEM(maxarcs); |
649 | 0 | MS_COPYSTELEM(minincrement); |
650 | 0 | MS_COPYSTELEM(maxincrement); |
651 | 0 | MS_COPYSTELEM(minsubdivides); |
652 | 0 | MS_COPYSTELEM(maxsubdivides); |
653 | 0 | MS_COPYSTELEM(bvertical); |
654 | 0 | MS_COPYSTELEM(blabelaxes); |
655 | 0 | MS_COPYSTELEM(ilabelstate); |
656 | 0 | MS_COPYSTELEM(ilabeltype); |
657 | 0 | MS_COPYRECT(&(dst->extent), &(src->extent)); |
658 | 0 | MS_COPYSTRING(dst->labelformat, src->labelformat); |
659 | |
|
660 | 0 | return MS_SUCCESS; |
661 | 0 | } |
662 | | |
663 | | #ifdef why_on_earth_would_you_copy_a_labelcache |
664 | | |
665 | | /*********************************************************************** |
666 | | * msCopyLabelCacheMember() * |
667 | | * * |
668 | | * Copy a labelCacheMemberObj using msCopyStyle(), msCopyPoint() * |
669 | | * * |
670 | | * Note: since it seems most users will want to clone maps rather than * |
671 | | * make exact copies, this method might not get much use. * |
672 | | **********************************************************************/ |
673 | | |
674 | | int msCopyLabelCacheMember(labelCacheMemberObj *dst, |
675 | | const labelCacheMemberObj *src) { |
676 | | int i; |
677 | | |
678 | | MS_COPYSTELEM(featuresize); |
679 | | |
680 | | MS_COPYSTELEM(numstyles); |
681 | | for (i = 0; i < dst->numstyles; i++) { |
682 | | msCopyStyle(&(dst->styles[i]), &(src->styles[i])); |
683 | | } |
684 | | |
685 | | MS_COPYSTELEM(numlabels); |
686 | | dst->labels = (labelObj *)msSmallMalloc(sizeof(labelObj) * dst->numlabels); |
687 | | for (i = 0; i < dst->numlabels; i++) { |
688 | | msCopyLabel(&(dst->labels[i]), &(src->labels[i])); |
689 | | } |
690 | | |
691 | | MS_COPYSTELEM(layerindex); |
692 | | MS_COPYSTELEM(classindex); |
693 | | MS_COPYSTELEM(tileindex); |
694 | | MS_COPYSTELEM(shapeindex); |
695 | | MS_COPYPOINT(&(dst->point), &(src->point)); |
696 | | /* msCopyShape(&(dst->poly), &(src->poly)); */ |
697 | | MS_COPYSTELEM(status); |
698 | | |
699 | | return MS_SUCCESS; |
700 | | } |
701 | | |
702 | | /*********************************************************************** |
703 | | * msCopyMarkerCacheMember() * |
704 | | * * |
705 | | * Copy a markerCacheMemberObj * |
706 | | **********************************************************************/ |
707 | | |
708 | | int msCopyMarkerCacheMember(markerCacheMemberObj *dst, |
709 | | const markerCacheMemberObj *src) { |
710 | | MS_COPYSTELEM(id); |
711 | | |
712 | | /* msCopyShape(&(dst->poly), &(src->poly)); */ |
713 | | return MS_SUCCESS; |
714 | | } |
715 | | |
716 | | /*********************************************************************** |
717 | | * msCopyLabelCacheSlot() * |
718 | | **********************************************************************/ |
719 | | |
720 | | int msCopyLabelCacheSlot(labelCacheSlotObj *dst, const labelCacheSlotObj *src) { |
721 | | int i; |
722 | | |
723 | | for (i = 0; i < dst->numlabels; i++) { |
724 | | msCopyLabelCacheMember(&(dst->labels[i]), &(src->labels[i])); |
725 | | } |
726 | | MS_COPYSTELEM(cachesize); |
727 | | MS_COPYSTELEM(nummarkers); |
728 | | for (i = 0; i < dst->nummarkers; i++) { |
729 | | msCopyMarkerCacheMember(&(dst->markers[i]), &(src->markers[i])); |
730 | | } |
731 | | MS_COPYSTELEM(markercachesize); |
732 | | |
733 | | return MS_SUCCESS; |
734 | | } |
735 | | |
736 | | /*********************************************************************** |
737 | | * msCopyLabelCache() * |
738 | | **********************************************************************/ |
739 | | |
740 | | int msCopyLabelCache(labelCacheObj *dst, const labelCacheObj *src) { |
741 | | int p; |
742 | | MS_COPYSTELEM(numlabels); |
743 | | |
744 | | for (p = 0; p < MS_MAX_LABEL_PRIORITY; p++) { |
745 | | msCopyLabelCacheSlot(&(dst->slots[p]), &(src->slots[p])); |
746 | | } |
747 | | |
748 | | return MS_SUCCESS; |
749 | | } |
750 | | |
751 | | #endif |
752 | | |
753 | | /*********************************************************************** |
754 | | * msCopyResult() * |
755 | | **********************************************************************/ |
756 | | |
757 | 0 | int msCopyResult(resultObj *dst, const resultObj *src) { |
758 | 0 | MS_COPYSTELEM(shapeindex); |
759 | 0 | MS_COPYSTELEM(tileindex); |
760 | 0 | MS_COPYSTELEM(classindex); |
761 | 0 | MS_COPYSTELEM(resultindex); |
762 | |
|
763 | 0 | return MS_SUCCESS; |
764 | 0 | } |
765 | | |
766 | | /*********************************************************************** |
767 | | * msCopyResultCache() * |
768 | | **********************************************************************/ |
769 | | |
770 | 0 | int msCopyResultCache(resultCacheObj *dst, const resultCacheObj *src) { |
771 | 0 | int i; |
772 | 0 | MS_COPYSTELEM(cachesize); |
773 | 0 | MS_COPYSTELEM(numresults); |
774 | 0 | for (i = 0; i < dst->numresults; i++) { |
775 | 0 | msCopyResult(&(dst->results[i]), &(src->results[i])); |
776 | 0 | } |
777 | 0 | MS_COPYRECT(&(dst->bounds), &(src->bounds)); |
778 | |
|
779 | 0 | return MS_SUCCESS; |
780 | 0 | } |
781 | | |
782 | | /*********************************************************************** |
783 | | * msCopyReferenceMap() * |
784 | | * * |
785 | | * Copy a referenceMapObj using mapfile.c:initReferenceMap(), * |
786 | | * msCopyRect(), msCopyColor() * |
787 | | **********************************************************************/ |
788 | | |
789 | | int msCopyReferenceMap(referenceMapObj *dst, const referenceMapObj *src, |
790 | 0 | mapObj *map) { |
791 | |
|
792 | 0 | initReferenceMap(dst); |
793 | |
|
794 | 0 | MS_COPYRECT(&(dst->extent), &(src->extent)); |
795 | |
|
796 | 0 | MS_COPYSTELEM(height); |
797 | 0 | MS_COPYSTELEM(width); |
798 | |
|
799 | 0 | MS_COPYCOLOR(&(dst->color), &(src->color)); |
800 | 0 | MS_COPYCOLOR(&(dst->outlinecolor), &(src->outlinecolor)); |
801 | 0 | MS_COPYSTRING(dst->image, src->image); |
802 | |
|
803 | 0 | MS_COPYSTELEM(status); |
804 | 0 | MS_COPYSTELEM(marker); |
805 | 0 | MS_COPYSTRING(dst->markername, src->markername); |
806 | 0 | MS_COPYSTELEM(markersize); |
807 | 0 | MS_COPYSTELEM(minboxsize); |
808 | 0 | MS_COPYSTELEM(maxboxsize); |
809 | 0 | dst->map = map; |
810 | |
|
811 | 0 | return MS_SUCCESS; |
812 | 0 | } |
813 | | |
814 | | /*********************************************************************** |
815 | | * msCopyScalebar() * |
816 | | * * |
817 | | * Copy a scalebarObj, using initScalebar(), msCopyColor(), * |
818 | | * and msCopyLabel() * |
819 | | **********************************************************************/ |
820 | | |
821 | 0 | int msCopyScalebar(scalebarObj *dst, const scalebarObj *src) { |
822 | |
|
823 | 0 | initScalebar(dst); |
824 | |
|
825 | 0 | MS_COPYCOLOR(&(dst->imagecolor), &(src->imagecolor)); |
826 | 0 | MS_COPYSTELEM(height); |
827 | 0 | MS_COPYSTELEM(width); |
828 | 0 | MS_COPYSTELEM(style); |
829 | 0 | MS_COPYSTELEM(intervals); |
830 | |
|
831 | 0 | if (msCopyLabel(&(dst->label), &(src->label)) != MS_SUCCESS) { |
832 | 0 | msSetError(MS_MEMERR, "Failed to copy label.", "msCopyScalebar()"); |
833 | 0 | return MS_FAILURE; |
834 | 0 | } |
835 | | |
836 | 0 | MS_COPYCOLOR(&(dst->color), &(src->color)); |
837 | 0 | MS_COPYCOLOR(&(dst->backgroundcolor), &(src->backgroundcolor)); |
838 | |
|
839 | 0 | MS_COPYCOLOR(&(dst->outlinecolor), &(src->outlinecolor)); |
840 | |
|
841 | 0 | MS_COPYSTELEM(units); |
842 | 0 | MS_COPYSTELEM(status); |
843 | 0 | MS_COPYSTELEM(position); |
844 | 0 | MS_COPYSTELEM(transparent); |
845 | 0 | MS_COPYSTELEM(postlabelcache); |
846 | 0 | MS_COPYSTELEM(align); |
847 | |
|
848 | 0 | return MS_SUCCESS; |
849 | 0 | } |
850 | | |
851 | | /*********************************************************************** |
852 | | * msCopyLegend() * |
853 | | * * |
854 | | * Copy a legendObj, using msCopyColor() * |
855 | | **********************************************************************/ |
856 | | |
857 | 0 | int msCopyLegend(legendObj *dst, const legendObj *src, mapObj *map) { |
858 | 0 | int return_value; |
859 | |
|
860 | 0 | MS_COPYCOLOR(&(dst->imagecolor), &(src->imagecolor)); |
861 | |
|
862 | 0 | return_value = msCopyLabel(&(dst->label), &(src->label)); |
863 | 0 | if (return_value != MS_SUCCESS) { |
864 | 0 | msSetError(MS_MEMERR, "Failed to copy label.", "msCopyLegend()"); |
865 | 0 | return MS_FAILURE; |
866 | 0 | } |
867 | | |
868 | 0 | MS_COPYSTELEM(keysizex); |
869 | 0 | MS_COPYSTELEM(keysizey); |
870 | 0 | MS_COPYSTELEM(keyspacingx); |
871 | 0 | MS_COPYSTELEM(keyspacingy); |
872 | |
|
873 | 0 | MS_COPYCOLOR(&(dst->outlinecolor), &(src->outlinecolor)); |
874 | |
|
875 | 0 | MS_COPYSTELEM(status); |
876 | 0 | MS_COPYSTELEM(height); |
877 | 0 | MS_COPYSTELEM(width); |
878 | 0 | MS_COPYSTELEM(position); |
879 | 0 | MS_COPYSTELEM(transparent); |
880 | 0 | MS_COPYSTELEM(postlabelcache); |
881 | |
|
882 | 0 | #ifndef __cplusplus |
883 | 0 | MS_COPYSTRING(dst->template, src->template); |
884 | | #else |
885 | | MS_COPYSTRING(dst->_template, src->_template); |
886 | | #endif |
887 | 0 | dst->map = map; |
888 | |
|
889 | 0 | return MS_SUCCESS; |
890 | 0 | } |
891 | | |
892 | | int msCopyScaleTokenEntry(const scaleTokenEntryObj *src, |
893 | 0 | scaleTokenEntryObj *dst) { |
894 | 0 | MS_COPYSTRING(dst->value, src->value); |
895 | 0 | MS_COPYSTELEM(minscale); |
896 | 0 | MS_COPYSTELEM(maxscale); |
897 | 0 | return MS_SUCCESS; |
898 | 0 | } |
899 | | |
900 | 0 | int msCopyScaleToken(const scaleTokenObj *src, scaleTokenObj *dst) { |
901 | 0 | int i; |
902 | 0 | MS_COPYSTRING(dst->name, src->name); |
903 | 0 | MS_COPYSTELEM(n_entries); |
904 | 0 | dst->tokens = (scaleTokenEntryObj *)msSmallCalloc(src->n_entries, |
905 | 0 | sizeof(scaleTokenEntryObj)); |
906 | 0 | for (i = 0; i < src->n_entries; i++) { |
907 | 0 | msCopyScaleTokenEntry(&src->tokens[i], &dst->tokens[i]); |
908 | 0 | } |
909 | 0 | return MS_SUCCESS; |
910 | 0 | } |
911 | | |
912 | | int msCopyCompositingFilter(CompositingFilter **pdst, |
913 | 0 | const CompositingFilter *src) { |
914 | 0 | CompositingFilter *dst = NULL; |
915 | 0 | if (!src) { |
916 | 0 | *pdst = NULL; |
917 | 0 | return MS_SUCCESS; |
918 | 0 | } |
919 | 0 | while (src) { |
920 | 0 | if (!dst) { |
921 | 0 | dst = *pdst = msSmallMalloc(sizeof(CompositingFilter)); |
922 | 0 | } else { |
923 | 0 | dst->next = msSmallMalloc(sizeof(CompositingFilter)); |
924 | 0 | dst = dst->next; |
925 | 0 | } |
926 | 0 | dst->filter = msStrdup(src->filter); |
927 | 0 | dst->next = NULL; |
928 | 0 | src = src->next; |
929 | 0 | } |
930 | 0 | return MS_SUCCESS; |
931 | 0 | } |
932 | | |
933 | 0 | int msCopyCompositer(LayerCompositer **ldst, const LayerCompositer *src) { |
934 | 0 | LayerCompositer *dst = NULL; |
935 | 0 | if (!src) { |
936 | 0 | *ldst = NULL; |
937 | 0 | return MS_SUCCESS; |
938 | 0 | } |
939 | | |
940 | 0 | while (src) { |
941 | 0 | if (!dst) { |
942 | 0 | dst = *ldst = msSmallMalloc(sizeof(LayerCompositer)); |
943 | 0 | } else { |
944 | 0 | dst->next = msSmallMalloc(sizeof(LayerCompositer)); |
945 | 0 | dst = dst->next; |
946 | 0 | } |
947 | 0 | dst->comp_op = src->comp_op; |
948 | 0 | dst->opacity = src->opacity; |
949 | 0 | dst->next = NULL; |
950 | 0 | msCopyCompositingFilter(&dst->filter, src->filter); |
951 | 0 | src = src->next; |
952 | 0 | } |
953 | 0 | return MS_SUCCESS; |
954 | 0 | } |
955 | | |
956 | | /*********************************************************************** |
957 | | * msCopyLayer() * |
958 | | * * |
959 | | * Copy a layerObj, using mapfile.c:initClass(), msCopyClass(), * |
960 | | * msCopyColor(), msCopyProjection(), msShapefileOpen(), * |
961 | | * msCreateHashTable(), msCopyHashTable(), msCopyExpression() * |
962 | | * * |
963 | | * As it stands, we are not copying a layer's resultcache * |
964 | | **********************************************************************/ |
965 | | |
966 | 0 | int msCopyLayer(layerObj *dst, const layerObj *src) { |
967 | 0 | int i, return_value; |
968 | 0 | featureListNodeObjPtr current; |
969 | |
|
970 | 0 | MS_COPYSTELEM(index); |
971 | 0 | MS_COPYSTRING(dst->classitem, src->classitem); |
972 | |
|
973 | 0 | MS_COPYSTELEM(classitemindex); |
974 | |
|
975 | 0 | for (i = 0; i < src->numscaletokens; i++) { |
976 | 0 | if (msGrowLayerScaletokens(dst) == NULL) |
977 | 0 | return MS_FAILURE; |
978 | 0 | initScaleToken(&dst->scaletokens[i]); |
979 | 0 | msCopyScaleToken(&src->scaletokens[i], &dst->scaletokens[i]); |
980 | 0 | dst->numscaletokens++; |
981 | 0 | } |
982 | | |
983 | 0 | for (i = 0; i < src->numclasses; i++) { |
984 | 0 | if (msGrowLayerClasses(dst) == NULL) |
985 | 0 | return MS_FAILURE; |
986 | 0 | #ifndef __cplusplus |
987 | 0 | initClass(dst->class[i]); |
988 | 0 | return_value = msCopyClass(dst->class[i], src -> class[i], dst); |
989 | | #else |
990 | | initClass(dst->_class[i]); |
991 | | return_value = msCopyClass(dst->_class[i], src->_class[i], dst); |
992 | | #endif |
993 | 0 | if (return_value != MS_SUCCESS) { |
994 | 0 | msSetError(MS_MEMERR, "Failed to copy class.", "msCopyLayer()"); |
995 | 0 | return MS_FAILURE; |
996 | 0 | } |
997 | 0 | dst->numclasses++; |
998 | 0 | } |
999 | 0 | MS_COPYSTRING(dst->header, src->header); |
1000 | 0 | MS_COPYSTRING(dst->footer, src->footer); |
1001 | 0 | #ifndef __cplusplus |
1002 | 0 | MS_COPYSTRING(dst->template, src->template); |
1003 | | #else |
1004 | | MS_COPYSTRING(dst->_template, src->_template); |
1005 | | #endif |
1006 | |
|
1007 | 0 | MS_COPYSTRING(dst->name, src->name); |
1008 | 0 | MS_COPYSTRING(dst->group, src->group); |
1009 | 0 | MS_COPYSTRING(dst->data, src->data); |
1010 | 0 | MS_COPYSTRING(dst->encoding, src->encoding); |
1011 | |
|
1012 | 0 | MS_COPYSTELEM(rendermode); |
1013 | 0 | MS_COPYSTELEM(status); |
1014 | 0 | MS_COPYSTELEM(type); |
1015 | 0 | MS_COPYSTELEM(tolerance); |
1016 | 0 | MS_COPYSTELEM(toleranceunits); |
1017 | 0 | MS_COPYSTELEM(symbolscaledenom); |
1018 | 0 | MS_COPYSTELEM(scalefactor); |
1019 | 0 | MS_COPYSTELEM(minscaledenom); |
1020 | 0 | MS_COPYSTELEM(maxscaledenom); |
1021 | |
|
1022 | 0 | MS_COPYSTELEM(labelminscaledenom); |
1023 | 0 | MS_COPYSTELEM(labelmaxscaledenom); |
1024 | 0 | MS_COPYSTELEM(mingeowidth); |
1025 | 0 | MS_COPYSTELEM(maxgeowidth); |
1026 | |
|
1027 | 0 | MS_COPYSTELEM(sizeunits); |
1028 | 0 | MS_COPYSTELEM(maxfeatures); |
1029 | |
|
1030 | 0 | MS_COPYCOLOR(&(dst->offsite), &(src->offsite)); |
1031 | |
|
1032 | 0 | MS_COPYSTELEM(transform); |
1033 | 0 | MS_COPYSTELEM(labelcache); |
1034 | 0 | MS_COPYSTELEM(postlabelcache); |
1035 | |
|
1036 | 0 | MS_COPYSTRING(dst->labelitem, src->labelitem); |
1037 | 0 | MS_COPYSTELEM(labelitemindex); |
1038 | |
|
1039 | 0 | MS_COPYSTRING(dst->tileitem, src->tileitem); |
1040 | 0 | MS_COPYSTELEM(tileitemindex); |
1041 | |
|
1042 | 0 | MS_COPYSTRING(dst->tilesrs, src->tilesrs); |
1043 | |
|
1044 | 0 | MS_COPYSTRING(dst->tileindex, src->tileindex); |
1045 | |
|
1046 | 0 | return_value = msCopyProjection(&(dst->projection), &(src->projection)); |
1047 | 0 | if (return_value != MS_SUCCESS) { |
1048 | 0 | msSetError(MS_MEMERR, "Failed to copy projection.", "msCopyLayer()"); |
1049 | 0 | return MS_FAILURE; |
1050 | 0 | } |
1051 | | |
1052 | 0 | return_value = msCopyCluster(&(dst->cluster), &(src->cluster)); |
1053 | 0 | if (return_value != MS_SUCCESS) { |
1054 | 0 | return MS_FAILURE; |
1055 | 0 | } |
1056 | | |
1057 | 0 | MS_COPYSTELEM(project); |
1058 | 0 | MS_COPYSTELEM(units); |
1059 | |
|
1060 | 0 | current = src->features; |
1061 | 0 | while (current != NULL) { |
1062 | 0 | insertFeatureList(&(dst->features), &(current->shape)); |
1063 | 0 | current = current->next; |
1064 | 0 | } |
1065 | |
|
1066 | 0 | MS_COPYSTRING(dst->connection, src->connection); |
1067 | 0 | MS_COPYSTELEM(connectiontype); |
1068 | |
|
1069 | 0 | MS_COPYSTRING(dst->plugin_library, src->plugin_library); |
1070 | 0 | MS_COPYSTRING(dst->plugin_library_original, src->plugin_library_original); |
1071 | | |
1072 | | /* Do not copy *layerinfo, items, or iteminfo. these are all initialized |
1073 | | when the copied layer is opened */ |
1074 | |
|
1075 | 0 | return_value = msCopyExpression(&(dst->filter), &(src->filter)); |
1076 | 0 | if (return_value != MS_SUCCESS) { |
1077 | 0 | msSetError(MS_MEMERR, "Failed to copy filter.", "msCopyLayer()"); |
1078 | 0 | return MS_FAILURE; |
1079 | 0 | } |
1080 | | |
1081 | 0 | MS_COPYSTRING(dst->filteritem, src->filteritem); |
1082 | 0 | MS_COPYSTELEM(filteritemindex); |
1083 | |
|
1084 | 0 | MS_COPYSTRING(dst->styleitem, src->styleitem); |
1085 | 0 | MS_COPYSTELEM(styleitemindex); |
1086 | |
|
1087 | 0 | MS_COPYSTRING(dst->requires, src->requires); |
1088 | 0 | MS_COPYSTRING(dst->labelrequires, src->labelrequires); |
1089 | |
|
1090 | 0 | msCopyHashTable(&(dst->metadata), &(src->metadata)); |
1091 | 0 | msCopyHashTable(&dst->validation, &src->validation); |
1092 | 0 | msCopyHashTable(&dst->connectionoptions, &src->connectionoptions); |
1093 | |
|
1094 | 0 | MS_COPYSTELEM(debug); |
1095 | |
|
1096 | 0 | dst->processing = CSLDuplicate(src->processing); |
1097 | |
|
1098 | 0 | MS_COPYSTELEM(numjoins); |
1099 | |
|
1100 | 0 | for (i = 0; i < dst->numjoins; i++) { |
1101 | 0 | initJoin(&(dst->joins[i])); |
1102 | 0 | return_value = msCopyJoin(&(dst->joins[i]), &(src->joins[i])); |
1103 | 0 | if (return_value != MS_SUCCESS) |
1104 | 0 | return MS_FAILURE; |
1105 | 0 | } |
1106 | | |
1107 | 0 | MS_COPYRECT(&(dst->extent), &(src->extent)); |
1108 | |
|
1109 | 0 | MS_COPYSTRING(dst->classgroup, src->classgroup); |
1110 | 0 | MS_COPYSTRING(dst->mask, src->mask); |
1111 | |
|
1112 | 0 | if (src->grid) { |
1113 | 0 | if (dst->grid) { |
1114 | 0 | freeGrid(dst->grid); |
1115 | 0 | msFree(dst->grid); |
1116 | 0 | } |
1117 | 0 | dst->grid = (void *)malloc(sizeof(graticuleObj)); |
1118 | 0 | MS_CHECK_ALLOC(dst->grid, sizeof(graticuleObj), -1); |
1119 | 0 | initGrid(dst->grid); |
1120 | 0 | msCopyGrid(dst->grid, src->grid); |
1121 | 0 | } |
1122 | | |
1123 | 0 | if (src->compositer) { |
1124 | 0 | msCopyCompositer(&dst->compositer, src->compositer); |
1125 | 0 | } |
1126 | |
|
1127 | 0 | return MS_SUCCESS; |
1128 | 0 | } |
1129 | | |
1130 | | /*********************************************************************** |
1131 | | * msCopyMap() * |
1132 | | * * |
1133 | | * Copy a mapObj, using mapfile.c:initLayer(), msCopyLayer(), * |
1134 | | |
1135 | | * msCopyLegend(), msCopyScalebar(), msCopyProjection() * |
1136 | | * msCopyOutputFormat(), msCopyWeb(), msCopyReferenceMap() * |
1137 | | **********************************************************************/ |
1138 | | |
1139 | 0 | int msCopyMap(mapObj *dst, const mapObj *src) { |
1140 | 0 | int i, return_value; |
1141 | 0 | outputFormatObj *format; |
1142 | |
|
1143 | 0 | MS_COPYSTRING(dst->name, src->name); |
1144 | 0 | MS_COPYSTELEM(status); |
1145 | 0 | MS_COPYSTELEM(height); |
1146 | 0 | MS_COPYSTELEM(width); |
1147 | 0 | MS_COPYSTELEM(maxsize); |
1148 | |
|
1149 | 0 | for (i = 0; i < src->numlayers; i++) { |
1150 | 0 | if (msGrowMapLayers(dst) == NULL) |
1151 | 0 | return MS_FAILURE; |
1152 | 0 | initLayer((GET_LAYER(dst, i)), dst); |
1153 | |
|
1154 | 0 | return_value = msCopyLayer((GET_LAYER(dst, i)), (GET_LAYER(src, i))); |
1155 | 0 | if (return_value != MS_SUCCESS) { |
1156 | 0 | msSetError(MS_MEMERR, "Failed to copy layer.", "msCopyMap()"); |
1157 | 0 | return MS_FAILURE; |
1158 | 0 | } |
1159 | 0 | dst->numlayers++; |
1160 | 0 | } |
1161 | | |
1162 | 0 | return_value = msCopyFontSet(&(dst->fontset), &(src->fontset), dst); |
1163 | 0 | if (return_value != MS_SUCCESS) { |
1164 | 0 | msSetError(MS_MEMERR, "Failed to copy fontset.", "msCopyMap()"); |
1165 | 0 | return MS_FAILURE; |
1166 | 0 | } |
1167 | | |
1168 | 0 | return_value = msCopySymbolSet(&(dst->symbolset), &(src->symbolset), dst); |
1169 | 0 | if (return_value != MS_SUCCESS) { |
1170 | 0 | msSetError(MS_MEMERR, "Failed to copy symbolset.", "msCopyMap()"); |
1171 | 0 | return MS_FAILURE; |
1172 | 0 | } |
1173 | | |
1174 | | /* msCopyLabelCache(&(dst->labelcache), &(src->labelcache)); */ |
1175 | 0 | MS_COPYRECT(&(dst->extent), &(src->extent)); |
1176 | |
|
1177 | 0 | MS_COPYSTELEM(cellsize); |
1178 | 0 | MS_COPYSTELEM(units); |
1179 | 0 | MS_COPYSTELEM(scaledenom); |
1180 | 0 | MS_COPYSTELEM(defresolution); |
1181 | 0 | MS_COPYSTELEM(resolution); |
1182 | 0 | MS_COPYSTRING(dst->shapepath, src->shapepath); |
1183 | 0 | MS_COPYSTRING(dst->mappath, src->mappath); |
1184 | 0 | MS_COPYSTELEM(sldurl); |
1185 | |
|
1186 | 0 | MS_COPYCOLOR(&(dst->imagecolor), &(src->imagecolor)); |
1187 | | |
1188 | | /* clear existing destination format list */ |
1189 | 0 | if (dst->outputformat && --dst->outputformat->refcount < 1) { |
1190 | 0 | msFreeOutputFormat(dst->outputformat); |
1191 | 0 | dst->outputformat = NULL; |
1192 | 0 | } |
1193 | |
|
1194 | 0 | for (i = 0; i < dst->numoutputformats; i++) { |
1195 | 0 | if (--dst->outputformatlist[i]->refcount < 1) |
1196 | 0 | msFreeOutputFormat(dst->outputformatlist[i]); |
1197 | 0 | } |
1198 | 0 | if (dst->outputformatlist != NULL) |
1199 | 0 | msFree(dst->outputformatlist); |
1200 | 0 | dst->outputformatlist = NULL; |
1201 | 0 | dst->outputformat = NULL; |
1202 | 0 | dst->numoutputformats = 0; |
1203 | |
|
1204 | 0 | for (i = 0; i < src->numoutputformats; i++) |
1205 | 0 | msAppendOutputFormat(dst, msCloneOutputFormat(src->outputformatlist[i])); |
1206 | | |
1207 | | /* set the active output format */ |
1208 | 0 | MS_COPYSTRING(dst->imagetype, src->imagetype); |
1209 | 0 | format = msSelectOutputFormat(dst, dst->imagetype); |
1210 | 0 | msApplyOutputFormat(&(dst->outputformat), format, MS_NOOVERRIDE); |
1211 | |
|
1212 | 0 | return_value = msCopyProjection(&(dst->projection), &(src->projection)); |
1213 | 0 | if (return_value != MS_SUCCESS) { |
1214 | 0 | msSetError(MS_MEMERR, "Failed to copy projection.", "msCopyMap()"); |
1215 | 0 | return MS_FAILURE; |
1216 | 0 | } |
1217 | | |
1218 | | /* No need to copy latlon projection */ |
1219 | | |
1220 | 0 | return_value = msCopyReferenceMap(&(dst->reference), &(src->reference), dst); |
1221 | 0 | if (return_value != MS_SUCCESS) { |
1222 | 0 | msSetError(MS_MEMERR, "Failed to copy reference.", "msCopyMap()"); |
1223 | 0 | return MS_FAILURE; |
1224 | 0 | } |
1225 | | |
1226 | 0 | return_value = msCopyScalebar(&(dst->scalebar), &(src->scalebar)); |
1227 | 0 | if (return_value != MS_SUCCESS) { |
1228 | 0 | msSetError(MS_MEMERR, "Failed to copy scalebar.", "msCopyMap()"); |
1229 | 0 | return MS_FAILURE; |
1230 | 0 | } |
1231 | | |
1232 | 0 | return_value = msCopyLegend(&(dst->legend), &(src->legend), dst); |
1233 | 0 | if (return_value != MS_SUCCESS) { |
1234 | 0 | msSetError(MS_MEMERR, "Failed to copy legend.", "msCopyMap()"); |
1235 | 0 | return MS_FAILURE; |
1236 | 0 | } |
1237 | | |
1238 | 0 | return_value = msCopyQueryMap(&(dst->querymap), &(src->querymap)); |
1239 | 0 | if (return_value != MS_SUCCESS) { |
1240 | 0 | msSetError(MS_MEMERR, "Failed to copy querymap.", "msCopyMap()"); |
1241 | 0 | return MS_FAILURE; |
1242 | 0 | } |
1243 | | |
1244 | 0 | return_value = msCopyWeb(&(dst->web), &(src->web), dst); |
1245 | 0 | if (return_value != MS_SUCCESS) { |
1246 | 0 | msSetError(MS_MEMERR, "Failed to copy web.", "msCopyMap()"); |
1247 | 0 | return MS_FAILURE; |
1248 | 0 | } |
1249 | | |
1250 | 0 | if (src->layerorder) { |
1251 | 0 | for (i = 0; i < dst->numlayers; i++) { |
1252 | 0 | MS_COPYSTELEM(layerorder[i]); |
1253 | 0 | } |
1254 | 0 | } |
1255 | 0 | MS_COPYSTELEM(debug); |
1256 | 0 | MS_COPYSTRING(dst->datapattern, src->datapattern); |
1257 | 0 | MS_COPYSTRING(dst->templatepattern, src->templatepattern); |
1258 | |
|
1259 | 0 | if (msCopyHashTable(&(dst->configoptions), &(src->configoptions)) != |
1260 | 0 | MS_SUCCESS) |
1261 | 0 | return MS_FAILURE; |
1262 | | |
1263 | 0 | return MS_SUCCESS; |
1264 | 0 | } |
1265 | | |
1266 | 0 | int msCopyRasterBuffer(rasterBufferObj *dst, const rasterBufferObj *src) { |
1267 | 0 | *dst = *src; |
1268 | 0 | if (src->type == MS_BUFFER_BYTE_RGBA) { |
1269 | 0 | dst->data.rgba = src->data.rgba; |
1270 | 0 | dst->data.rgba.pixels = |
1271 | 0 | msSmallMalloc(((size_t)src->height) * src->data.rgba.row_step); |
1272 | 0 | memcpy(dst->data.rgba.pixels, src->data.rgba.pixels, |
1273 | 0 | ((size_t)src->data.rgba.row_step) * src->height); |
1274 | 0 | dst->data.rgba.r = |
1275 | 0 | dst->data.rgba.pixels + (src->data.rgba.r - src->data.rgba.pixels); |
1276 | 0 | dst->data.rgba.g = |
1277 | 0 | dst->data.rgba.pixels + (src->data.rgba.g - src->data.rgba.pixels); |
1278 | 0 | dst->data.rgba.b = |
1279 | 0 | dst->data.rgba.pixels + (src->data.rgba.b - src->data.rgba.pixels); |
1280 | 0 | if (src->data.rgba.a) { |
1281 | 0 | dst->data.rgba.a = |
1282 | 0 | dst->data.rgba.pixels + (src->data.rgba.a - src->data.rgba.pixels); |
1283 | 0 | } else { |
1284 | 0 | dst->data.rgba.a = NULL; |
1285 | 0 | } |
1286 | 0 | } |
1287 | 0 | return MS_SUCCESS; |
1288 | 0 | } |