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 |
#ifndef __P2TC_REFINE_UTILS_H__
|
34 |
#define __P2TC_REFINE_UTILS_H__
|
35 |
|
36 |
#ifdef __cplusplus
|
37 |
extern "C"
|
38 |
{
|
39 |
#endif
|
40 |
|
41 |
#include <glib.h>
|
42 |
|
43 |
/* The code for the Hash Set is partially based on the example given at
|
44 |
* http://developer.gnome.org/glib/2.29/glib-Hash-Tables.html
|
45 |
*/
|
46 |
|
47 |
typedef GHashTable P2trHashSet;
|
48 |
typedef GHashTableIter P2trHashSetIter;
|
49 |
|
50 |
#define p2tr_hash_set_new_default() g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, NULL)
|
51 |
#define p2tr_hash_set_new(hash_func, equal_func, destroy) g_hash_table_new_full ((hash_func), (equal_func), (destroy),NULL)
|
52 |
#define p2tr_hash_set_insert(set,element) \
|
53 |
G_STMT_START \
|
54 |
{ \
|
55 |
/* The "obvious" code (presented below) won't work: */ \
|
56 |
/* g_hash_table_insert ((set), (element), (element)) */ \
|
57 |
/* since it will cause double evaluation of (element) which is a */ \
|
58 |
/* problem! */ \
|
59 |
gpointer P2TR_HASH_SET_ELEM = (element); \
|
60 |
g_hash_table_insert ((set), P2TR_HASH_SET_ELEM, P2TR_HASH_SET_ELEM); \
|
61 |
} \
|
62 |
G_STMT_END
|
63 |
#define p2tr_hash_set_contains(set,element) g_hash_table_lookup_extended ((set), (element), NULL, NULL)
|
64 |
#define p2tr_hash_set_remove(set,element) g_hash_table_remove ((set), (element))
|
65 |
#define p2tr_hash_set_remove_all(set) g_hash_table_remove_all ((set))
|
66 |
#define p2tr_hash_set_free(set) g_hash_table_destroy(set)
|
67 |
#define p2tr_hash_set_size(set) g_hash_table_size(set)
|
68 |
|
69 |
#define p2tr_hash_set_iter_init(iter,hash_set) g_hash_table_iter_init ((iter),(hash_set))
|
70 |
#define p2tr_hash_set_iter_next(iter,val) g_hash_table_iter_next ((iter),(val),NULL)
|
71 |
#define p2tr_hash_set_iter_remove(iter) g_hash_table_iter_remove ((iter))
|
72 |
|
73 |
#define g_list_cyclic_prev(list,elem) (((elem)->prev != NULL) ? (elem)->prev : g_list_last ((elem)))
|
74 |
#define g_list_cyclic_next(list,elem) (((elem)->next != NULL) ? (elem)->next : g_list_first ((elem)))
|
75 |
|
76 |
#define foreach(iter,list) for ((iter) = (list); (iter) != NULL; (iter) = (iter)->next)
|
77 |
|
78 |
#define p2tr_exception_numeric g_error
|
79 |
#define p2tr_exception_programmatic g_error
|
80 |
#define p2tr_exception_geometric g_error
|
81 |
|
82 |
GList* p2tr_utils_new_reversed_pointer_list (int count, ...);
|
83 |
|
84 |
#ifdef __cplusplus
|
85 |
}
|
86 |
#endif
|
87 |
|
88 |
#endif
|