GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
vector/Vlib/list.c
Go to the documentation of this file.
1 
21 #include <stdlib.h>
22 #include <grass/Vect.h>
23 #include <grass/gis.h>
24 
34 struct ilist *Vect_new_list(void)
35 {
36  struct ilist *p;
37 
38  p = (struct ilist *)G_malloc(sizeof(struct ilist));
39 
40  if (p) {
41  p->value = NULL;
42  p->n_values = 0;
43  p->alloc_values = 0;
44  }
45 
46  return p;
47 }
48 
59 int Vect_reset_list(struct ilist *list)
60 {
61  list->n_values = 0;
62 
63  return 0;
64 }
65 
74 int Vect_destroy_list(struct ilist *list)
75 {
76  if (list) { /* probably a moot test */
77  if (list->alloc_values) {
78  G_free((void *)list->value);
79  }
80  G_free((void *)list);
81  }
82  list = NULL;
83 
84  return 0;
85 }
86 
96 int Vect_list_append(struct ilist *list, int val)
97 {
98  int i;
99  size_t size;
100 
101  if (list == NULL)
102  return 1;
103 
104  for (i = 0; i < list->n_values; i++) {
105  if (val == list->value[i])
106  return 0;
107  }
108 
109  if (list->n_values == list->alloc_values) {
110  size = (list->n_values + 1000) * sizeof(int);
111  list->value = (int *)G_realloc((void *)list->value, size);
112  list->alloc_values = list->n_values + 1000;
113  }
114 
115  list->value[list->n_values] = val;
116  list->n_values++;
117 
118  return 0;
119 }
120 
130 int Vect_list_append_list(struct ilist *alist, struct ilist *blist)
131 {
132  int i;
133 
134  if (alist == NULL || blist == NULL)
135  return 1;
136 
137  for (i = 0; i < blist->n_values; i++)
138  Vect_list_append(alist, blist->value[i]);
139 
140  return 0;
141 }
142 
152 int Vect_list_delete(struct ilist *list, int val)
153 {
154  int i, j;
155 
156  if (list == NULL)
157  return 1;
158 
159  for (i = 0; i < list->n_values; i++) {
160  if (val == list->value[i]) {
161  for (j = i + 1; j < list->n_values; j++)
162  list->value[j - 1] = list->value[j];
163 
164  list->n_values--;
165  return 0;
166  }
167  }
168 
169  return 0;
170 }
171 
181 int Vect_list_delete_list(struct ilist *alist, struct ilist *blist)
182 {
183  int i;
184 
185  if (alist == NULL || blist == NULL)
186  return 1;
187 
188  for (i = 0; i < blist->n_values; i++)
189  Vect_list_delete(alist, blist->value[i]);
190 
191  return 0;
192 }
193 
203 int Vect_val_in_list(struct ilist *list, int val)
204 {
205  int i;
206 
207  if (list == NULL)
208  return 0;
209 
210  for (i = 0; i < list->n_values; i++) {
211  if (val == list->value[i])
212  return 1;
213  }
214 
215  return 0;
216 }
int Vect_destroy_list(struct ilist *list)
Frees all memory associated with a struct ilist, including the struct itself.
void G_free(void *buf)
Free allocated memory.
Definition: gis/alloc.c:142
struct ilist * Vect_new_list(void)
Creates and initializes a struct ilist.
int Vect_list_delete(struct ilist *list, int val)
Remove a given value (item) from list.
tuple size
value.Bind(wx.EVT_TEXT, self.OnVolumeIsosurfMap)
Definition: tools.py:2334
int Vect_reset_list(struct ilist *list)
Reset ilist structure.
int Vect_list_append_list(struct ilist *alist, struct ilist *blist)
Append new items to the end of list if not yet present.
int Vect_list_append(struct ilist *list, int val)
Append new item to the end of list if not yet present.
return NULL
Definition: dbfopen.c:1394
int Vect_list_delete_list(struct ilist *alist, struct ilist *blist)
Delete list from existing list.
int Vect_val_in_list(struct ilist *list, int val)
Find a given item in the list.