File: mapserver.h

package info (click to toggle)
mapserver 5.6.5-2%2Bsqueeze3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 15,900 kB
  • ctags: 25,593
  • sloc: ansic: 201,813; cpp: 49,629; cs: 11,792; python: 5,233; perl: 3,249; sh: 1,199; makefile: 884; lex: 592; java: 466; xml: 373; yacc: 334; tcl: 158; ruby: 53
file content (2681 lines) | stat: -rw-r--r-- 111,875 bytes parent folder | download
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
/******************************************************************************
 * $Id: mapserver.h 10352 2010-07-14 09:45:57Z dmorissette $
 *
 * Project:  MapServer
 * Purpose:  Primary MapServer include file.
 * Author:   Steve Lime and the MapServer team.
 *
 ******************************************************************************
 * Copyright (c) 1996-2005 Regents of the University of Minnesota.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in 
 * all copies of this Software or works derived from this Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 *****************************************************************************/

#ifndef MAP_H
#define MAP_H

/*
** MapServer version - to be updated for every release 
*/
#define MS_VERSION "5.6.5"

#define MS_VERSION_MAJOR    5
#define MS_VERSION_MINOR    6
#define MS_VERSION_REV      5

#define MS_VERSION_NUM (MS_VERSION_MAJOR*10000+MS_VERSION_MINOR*100+MS_VERSION_REV)


/* 
** Main includes. If a particular header was needed by several .c files then
** I just put it here. What the hell, it works and it's all right here. -SDL-
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#if defined(_WIN32) && !defined(__CYGWIN__)
#include <direct.h>
#include <memory.h>
#include <malloc.h>
#include <process.h>
#include <float.h>
#else
#include <unistd.h>
#endif

#ifndef DISABLE_CVSID
#  define MS_CVSID(string)     static char ms_cvsid[] = string; \
static char *cvsid_aw(void) { return( cvsid_aw() ? ((char *) NULL) : ms_cvsid ); }
#else
#  define MS_CVSID(string)
#endif

#if defined(_WIN32) && !defined(__CYGWIN__)
#  define MS_DLL_EXPORT     __declspec(dllexport)
#else
#define  MS_DLL_EXPORT
#endif

/* definition of  ms_int32/ms_uint32 */
#include <limits.h>
#ifndef _WIN32
#include <stdint.h>
#endif

#ifdef _WIN32
#ifndef SIZE_MAX
#ifdef _WIN64 
#define SIZE_MAX _UI64_MAX
#else
#define SIZE_MAX UINT_MAX
#endif
#endif
#endif

#if ULONG_MAX == 0xffffffff
typedef long            ms_int32;
typedef unsigned long   ms_uint32;
#elif UINT_MAX == 0xffffffff
typedef int             ms_int32;
typedef unsigned int    ms_uint32;
#else
typedef int32_t         ms_int32;
typedef uint32_t        ms_uint32;
#endif

/*forward declaration of rendering object*/
struct rendererVTable;
struct tilecache;
typedef struct rendererVTable rendererVTableObj;
typedef struct tilecache tileCacheObj;



/* ms_bitarray is used by the bit mask in mapbit.c */
typedef ms_uint32 *     ms_bitarray;

#include "maperror.h"
#include "mapprimitive.h"
#include "mapshape.h"
#include "mapsymbol.h"
#include "maptree.h" /* quadtree spatial index */
#include "maphash.h"
#include "mapio.h"

#include "mapproject.h"
#include "cgiutil.h"


#include <gd.h>

#if defined USE_PDF
#include <pdflib.h>
#endif


#include <sys/types.h> /* regular expression support */

/* The regex lib from the system and the regex lib from PHP needs to
 * be separated here. We separate here via its directory location.
 */
#include "mapregex.h"


#ifdef USE_OGR
#define CPL_SUPRESS_CPLUSPLUS
#include "ogr_api.h"
#endif


#if defined(_WIN32) && !defined(__CYGWIN__)
#define snprintf _snprintf
#endif

