/[zanavi_public1]/navit/navit/maptool/refine/pslg.c
ZANavi

Contents of /navit/navit/maptool/refine/pslg.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 31 - (show annotations) (download)
Mon Feb 4 17:41:59 2013 UTC (11 years, 1 month ago) by zoff99
File MIME type: text/plain
File size: 3619 byte(s)
new map version, lots of fixes and experimental new features
1 /*
2 * This file is a part of Poly2Tri-C
3 * (c) Barak Itkin <lightningismyname@gmail.com>
4 * http://code.google.com/p/poly2tri-c/
5 *
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without modification,
9 * are permitted provided that the following conditions are met:
10 *
11 * * Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
16 * * Neither the name of Poly2Tri nor the names of its contributors may be
17 * used to endorse or promote products derived from this software without specific
18 * prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 #include <glib.h>
34 #include "pslg.h"
35
36 static void
37 free_bounded_line_if_not_null (gpointer line)
38 {
39 p2tr_bounded_line_free ((P2trBoundedLine*)line);
40 }
41
42 /* A PSLG which is essentially a set of lines, will be represented by a
43 * hash table. When it will have an entry where both key and value are
44 * a line, it means that this is a new line and therefore should be
45 * freed. When it has an entry where the key is a line and the value is
46 * NULL, it means this is a line that should not be freed.
47 * This behaiour will be acheived by a NULL key free function and a
48 * real free function for values */
49 P2trPSLG*
50 p2tr_pslg_new (void)
51 {
52 return g_hash_table_new_full (NULL, NULL, NULL, free_bounded_line_if_not_null);
53 }
54
55 void
56 p2tr_pslg_add_new_line (P2trPSLG *pslg,
57 const P2trVector2 *start,
58 const P2trVector2 *end)
59 {
60 P2trBoundedLine *line = p2tr_bounded_line_new (start, end);
61 /* We would like to free this line, so also add it as a value */
62 g_hash_table_insert (pslg, line, line);
63 }
64
65 /* Add a line that needs not to be freed */
66 void
67 p2tr_pslg_add_existing_line (P2trPSLG *pslg,
68 const P2trBoundedLine *line)
69 {
70 g_hash_table_insert (pslg, (P2trBoundedLine*) line, NULL);
71 }
72
73 guint
74 p2tr_pslg_size (P2trPSLG *pslg)
75 {
76 return g_hash_table_size (pslg);
77 }
78
79 void
80 p2tr_pslg_iter_init (P2trPSLGIter *iter,
81 P2trPSLG *pslg)
82 {
83 g_hash_table_iter_init (iter, pslg);
84 }
85
86 gboolean
87 p2tr_pslg_iter_next (P2trPSLGIter *iter,
88 const P2trBoundedLine **line)
89 {
90 /* The values are always stored in the key */
91 return g_hash_table_iter_next (iter, (gpointer*)line, NULL);
92 }
93
94 gboolean
95 p2tr_pslg_contains_line (P2trPSLG *pslg,
96 const P2trBoundedLine *line)
97 {
98 return g_hash_table_lookup_extended (pslg, line, NULL, NULL);
99 }
100
101 void
102 p2tr_pslg_free (P2trPSLG *pslg)
103 {
104 g_hash_table_destroy (pslg);
105 }

   
Visit the ZANavi Wiki