~ubuntu-branches/debian/squeeze/freeciv/squeeze

« back to all changes in this revision

Viewing changes to utility/speclist.h

  • Committer: Bazaar Package Importer
  • Author(s): Jordi Mallach
  • Date: 2008-07-08 18:34:23 UTC
  • mfrom: (5.1.9 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080708183423-c80u1h25xmj6h9s0
Tags: 2.1.5-2
Export datarootdir=/usr/share in debian/rules, so make calls can
have a correct value for LOCALEDIR (closes: #489455). Thanks Loïc Minier
for the help to solve this.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
   including this file would provide a struct definition for:
31
31
      struct foo_list;
32
32
   and prototypes for the following functions:
33
 
      void foo_list_init(struct foo_list *This);
 
33
      struct foolist *foo_list_new();
34
34
      int  foo_list_size(struct foo_list *This);
35
35
      foo_t *foo_list_get(struct foo_list *This, int index);
36
 
      void foo_list_insert(struct foo_list *This, foo_t *pfoo);
37
 
      void foo_list_insert_back(struct foo_list *This, foo_t *pfoo);
 
36
      void foo_list_prepend(struct foo_list *This, foo_t *pfoo);
 
37
      void foo_list_append(struct foo_list *This, foo_t *pfoo);
38
38
      void foo_list_unlink(struct foo_list *This, foo_t *pfoo);
39
39
      void foo_list_unlink_all(struct foo_list *This);
 
40
      bool foo_list_search(struct foo_list *this, foo_t *pfoo);
40
41
      void foo_list_sort(struct foo_list *This, 
41
42
         int (*compar)(const void *, const void *));
42
43
 
57
58
*/
58
59
 
59
60
#include "genlist.h"
 
61
#include "mem.h"
60
62
 
61
63
#ifndef SPECLIST_TAG
62
64
#error Must define a SPECLIST_TAG to use this header
73
75
#define SPECLIST_FOO(suffix) SPECLIST_PASTE(SPECLIST_TAG, suffix)
74
76
 
75
77
SPECLIST_LIST {
76
 
  struct genlist list;
 
78
  struct genlist *list;
77
79
};
78
80
 
79
 
static inline void SPECLIST_FOO(_list_init) (SPECLIST_LIST *tthis)
80
 
{
81
 
  genlist_init(&tthis->list);
82
 
}
83
 
 
84
 
static inline void SPECLIST_FOO(_list_insert) (SPECLIST_LIST *tthis, SPECLIST_TYPE *pfoo)
85
 
{
86
 
  genlist_insert(&tthis->list, pfoo, 0);
 
81
static inline SPECLIST_LIST *SPECLIST_FOO(_list_new) (void)
 
82
{
 
83
  SPECLIST_LIST *speclist = (SPECLIST_LIST *)fc_malloc(sizeof(*speclist));
 
84
 
 
85
  speclist->list = genlist_new();
 
86
  return speclist;
 
87
}
 
88
 
 
89
static inline SPECLIST_LIST *SPECLIST_FOO(_list_copy) (SPECLIST_LIST *plist)
 
90
{
 
91
  SPECLIST_LIST *newlist = (SPECLIST_LIST *)fc_malloc(sizeof(*newlist));
 
92
 
 
93
  newlist->list = genlist_copy(plist ? plist->list : NULL);
 
94
 
 
95
  return newlist;
 
96
}
 
97
 
 
98
static inline void SPECLIST_FOO(_list_prepend) (SPECLIST_LIST *tthis, SPECLIST_TYPE *pfoo)
 
99
{
 
100
  genlist_prepend(tthis->list, pfoo);
87
101
}
88
102
 
89
103
static inline void SPECLIST_FOO(_list_unlink) (SPECLIST_LIST *tthis, SPECLIST_TYPE *pfoo)
90
104
{
91
 
  genlist_unlink(&tthis->list, pfoo);
 
105
  genlist_unlink(tthis->list, pfoo);
92
106
}
93
107
 
94
108
static inline int SPECLIST_FOO(_list_size) (const SPECLIST_LIST *tthis)
95
109
{
96
 
  return genlist_size(&tthis->list);
 
110
  return genlist_size(tthis->list);
97
111
}
98
112
 
99
113
static inline SPECLIST_TYPE *SPECLIST_FOO(_list_get) (const SPECLIST_LIST *tthis, int index)
100
114
{
101
 
  return genlist_get(&tthis->list, index);
 
115
  return (SPECLIST_TYPE *)genlist_get(tthis->list, index);
102
116
}
103
117
 
104
 
static inline void SPECLIST_FOO(_list_insert_back) (SPECLIST_LIST *tthis, SPECLIST_TYPE *pfoo)
 
118
static inline void SPECLIST_FOO(_list_append) (SPECLIST_LIST *tthis, SPECLIST_TYPE *pfoo)
105
119
{
106
 
  genlist_insert(&tthis->list, pfoo, -1);
 
120
  genlist_append(tthis->list, pfoo);
107
121
}
108
122
 
109
123
static inline void SPECLIST_FOO(_list_unlink_all) (SPECLIST_LIST *tthis)
110
124
{
111
 
  genlist_unlink_all(&tthis->list);
 
125
  genlist_unlink_all(tthis->list);
 
126
}
 
127
 
 
128
static inline void SPECLIST_FOO(_list_free) (SPECLIST_LIST *tthis)
 
129
{
 
130
  genlist_free(tthis->list);
 
131
  free(tthis);
 
132
}
 
133
 
 
134
/****************************************************************************
 
135
  Return TRUE iff this element is in the list.
 
136
 
 
137
  This is an O(n) operation.  Hence, "search".
 
138
****************************************************************************/
 
139
static inline bool SPECLIST_FOO(_list_search) (SPECLIST_LIST *tthis,
 
140
                                               const SPECLIST_TYPE *pfoo)
 
141
{
 
142
  return genlist_search(tthis->list, pfoo);
112
143
}
113
144
 
114
145
static inline void SPECLIST_FOO(_list_sort) (SPECLIST_LIST * tthis, int (*compar) (const void *, const void *))
115
146
{
116
 
  genlist_sort(&tthis->list, compar);
 
147
  genlist_sort(tthis->list, compar);
117
148
}
118
149
 
119
150
#undef SPECLIST_TAG