#ifdef __cplusplus
extern "C" {
#endif

/* General defines, wrapable */

#define MS_TRUE 1 /* logical control variables */
#define MS_FALSE 0
#define MS_UNKNOWN -1
#define MS_ON 1
#define MS_OFF 0
#define MS_DEFAULT 2
#define MS_EMBED 3
#define MS_DELETE 4
#define MS_YES 1
#define MS_NO 0

/* For layer transparency, allows alpha transparent pixmaps to be used
   with RGB map images */
#define MS_GD_ALPHA 1000

/* Number of layer, class and style ptrs to alloc at once in the 
   corresponding msGrow...() functions. Replaces former MS_MAXLAYERS, 
   MS_MAXCLASSES and MS_MAXSTYLES with dynamic allocation (see RFC-17). */
#define MS_LAYER_ALLOCSIZE 64
#define MS_CLASS_ALLOCSIZE 8
#define MS_STYLE_ALLOCSIZE 4

#define MS_MAX_LABEL_PRIORITY     10
#define MS_DEFAULT_LABEL_PRIORITY 1

/* General defines, not wrapable */
#ifndef SWIG
#define MS_DEFAULT_MAPFILE_PATTERN "\\.map$"

#define MS_TEMPLATE_MAGIC_STRING "MapServer Template"
#define MS_TEMPLATE_EXPR "\\.(xml|wml|html|htm|svg|kml|gml|js|tmpl)$"

#define MS_INDEX_EXTENSION ".qix"

#define MS_QUERY_MAGIC_STRING "MapServer Query"
#define MS_QUERY_EXTENSION ".qy"

#define MS_DEG_TO_RAD .0174532925199432958
#define MS_RAD_TO_DEG   57.29577951

#define MS_RED 0
#define MS_GREEN 1
#define MS_BLUE 2

#define MS_MAXCOLORS 256

#define MS_MISSING_DATA_IGNORE 0
#define MS_MISSING_DATA_FAIL 1
#define MS_MISSING_DATA_LOG 2

#define MS_BUFFER_LENGTH 2048 /* maximum input line length */
#define MS_URL_LENGTH 1024
#define MS_MAXPATHLEN 1024

#define MS_MAXIMAGESIZE_DEFAULT 2048

#define MS_MAXPROJARGS 20
#define MS_MAXJOINS 20
#define MS_ITEMNAMELEN 32
#define MS_NAMELEN 20

#define MS_MINSYMBOLSIZE 0   /* in pixels */
#define MS_MAXSYMBOLSIZE 500

#define MS_MINSYMBOLWIDTH 0   /* in pixels */
#define MS_MAXSYMBOLWIDTH 32

#define MS_URL 0 /* template types */
#define MS_FILE 1

#define MS_MINFONTSIZE 4
#define MS_MAXFONTSIZE 256

#define MS_LABELCACHEINITSIZE 100
#define MS_LABELCACHEINCREMENT 10

#define MS_RESULTCACHEINITSIZE 10
#define MS_RESULTCACHEINCREMENT 10

#define MS_FEATUREINITSIZE 10 /* how many points initially can a feature have */
#define MS_FEATUREINCREMENT 10

#define MS_EXPRESSION 2000 /* todo: make this an enum */
#define MS_REGEX 2001
#define MS_STRING 2002
#define MS_NUMBER 2003
#define MS_COMMENT 2004
#define MS_IREGEX 2005
#define MS_ISTRING 2006
#define MS_BINDING 2007

/* boolean options for the expression object. */
#define MS_EXP_INSENSITIVE 1

/* General macro definitions */
#define MS_MIN(a,b) (((a)<(b))?(a):(b))
#define MS_MAX(a,b) (((a)>(b))?(a):(b))
#define MS_ABS(a) (((a)<0) ? -(a) : (a))
#define MS_SGN(a) (((a)<0) ? -1 : 1)

#define MS_NINT_GENERIC(x) ((x) >= 0.0 ? ((long) ((x)+.5)) : ((long) ((x)-.5)))

#ifdef _MSC_VER
#define msIsNan(x) _isnan(x)
#else
#define msIsNan(x) isnan(x)
#endif

/* see http://mega-nerd.com/FPcast/ for some discussion of fast
   conversion to nearest int.  We avoid lrint() for now because it
   would be hard to include math.h "properly". */

#if defined(WE_HAVE_THE_C99_LRINT) && !defined(USE_GENERIC_MS_NINT)
#   define MS_NINT(x) lrint(x)
/*#   define MS_NINT(x) lround(x) */
#elif defined(_MSC_VER) && defined(_WIN32) && !defined(USE_GENERIC_MS_NINT)
    static __inline long int MS_NINT (double flt) 
    {	int intgr;
  
    _asm
        {	fld flt
                    fistp intgr
                    } ;
			
    return intgr ;
    } 
#elif defined(i386) && defined(__GNUC_PREREQ) && !defined(USE_GENERIC_MS_NINT)
    static __inline long int MS_NINT( double __x ) 
    {
        long int __lrintres;                                                        
        __asm__ __volatile__                                                        
          ("fistpl %0"                                                              
           : "=m" (__lrintres) : "t" (__x) : "st");                                 
        return __lrintres;
    }
#else
#  define MS_NINT(x)      MS_NINT_GENERIC(x)
#endif


#define MS_PEN_TRANSPARENT -1
#define MS_PEN_UNSET     -4

/* #define MS_VALID_EXTENT(minx, miny, maxx, maxy)  (((minx<maxx) && (miny<maxy))?MS_TRUE:MS_FALSE) */
#define MS_VALID_EXTENT(rect)  (((rect.minx < rect.maxx && rect.miny < rect.maxy))?MS_TRUE:MS_FALSE)

#define MS_INIT_COLOR(color,r,g,b) { (color).red = r; (color).green = g; (color).blue = b; (color).pen = MS_PEN_UNSET; }
#define MS_VALID_COLOR(color) (((color).red==-1 || (color).green==-1 || (color).blue==-1)?MS_FALSE:MS_TRUE)
#define MS_TRANSPARENT_COLOR(color) (((color).red==-255 || (color).green==-255 || (color).blue==-255)?MS_TRUE:MS_FALSE)
#define MS_COMPARE_COLORS(a,b) (((a).red!=(b).red || (a).green!=(b).green || (a).blue!=(b).blue)?MS_FALSE:MS_TRUE)
#define MS_COLOR_GETRGB(color) (MS_VALID_COLOR(color)?((color).red *0x10000 + (color).green *0x100 + (color).blue):-1)

#define MS_IMAGE_MIME_TYPE(format) (format->mimetype ? format->mimetype : "unknown")
#define MS_IMAGE_EXTENSION(format)  (format->extension ? format->extension : "unknown")

#define MS_DRIVER_GD(format)  (strncasecmp((format)->driver,"gd/",3)==0)
#define MS_DRIVER_SWF(format) (strncasecmp((format)->driver,"swf",3)==0)
#define MS_DRIVER_GDAL(format)  (strncasecmp((format)->driver,"gdal/",5)==0)
#define MS_DRIVER_PDF(format) (strncasecmp((format)->driver,"pdf",3)==0)
#define MS_DRIVER_IMAGEMAP(format)  (strncasecmp((format)->driver,"imagemap",8)==0)
#define MS_DRIVER_SVG(format) (strncasecmp((format)->driver,"svg",3)==0)
#define MS_DRIVER_AGG(format) (strncasecmp((format)->driver,"agg/",4)==0)
#define MS_DRIVER_CAIRO(format) (strncasecmp((format)->driver,"cairo/",6)==0)
#define MS_DRIVER_OGL(format) (strncasecmp((format)->driver,"ogl/",4)==0)
#define MS_DRIVER_TEMPLATE(format) (strncasecmp((format)->driver,"template",8)==0)

#define MS_RENDER_WITH_GD       1
#define MS_RENDER_WITH_SWF      2
#define MS_RENDER_WITH_RAWDATA  3
#define MS_RENDER_WITH_PDF      4
#define MS_RENDER_WITH_IMAGEMAP 5
#define MS_RENDER_WITH_SVG      6
#define MS_RENDER_WITH_AGG      7
#define MS_RENDER_WITH_TEMPLATE 8 /* query results only */
#define MS_RENDER_WITH_CAIRO_RASTER   9
#define MS_RENDER_WITH_CAIRO_PDF 10
#define MS_RENDER_WITH_CAIRO_SVG 11
#define MS_RENDER_WITH_OGL      12

#define MS_RENDERER_GD(format)  ((format)->renderer == MS_RENDER_WITH_GD)
#define MS_RENDERER_SWF(format) ((format)->renderer == MS_RENDER_WITH_SWF)
#define MS_RENDERER_RAWDATA(format) ((format)->renderer == MS_RENDER_WITH_RAWDATA)
#define MS_RENDERER_PDF(format) ((format)->renderer == MS_RENDER_WITH_PDF)
#define MS_RENDERER_IMAGEMAP(format) ((format)->renderer == MS_RENDER_WITH_IMAGEMAP)
#define MS_RENDERER_SVG(format) ((format)->renderer == MS_RENDER_WITH_SVG)
#define MS_RENDERER_AGG(format) ((format)->renderer == MS_RENDER_WITH_AGG)
#define MS_RENDERER_PLUGIN(format) ((format)->renderer >= MS_RENDER_WITH_CAIRO_RASTER)
#define MS_RENDERER_TEMPLATE(format) ((format)->renderer == MS_RENDER_WITH_TEMPLATE)

#define MS_CELLSIZE(min,max,d) ((max - min)/(d-1)) /* where min/max are from an MapServer pixel center-to-pixel center extent */
#define MS_OWS_CELLSIZE(min,max,d) ((max - min)/d) /* where min/max are from an OGC pixel outside edge-to-pixel outside edge extent */
#define MS_MAP2IMAGE_X(x,minx,cx) (MS_NINT((x - minx)/cx))
#define MS_MAP2IMAGE_Y(y,maxy,cy) (MS_NINT((maxy - y)/cy))
#define MS_IMAGE2MAP_X(x,minx,cx) (minx + cx*x)
#define MS_IMAGE2MAP_Y(y,maxy,cy) (maxy - cy*y)

/* this version of MS_MAP2IMAGE takes 1/cellsize and is much faster */
#define MS_MAP2IMAGE_X_IC(x,minx,icx) (MS_NINT((x - minx)*icx))
#define MS_MAP2IMAGE_Y_IC(y,maxy,icy) (MS_NINT((maxy - y)*icy))

#define MS_MAP2IMAGE_X_IC_DBL(x,minx,icx) ((x - minx)*icx)
#define MS_MAP2IMAGE_Y_IC_DBL(y,maxy,icy) ((maxy - y)*icy)

/* For CARTO symbols */
#define MS_PI    3.14159265358979323846
#define MS_PI2   1.57079632679489661923  /* (MS_PI / 2) */
#define MS_3PI2  4.71238898038468985769  /* (3 * MS_PI2) */
#define MS_2PI   6.28318530717958647693  /* (2 * MS_PI) */

#define MS_ENCRYPTION_KEY_SIZE  16   /* Key size: 128 bits = 16 bytes */

#define GET_LAYER(map, pos) map->layers[pos]
#define MS_REFCNT_INCR(obj) obj->refcount++
#define MS_REFCNT_DECR(obj) (--(obj->refcount))
#define MS_REFCNT_INIT(obj) obj->refcount=1
#define MS_REFCNT_DECR_IS_NOT_ZERO(obj) (MS_REFCNT_DECR(obj))>0
#define MS_REFCNT_DECR_IS_ZERO(obj) (MS_REFCNT_DECR(obj))<=0

#endif

/* General enumerated types - needed by scripts */
enum MS_FILE_TYPE {MS_FILE_MAP, MS_FILE_SYMBOL};
enum MS_UNITS {MS_INCHES, MS_FEET, MS_MILES, MS_METERS, MS_KILOMETERS, MS_DD, MS_PIXELS, MS_PERCENTAGES, MS_NAUTICALMILES};
enum MS_SHAPE_TYPE {MS_SHAPE_POINT, MS_SHAPE_LINE, MS_SHAPE_POLYGON, MS_SHAPE_NULL};
enum MS_LAYER_TYPE {MS_LAYER_POINT, MS_LAYER_LINE, MS_LAYER_POLYGON, MS_LAYER_RASTER, MS_LAYER_ANNOTATION, MS_LAYER_QUERY, MS_LAYER_CIRCLE, MS_LAYER_TILEINDEX, MS_LAYER_CHART};
enum MS_FONT_TYPE {MS_TRUETYPE, MS_BITMAP};

#define MS_POSITIONS_LENGTH 12
enum MS_POSITIONS_ENUM {MS_UL=101, MS_LR, MS_UR, MS_LL, MS_CR, MS_CL, MS_UC, MS_LC, MS_CC, MS_AUTO, MS_XY, MS_FOLLOW}; /* Added MS_FOLLOW for bug #1620 implementation. */

enum MS_BITMAP_FONT_SIZES {MS_TINY , MS_SMALL, MS_MEDIUM, MS_LARGE, MS_GIANT};
enum MS_QUERYMAP_STYLES {MS_NORMAL, MS_HILITE, MS_SELECTED};
enum MS_CONNECTION_TYPE {MS_INLINE, MS_SHAPEFILE, MS_TILED_SHAPEFILE, MS_SDE, MS_OGR, MS_UNUSED_1, MS_POSTGIS, MS_WMS, MS_ORACLESPATIAL, MS_WFS, MS_GRATICULE, MS_MYGIS, MS_RASTER, MS_PLUGIN };
enum MS_JOIN_CONNECTION_TYPE {MS_DB_XBASE, MS_DB_CSV, MS_DB_MYSQL, MS_DB_ORACLE, MS_DB_POSTGRES};
enum MS_JOIN_TYPE {MS_JOIN_ONE_TO_ONE, MS_JOIN_ONE_TO_MANY};

#define MS_SINGLE 0 /* modes for searching (spatial/database) */
#define MS_MULTIPLE 1

enum MS_QUERY_MODE {MS_QUERY_SINGLE, MS_QUERY_MULTIPLE};
enum MS_QUERY_TYPE {MS_QUERY_IS_NULL, MS_QUERY_BY_POINT, MS_QUERY_BY_RECT, MS_QUERY_BY_SHAPE, MS_QUERY_BY_ATTRIBUTE, MS_QUERY_BY_INDEX, MS_QUERY_BY_OPERATOR};

enum MS_ALIGN_VALUE {MS_ALIGN_LEFT, MS_ALIGN_CENTER, MS_ALIGN_RIGHT}; 

enum MS_CAPS_JOINS_AND_CORNERS {MS_CJC_NONE, MS_CJC_BEVEL, MS_CJC_BUTT, MS_CJC_MITER, MS_CJC_ROUND, MS_CJC_SQUARE, MS_CJC_TRIANGLE}; 
enum MS_RETURN_VALUE {MS_SUCCESS, MS_FAILURE, MS_DONE};
enum MS_IMAGEMODE { MS_IMAGEMODE_PC256, MS_IMAGEMODE_RGB, MS_IMAGEMODE_RGBA, MS_IMAGEMODE_INT16, MS_IMAGEMODE_FLOAT32, MS_IMAGEMODE_BYTE, MS_IMAGEMODE_NULL };

enum MS_GEOS_OPERATOR {MS_GEOS_EQUALS, MS_GEOS_DISJOINT, MS_GEOS_TOUCHES, MS_GEOS_OVERLAPS, MS_GEOS_CROSSES, MS_GEOS_INTERSECTS, MS_GEOS_WITHIN, MS_GEOS_CONTAINS, MS_GEOS_BEYOND, MS_GEOS_DWITHIN};
#define MS_FILE_DEFAULT MS_FILE_MAP   

#ifndef SWIG
/* Filter object */    
typedef enum 
{
    FILTER_NODE_TYPE_UNDEFINED = -1,
    FILTER_NODE_TYPE_LOGICAL = 0,
    FILTER_NODE_TYPE_SPATIAL = 1,
    FILTER_NODE_TYPE_COMPARISON = 2,
    FILTER_NODE_TYPE_PROPERTYNAME = 3,
    FILTER_NODE_TYPE_BBOX = 4,
    FILTER_NODE_TYPE_LITERAL = 5,
    FILTER_NODE_TYPE_BOUNDARY = 6,
    FILTER_NODE_TYPE_GEOMETRY_POINT = 7,
    FILTER_NODE_TYPE_GEOMETRY_LINE = 8,
    FILTER_NODE_TYPE_GEOMETRY_POLYGON = 9,
    FILTER_NODE_TYPE_FEATUREID = 10
} FilterNodeType;


/************************************************************************/
/*                          FilterEncodingNode                          */
/************************************************************************/

typedef struct _FilterNode
{
    FilterNodeType      eType;
    char                *pszValue;
    void                *pOther;
    char                *pszSRS;
    struct _FilterNode  *psLeftNode;
    struct _FilterNode  *psRightNode;
} FilterEncodingNode;

/************************************************************************/
/*                             labelPathObj                             */
/*                                                                      */
/*      Label path object - used to hold path and bounds of curved      */
/*      labels - Bug #1620 implementation.                              */
/************************************************************************/

typedef struct {
  multipointObj path;
  shapeObj bounds;
  double *angles;
} labelPathObj;
#endif /*SWIG*/

/************************************************************************/
/*                              fontSetObj                              */
/*                                                                      */
/*      used to hold aliases for TRUETYPE fonts                         */
/************************************************************************/

typedef struct {
#ifdef SWIG
    %immutable;
#endif
    char *filename; 
    int numfonts;
    hashTableObj fonts;
#ifdef SWIG
    %mutable;
#endif

#ifndef SWIG
    struct map_obj *map;
#endif
} fontSetObj;

/************************************************************************/
/*                         featttureListNodeObj                         */
/*                                                                      */
/*      for inline features, shape caches and queries                   */
/************************************************************************/
#ifndef SWIG
typedef struct listNode {
    shapeObj shape;
    struct listNode *next;
    struct listNode *tailifhead; /* this is the tail node in the list, if this is the head element, otherwise NULL */
} featureListNodeObj;

typedef featureListNodeObj * featureListNodeObjPtr;
#endif

/************************************************************************/
/*                              paletteObj                              */
/*                                                                      */
/*      used to hold colors while a map file is read                    */
/************************************************************************/
#ifndef SWIG
typedef struct {
    colorObj colors[MS_MAXCOLORS-1];
    int      colorvalue[MS_MAXCOLORS-1];
    int numcolors;
} paletteObj;
#endif

/************************************************************************/
/*                            expressionObj                             */
/************************************************************************/

#ifndef SWIG
typedef struct {
    char *string;
    int type;
    /* container for expression options such as case-insensitiveness */
    /* This is a boolean container. */
    int flags;
    
    /* logical expression options */
    char **items;
    int *indexes;
    int numitems;
    
    /* regular expression options */
    ms_regex_t regex; /* compiled regular expression to be matched */
    int compiled;
} expressionObj;
#endif

/************************************************************************/
/*                               joinObj                                */
/*                                                                      */
/*      simple way to access other XBase files, one-to-one or           */
/*      one-to-many supported                                           */
/************************************************************************/

#ifndef SWIG
typedef struct {
    char *name;
    char **items, **values; /* items/values (process 1 record at a time) */
    int numitems;
    
    char *table;
    char *from, *to; /* item names */
    
    void *joininfo; /* vendor specific (i.e. XBase, MySQL, etc.) stuff to allow for persistant access */
    
    char *header, *footer;
#ifndef __cplusplus
    char *template;
#else
    char *_template;
#endif
    
    enum MS_JOIN_TYPE type;
    char *connection;
    enum MS_JOIN_CONNECTION_TYPE connectiontype;
} joinObj;
#endif

/************************************************************************/
/*                           outputFormatObj                            */
/*                                                                      */
/*      see mapoutput.c for most related code.                          */
/************************************************************************/

typedef struct {
    char *name;
    char *mimetype;
    char *driver;
    char *extension;
    int  renderer;  /* MS_RENDER_WITH_* */
    int  imagemode; /* MS_IMAGEMODE_* value. */
    int  transparent;
    int  bands;
    int  numformatoptions;
    char **formatoptions;
    int  refcount;
    int inmapfile; /* boolean value for writing */
    rendererVTableObj *vtable;
} outputFormatObj;

/* The following is used for "don't care" values in transparent, interlace and
   imagequality values. */
#define MS_NOOVERRIDE  -1111 

/************************************************************************/
/*                             queryObj                                 */
/*                                                                      */
/*      encapsulates the information necessary to perform a query       */
/************************************************************************/
#ifndef SWIG
typedef struct {
  int type; /* MS_QUERY_TYPE */
  int mode; /* MS_QUERY_MODE */

  int layer;

  pointObj point; /* by point */
  double buffer;
  int maxresults;

  rectObj rect; /* by rect */
  shapeObj *shape; /* by shape & operator (OGC filter) */

  long shapeindex; /* by index */
  long tileindex; 
  int clear_resultcache;

  char *item; /* by attribute */
  char *str;

  int op; /* by GEOS operator */

  int slayer; /* selection layer, used for msQueryByFeatures() (note this is not a query mode per se) */
} queryObj;
#endif

/************************************************************************/
/*                             queryMapObj                              */
/*                                                                      */
/*      used to visualize query results                                 */
/************************************************************************/
typedef struct {
    int height, width;
    int status;
    int style; /* HILITE, SELECTED or NORMAL */
    colorObj color;
} queryMapObj;

/* Define supported bindings here (only covers existing bindings at first). Not accessible directly using MapScript. */
#define MS_STYLE_BINDING_LENGTH 8
enum MS_STYLE_BINDING_ENUM { MS_STYLE_BINDING_SIZE, MS_STYLE_BINDING_WIDTH, MS_STYLE_BINDING_ANGLE, MS_STYLE_BINDING_COLOR, MS_STYLE_BINDING_OUTLINECOLOR, MS_STYLE_BINDING_SYMBOL, MS_STYLE_BINDING_OUTLINEWIDTH, MS_STYLE_BINDING_OPACITY};
#define MS_LABEL_BINDING_LENGTH 6
enum MS_LABEL_BINDING_ENUM { MS_LABEL_BINDING_SIZE, MS_LABEL_BINDING_ANGLE, MS_LABEL_BINDING_COLOR, MS_LABEL_BINDING_OUTLINECOLOR, MS_LABEL_BINDING_FONT, MS_LABEL_BINDING_PRIORITY};

/************************************************************************/
/*                         attributeBindingObj                          */
/************************************************************************/
#ifndef SWIG
typedef struct {
  char *item;
  int index;
} attributeBindingObj;
#endif


/************************************************************************/
/*                               labelObj                               */
/*                                                                      */
/*      parameters needed to annotate a layer, legend or scalebar       */
/************************************************************************/

typedef struct {
  char *font;
  enum MS_FONT_TYPE type;
    
  colorObj color;
  colorObj outlinecolor;
  int outlinewidth;
  
  colorObj shadowcolor;
  int shadowsizex, shadowsizey;

  colorObj backgroundcolor;
  colorObj backgroundshadowcolor;
  int backgroundshadowsizex, backgroundshadowsizey;

  double size;
  double minsize, maxsize;

  int position;
  int offsetx, offsety;

  double angle;
  int autoangle; /* true or false */
  int autofollow;  /* true or false, bug #1620 implementation */

  int buffer; /* space to reserve around a label */

  int antialias;
  int align;

  char wrap;
  int maxlength;
  int minlength;
  double space_size_10; /*cached size of a single space character -
                       used for label text alignment of rfc40 */

  int minfeaturesize; /* minimum feature size (in pixels) to label */
  int autominfeaturesize; /* true or false */

  double minscaledenom,maxscaledenom;
  
  int mindistance;
  int repeatdistance;
  int partials; /* can labels run of an image */

  int force; /* labels *must* be drawn */

  char *encoding;

  int priority;  /* Priority level 1 to MS_MAX_LABEL_PRIORITY, default=1 */

#ifndef SWIG
  attributeBindingObj bindings[MS_LABEL_BINDING_LENGTH];
  int numbindings;
#endif

} labelObj;

/************************************************************************/
/*                                webObj                                */
/*                                                                      */
/*      holds parameters for a mapserver/mapscript interface            */
/************************************************************************/

typedef struct {
  char *log;
  char *imagepath, *imageurl;

#ifdef SWIG
%immutable;
#endif /* SWIG */
  struct map_obj *map;
#ifdef SWIG
%mutable;
#endif /* SWIG */

#ifndef __cplusplus
  char *template;
#else
  char *_template;
#endif

  char *header, *footer;
  char *empty, *error; /* error handling */
  rectObj extent; /* clipping extent */
  double minscaledenom, maxscaledenom;
  char *mintemplate, *maxtemplate;

  char *queryformat; /* what format is the query to be returned, given as a MIME type */
  char *legendformat;
  char *browseformat;

#ifdef SWIG
%immutable;
#endif /* SWIG */
  hashTableObj metadata;
  hashTableObj validation;
#ifdef SWIG
%mutable;
#endif /* SWIG */

} webObj;

/************************************************************************/
/*                               styleObj                               */
/*                                                                      */
/*      holds parameters for symbolization, multiple styles may be      */
/*      applied within a classObj                                       */
/************************************************************************/

typedef struct {
#ifdef SWIG
%immutable;
#endif /* SWIG */
  int refcount;
#ifdef SWIG
%mutable;
#endif /* SWIG */
  
#ifndef SWIG
  /*private vars for rfc48*/
  char *_geomtransformexpression;
  int _geomtransform;
#endif
  
  /*should an angle be automatically computed*/
  int autoangle;

  colorObj color;
  colorObj backgroundcolor;
  colorObj outlinecolor;

  int opacity;

  /* Stuff to handle Color Range Styles */
  colorObj mincolor;
  colorObj maxcolor;
  double minvalue;
  double maxvalue;
  char *rangeitem;
  int rangeitemindex;
  
  int symbol;
  char *symbolname;

  double size;
  double minsize, maxsize;

  int patternlength;  /*moved from symbolObj in version 6.0*/                     
  double pattern[MS_MAXPATTERNLENGTH]; /*moved from symbolObj in version 6.0*/ 
  
  double gap; /*moved from symbolObj in version 6.0*/
  int position; /*moved from symbolObj in version 6.0*/
  
  int linecap, linejoin; /*moved from symbolObj in version 6.0*/
  double linejoinmaxsize; /*moved from symbolObj in version 6.0*/
  
  double width;
  double outlinewidth;
  double minwidth, maxwidth;

  double offsetx, offsety; /* for shadows, hollow symbols, etc... */

  double angle;

  int antialias;

  double minscaledenom, maxscaledenom;

#ifndef SWIG
  attributeBindingObj bindings[MS_STYLE_BINDING_LENGTH];
  int numbindings;
#endif
} styleObj;

/************************************************************************/
/*                               classObj                               */
/*                                                                      */
/*      basic symbolization and classification information              */
/************************************************************************/

typedef struct class_obj{
#ifndef SWIG
  expressionObj expression; /* the expression to be matched */
#endif

  int status;

#ifndef SWIG
  styleObj **styles;
  int maxstyles;
#endif

  int numstyles;

#ifdef SWIG
%immutable;
#endif /* SWIG */
  labelObj label;
#ifdef SWIG
%mutable;
#endif /* SWIG */

  char *name; /* should be unique within a layer */
  char *title; /* used for legend labeling */

#ifndef SWIG
  expressionObj text;
#endif /* not SWIG */

#ifndef __cplusplus
  char *template;
#else /* __cplusplus */
  char *_template;
#endif /* __cplusplus */

  int type;

#ifdef SWIG
%immutable;
#endif /* SWIG */
  hashTableObj metadata;
  hashTableObj validation;
#ifdef SWIG
%mutable;
#endif /* SWIG */

  double minscaledenom, maxscaledenom;
#ifdef SWIG
%immutable;
#endif /* SWIG */
  int refcount;
  struct layer_obj *layer;
#ifdef SWIG
%mutable;
#endif /* SWIG */
  int debug;

  char *keyimage;
  
   char *group;
} classObj;

/************************************************************************/
/*                         labelCacheMemberObj                          */
/*                                                                      */
/*      structures to implement label caching and collision             */
/*      avoidance etc                                                   */
/*                                                                      */
/*        Note: These are scriptable, but are read only.                */
/************************************************************************/

#ifdef SWIG
%immutable;
#endif /* SWIG */
typedef struct {
  char *text;
  double featuresize;

  styleObj *styles; /* copied from the classObj, only present if there is a marker to be drawn */
  int numstyles;

  labelObj label; /* copied from the classObj */

  int layerindex; /* indexes */
  int classindex;
  int tileindex;
  int shapeindex;

  int shapetype; /* source geometry type */

  pointObj point; /* label point */
  shapeObj *poly; /* label bounding box */

  int status; /* has this label been drawn or not */

#ifndef SWIG
  labelPathObj *labelpath;  /* Path & bounds of curved labels.  Bug #1620 implementation */
#endif /* SWIG */
  
} labelCacheMemberObj;

/************************************************************************/
/*                         markerCacheMemberObj                         */
/************************************************************************/
typedef struct {
  int id; /* corresponding label */
  shapeObj *poly; /* marker bounding box (POINT layers only) */
} markerCacheMemberObj;

/************************************************************************/
/*                          labelCacheSlotObj                           */
/************************************************************************/
typedef struct {
  labelCacheMemberObj *labels;
  int numlabels;
  int cachesize;
  markerCacheMemberObj *markers;
  int nummarkers;
  int markercachesize;
} labelCacheSlotObj;

/************************************************************************/
/*                            labelCacheObj                             */
/************************************************************************/
typedef struct {
    /* One labelCacheSlotObj for each priority level */
    labelCacheSlotObj slots[MS_MAX_LABEL_PRIORITY];
    /* numlabels is deprecated, maintained only for backwards compatibility
     * between MS 4.10 and 5.0 and should be removed in a future release.
     * The slots[].numlabels are the real values to rely on.
     */
    int numlabels;
} labelCacheObj;

/************************************************************************/
/*                         resultCacheMemberObj                         */
/************************************************************************/
typedef struct {
  long shapeindex;
  int tileindex;
  int classindex;
} resultCacheMemberObj;
#ifdef SWIG
%mutable;
#endif /* SWIG */


/************************************************************************/
/*                            resultCacheObj                            */
/************************************************************************/
typedef struct {

#ifndef SWIG
  resultCacheMemberObj *results;
  int cachesize;
#endif /* not SWIG */

#ifdef SWIG
%immutable;
#endif /* SWIG */
  int numresults;
  rectObj bounds;
#ifdef SWIG
%mutable;
#endif /* SWIG */

  /*used to force the result retreiving to use getshape instead of msLayerResultGetShape #3305*/
  int usegetshape;

} resultCacheObj;


/************************************************************************/
/*                             symbolSetObj                             */
/************************************************************************/
typedef struct {
  char *filename;
  int imagecachesize;
#ifdef SWIG
  %immutable;
#endif /* SWIG */
  int numsymbols;
  int maxsymbols;
#ifdef SWIG
%mutable;
#endif /* SWIG */
#ifndef SWIG
  int refcount;
  symbolObj** symbol;
  struct map_obj *map;
  fontSetObj *fontset; /* a pointer to the main mapObj version */
  struct imageCacheObj *imagecache;
#endif /* not SWIG */
} symbolSetObj;

/************************************************************************/
/*                           referenceMapObj                            */
/************************************************************************/
typedef struct {
  rectObj extent;
  int height, width;
  colorObj color;
  colorObj outlinecolor;
  char *image;
  int status;
  int marker;
  char *markername;
  int markersize;
  int minboxsize;
  int maxboxsize;
#ifdef SWIG
%immutable;
#endif /* SWIG */
  struct map_obj *map;
#ifdef SWIG
%mutable;
#endif /* SWIG */
} referenceMapObj;

/************************************************************************/
/*                             scalebarObj                              */
/************************************************************************/
typedef struct {
  colorObj imagecolor;
  int height, width;
  int style;
  int intervals;
  labelObj label;
  colorObj color;
  colorObj backgroundcolor;
  colorObj outlinecolor;
  int units;
  int status; /* ON, OFF or EMBED */
  int position; /* for embeded scalebars */
#ifndef SWIG
  int transparent;
  int interlace;
#endif /* not SWIG */
  int postlabelcache;
  int align;
} scalebarObj;

/************************************************************************/
/*                              legendObj                               */
/************************************************************************/

typedef struct {
  colorObj imagecolor;
#ifdef SWIG
        %immutable;
#endif
  labelObj label;
#ifdef SWIG
        %mutable;
#endif
  int keysizex, keysizey;
  int keyspacingx, keyspacingy;
  colorObj outlinecolor; /* Color of outline of box, -1 for no outline */
  int status; /* ON, OFF or EMBED */
  int height, width;
  int position; /* for embeded legends */
#ifndef SWIG
  int transparent;
  int interlace;
#endif /* not SWIG */
  int postlabelcache;
#ifndef __cplusplus
   char *template;
#else /* __cplusplus */
   char *_template;
#endif /* __cplusplus */
#ifdef SWIG
%immutable;
#endif /* SWIG */
  struct map_obj *map;
#ifdef SWIG
%mutable;
#endif /* SWIG */
} legendObj;

/************************************************************************/
/*                             graticuleObj                             */
/************************************************************************/
#ifndef SWIG
typedef struct
{
  double    dwhichlatitude;
  double    dwhichlongitude;
  double    dstartlatitude;
  double    dstartlongitude;
  double    dendlatitude;
  double    dendlongitude;
  double    dincrementlatitude;
  double    dincrementlongitude;
  double    minarcs;
  double    maxarcs;
  double    minincrement;
  double    maxincrement;
  double    minsubdivides;
  double    maxsubdivides;
  int     bvertical;
  int     blabelaxes;
  int     ilabelstate;
  int     ilabeltype;
  rectObj   extent;
  lineObj   *pboundinglines;
  pointObj  *pboundingpoints;
  char    *labelformat;
} graticuleObj;

typedef struct
{
  int nTop;
  pointObj *pasTop;
  char  **papszTopLabels;
  int nBottom;
  pointObj *pasBottom;
  char  **papszBottomLabels;
  int nLeft;
  pointObj *pasLeft;
  char  **papszLeftLabels;
  int nRight;
  pointObj *pasRight;
  char  **papszRightLabels;
  
}graticuleIntersectionObj;

struct layerVTable;
typedef struct layerVTable layerVTableObj;

#endif /*SWIG*/

/************************************************************************/
/*                               layerObj                               */
/*                                                                      */
/*      base unit of a map.                                             */
/************************************************************************/

typedef struct layer_obj {

  char *classitem; /* .DBF item to be used for symbol lookup */

#ifndef SWIG
  int classitemindex;
  resultCacheObj *resultcache; /* holds the results of a query against this layer */
  int annotate; /* boolean flag for annotation */
  double scalefactor; /* computed, not set */
#ifndef __cplusplus
  classObj **class; /* always at least 1 class */
#else /* __cplusplus */
  classObj **_class;
#endif /* __cplusplus */
#endif /* not SWIG */

#ifdef SWIG
%immutable;
#endif /* SWIG */
  /* reference counting, RFC24 */
  int refcount;
  int numclasses;
  int maxclasses;
  int index;
  struct map_obj *map;
#ifdef SWIG
%mutable;
#endif /* SWIG */

  char *header, *footer; /* only used with multi result queries */

#ifndef __cplusplus
  char *template; /* global template, used across all classes */
#else /* __cplusplus */
  char *_template;
#endif /* __cplusplus */

  char *name; /* should be unique */
  char *group; /* shouldn't be unique it's supposed to be a group right? */

  int status; /* on or off */
  char *data; /* filename, can be relative or full path */

  enum MS_LAYER_TYPE type;

  double tolerance; /* search buffer for point and line queries (in toleranceunits) */
  int toleranceunits;

  double symbolscaledenom; /* scale at which symbols are default size */
  double minscaledenom, maxscaledenom;
  double labelminscaledenom, labelmaxscaledenom;
  double mingeowidth, maxgeowidth; /* map width (in map units) at which the layer should be drawn */

  int sizeunits; /* applies to all classes */

  int maxfeatures;

  colorObj offsite; /* transparent pixel value for raster images */

  int transform; /* does this layer have to be transformed to file coordinates */

  int labelcache, postlabelcache; /* on or off */

  char *labelitem;
#ifndef SWIG
  int labelitemindex;
#endif /* not SWIG */

  char *tileitem;
  char *tileindex; /* layer index file for tiling support */

#ifndef SWIG
  int tileitemindex;
  projectionObj projection; /* projection information for the layer */
  int project; /* boolean variable, do we need to project this layer or not */
#endif /* not SWIG */

  int units; /* units of the projection */

#ifndef SWIG
  featureListNodeObjPtr features; /* linked list so we don't need a counter */
  featureListNodeObjPtr currentfeature; /* pointer to the current feature */
#endif /* SWIG */

  char *connection;
  char *plugin_library;
  char *plugin_library_original; /* this is needed for mapfile writing */
  enum MS_CONNECTION_TYPE connectiontype;

#ifndef SWIG
  layerVTableObj *vtable;

  /* SDL has converted OracleSpatial, SDE, Graticules, MyGIS */
  void *layerinfo; /* all connection types should use this generic pointer to a vendor specific structure */
  void *wfslayerinfo; /* For WFS layers, will contain a msWFSLayerInfo struct */
#endif /* not SWIG */

  /* attribute/classification handling components */
#ifdef SWIG
%immutable;
#endif /* SWIG */
  int numitems;
#ifdef SWIG
%mutable;
#endif /* SWIG */

#ifndef SWIG
  char **items;
  void *iteminfo; /* connection specific information necessary to retrieve values */
  expressionObj filter; /* connection specific attribute filter */
  int bandsitemindex;
  int filteritemindex;
  int styleitemindex;
#endif /* not SWIG */

  char *bandsitem; /* which item in a tile contains bands to use (tiled raster data only) */
  char *filteritem;
  char *styleitem; /* item to be used for style lookup - can also be 'AUTO' */

  char *requires; /* context expressions, simple enough to not use expressionObj */
  char *labelrequires;

#ifdef SWIG
%immutable;
#endif /* SWIG */
  hashTableObj metadata;
  hashTableObj validation;
#ifdef SWIG
%mutable;
#endif /* SWIG */

  int opacity; /* opacity (was transparency) value 0-100 */
  
  int dump;
  int debug;
#ifndef SWIG
  char **processing;
  joinObj *joins;
#endif /* not SWIG */
#ifdef SWIG
%immutable;
#endif /* SWIG */
  
#ifndef SWIGJAVA  
  rectObj extent;
#endif /* not SWIGJAVA */

  int numprocessing;
  int numjoins;
#ifdef SWIG
%mutable;
#endif /* SWIG */

  char *classgroup;
} layerObj;

/************************************************************************/
/*                                mapObj                                */
/*                                                                      */
/*      encompasses everything used in an Internet mapping              */
/*      application.                                                    */
/************************************************************************/

/* MAP OBJECT -  */
typedef struct map_obj{ /* structure for a map */
  char *name; /* small identifier for naming etc. */
  int status; /* is map creation on or off */
  int height, width;
  int maxsize;

#ifndef SWIG
  layerObj **layers;
#endif /* SWIG */

#ifdef SWIG
%immutable;
#endif /* SWIG */
  /* reference counting, RFC24 */
  int refcount;
  int numlayers; /* number of layers in mapfile */
  int maxlayers; /* allocated size of layers[] array */

  symbolSetObj symbolset;
  fontSetObj fontset;

  labelCacheObj labelcache; /* we need this here so multiple feature processors can access it */
#ifdef SWIG
%mutable;
#endif /* SWIG */

  int transparent; /* TODO - Deprecated */
  int interlace; /* TODO - Deprecated */
  int imagequality; /* TODO - Deprecated */

  rectObj extent; /* map extent array */
  double cellsize; /* in map units */


#ifndef SWIG
  geotransformObj gt; /* rotation / geotransform */
  rectObj saved_extent;
#endif /*SWIG*/

  enum MS_UNITS units; /* units of the projection */
  double scaledenom; /* scale of the output image */
  double resolution;
  double defresolution; /* default resolution: used for calculate the scalefactor */

  char *shapepath; /* where are the shape files located */
  char *mappath; /* path of the mapfile, all path are relative to this path */

#ifndef SWIG
  paletteObj palette; /* holds a map palette */
#endif /*SWIG*/
  colorObj imagecolor; /* holds the initial image color value */

#ifdef SWIG
%immutable;
#endif /* SWIG */
  int numoutputformats;
  outputFormatObj **outputformatlist;
  outputFormatObj *outputformat;

  char *imagetype; /* name of current outputformat */
#ifdef SWIG
  %mutable;
#endif /* SWIG */

#ifndef SWIG
  projectionObj projection; /* projection information for output map */
  projectionObj latlon; /* geographic projection definition */
#endif /* not SWIG */

#ifdef SWIG
%immutable;
#endif /* SWIG */  
  referenceMapObj reference;
  scalebarObj scalebar;
  legendObj legend;

  queryMapObj querymap;

  webObj web;
#ifdef SWIG
%mutable;
#endif /* SWIG */

  int *layerorder;

  int debug;

  char *datapattern, *templatepattern; /* depricated, use VALIDATION ... END block instead */

#ifdef SWIG
%immutable;
#endif /* SWIG */
  hashTableObj configoptions;
#ifdef SWIG
%mutable;
#endif /* SWIG */

#ifndef SWIG
  /* Private encryption key information - see mapcrypto.c */
  int encryption_key_loaded;        /* MS_TRUE once key has been loaded */
  unsigned char encryption_key[MS_ENCRYPTION_KEY_SIZE]; /* 128bits encryption key */

  queryObj query;
#endif
} mapObj;


/************************************************************************/
/*                                pdfObj                                */
/************************************************************************/

#ifdef USE_PDF
typedef struct {
  mapObj *map;
  PDF *pdf;
  void    *imagetmp;  /* used when the FORMATOPTION "OUTPUT_TYPE=RASTER" */
} PDFObj; 
#endif

/************************************************************************/
/*                                SVGObj                                */
/************************************************************************/
#ifndef SWIG
typedef struct  {
  mapObj *map;
  FILE *stream;
  char *filename;
  int streamclosed; /* track if a save image is done */
  int compressed; /*track if output is set to be svgz */
} SVGObj;
#endif /*SWIG*/

/************************************************************************/
/*                               imageObj                               */
/*                                                                      */
/*      A wrapper for GD and other images.                              */
/************************************************************************/
typedef struct {
#ifdef SWIG
%immutable;
#endif
  int width, height;
  double resolution;
  double resolutionfactor;

  char *imagepath, *imageurl;

  outputFormatObj *format;
#ifndef SWIG
  void *imageextra; /* AGG specific */
  tileCacheObj *tilecache;
  int ntiles;
#endif
  int buffer_format; /* tells if the alpha channel is GD or AGG style  */
#ifdef SWIG
%mutable;
#endif
  int renderer;
#ifndef SWIG
  int size;
#endif

#ifndef SWIG
  union {
	void *plugin;
    gdImagePtr gd;
#ifdef USE_MING_FLASH
    void *swf;
#endif
#ifdef USE_PDF
    PDFObj *pdf;
#endif

    SVGObj *svg;

    char *imagemap;
    short *raw_16bit;
    float *raw_float;
    unsigned char *raw_byte;
  } img;
#endif
} imageObj;


/************************************************************************/
/*                             layerVTable                              */
/*                                                                      */
/*      contains function pointers to the layer operations.  If you     */
/*      add new functions to here, remember to update                   */
/*      populateVirtualTable in maplayer.c                              */
/************************************************************************/
#ifndef SWIG
struct layerVTable {
    int (*LayerInitItemInfo)(layerObj *layer);
    void (*LayerFreeItemInfo)(layerObj *layer);
    int (*LayerOpen)(layerObj *layer);
    int (*LayerIsOpen)(layerObj *layer);
    int (*LayerWhichShapes)(layerObj *layer, rectObj rect);
    int (*LayerNextShape)(layerObj *layer, shapeObj *shape);
    int (*LayerResultsGetShape)(layerObj *layer, shapeObj *shape, 
                         int tile, long record);
    int (*LayerGetShape)(layerObj *layer, shapeObj *shape, 
                         int tile, long record);
    int (*LayerClose)(layerObj *layer);
    int (*LayerGetItems)(layerObj *layer);
    int (*LayerGetExtent)(layerObj *layer, rectObj *extent);
    int (*LayerGetAutoStyle)(mapObj *map, layerObj *layer, classObj *c, 
                             int tile, long record);

    int (*LayerCloseConnection)(layerObj *layer);

    int (*LayerSetTimeFilter)(layerObj *layer, 
                              const char *timestring, 
                              const char *timefield);

    int (*LayerApplyFilterToLayer)(FilterEncodingNode *psNode, mapObj *map,
                                   int iLayerIndex, 
                                   int bOnlySpatialFilter);

    int (*LayerCreateItems)(layerObj *layer, int nt);
    int (*LayerGetNumFeatures)(layerObj *layer);
};
#endif /*SWIG*/

/* Function prototypes, wrapable */
MS_DLL_EXPORT int msSaveImage(mapObj *map, imageObj *img, char *filename);
MS_DLL_EXPORT void msFreeImage(imageObj *img);
MS_DLL_EXPORT int msSetup(void);
MS_DLL_EXPORT void msCleanup(void);
MS_DLL_EXPORT mapObj *msLoadMapFromString(char *buffer, char *new_mappath);

/* Function prototypes, not wrapable */

#ifndef SWIG

/*
** helper functions not part of the general API but needed in
** a few other places (like mapscript)... found in mapfile.c
*/
int getString(char **s);
int getDouble(double *d);
int getInteger(int *i);
int getSymbol(int n, ...);
int getCharacter(char *c);

int msBuildPluginLibraryPath(char **dest, const char *lib_str, mapObj *map);

MS_DLL_EXPORT int  hex2int(char *hex);

MS_DLL_EXPORT void initJoin(joinObj *join);
MS_DLL_EXPORT void initSymbol(symbolObj *s);
MS_DLL_EXPORT int initMap(mapObj *map);
MS_DLL_EXPORT layerObj *msGrowMapLayers( mapObj *map );
MS_DLL_EXPORT int initLayer(layerObj *layer, mapObj *map);
MS_DLL_EXPORT int freeLayer( layerObj * );
MS_DLL_EXPORT classObj *msGrowLayerClasses( layerObj *layer );
MS_DLL_EXPORT int initClass(classObj *_class);
MS_DLL_EXPORT int freeClass( classObj * );
MS_DLL_EXPORT styleObj *msGrowClassStyles( classObj *_class );
MS_DLL_EXPORT int msMaybeAllocateStyle(classObj* c, int idx);
MS_DLL_EXPORT void initLabel(labelObj *label);
MS_DLL_EXPORT void resetClassStyle(classObj *_class);
MS_DLL_EXPORT int initStyle(styleObj *style);
MS_DLL_EXPORT int freeStyle(styleObj *style);
MS_DLL_EXPORT void initReferenceMap(referenceMapObj *ref);
MS_DLL_EXPORT void initScalebar(scalebarObj *scalebar);
MS_DLL_EXPORT void initGrid( graticuleObj *pGraticule );
MS_DLL_EXPORT void initWeb(webObj *web);
MS_DLL_EXPORT void freeWeb(webObj *web);
MS_DLL_EXPORT void initResultCache(resultCacheObj *resultcache);

MS_DLL_EXPORT featureListNodeObjPtr insertFeatureList(featureListNodeObjPtr *list, shapeObj *shape);
MS_DLL_EXPORT void freeFeatureList(featureListNodeObjPtr list);

/* To be used *only* within the mapfile loading phase */
MS_DLL_EXPORT int loadExpressionString(expressionObj *exp, char *value);
/* Use this next, thread safe wrapper, function everywhere else */
MS_DLL_EXPORT int msLoadExpressionString(expressionObj *exp, char *value);
MS_DLL_EXPORT char *msGetExpressionString(expressionObj *exp);
MS_DLL_EXPORT void freeExpression(expressionObj *exp);
MS_DLL_EXPORT char *msGetExpressionString(expressionObj *exp);

MS_DLL_EXPORT void msLayerSubstituteString(layerObj *layer, const char *from, const char *to);
MS_DLL_EXPORT void msApplyDefaultSubstitutions(mapObj *map);

MS_DLL_EXPORT int getClassIndex(layerObj *layer, char *str);

/* For maplabel and mappdf */
int labelInImage(int width, int height, shapeObj *lpoly, int buffer);
int intersectLabelPolygons(shapeObj *p1, shapeObj *p2);
pointObj get_metrics_line(pointObj *p, int position, rectObj rect, int ox, int oy, double angle, int buffer, lineObj *poly);
pointObj get_metrics(pointObj *p, int position, rectObj rect, int ox, int oy, double angle, int buffer, shapeObj *poly);
double dist(pointObj a, pointObj b);
   
/*
** Main API Functions
*/

/* mapobject.c */

MS_DLL_EXPORT void msFreeMap(mapObj *map);
MS_DLL_EXPORT mapObj *msNewMapObj(void);
MS_DLL_EXPORT const char *msGetConfigOption( mapObj *map, const char *key);
MS_DLL_EXPORT int msSetConfigOption( mapObj *map, const char *key, const char *value);
MS_DLL_EXPORT int msTestConfigOption( mapObj *map, const char *key, 
                                      int default_result );
MS_DLL_EXPORT void msApplyMapConfigOptions( mapObj *map );
MS_DLL_EXPORT int msMapComputeGeotransform( mapObj *map );

MS_DLL_EXPORT void msMapPixelToGeoref( mapObj *map, double *x, double *y );
MS_DLL_EXPORT void msMapGeorefToPixel( mapObj *map, double *x, double *y );

MS_DLL_EXPORT int msMapSetExtent(mapObj *map, double minx, double miny, 
                                 double maxx, double maxy);
MS_DLL_EXPORT int msMapOffsetExtent( mapObj *map, double x, double y);
MS_DLL_EXPORT int msMapScaleExtent( mapObj *map, double zoomfactor, 
					 double minscaledenom, double maxscaledenom);
MS_DLL_EXPORT int msMapSetCenter( mapObj *map, pointObj *center);
MS_DLL_EXPORT int msMapSetRotation( mapObj *map, double rotation_angle );
MS_DLL_EXPORT int msMapSetSize( mapObj *map, int width, int height );
MS_DLL_EXPORT int msMapSetSize( mapObj *map, int width, int height );
MS_DLL_EXPORT int msMapSetFakedExtent( mapObj *map );
MS_DLL_EXPORT int msMapRestoreRealExtent( mapObj *map );
MS_DLL_EXPORT int msMapLoadOWSParameters( mapObj *map, cgiRequestObj *request,
                                          const char *wmtver_string );
MS_DLL_EXPORT int msMapIgnoreMissingData( mapObj *map );

/* mapfile.c */

MS_DLL_EXPORT int msValidateParameter(char *value, char *pattern1, char *pattern2, char *pattern3, char *pattern4);
MS_DLL_EXPORT int msGetLayerIndex(mapObj *map, char *name);
MS_DLL_EXPORT int msGetSymbolIndex(symbolSetObj *set, char *name, int try_addimage_if_notfound);
MS_DLL_EXPORT mapObj  *msLoadMap(char *filename, char *new_mappath);
MS_DLL_EXPORT int msSaveMap(mapObj *map, char *filename);
MS_DLL_EXPORT void msFreeCharArray(char **array, int num_items);
MS_DLL_EXPORT int msUpdateScalebarFromString(scalebarObj *scalebar, char *string, int url_string);
MS_DLL_EXPORT int msUpdateQueryMapFromString(queryMapObj *querymap, char *string, int url_string);
MS_DLL_EXPORT int msUpdateLabelFromString(labelObj *label, char *string);
MS_DLL_EXPORT int msUpdateReferenceMapFromString(referenceMapObj *ref, char *string, int url_string);
MS_DLL_EXPORT int msUpdateLegendFromString(legendObj *legend, char *string, int url_string);
MS_DLL_EXPORT int msUpdateWebFromString(webObj *web, char *string, int url_string);
MS_DLL_EXPORT int msUpdateStyleFromString(styleObj *style, char *string, int url_string);
MS_DLL_EXPORT int msUpdateClassFromString(classObj *_class, char *string, int url_string);
MS_DLL_EXPORT int msUpdateLayerFromString(layerObj *layer, char *string, int url_string);
MS_DLL_EXPORT int msUpdateMapFromURL(mapObj *map, char *variable, char *string);
MS_DLL_EXPORT int msEvalRegex(char *e, char *s);
MS_DLL_EXPORT void msFree(void *p);
MS_DLL_EXPORT char **msTokenizeMap(char *filename, int *numtokens);
MS_DLL_EXPORT int msInitLabelCache(labelCacheObj *cache);
MS_DLL_EXPORT int msFreeLabelCache(labelCacheObj *cache);
MS_DLL_EXPORT int msCheckConnection(layerObj * layer); /* connection pooling functions (mapfile.c) */
MS_DLL_EXPORT void msCloseConnections(mapObj *map); 

#if defined USE_PDF
MS_DLL_EXPORT PDF *msDrawMapPDF(mapObj *map, PDF *pdf, hashTableObj fontHash); /* mappdf.c */
#endif /* USE_PDF */

MS_DLL_EXPORT void msOGRCleanup(void);
MS_DLL_EXPORT void msGDALCleanup(void);
MS_DLL_EXPORT void msGDALInitialize(void);
   

MS_DLL_EXPORT imageObj *msDrawScalebar(mapObj *map); /* in mapscale.c */
MS_DLL_EXPORT int msCalculateScale(rectObj extent, int units, int width, int height, double resolution, double *scaledenom);
MS_DLL_EXPORT double GetDeltaExtentsUsingScale(double scale, int units, double centerLat, int width, double resolution);
MS_DLL_EXPORT double Pix2Georef(int nPixPos, int nPixMin, int nPixMax, double dfGeoMin, double dfGeoMax, int bULisYOrig);
MS_DLL_EXPORT double msInchesPerUnit(int units, double center_lat);
MS_DLL_EXPORT int msEmbedScalebar(mapObj *map, imageObj *img);

MS_DLL_EXPORT int msPointInRect(pointObj *p, rectObj *rect); /* in mapsearch.c */
MS_DLL_EXPORT int msRectOverlap(rectObj *a, rectObj *b);
MS_DLL_EXPORT int msRectContained(rectObj *a, rectObj *b);

MS_DLL_EXPORT void msRectToFormattedString(rectObj *rect, char *format,
                                           char *buffer, int buffer_length);
MS_DLL_EXPORT void msPointToFormattedString(pointObj *point, const char*format,
                                           char *buffer, int buffer_length);

MS_DLL_EXPORT void msMergeRect(rectObj *a, rectObj *b);
MS_DLL_EXPORT double msDistancePointToPoint(pointObj *a, pointObj *b);
MS_DLL_EXPORT double msSquareDistancePointToPoint(pointObj *a, pointObj *b);
MS_DLL_EXPORT double msDistancePointToSegment(pointObj *p, pointObj *a, pointObj *b);
MS_DLL_EXPORT double msSquareDistancePointToSegment(pointObj *p, pointObj *a, pointObj *b);
MS_DLL_EXPORT double msDistancePointToShape(pointObj *p, shapeObj *shape);
MS_DLL_EXPORT double msSquareDistancePointToShape(pointObj *p, shapeObj *shape);
MS_DLL_EXPORT double msDistanceSegmentToSegment(pointObj *pa, pointObj *pb, pointObj *pc, pointObj *pd);
MS_DLL_EXPORT double msDistanceShapeToShape(shapeObj *shape1, shapeObj *shape2);
MS_DLL_EXPORT int msIntersectSegments(pointObj *a, pointObj *b, pointObj *c, pointObj *d);
MS_DLL_EXPORT int msPointInPolygon(pointObj *p, lineObj *c);
MS_DLL_EXPORT int msIntersectMultipointPolygon(shapeObj *multipoint, shapeObj *polygon);
MS_DLL_EXPORT int msIntersectPointPolygon(pointObj *p, shapeObj *polygon);
MS_DLL_EXPORT int msIntersectPolylinePolygon(shapeObj *line, shapeObj *poly);
MS_DLL_EXPORT int msIntersectPolygons(shapeObj *p1, shapeObj *p2);
MS_DLL_EXPORT int msIntersectPolylines(shapeObj *line1, shapeObj *line2);

MS_DLL_EXPORT int msInitQuery(queryObj *query); /* in mapquery.c */
MS_DLL_EXPORT void msFreeQuery(queryObj *query);
MS_DLL_EXPORT int msSaveQuery(mapObj *map, char *filename);
MS_DLL_EXPORT int msLoadQuery(mapObj *map, char *filename);
MS_DLL_EXPORT int msExecuteQuery(mapObj *map);

MS_DLL_EXPORT int msQueryByIndex(mapObj *map); /* various query methods, all rely on the queryObj hung off the mapObj */
MS_DLL_EXPORT int msQueryByAttributes(mapObj *map);
MS_DLL_EXPORT int msQueryByPoint(mapObj *map);
MS_DLL_EXPORT int msQueryByRect(mapObj *map);
MS_DLL_EXPORT int msQueryByFeatures(mapObj *map);
MS_DLL_EXPORT int msQueryByShape(mapObj *map);
MS_DLL_EXPORT int msQueryByOperator(mapObj *map);

MS_DLL_EXPORT int msGetQueryResultBounds(mapObj *map, rectObj *bounds);
MS_DLL_EXPORT int msIsLayerQueryable(layerObj *lp);
MS_DLL_EXPORT void msQueryFree(mapObj *map, int qlayer); /* todo: rename */
MS_DLL_EXPORT int msRasterQueryByShape(mapObj *map, layerObj *layer, shapeObj *selectshape);
MS_DLL_EXPORT int msRasterQueryByRect(mapObj *map, layerObj *layer, rectObj queryRect);
MS_DLL_EXPORT int msRasterQueryByPoint(mapObj *map, layerObj *layer, int mode, pointObj p, double buffer, int maxresults );

/* in mapstring.c */
MS_DLL_EXPORT void msStringTrim(char *str); 
MS_DLL_EXPORT void msStringTrimBlanks(char *string); 
MS_DLL_EXPORT char *msStringTrimLeft(char *string);
MS_DLL_EXPORT char *msStringChop(char *string);
MS_DLL_EXPORT void msStringTrimEOL(char *string);
MS_DLL_EXPORT char *msReplaceSubstring(char *str, const char *old, const char *sznew);
MS_DLL_EXPORT void msReplaceChar(char *str, char old, char sznew);
MS_DLL_EXPORT char *msCaseReplaceSubstring(char *str, const char *old, const char *sznew);
MS_DLL_EXPORT char *msStripPath(char *fn);
MS_DLL_EXPORT char *msGetPath(char *fn);
MS_DLL_EXPORT char *msBuildPath(char *pszReturnPath, const char *abs_path, const char *path);
MS_DLL_EXPORT char *msBuildPath3(char *pszReturnPath, const char *abs_path, const char *path1, const char *path2);
MS_DLL_EXPORT char *msTryBuildPath(char *szReturnPath, const char *abs_path, const char *path);
MS_DLL_EXPORT char *msTryBuildPath3(char *szReturnPath, const char *abs_path, const char *path1, const char *path2);
MS_DLL_EXPORT char **msStringSplit(const char *string, char cd, int *num_tokens);
MS_DLL_EXPORT char **msStringTokenize( const char *pszLine, const char *pszDelim, int *num_tokens, int preserve_quote);
MS_DLL_EXPORT int msCountChars(char *str, char ch);
MS_DLL_EXPORT char *msLongToString(long value);
MS_DLL_EXPORT char *msDoubleToString(double value, int force_f);
MS_DLL_EXPORT char *msIntToString(int value);
MS_DLL_EXPORT void msStringToUpper(char *string);
MS_DLL_EXPORT void msStringToLower(char *string);
MS_DLL_EXPORT int msEncodeChar(const char);
MS_DLL_EXPORT char *msEncodeUrlExcept(const char*, const char);
MS_DLL_EXPORT char *msEncodeUrl(const char*);
MS_DLL_EXPORT char *msEncodeHTMLEntities(const char *string);
MS_DLL_EXPORT void msDecodeHTMLEntities(const char *string);
MS_DLL_EXPORT int msIsXMLTagValid(const char *string);
MS_DLL_EXPORT char *msStringConcatenate(char *pszDest, char *pszSrc);
MS_DLL_EXPORT char *msJoinStrings(char **array, int arrayLength, const char *delimeter);
MS_DLL_EXPORT char *msHashString(const char *pszStr);
MS_DLL_EXPORT char *msCommifyString(char *str);
MS_DLL_EXPORT const char *msCaseFindSubstring(const char *haystack, const char *needle);
MS_DLL_EXPORT int msHexToInt(char *hex);
MS_DLL_EXPORT char *msGetEncodedString(const char *string, const char *encoding);
MS_DLL_EXPORT char *msConvertWideStringToUTF8 (const wchar_t* string, const char* encoding);
MS_DLL_EXPORT int msGetNextGlyph(const char **in_ptr, char *out_string);
MS_DLL_EXPORT int msGetNumGlyphs(const char *in_ptr);
MS_DLL_EXPORT int msGetUnicodeEntity(const char *inptr, int *unicode);
MS_DLL_EXPORT int msStringIsInteger(const char *string);
MS_DLL_EXPORT int msUTF8ToUniChar(const char *str, int *chPtr); /* maptclutf.c */
MS_DLL_EXPORT char* msGetFirstLine(char* text);

#ifdef NEED_STRDUP
MS_DLL_EXPORT char *strdup(char *s);
#endif /* NEED_STRDUP */

#ifdef NEED_STRRSTR
MS_DLL_EXPORT char *strrstr(char *string, char *find);
#endif /* NEED_STRRSTR */

#ifdef NEED_STRCASESTR
MS_DLL_EXPORT char *strcasestr(const char *s, const char *find);
#endif /* NEED_STRCASESTR */

#ifdef NEED_STRNCASECMP
MS_DLL_EXPORT int strncasecmp(const char *s1, const char *s2, int len);
#endif /* NEED_STRNCASECMP */

#ifdef NEED_STRCASECMP
MS_DLL_EXPORT int strcasecmp(const char *s1, const char *s2);
#endif /* NEED_STRCASECMP */

#ifdef NEED_STRLCAT
MS_DLL_EXPORT size_t strlcat(char *dst, const char *src, size_t siz);
#endif /* NEED_STRLCAT */

/* in mapsymbol.c */
/* Use this function *only* with mapfile loading phase */
MS_DLL_EXPORT int loadSymbolSet(symbolSetObj *symbolset, mapObj *map);
/* Use this threadsafe wrapper everywhere else */
MS_DLL_EXPORT int msLoadSymbolSet(symbolSetObj *symbolset, mapObj *map);
MS_DLL_EXPORT int msCopySymbol(symbolObj *dst, symbolObj *src, mapObj *map);
MS_DLL_EXPORT int msCopySymbolSet(symbolSetObj *dst, symbolSetObj *src, mapObj *map);
MS_DLL_EXPORT void msInitSymbolSet(symbolSetObj *symbolset);
MS_DLL_EXPORT symbolObj *msGrowSymbolSet( symbolSetObj *symbolset );
MS_DLL_EXPORT int msAddImageSymbol(symbolSetObj *symbolset, char *filename);
MS_DLL_EXPORT int msFreeSymbolSet(symbolSetObj *symbolset);
MS_DLL_EXPORT int msFreeSymbol(symbolObj *symbol);
MS_DLL_EXPORT int msAddNewSymbol(mapObj *map, char *name);
MS_DLL_EXPORT int msAppendSymbol(symbolSetObj *symbolset, symbolObj *symbol);
MS_DLL_EXPORT symbolObj *msRemoveSymbol(symbolSetObj *symbolset, int index);
MS_DLL_EXPORT int msSaveSymbolSet(symbolSetObj *symbolset, const char *filename);
MS_DLL_EXPORT int msLoadImageSymbol(symbolObj *symbol, const char *filename);
MS_DLL_EXPORT symbolObj *msRotateSymbol(symbolObj *symbol, double angle);

MS_DLL_EXPORT imageObj *msSymbolGetImageGD(symbolObj *symbol, outputFormatObj *format);
MS_DLL_EXPORT int msSymbolSetImageGD(symbolObj *symbol, imageObj *image);

MS_DLL_EXPORT int msGetMarkerSize(symbolSetObj *symbolset, styleObj *style, int *width, int *height, double scalefactor);
MS_DLL_EXPORT int msGetCharacterSize(char *character, int size, char *font, rectObj *rect);
MS_DLL_EXPORT double msSymbolGetDefaultSize(symbolObj *s);
MS_DLL_EXPORT void freeImageCache(struct imageCacheObj *ic);

MS_DLL_EXPORT imageObj *msDrawLegend(mapObj *map, int scale_independent); /* in maplegend.c */
MS_DLL_EXPORT int msLegendCalcSize(mapObj *map, int scale_independent, int *size_x, int *size_y, layerObj *lp);
MS_DLL_EXPORT int msEmbedLegend(mapObj *map, imageObj *img);
MS_DLL_EXPORT int msDrawLegendIcon(mapObj* map, layerObj* lp, classObj* myClass, int width, int height, imageObj *img, int dstX, int dstY);
MS_DLL_EXPORT imageObj *msCreateLegendIcon(mapObj* map, layerObj* lp, classObj* myClass, int width, int height);
   
MS_DLL_EXPORT int msLoadFontSet(fontSetObj *fontSet, mapObj *map); /* in maplabel.c */
MS_DLL_EXPORT int msInitFontSet(fontSetObj *fontset);
MS_DLL_EXPORT int msFreeFontSet(fontSetObj *fontset);
MS_DLL_EXPORT char *msTransformLabelText(mapObj *map, imageObj* image, labelObj *label, char *text);
MS_DLL_EXPORT int msGetLabelSize(imageObj *img, char *string, labelObj *label, rectObj *rect, fontSetObj *fontSet, double scalefactor, int adjustBaseline,double **advances);
MS_DLL_EXPORT int msAddLabel(mapObj *map, int layerindex, int classindex, shapeObj *shape, pointObj *point, labelPathObj *labelpath, char *string, double featuresize, labelObj *label);
MS_DLL_EXPORT void msTestLabelCacheCollisions(labelCacheObj *labelcache, labelObj *labelPtr, int mapwidth, int mapheight, int buffer, labelCacheMemberObj *cachePtr, int current_priority, int current_label, int mindistance, double label_size);
MS_DLL_EXPORT labelCacheMemberObj *msGetLabelCacheMember(labelCacheObj *labelcache, int i);

MS_DLL_EXPORT gdFontPtr msGetBitmapFont(int size);
MS_DLL_EXPORT int msImageTruetypePolyline(symbolSetObj *symbolset, imageObj *img, shapeObj *p, styleObj *style, double scalefactor);
MS_DLL_EXPORT int msImageTruetypeArrow(symbolSetObj *symbolset, gdImagePtr img, shapeObj *p, styleObj *style, double scalefactor);

MS_DLL_EXPORT void msFreeShape(shapeObj *shape); /* in mapprimitive.c */
MS_DLL_EXPORT void msFreeLabelPathObj(labelPathObj *path);
MS_DLL_EXPORT shapeObj *msShapeFromWKT(const char *string);
MS_DLL_EXPORT char *msShapeToWKT(shapeObj *shape);
MS_DLL_EXPORT void msInitShape(shapeObj *shape);
MS_DLL_EXPORT void msShapeDeleteLine( shapeObj *shape, int line );
MS_DLL_EXPORT int msCopyShape(shapeObj *from, shapeObj *to);
MS_DLL_EXPORT int *msGetOuterList(shapeObj *shape);
MS_DLL_EXPORT int *msGetInnerList(shapeObj *shape, int r, int *outerlist);
MS_DLL_EXPORT void msComputeBounds(shapeObj *shape);
MS_DLL_EXPORT void msRectToPolygon(rectObj rect, shapeObj *poly);
MS_DLL_EXPORT void msClipPolylineRect(shapeObj *shape, rectObj rect);
MS_DLL_EXPORT void msClipPolygonRect(shapeObj *shape, rectObj rect);
MS_DLL_EXPORT void msTransformShape(shapeObj *shape, rectObj extent, double cellsize, imageObj *image);
MS_DLL_EXPORT void msOffsetPointRelativeTo(pointObj *point, layerObj *layer);
MS_DLL_EXPORT void msOffsetShapeRelativeTo(shapeObj *shape, layerObj *layer);
MS_DLL_EXPORT void msTransformShapeToPixel(shapeObj *shape, rectObj extent, double cellsize);
MS_DLL_EXPORT void msTransformPixelToShape(shapeObj *shape, rectObj extent, double cellsize);
MS_DLL_EXPORT void msImageCartographicPolyline(gdImagePtr im, shapeObj *p, styleObj *style, symbolObj *symbol, int c, double size, double scalefactor);
MS_DLL_EXPORT void msPolylineComputeLineSegments(shapeObj *shape, double ***segment_lengths, double **line_lengths, int *max_line_index, double *max_line_length, int *segment_index, double *total_length);
MS_DLL_EXPORT pointObj** msPolylineLabelPoint(shapeObj *p, int min_length, int repeat_distance, double ***angles, double ***lengths, int *numpoints, int center_on_longest_segment);
MS_DLL_EXPORT pointObj** msPolylineLabelPointExtended(shapeObj *p, int min_length, int repeat_distance, double ***angles, double ***lengths, int *numpoints, int *regularLines, int numlines, int center_on_longest_segment);
MS_DLL_EXPORT void msPolylineLabelPointLineString(shapeObj *p, int min_length, int repeat_distance, double ***angles, double ***lengths, double** segment_lengths, 
                                                  int line_index, double line_length, double total_length, int segment_index, 
                                                  int* labelpoints_index, int* labelpoints_size, pointObj ***labelpoints, int center_on_longest_segment);
MS_DLL_EXPORT labelPathObj** msPolylineLabelPath(imageObj *img, shapeObj *p, int min_length, fontSetObj *fontset, char *string, labelObj *label, double scalefactor, int *numpaths, int** regular_lines, int* num_regular_Lines);
MS_DLL_EXPORT void msPolylineLabelPathLineString(imageObj *img, shapeObj *p, int min_length, fontSetObj *fontset, char *string, labelObj *label, double scalefactor,
                                                 int line_index, double** segment_lengths, double line_length, double total_length, 
                                                 int* labelpaths_index, int* labelpaths_size, labelPathObj ***labelpaths, int** regular_lines, int *regular_lines_index, int* regular_lines_size);
MS_DLL_EXPORT int msPolygonLabelPoint(shapeObj *p, pointObj *lp, double min_dimension);
MS_DLL_EXPORT int msAddLine(shapeObj *p, lineObj *new_line);
MS_DLL_EXPORT int msAddLineDirectly(shapeObj *p, lineObj *new_line);
MS_DLL_EXPORT int msAddPointToLine(lineObj *line, pointObj *point );
MS_DLL_EXPORT double msGetPolygonArea(shapeObj *p);
MS_DLL_EXPORT int msGetPolygonCentroid(shapeObj *p, pointObj *lp, double *miny, double *maxy);

MS_DLL_EXPORT int msDrawRasterLayer(mapObj *map, layerObj *layer, imageObj *image); /* in mapraster.c */
MS_DLL_EXPORT imageObj *msDrawReferenceMap(mapObj *map);

MS_DLL_EXPORT size_t msGetBitArraySize(int numbits); /* in mapbits.c */
MS_DLL_EXPORT ms_bitarray msAllocBitArray(int numbits);
MS_DLL_EXPORT int msGetBit(ms_bitarray array, int index);
MS_DLL_EXPORT void msSetBit(ms_bitarray array, int index, int value);
MS_DLL_EXPORT void msSetAllBits(ms_bitarray array, int index, int value);
MS_DLL_EXPORT void msFlipBit(ms_bitarray array, int index);
MS_DLL_EXPORT int msGetNextBit(ms_bitarray array, int index, int size);

MS_DLL_EXPORT int msLayerInitItemInfo(layerObj *layer);
MS_DLL_EXPORT void msLayerFreeItemInfo(layerObj *layer); 

MS_DLL_EXPORT int msLayerOpen(layerObj *layer); /* in maplayer.c */
MS_DLL_EXPORT int msLayerIsOpen(layerObj *layer);
MS_DLL_EXPORT void msLayerClose(layerObj *layer);
MS_DLL_EXPORT int msLayerWhichShapes(layerObj *layer, rectObj rect);
MS_DLL_EXPORT int msLayerWhichItems(layerObj *layer, int get_all, char *metadata); 
MS_DLL_EXPORT int msLayerNextShape(layerObj *layer, shapeObj *shape);
MS_DLL_EXPORT int msLayerGetItems(layerObj *layer);
MS_DLL_EXPORT int msLayerSetItems(layerObj *layer, char **items, int numitems);
MS_DLL_EXPORT int msLayerResultsGetShape(layerObj *layer, shapeObj *shape, int tile, long record);
MS_DLL_EXPORT int msLayerGetShape(layerObj *layer, shapeObj *shape, int tile, long record);
MS_DLL_EXPORT int msLayerGetExtent(layerObj *layer, rectObj *extent);
MS_DLL_EXPORT int msLayerSetExtent( layerObj *layer, double minx, double miny, double maxx, double maxy);
MS_DLL_EXPORT int msLayerGetAutoStyle(mapObj *map, layerObj *layer, classObj *c, int tile, long record);
MS_DLL_EXPORT void msLayerAddProcessing( layerObj *layer, const char *directive );
MS_DLL_EXPORT void msLayerSetProcessingKey( layerObj *layer, const char *key, 
                                            const char *value);
MS_DLL_EXPORT char *msLayerGetProcessing( layerObj *layer, int proc_index);
MS_DLL_EXPORT char *msLayerGetProcessingKey( layerObj *layer, const char *);
MS_DLL_EXPORT int msLayerClearProcessing( layerObj *layer );
MS_DLL_EXPORT char* msLayerGetFilterString( layerObj *layer );

MS_DLL_EXPORT int msLayerSetTimeFilter(layerObj *lp, const char *timestring, 
                                       const char *timefield);
/* Helper functions for layers */ 
MS_DLL_EXPORT int msLayerMakeBackticsTimeFilter(layerObj *lp, const char *timestring, 
                                                 const char *timefield);

MS_DLL_EXPORT int msLayerMakePlainTimeFilter(layerObj *lp, const char *timestring, 
                                             const char *timefield);

MS_DLL_EXPORT int msLayerApplyCondSQLFilterToLayer(FilterEncodingNode *psNode, mapObj *map, 
                                                   int iLayerIndex, int bOnlySpatialFilter);

MS_DLL_EXPORT int msLayerApplyPlainFilterToLayer(FilterEncodingNode *psNode, mapObj *map, 
                                                 int iLayerIndex, int bOnlySpatialFilter);


/* maplayer.c */
MS_DLL_EXPORT int msLayerGetNumFeatures(layerObj *layer);

/* These are special because SWF is using these */
int msOGRLayerNextShape(layerObj *layer, shapeObj *shape);
int msOGRLayerGetItems(layerObj *layer);
void msOGRLayerFreeItemInfo(layerObj *layer);
int msOGRLayerGetShape(layerObj *layer, shapeObj *shape, int tile, long record);
int msOGRLayerResultGetShape(layerObj *layer, shapeObj *shape, int tile, long record);
int msOGRLayerGetExtent(layerObj *layer, rectObj *extent);

#ifdef USE_OGR
MS_DLL_EXPORT int msOGRGeometryToShape(OGRGeometryH hGeometry, shapeObj *shape,
                         OGRwkbGeometryType type);
#endif /* USE_OGR */

MS_DLL_EXPORT int drawSDE(mapObj *map, layerObj *layer, gdImagePtr img);

MS_DLL_EXPORT int msInitializeVirtualTable(layerObj *layer);
MS_DLL_EXPORT int msConnectLayer(layerObj *layer, const int connectiontype, 
                                 const char *library_str);

MS_DLL_EXPORT int msINLINELayerInitializeVirtualTable(layerObj *layer);
MS_DLL_EXPORT int msShapeFileLayerInitializeVirtualTable(layerObj *layer);
MS_DLL_EXPORT int msTiledSHPLayerInitializeVirtualTable(layerObj *layer);
MS_DLL_EXPORT int msSDELayerInitializeVirtualTable(layerObj *layer);
MS_DLL_EXPORT int msOGRLayerInitializeVirtualTable(layerObj *layer);
MS_DLL_EXPORT int msPostGISLayerInitializeVirtualTable(layerObj *layer);
MS_DLL_EXPORT int msOracleSpatialLayerInitializeVirtualTable(layerObj *layer);
MS_DLL_EXPORT int msWFSLayerInitializeVirtualTable(layerObj *layer);
MS_DLL_EXPORT int msGraticuleLayerInitializeVirtualTable(layerObj *layer);
MS_DLL_EXPORT int msMYGISLayerInitializeVirtualTable(layerObj *layer);
MS_DLL_EXPORT int msRASTERLayerInitializeVirtualTable(layerObj *layer);
MS_DLL_EXPORT int msPluginLayerInitializeVirtualTable(layerObj *layer);

/* ==================================================================== */
/*      Prototypes for functions in mapdraw.c                           */
/* ==================================================================== */
MS_DLL_EXPORT void msClearLayerPenValues(layerObj *layer);
MS_DLL_EXPORT void msClearScalebarPenValues(scalebarObj *scalebar);
MS_DLL_EXPORT void msClearLegendPenValues(legendObj *legend);
MS_DLL_EXPORT void msClearReferenceMapPenValues(referenceMapObj *referencemap);
MS_DLL_EXPORT void msClearQueryMapPenValues(queryMapObj *querymap);
MS_DLL_EXPORT void msClearPenValues(mapObj *map);

MS_DLL_EXPORT imageObj *msPrepareImage(mapObj *map, int allow_nonsquare);
MS_DLL_EXPORT imageObj *msDrawMap(mapObj *map, int querymap);
MS_DLL_EXPORT int msLayerIsVisible(mapObj *map, layerObj *layer);
MS_DLL_EXPORT int msDrawLayer(mapObj *map, layerObj *layer, imageObj *image);
MS_DLL_EXPORT int msDrawVectorLayer(mapObj *map, layerObj *layer, imageObj *image);
MS_DLL_EXPORT int msDrawQueryLayer(mapObj *map, layerObj *layer, imageObj *image);
MS_DLL_EXPORT int msDrawWMSLayer(mapObj *map, layerObj *layer, imageObj *image);
MS_DLL_EXPORT int msDrawWFSLayer(mapObj *map, layerObj *layer, imageObj *image);
MS_DLL_EXPORT int msDrawShape(mapObj *map, layerObj *layer, shapeObj *shape, imageObj *image, int style, int querymapMode);
MS_DLL_EXPORT int msDrawPoint(mapObj *map, layerObj *layer, pointObj *point, imageObj *image, int classindex, char *labeltext);

  /*Range Support*/
MS_DLL_EXPORT int msShapeToRange(styleObj *style, shapeObj *shape);
MS_DLL_EXPORT int msValueToRange(styleObj *style, double fieldVal);

MS_DLL_EXPORT void msCircleDrawLineSymbol(symbolSetObj *symbolset, imageObj *image, pointObj *p, double r, styleObj *style, double scalefactor);
MS_DLL_EXPORT void msCircleDrawShadeSymbol(symbolSetObj *symbolset, imageObj *image, pointObj *p, double r, styleObj *style, double scalefactor);
MS_DLL_EXPORT void msDrawMarkerSymbol(symbolSetObj *symbolset,imageObj *image, pointObj *p, styleObj *style, double scalefactor);
MS_DLL_EXPORT void msDrawLineSymbol(symbolSetObj *symbolset, imageObj *image, shapeObj *p, styleObj *style, double scalefactor);
MS_DLL_EXPORT void msDrawShadeSymbol(symbolSetObj *symbolset, imageObj *image, shapeObj *p, styleObj *style, double scalefactor);

MS_DLL_EXPORT int msDrawLabel(mapObj *map, imageObj *image, pointObj labelPnt, char *string, labelObj *label, double scalefactor);
MS_DLL_EXPORT int msDrawText(imageObj *image, pointObj labelPnt, char *string, labelObj *label, fontSetObj *fontset, double scalefactor);
MS_DLL_EXPORT int msDrawTextLine(imageObj *image, char *string, labelObj *label, labelPathObj *labelpath, fontSetObj *fontset, double scalefactor);
MS_DLL_EXPORT int msDrawLabelCache(imageObj *image, mapObj *map);

MS_DLL_EXPORT void msImageStartLayer(mapObj *map, layerObj *layer, imageObj *image);
MS_DLL_EXPORT void msImageEndLayer(mapObj *map, layerObj *layer, imageObj *image);

MS_DLL_EXPORT void msDrawStartShape(mapObj *map, layerObj *layer, imageObj *image, shapeObj *shape);
MS_DLL_EXPORT void msDrawEndShape(mapObj *map, layerObj *layer, imageObj *image, shapeObj *shape);
/* ==================================================================== */
/*      End of Prototypes for functions in mapdraw.c                    */
/* ==================================================================== */

/* ==================================================================== */
/*      Prototypes for functions in mapimagemap.c                       */
/* ==================================================================== */
MS_DLL_EXPORT imageObj *msImageCreateIM(int width, int height, outputFormatObj *format, char *imagepath, char *imageurl, double resolution, double defresolution);
MS_DLL_EXPORT imageObj *msImageLoadIM( const char *filename );
MS_DLL_EXPORT imageObj *msImageLoadGD( const char *filename );
MS_DLL_EXPORT imageObj *msImageLoadGDCtx( gdIOCtx *ctx, const char *driver );
MS_DLL_EXPORT void msImageInitIM( imageObj *image );
MS_DLL_EXPORT void msImageStartLayerIM(mapObj *map, layerObj *layer, imageObj *image);
MS_DLL_EXPORT int msSaveImageIM(imageObj* img, char *filename, outputFormatObj *format);
MS_DLL_EXPORT int msSaveImageIM_LL(imageObj* img, char *filename, int type, int transparent, int interlace, int quality);
MS_DLL_EXPORT void msFreeImagexsIM(imageObj* img);
MS_DLL_EXPORT void msFreeImageIM(imageObj* img);
MS_DLL_EXPORT void msCircleDrawLineSymbolIM(symbolSetObj *symbolset, imageObj* img, pointObj *p, double r, styleObj *style, double scalefactor);
MS_DLL_EXPORT void msCircleDrawShadeSymbolIM(symbolSetObj *symbolset, imageObj* img, pointObj *p, double r, styleObj *style, double scalefactor);
MS_DLL_EXPORT void msDrawMarkerSymbolIM(symbolSetObj *symbolset, imageObj* img, pointObj *p, styleObj *style, double scalefactor);
MS_DLL_EXPORT void msDrawLineSymbolIM(symbolSetObj *symbolset, imageObj* img, shapeObj *p, styleObj *style, double scalefactor);
MS_DLL_EXPORT void msDrawShadeSymbolIM(symbolSetObj *symbolset, imageObj* img, shapeObj *p, styleObj *style, double scalefactor);
MS_DLL_EXPORT int msDrawTextIM(imageObj* img, pointObj labelPnt, char *string, labelObj *label, fontSetObj *fontset, double scalefactor);
MS_DLL_EXPORT int msDrawLabelCacheIM(imageObj* img, mapObj *map);
/* ==================================================================== */
/*      End of Prototypes for functions in mapimagemap.c                */
/* ==================================================================== */

/* ==================================================================== */
/*      Prototypes for functions in mapgd.c                             */
/* ==================================================================== */
MS_DLL_EXPORT imageObj *msImageLoadGDCtx(gdIOCtx* ctx, const char *driver);
MS_DLL_EXPORT int msCompareColors(colorObj *c1, colorObj *c2);
MS_DLL_EXPORT void msPreAllocateColorsGD(imageObj *image, mapObj *map);
MS_DLL_EXPORT imageObj *msImageCreateGD(int width, int height, outputFormatObj *format, char *imagepath, char *imageurl, double resolution, double defresolution);
MS_DLL_EXPORT imageObj *msImageLoadGD( const char *filename );
MS_DLL_EXPORT void msImageInitGD( imageObj *image, colorObj *background );
MS_DLL_EXPORT int msImageSetPenGD(gdImagePtr img, colorObj *color);

#define RESOLVE_PEN_GD(img,color) { if( (color).pen == MS_PEN_UNSET ) msImageSetPenGD( img, &(color) ); }

MS_DLL_EXPORT gdIOCtx *msNewGDFileCtx(FILE *file);
MS_DLL_EXPORT int msSaveImageGD(imageObj *img, char *filename, outputFormatObj *format);
MS_DLL_EXPORT unsigned char *msSaveImageBufferGD(imageObj *img, int *bufsize, outputFormatObj *format);
MS_DLL_EXPORT int msSaveImageGDCtx(imageObj *img, gdIOCtx* ctx, outputFormatObj *format);
MS_DLL_EXPORT int msSaveImageGD_LL(imageObj *img, char *filename, int type, int transparent, int interlace, int quality);
MS_DLL_EXPORT void msFreeImageGD(imageObj *img);

MS_DLL_EXPORT void msCircleDrawLineSymbolGD(symbolSetObj *symbolset, imageObj *img, pointObj *p, double r, styleObj *style, double scalefactor);
MS_DLL_EXPORT void msCircleDrawShadeSymbolGD(symbolSetObj *symbolset, imageObj *img, pointObj *p, double r, styleObj *style, double scalefactor);
MS_DLL_EXPORT void msDrawMarkerSymbolGD(symbolSetObj *symbolset, imageObj *img, pointObj *p, styleObj *style, double scalefactor);
MS_DLL_EXPORT void msDrawLineSymbolGD(symbolSetObj *symbolset, imageObj *img, shapeObj *p, styleObj *style, double scalefactor);
MS_DLL_EXPORT void msDrawShadeSymbolGD(symbolSetObj *symbolset, imageObj *img, shapeObj *p, styleObj *style, double scalefactor);

MS_DLL_EXPORT int msDrawTextGD(imageObj *img, pointObj labelPnt, char *string, labelObj *label, fontSetObj *fontset, double scalefactor);
MS_DLL_EXPORT int msDrawTextLineGD(imageObj *img, char *string, labelObj *label, labelPathObj *labelpath, fontSetObj *fontset, double scalefactor);

MS_DLL_EXPORT void msImageCopyMerge (imageObj *dst, imageObj *src, int dstX, int dstY, int srcX, int srcY, int w, int h, int pct);
MS_DLL_EXPORT void msImageCopyMergeNoAlpha (imageObj *dst, imageObj *src, int dstX, int dstY, int srcX, int srcY, int w, int h, int pct, colorObj *transparent);

#ifdef USE_AGG
/* ==================================================================== */
/*      Prototypes for functions in mapagg.cpp                          */
/* ==================================================================== */

MS_DLL_EXPORT imageObj *msImageCreateAGG(int width, int height, outputFormatObj *format, char *imagepath, char *imageurl, double resolution, double defresolution);
MS_DLL_EXPORT void msImageInitAGG( imageObj *image, colorObj *background );

MS_DLL_EXPORT int msSaveImageAGG(imageObj *img, char *filename, outputFormatObj *format);
MS_DLL_EXPORT unsigned char *msSaveImageBufferAGG(imageObj *img, int *bufsize, outputFormatObj *format);
MS_DLL_EXPORT int msSaveImageAGGCtx(imageObj *img, gdIOCtx* ctx, outputFormatObj *format);
MS_DLL_EXPORT int msSaveImageAGG_LL(imageObj *img, char *filename, int type, int transparent, int interlace, int quality);
MS_DLL_EXPORT void msFreeImageAGG(imageObj *img);

MS_DLL_EXPORT void msPieSliceAGG(imageObj *image, styleObj *style, double center_x, double center_y, double diameter, double start, double end);
MS_DLL_EXPORT void msFilledRectangleAGG (imageObj *image, styleObj *style, double c1_x, double c1_y, double c2_x, double c2_y );
MS_DLL_EXPORT void msCircleDrawLineSymbolAGG(symbolSetObj *symbolset, imageObj *image, pointObj *p, double r, styleObj *style, double scalefactor);
MS_DLL_EXPORT void msCircleDrawShadeSymbolAGG(symbolSetObj *symbolset, imageObj *image, pointObj *p, double r, styleObj *style, double scalefactor);
MS_DLL_EXPORT void msDrawMarkerSymbolAGG(symbolSetObj *symbolset, imageObj *image, pointObj *p, styleObj *style, double scalefactor);
MS_DLL_EXPORT void msDrawLineSymbolAGG(symbolSetObj *symbolset, imageObj *image, shapeObj *p, styleObj *style, double scalefactor);
MS_DLL_EXPORT void msDrawShadeSymbolAGG(symbolSetObj *symbolset, imageObj *image,shapeObj *p, styleObj *style, double scalefactor);
int msGetTruetypeTextBBoxAGG(imageObj *img, char *font, double size, char *string, rectObj *rect, double **advances);
int msGetRasterTextBBoxAGG(imageObj *img, int size, char *string, rectObj *rect);
MS_DLL_EXPORT int msDrawTextAGG(imageObj *imgage, pointObj labelPnt, char *string, labelObj *label, fontSetObj *fontset, double scalefactor);

MS_DLL_EXPORT int msDrawTextLineAGG(imageObj *image, char *string, labelObj *label, labelPathObj *labelpath, fontSetObj *fontset, double scalefactor);

MS_DLL_EXPORT void msTransformShapeAGG(shapeObj *shape, rectObj extent, double cellsize);

MS_DLL_EXPORT void msFreeSymbolCacheAGG(void *buffer);

MS_DLL_EXPORT void msAlphaGD2AGG(imageObj *im);
MS_DLL_EXPORT void msAlphaAGG2GD(imageObj *im);
MS_DLL_EXPORT void msImageCopyMergeAGG (imageObj *dst, imageObj *src, int pct);
#endif  /* USE_AGG  */

/* various JOIN functions (in mapjoin.c) */
MS_DLL_EXPORT int msJoinConnect(layerObj *layer, joinObj *join);
MS_DLL_EXPORT int msJoinPrepare(joinObj *join, shapeObj *shape);
MS_DLL_EXPORT int msJoinNext(joinObj *join);
MS_DLL_EXPORT int msJoinClose(joinObj *join);

/*in mapraster.c */
MS_DLL_EXPORT int msDrawRasterLayerLow(mapObj *map, layerObj *layer, imageObj *image);
MS_DLL_EXPORT int msAddColorGD(mapObj *map, gdImagePtr img, int cmt, int r, int g, int b);
#ifdef USE_AGG
MS_DLL_EXPORT int msAddColorAGG(mapObj *map, gdImagePtr img, int cmt, int r, int g, int b);
#endif
MS_DLL_EXPORT int msGetClass(layerObj *layer, colorObj *color);
MS_DLL_EXPORT int msGetClass_Float(layerObj *layer, float fValue);

/* in mapdrawgdal.c */
MS_DLL_EXPORT int msDrawRasterLayerGDAL(mapObj *map, layerObj *layer, imageObj *image, void *hDSVoid );
MS_DLL_EXPORT int msGetGDALGeoTransform(void *hDS, mapObj *map, layerObj *layer, double *padfGeoTransform );
MS_DLL_EXPORT int *msGetGDALBandList( layerObj *layer, void *hDS, int max_bands, int *band_count );
MS_DLL_EXPORT double msGetGDALNoDataValue( layerObj *layer, void *hBand, int *pbGotNoData );

/* in mapchart.c */
MS_DLL_EXPORT int msDrawChartLayer(mapObj *map, layerObj *layer, imageObj *image);

/* ==================================================================== */
/*      End of prototypes for functions in mapgd.c                      */
/* ==================================================================== */

/* ==================================================================== */
/*      Prototypes for functions in maputil.c                           */
/* ==================================================================== */

MS_DLL_EXPORT int msExtentsOverlap(mapObj *map, layerObj *layer);

/* For mappdf */
MS_DLL_EXPORT int getRgbColor(mapObj *map,int i,int *r,int *g,int *b); /* maputil.c */
MS_DLL_EXPORT int msBindLayerToShape(layerObj *layer, shapeObj *shape, int querymapMode);
MS_DLL_EXPORT int msValidateContexts(mapObj *map);
MS_DLL_EXPORT int msEvalContext(mapObj *map, layerObj *layer, char *context);
MS_DLL_EXPORT int msEvalExpression(expressionObj *expression, int itemindex, char **items, int numitems);
MS_DLL_EXPORT int msShapeGetClass(layerObj *layer, shapeObj *shape, double scaledenom, int *classgroup, int numclasses);
MS_DLL_EXPORT char *msShapeGetAnnotation(layerObj *layer, shapeObj *shape);
MS_DLL_EXPORT int msAdjustImage(rectObj rect, int *width, int *height);
MS_DLL_EXPORT double msAdjustExtent(rectObj *rect, int width, int height);
MS_DLL_EXPORT int msConstrainExtent(rectObj *bounds, rectObj *rect, double overlay);
MS_DLL_EXPORT int *msGetLayersIndexByGroup(mapObj *map, char *groupname, int *nCount);
MS_DLL_EXPORT unsigned char *msSaveImageBuffer(imageObj* image, int *size_ptr, outputFormatObj *format);
MS_DLL_EXPORT shapeObj* msOffsetPolyline(shapeObj* shape, double offsetx, double offsety);
/* Functions to chnage the drawing order of the layers. */
/* Defined in mapobject.c */
MS_DLL_EXPORT int msMoveLayerUp(mapObj *map, int nLayerIndex);
MS_DLL_EXPORT int msMoveLayerDown(mapObj *map, int nLayerIndex);
MS_DLL_EXPORT int msSetLayersdrawingOrder(mapObj *self, int *panIndexes);
MS_DLL_EXPORT int msInsertLayer(mapObj *map, layerObj *layer, int nIndex);
MS_DLL_EXPORT layerObj *msRemoveLayer(mapObj *map, int nIndex);

/* Defined in layerobject.c */
MS_DLL_EXPORT int msInsertClass(layerObj *layer,classObj *classobj,int nIndex);
MS_DLL_EXPORT classObj *msRemoveClass(layerObj *layer, int nIndex);
MS_DLL_EXPORT int msMoveClassUp(layerObj *layer, int nClassIndex);
MS_DLL_EXPORT int msMoveClassDown(layerObj *layer, int nClassIndex);

/* classobject.c */
MS_DLL_EXPORT int msMoveStyleUp(classObj *classo, int nStyleIndex);
MS_DLL_EXPORT int msMoveStyleDown(classObj *classo, int nStyleIndex);
MS_DLL_EXPORT int msDeleteStyle(classObj *classo, int iStyleIndex);
MS_DLL_EXPORT int msInsertStyle(classObj *classo, styleObj *style,
                                int nStyleIndex);
MS_DLL_EXPORT styleObj *msRemoveStyle(classObj *classo, int index);

/* Measured shape utility functions. */
MS_DLL_EXPORT pointObj *msGetPointUsingMeasure(shapeObj *shape, double m);
MS_DLL_EXPORT pointObj *msGetMeasureUsingPoint(shapeObj *shape, pointObj *point);

MS_DLL_EXPORT char **msGetAllGroupNames(mapObj* map, int *numTok);
MS_DLL_EXPORT char *msTmpFile(const char *mappath, const char *tmppath, const char *ext);
MS_DLL_EXPORT void msForceTmpFileBase( const char *new_base );


MS_DLL_EXPORT imageObj *msImageCreate(int width, int height, outputFormatObj *format, char *imagepath, char *imageurl, mapObj *map);

MS_DLL_EXPORT int msAlphaBlend (int dst, int src);

MS_DLL_EXPORT int msCheckParentPointer(void* p, char* objname);

MS_DLL_EXPORT int *msAllocateValidClassGroups(layerObj *lp, int *nclasses);
/* ==================================================================== */
/*      End of prototypes for functions in maputil.c                    */
/* ==================================================================== */


/* ==================================================================== */
/*      End of prototypes for functions in mapswf.c                     */
/* ==================================================================== */

/* ==================================================================== */


/* ==================================================================== */
/*      prototypes for functions in mapsvg.c                            */
/* ==================================================================== */

MS_DLL_EXPORT imageObj *msImageCreateSVG(int width, int height, 
                                         outputFormatObj *format, char *imagepath, 
                                         char *imageurl, mapObj *map);

MS_DLL_EXPORT void msImageStartLayerSVG(mapObj *map, layerObj *layer, 
                                          imageObj *image);

MS_DLL_EXPORT void msDrawLineSymbolSVG(symbolSetObj *symbolset, imageObj *image, 
                                       shapeObj *p, styleObj *style, 
                                       double scalefactor);
MS_DLL_EXPORT void msTransformShapeSVG(shapeObj *shape, rectObj extent, double cellsize,
                                       imageObj *image);
MS_DLL_EXPORT int msSaveImageSVG(imageObj *image, char *filename);
MS_DLL_EXPORT int msSaveImagetoFpSVG(imageObj *image, FILE *fp);
MS_DLL_EXPORT void msFreeImageSVG(imageObj *image);

MS_DLL_EXPORT void msDrawMarkerSymbolSVG(symbolSetObj *symbolset, 
                                         imageObj *image, 
                                         pointObj *p, styleObj *style, 
                                         double scalefactor);

MS_DLL_EXPORT int msDrawTextSVG(imageObj *image, pointObj labelPnt, char *string, 
                                labelObj *label, fontSetObj *fontset, 
                                double scalefactor);
MS_DLL_EXPORT int msDrawLabelCacheSVG(imageObj *image, mapObj *map);

MS_DLL_EXPORT int msDrawRasterLayerSVG(mapObj *map, layerObj *layer, 
                                       imageObj *image);
MS_DLL_EXPORT void msDrawShadeSymbolSVG(symbolSetObj *symbolset, 
                                        imageObj *image, shapeObj *p, 
                                        styleObj *style, double scalefactor);


/* ==================================================================== */
/*      prototypes for functions in mapoutput.c                         */
/* ==================================================================== */

MS_DLL_EXPORT void msApplyDefaultOutputFormats( mapObj * );
MS_DLL_EXPORT void msFreeOutputFormat( outputFormatObj * );
MS_DLL_EXPORT int msGetOutputFormatIndex(mapObj *map, const char *imagetype);
MS_DLL_EXPORT int msRemoveOutputFormat(mapObj *map, const char *imagetype);
MS_DLL_EXPORT int msAppendOutputFormat(mapObj *map, outputFormatObj *format);
MS_DLL_EXPORT outputFormatObj *msSelectOutputFormat( mapObj *map, const char *imagetype );
MS_DLL_EXPORT void msApplyOutputFormat( outputFormatObj **target, outputFormatObj *format, int transparent, int interlaced, int imagequality );
MS_DLL_EXPORT const char *msGetOutputFormatOption( outputFormatObj *format, const char *optionkey, const char *defaultresult );
MS_DLL_EXPORT outputFormatObj *msCreateDefaultOutputFormat( mapObj *map, const char *driver );
MS_DLL_EXPORT int msPostMapParseOutputFormatSetup( mapObj *map );
MS_DLL_EXPORT void msSetOutputFormatOption( outputFormatObj *format, const char *key, const char *value );
MS_DLL_EXPORT void msGetOutputFormatMimeList( mapObj *map, char **mime_list, int max_mime );
MS_DLL_EXPORT void msGetOutputFormatMimeListImg( mapObj *map, char **mime_list, int max_mime );
MS_DLL_EXPORT void msGetOutputFormatMimeListWMS( mapObj *map, char **mime_list, int max_mime );
MS_DLL_EXPORT outputFormatObj *msCloneOutputFormat( outputFormatObj *format );
MS_DLL_EXPORT int msOutputFormatValidate( outputFormatObj *format );

#ifndef gdImageTrueColor
#  define gdImageTrueColor(x) (0)
#endif /* not gdImageTrueColor */

/* ==================================================================== */
/*      prototypes for functions in mapgdal.c                           */
/* ==================================================================== */
MS_DLL_EXPORT int msSaveImageGDAL( mapObj *map, imageObj *image, char *filename );
MS_DLL_EXPORT int msInitDefaultGDALOutputFormat( outputFormatObj *format );

/* ==================================================================== */
/*      End of prototypes for functions in mapoutput.c                  */
/* ==================================================================== */

/* ==================================================================== */
/*      Public prototype for mapogr.cpp functions.                      */
/* ==================================================================== */
int MS_DLL_EXPORT msOGRLayerWhichShapes(layerObj *layer, rectObj rect);
int MS_DLL_EXPORT msOGRLayerOpen(layerObj *layer, const char *pszOverrideConnection); /* in mapogr.cpp */
int MS_DLL_EXPORT msOGRLayerClose(layerObj *layer);

char MS_DLL_EXPORT *msOGRShapeToWKT(shapeObj *shape);
shapeObj MS_DLL_EXPORT *msOGRShapeFromWKT(const char *string);

/* ==================================================================== */
/*      prototypes for functions in mapcopy                             */
/* ==================================================================== */
MS_DLL_EXPORT int msCopyMap(mapObj *dst, mapObj *src);
MS_DLL_EXPORT int msCopyLayer(layerObj *dst, layerObj *src);
MS_DLL_EXPORT int msCopyPoint(pointObj *dst, pointObj *src);
MS_DLL_EXPORT int msCopyFontSet(fontSetObj *dst, fontSetObj *src, mapObj *map);
MS_DLL_EXPORT void copyProperty(void *dst, void *src, int size);
MS_DLL_EXPORT char *copyStringProperty(char **dst, char *src);
MS_DLL_EXPORT int msCopyClass(classObj *dst, classObj *src, layerObj *layer);
MS_DLL_EXPORT int msCopyStyle(styleObj *dst, styleObj *src);
 
/* ==================================================================== */
/*      end prototypes for functions in mapcopy                         */
/* ==================================================================== */

/* ==================================================================== */
/*      mappool.c: connection pooling API.                              */
/* ==================================================================== */
MS_DLL_EXPORT void *msConnPoolRequest( layerObj *layer );
MS_DLL_EXPORT void msConnPoolRelease( layerObj *layer, void * );
MS_DLL_EXPORT void msConnPoolRegister( layerObj *layer,
                                        void *conn_handle,
                                        void (*close)( void * ) );
MS_DLL_EXPORT void msConnPoolCloseUnreferenced( void );
MS_DLL_EXPORT void msConnPoolFinalCleanup( void );

/* ==================================================================== */
/*      prototypes for functions in mapcpl.c                            */
/* ==================================================================== */
MS_DLL_EXPORT const char *msGetBasename( const char *pszFullFilename );
MS_DLL_EXPORT void *msGetSymbol(const char *pszLibrary, 
                                const char *pszEntryPoint);

/* ==================================================================== */
/*      include definitions from mapows.h                               */
/* ==================================================================== */
#include "mapows.h"

/* ==================================================================== */
/*      prototypes for functions in mapgeos.c                         */
/* ==================================================================== */
MS_DLL_EXPORT void msGEOSSetup(void);
MS_DLL_EXPORT void msGEOSCleanup(void);
MS_DLL_EXPORT void msGEOSFreeGeometry(shapeObj *shape);

MS_DLL_EXPORT shapeObj *msGEOSShapeFromWKT(const char *string);
MS_DLL_EXPORT char *msGEOSShapeToWKT(shapeObj *shape);

MS_DLL_EXPORT shapeObj *msGEOSBuffer(shapeObj *shape, double width);
MS_DLL_EXPORT shapeObj *msGEOSSimplify(shapeObj *shape, double tolerance);
MS_DLL_EXPORT shapeObj *msGEOSTopologyPreservingSimplify(shapeObj *shape, double tolerance);
MS_DLL_EXPORT shapeObj *msGEOSConvexHull(shapeObj *shape);
MS_DLL_EXPORT shapeObj *msGEOSBoundary(shapeObj *shape);
MS_DLL_EXPORT pointObj *msGEOSGetCentroid(shapeObj *shape);
MS_DLL_EXPORT shapeObj *msGEOSUnion(shapeObj *shape1, shapeObj *shape2);
MS_DLL_EXPORT shapeObj *msGEOSIntersection(shapeObj *shape1, shapeObj *shape2);
MS_DLL_EXPORT shapeObj *msGEOSDifference(shapeObj *shape1, shapeObj *shape2);
MS_DLL_EXPORT shapeObj *msGEOSSymDifference(shapeObj *shape1, shapeObj *shape2);

MS_DLL_EXPORT int msGEOSContains(shapeObj *shape1, shapeObj *shape2);
MS_DLL_EXPORT int msGEOSOverlaps(shapeObj *shape1, shapeObj *shape2);
MS_DLL_EXPORT int msGEOSWithin(shapeObj *shape1, shapeObj *shape2);
MS_DLL_EXPORT int msGEOSCrosses(shapeObj *shape1, shapeObj *shape2);
MS_DLL_EXPORT int msGEOSIntersects(shapeObj *shape1, shapeObj *shape2);
MS_DLL_EXPORT int msGEOSTouches(shapeObj *shape1, shapeObj *shape2);
MS_DLL_EXPORT int msGEOSEquals(shapeObj *shape1, shapeObj *shape2);
MS_DLL_EXPORT int msGEOSDisjoint(shapeObj *shape1, shapeObj *shape2);

MS_DLL_EXPORT double msGEOSArea(shapeObj *shape);
MS_DLL_EXPORT double msGEOSLength(shapeObj *shape);
MS_DLL_EXPORT double msGEOSDistance(shapeObj *shape1, shapeObj *shape2);

/* ==================================================================== */
/*      prototypes for functions in mapcrypto.c                         */
/* ==================================================================== */
MS_DLL_EXPORT int msGenerateEncryptionKey(unsigned char *k);
MS_DLL_EXPORT int msReadEncryptionKeyFromFile(const char *keyfile, unsigned char *k);
MS_DLL_EXPORT void msEncryptStringWithKey(const unsigned char *key, const char *in, char *out);
MS_DLL_EXPORT void msDecryptStringWithKey(const unsigned char *key, const char *in, char *out);
MS_DLL_EXPORT char *msDecryptStringTokens(mapObj *map, const char *in);
MS_DLL_EXPORT void msHexEncode(const unsigned char *in, char *out, int numbytes);
MS_DLL_EXPORT int msHexDecode(const char *in, unsigned char *out, int numchars);


/* ==================================================================== */
/*      prototypes for functions in mapswf.c                            */
/* ==================================================================== */
#ifdef USE_MING_FLASH
MS_DLL_EXPORT imageObj *msImageCreateSWF(int width, int height, outputFormatObj *format, char *imagepath, char *imageurl, mapObj *map);
MS_DLL_EXPORT void msImageStartLayerSWF(mapObj *map, layerObj *layer, imageObj *image);
MS_DLL_EXPORT int msDrawLabelSWF(imageObj *image, pointObj labelPnt, char *string, labelObj *label, fontSetObj *fontset, double scalefactor);
MS_DLL_EXPORT int msDrawLabelCacheSWF(imageObj *image, mapObj *map);
MS_DLL_EXPORT void msDrawLineSymbolSWF(symbolSetObj *symbolset, imageObj *image, shapeObj *p, styleObj *style, double scalefactor);
MS_DLL_EXPORT void msDrawShadeSymbolSWF(symbolSetObj *symbolset, imageObj *image, shapeObj *p, styleObj *style, double scalefactor);
MS_DLL_EXPORT void msDrawMarkerSymbolSWF(symbolSetObj *symbolset, imageObj *image, pointObj *p, styleObj *style, double scalefactor);
MS_DLL_EXPORT int msDrawRasterLayerSWF(mapObj *map, layerObj *layer, imageObj *image);
MS_DLL_EXPORT int msDrawVectorLayerAsRasterSWF(mapObj *map, layerObj *layer, imageObj*image);
#ifdef USE_WMS_LYR 
MS_DLL_EXPORT int msDrawWMSLayerSWF(int nLayerId, httpRequestObj *pasReqInfo, int numRequests, mapObj *map, 
                                   layerObj *layer, imageObj *image);
#endif
MS_DLL_EXPORT void msTransformShapeSWF(shapeObj *shape, rectObj extent, double cellsize);
MS_DLL_EXPORT int msSaveImageSWF(imageObj *image, char *filename);
MS_DLL_EXPORT void msFreeImageSWF(imageObj *image);
MS_DLL_EXPORT int draw_textSWF(imageObj *image, pointObj labelPnt, char *string, labelObj *label, fontSetObj *fontset, double scalefactor);
MS_DLL_EXPORT void msDrawStartShapeSWF(mapObj *map, layerObj *layer, imageObj *image, shapeObj *shape);
#endif /* USE_MING_FLASH */

/* ==================================================================== */
/*      prototypes for functions in mappdf.c                            */
/* ==================================================================== */
#ifdef USE_PDF
MS_DLL_EXPORT PDF *msDrawMapPDF(mapObj *map, PDF *pdf, hashTableObj fontHash);
MS_DLL_EXPORT imageObj *msImageCreatePDF(int width, int height, outputFormatObj *format, char *imagepath, char *imageurl, mapObj *map);
MS_DLL_EXPORT void msImageStartLayerPDF(mapObj *map, layerObj *layer, imageObj *image);
MS_DLL_EXPORT int msDrawLabelPDF(imageObj *image, pointObj labelPnt, char *string, labelObj *label, fontSetObj *fontset, double scalefactor);
MS_DLL_EXPORT int msDrawLabelCachePDF(imageObj *image, mapObj *map);
MS_DLL_EXPORT void msDrawLineSymbolPDF(symbolSetObj *symbolset, imageObj *image, shapeObj *p, styleObj *style, double scalefactor);
MS_DLL_EXPORT void msDrawShadeSymbolPDF(symbolSetObj *symbolset, imageObj *image, shapeObj *p, styleObj *style, double scalefactor);
MS_DLL_EXPORT void msDrawMarkerSymbolPDF(symbolSetObj *symbolset, imageObj *image, pointObj *p, styleObj *style, double scalefactor);
MS_DLL_EXPORT int msDrawRasterLayerPDF(mapObj *map, layerObj *layer, imageObj *image);
MS_DLL_EXPORT int msDrawVectorLayerAsRasterPDF(mapObj *map, layerObj *layer, imageObj*image);
MS_DLL_EXPORT void msTransformShapePDF(shapeObj *shape, rectObj extent, double cellsize);
MS_DLL_EXPORT int msSaveImagePDF(imageObj *image, char *filename);
MS_DLL_EXPORT void msFreeImagePDF(imageObj *image);
MS_DLL_EXPORT int msDrawTextPDF(imageObj *image, pointObj labelPnt, char *string, labelObj *label, fontSetObj *fontset, double scalefactor);
MS_DLL_EXPORT void msDrawStartShapePDF(mapObj *map, layerObj *layer, imageObj *image, shapeObj *shape);
#ifdef USE_WMS_LYR 
MS_DLL_EXPORT int msDrawWMSLayerPDF(int nLayerId, httpRequestObj *pasReqInfo, 
                      int numRequests, mapObj *map, layerObj *layer, imageObj *image);
#endif

#endif /* USE_PDF */

/* ==================================================================== */
/*      End of prototypes for functions in mappdf.c                     */
/* ==================================================================== */


/* ==================================================================== */
/*      prototypes for functions in maprgbapng.c                        */
/* ==================================================================== */
#ifdef USE_RGBA_PNG
int msSaveImageRGBAQuantized(gdImagePtr img, gdIOCtx *ctx, outputFormatObj *format);
int msSaveImageRGBAPalette(gdImagePtr img, gdIOCtx *ctx ,outputFormatObj *format);
#endif /*USE_RGBA_PNG*/
/* ==================================================================== */
/*      end of prototypes for functions in maprgbapng.c                 */
/* ==================================================================== */

/* ==================================================================== */
/*      prototypes for functions in mapgeomtransform.c                        */
/* ==================================================================== */
#define MS_GEOMTRANSFORM_NONE 0
#define MS_GEOMTRANSFORM_START 1
#define MS_GEOMTRANSFORM_END 2
#define MS_GEOMTRANSFORM_VERTICES 3
#define MS_GEOMTRANSFORM_BBOX 4
#define MS_GEOMTRANSFORM_CENTROID 5
#define MS_GEOMTRANSFORM_BUFFER 6
#define MS_GEOMTRANSFORM_CONVEXHULL 7

MS_DLL_EXPORT int msDrawTransformedShape(mapObj *map, symbolSetObj *symbolset, imageObj *image, shapeObj *shape, styleObj *style, double scalefactor);
MS_DLL_EXPORT void msStyleSetGeomTransform(styleObj *style, char *transform);
MS_DLL_EXPORT char *msStyleGetGeomTransform(styleObj *style);
/* ==================================================================== */
/*      end of prototypes for functions in mapgeomtransform.c                 */
/* ==================================================================== */


/* ==================================================================== */
/*      prototypes for functions in mapgraticule.c                      */
/* ==================================================================== */
MS_DLL_EXPORT graticuleIntersectionObj *msGraticuleLayerGetIntersectionPoints(mapObj *map, layerObj *layer);
MS_DLL_EXPORT void msGraticuleLayerFreeIntersectionPoints( graticuleIntersectionObj *psValue);

/* ==================================================================== */
/*      end of prototypes for functions in mapgraticule.c               */
/* ==================================================================== */

#endif



/*
 * strokeStyleObj
 */
typedef struct {
    double width; /* line width in pixels */
    
    /* line pattern, e.g. dots, dashes, etc.. */
    int patternlength;
    double pattern[MS_MAXPATTERNLENGTH];
    
    /* must not be NULL, must be a valid color */
    /* color.alpha must be used if supported by the renderer */
    colorObj color;

    int linecap; /* MS_CJC_TRIANGLE, MS_CJC_SQUARE, MS_CJC_ROUND, MS_CJC_BUTT */
    int linejoin; /* MS_CJC_BEVEL MS_CJC_ROUND MS_CJC_MITER */
    double linejoinmaxsize;
} strokeStyleObj;



/*
 * fillStyleObj
 */
typedef struct {
    /* must not be NULL, must be a valid color *
     * color.alpha must be used if supported by the renderer */
    colorObj color;
    

    /* if not null, use the passed tile (which is a pointer to a
     * renderer specific structure) for tiling the polygon */
    void *tile;

} fillStyleObj;


/*
 * symbolStyleObj
 */
typedef struct {
    /* must not be NULL, must be a valid color */
    /* color.alpha must be used if supported by the renderer */
    colorObj color;
    colorObj backgroundcolor;
    
    double outlinewidth;
    colorObj outlinecolor;

    /* scalefactor to be applied on the tile or symbol*/
    double scale;

    /* rotation to apply on the symbol (and the tile?)
     * in radians */
    double rotation;
} symbolStyleObj;

struct tilecache {
    symbolObj *symbol;
    symbolStyleObj style;
    int width;
    int height;

    void *data;
    tileCacheObj *next;
};
/*
 * labelStyleObj
 */
typedef struct {
    /* full path to truetype font file */
    char *font;

    double size;
    double rotation;

    colorObj color;
    
    /* if outlinewidth is > 0, use the outlinecolor */
    double outlinewidth;
    colorObj outlinecolor;
    
    /* if shadowsizex or shadowsizey are != 0,
     * use the shadowcolor */
    double shadowsizex, shadowsizey;
    colorObj shadowcolor;

} labelStyleObj;

#ifndef SWIG
void msFreeRasterBuffer(rasterBufferObj *b);
#endif /* SWIG */

#ifndef SWIG
MS_DLL_EXPORT int msInitializeRendererVTable(outputFormatObj *outputformat);
MS_DLL_EXPORT int msPopulateRendererVTableCairoRaster( rendererVTableObj *renderer );
MS_DLL_EXPORT int msPopulateRendererVTableCairoSVG( rendererVTableObj *renderer );
MS_DLL_EXPORT int msPopulateRendererVTableCairoPDF( rendererVTableObj *renderer );
MS_DLL_EXPORT int msPopulateRendererVTableOGL( rendererVTableObj *renderer );

//allocate 50k for starters
#define MS_DEFAULT_BUFFER_ALLOC 50000

typedef struct _autobuffer {
    unsigned char *data;
    size_t size;
    size_t available;
    size_t _next_allocation_size;
} bufferObj;


int msSaveRasterBuffer(rasterBufferObj *data, FILE *stream,
        outputFormatObj *format);
int msSaveRasterBufferToBuffer(rasterBufferObj *data, bufferObj *buffer,
        outputFormatObj *format);

inline void msBufferInit(bufferObj *buffer);
inline void msBufferResize(bufferObj *buffer, size_t target_size);
MS_DLL_EXPORT  inline void msBufferFree(bufferObj *buffer);
MS_DLL_EXPORT  inline void msBufferAppend(bufferObj *buffer, void *data, size_t length);

struct rendererVTable {
	int supports_transparent_layers;
    int supports_pixel_buffer;
	int supports_imagecache;
    
    void (*renderLine)(imageObj *img, shapeObj *p, strokeStyleObj *style);
    void (*renderPolygon)(imageObj *img, shapeObj *p, colorObj *color);
    void (*renderPolygonTiled)(imageObj *img, shapeObj *p, imageObj *tile);
    void (*renderLineTiled)(imageObj *img, shapeObj *p, imageObj *tile);

    void (*renderGlyphs)(imageObj *img, double x, double y,
            labelStyleObj *style, char *text);
 
    void (*renderGlyphsLine)(imageObj *img,labelPathObj *labelpath,
            labelStyleObj *style, char *text);

    void (*renderVectorSymbol)(imageObj *img, double x, double y,
    		symbolObj *symbol, symbolStyleObj *style);
    
    void* (*createVectorSymbolTile)(int width, int height,
            symbolObj *symbol, symbolStyleObj *style);

    void (*renderPixmapSymbol)(imageObj *img, double x, double y,
        	symbolObj *symbol, symbolStyleObj *style);
    
    void* (*createPixmapSymbolTile)(int width, int height,
            symbolObj *symbol, symbolStyleObj *style);

    void (*renderEllipseSymbol)(imageObj *image, double x, double y, 
    		symbolObj *symbol, symbolStyleObj *style);
    
    void* (*createEllipseSymbolTile)(int width, int height,
            symbolObj *symbol, symbolStyleObj *style);
    
    void (*renderTruetypeSymbol)(imageObj *img, double x, double y,
            symbolObj *symbol, symbolStyleObj *style);

    void* (*createTruetypeSymbolTile)(int width, int height,
            symbolObj *symbol, symbolStyleObj *style);

    void (*renderTile)(imageObj *img, imageObj *tile, double x, double y);
    
    
    void (*getRasterBuffer)(imageObj *img,rasterBufferObj *rb);

    void (*mergeRasterBuffer)(imageObj *dest, rasterBufferObj *overlay, double opacity, int dstX, int dstY);
    /* image i/o */
    imageObj* (*createImage)(int width, int height, outputFormatObj *format, colorObj* bg);
    int (*saveImage)(imageObj *img, FILE *fp, outputFormatObj *format);
    /*...*/

    /* helper functions */
    int (*getTruetypeTextBBox)(imageObj *img,char *font, double size, char *string,
    		rectObj *rect, double **advances);
    
	void (*startNewLayer)(imageObj *img, double opacity);
	void (*closeNewLayer)(imageObj *img, double opacity);
	
    void (*transformShape)(shapeObj *shape, rectObj extend, double cellsize);
    void (*freeImage)(imageObj *image);
    void (*freeTile)(imageObj *tile);
    void (*freeSymbol)(symbolObj *symbol);
} ;

#endif /* SWIG */

#ifdef __cplusplus
}
#endif

#endif /* MAP_H */