]> git.itanic.dy.fi Git - maemo-mapper/blob - src/hashtable_itr.h
Added basic APRS support - Can be disabled by removing definition of INCLUDE_APRS
[maemo-mapper] / src / hashtable_itr.h
1 /*
2  * 
3  * This file is part of Maemo Mapper.
4  *
5  * Maemo Mapper is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * Maemo Mapper is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with Maemo Mapper.  If not, see <http://www.gnu.org/licenses/>.
17  * 
18  * 
19  * Parts of this code have been ported from Xastir by Rob Williams (10 Aug 2008):
20  * 
21  *  * XASTIR, Amateur Station Tracking and Information Reporting
22  * Copyright (C) 1999,2000  Frank Giannandrea
23  * Copyright (C) 2000-2007  The Xastir Group
24  * Copyright (C) 2002, 2004 Christopher Clark  <firstname.lastname@cl.cam.ac.uk> 
25  * 
26  */
27
28 #ifdef HAVE_CONFIG_H
29 #    include "config.h"
30 #endif
31
32 #ifdef INCLUDE_APRS
33
34 #ifndef __HASHTABLE_ITR_CWC22__
35 #define __HASHTABLE_ITR_CWC22__
36 #include "hashtable.h"
37 #include "hashtable_private.h" /* needed to enable inlining */
38
39 /*****************************************************************************/
40 /* This struct is only concrete here to allow the inlining of two of the
41  * accessor functions. */
42 struct hashtable_itr
43 {
44     struct hashtable *h;
45     struct entry *e;
46     struct entry *parent;
47     unsigned int index;
48 };
49
50
51 /*****************************************************************************/
52 /* hashtable_iterator
53  */
54
55 struct hashtable_itr *
56 hashtable_iterator(struct hashtable *h);
57
58 #if 0
59 // BZZZZT!  it is very, very wrong to be inlining this this way.
60 // If one calls hashtable_iterator on a hash table from which everything
61 // has been deleted, the iterator has a null for i->e.  
62 // It is not good to require the caller to check the internals of the iterator
63 // structure just to be sure there are no null pointers inside.
64 // For whatever reason, these are defined again in the hashtable_iterator.c
65 // file, not inlined.  I have modified the ones in hashtable_iterator so they
66 // actually check for nulls and don't try to dereference them.
67 /*****************************************************************************/
68 /* hashtable_iterator_key
69  * - return the value of the (key,value) pair at the current position */
70
71 extern inline void *
72 hashtable_iterator_key(struct hashtable_itr *i)
73 {
74     return i->e->k;
75 }
76
77 /*****************************************************************************/
78 /* value - return the value of the (key,value) pair at the current position */
79
80 extern inline void *
81 hashtable_iterator_value(struct hashtable_itr *i)
82 {
83     return i->e->v;
84 }
85 #else
86 // SO instead of inlining, just declare.  No need to be "extern"
87 // The ones in the .c file check their arguments and return nulls if they
88 // can't comply with the request.  Much nicer for the calling routine to 
89 // check a return value than to monkey with the internals of the struct.
90 void * hashtable_iterator_key(struct hashtable_itr *i);
91 void * hashtable_iterator_value(struct hashtable_itr *i);
92 #endif 
93
94 /*****************************************************************************/
95 /* advance - advance the iterator to the next element
96  *           returns zero if advanced to end of table */
97
98 int
99 hashtable_iterator_advance(struct hashtable_itr *itr);
100
101 /*****************************************************************************/
102 /* remove - remove current element and advance the iterator to the next element
103  *          NB: if you need the value to free it, read it before
104  *          removing. ie: beware memory leaks!
105  *          returns zero if advanced to end of table */
106
107 int
108 hashtable_iterator_remove(struct hashtable_itr *itr);
109
110 /*****************************************************************************/
111 /* search - overwrite the supplied iterator, to point to the entry
112  *          matching the supplied key.
113             h points to the hashtable to be searched.
114  *          returns zero if not found. */
115 int
116 hashtable_iterator_search(struct hashtable_itr *itr,
117                           struct hashtable *h, void *k);
118
119 #define DEFINE_HASHTABLE_ITERATOR_SEARCH(fnname, keytype) \
120 int fnname (struct hashtable_itr *i, struct hashtable *h, keytype *k) \
121 { \
122     return (hashtable_iterator_search(i,h,k)); \
123 }
124
125
126
127 #endif /* __HASHTABLE_ITR_CWC22__*/
128
129 #endif // INCLUDE_APRS
130
131 /*
132  * Copyright (C) 2002, 2004 Christopher Clark <firstname.lastname@cl.cam.ac.uk>
133  *
134  * Permission is hereby granted, free of charge, to any person obtaining a copy
135  * of this software and associated documentation files (the "Software"), to
136  * deal in the Software without restriction, including without limitation the
137  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
138  * sell copies of the Software, and to permit persons to whom the Software is
139  * furnished to do so, subject to the following conditions:
140  *
141  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
142  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
143  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
144  * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
145  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
146  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
147  * */
148
149