3 * This file is part of Maemo Mapper.
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.
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.
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/>.
19 * Parts of this code have been ported from Xastir by Rob Williams (10 Aug 2008):
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>
34 #ifndef __HASHTABLE_ITR_CWC22__
35 #define __HASHTABLE_ITR_CWC22__
36 #include "hashtable.h"
37 #include "hashtable_private.h" /* needed to enable inlining */
39 /*****************************************************************************/
40 /* This struct is only concrete here to allow the inlining of two of the
41 * accessor functions. */
51 /*****************************************************************************/
55 struct hashtable_itr *
56 hashtable_iterator(struct hashtable *h);
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 */
72 hashtable_iterator_key(struct hashtable_itr *i)
77 /*****************************************************************************/
78 /* value - return the value of the (key,value) pair at the current position */
81 hashtable_iterator_value(struct hashtable_itr *i)
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);
94 /*****************************************************************************/
95 /* advance - advance the iterator to the next element
96 * returns zero if advanced to end of table */
99 hashtable_iterator_advance(struct hashtable_itr *itr);
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 */
108 hashtable_iterator_remove(struct hashtable_itr *itr);
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. */
116 hashtable_iterator_search(struct hashtable_itr *itr,
117 struct hashtable *h, void *k);
119 #define DEFINE_HASHTABLE_ITERATOR_SEARCH(fnname, keytype) \
120 int fnname (struct hashtable_itr *i, struct hashtable *h, keytype *k) \
122 return (hashtable_iterator_search(i,h,k)); \
127 #endif /* __HASHTABLE_ITR_CWC22__*/
129 #endif // INCLUDE_APRS
132 * Copyright (C) 2002, 2004 Christopher Clark <firstname.lastname@cl.cam.ac.uk>
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:
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.