GRASS GIS 7 Programmer's Manual  7.9.dev(2021)-e5379bbd7
vector/diglib/list.c
Go to the documentation of this file.
1 /*
2  ****************************************************************************
3  *
4  * MODULE: Vector library
5  *
6  * AUTHOR(S): Original author CERL, probably Dave Gerdes.
7  * Update to GRASS 5.7 Radim Blazek.
8  *
9  * PURPOSE: Lower level functions for reading/writing/manipulating vectors.
10  *
11  * COPYRIGHT: (C) 2001 by the GRASS Development Team
12  *
13  * This program is free software under the GNU General Public
14  * License (>=v2). Read the file COPYING that comes with GRASS
15  * for details.
16  *
17  *****************************************************************************/
18 #include <stdlib.h>
19 #include <grass/vector.h>
20 
21 /* Init box list */
22 int dig_init_boxlist(struct boxlist *list, int have_boxes)
23 {
24  list->id = NULL;
25  list->box = NULL;
26  list->have_boxes = have_boxes != 0;
27  list->n_values = 0;
28  list->alloc_values = 0;
29 
30  return 1;
31 }
32 
33 /* Add item to box list, does not check for duplicates */
34 int dig_boxlist_add(struct boxlist *list, int id, const struct bound_box *box)
35 {
36  if (list->n_values == list->alloc_values) {
37  size_t size = (list->n_values + 1000) * sizeof(int);
38  void *p = G_realloc((void *)list->id, size);
39 
40  if (p == NULL)
41  return 0;
42  list->id = (int *)p;
43 
44  if (list->have_boxes) {
45  size = (list->n_values + 1000) * sizeof(struct bound_box);
46  p = G_realloc((void *)list->box, size);
47 
48  if (p == NULL)
49  return 0;
50  list->box = (struct bound_box *)p;
51  }
52 
53  list->alloc_values = list->n_values + 1000;
54  }
55 
56  list->id[list->n_values] = id;
57  if (list->have_boxes)
58  list->box[list->n_values] = *box;
59  list->n_values++;
60 
61  return 1;
62 }
int dig_boxlist_add(struct boxlist *list, int id, const struct bound_box *box)
Bounding box.
Definition: dig_structs.h:65
int * id
Array of ids.
Definition: dig_structs.h:1755
#define NULL
Definition: ccmath.h:32
int n_values
Number of items in the list.
Definition: dig_structs.h:1767
int dig_init_boxlist(struct boxlist *list, int have_boxes)
struct bound_box * box
Array of bounding boxes.
Definition: dig_structs.h:1759
int have_boxes
flag to indicate whether bounding boxes should be added
Definition: dig_structs.h:1763
int alloc_values
Allocated space for items.
Definition: dig_structs.h:1771
Definition: manage.h:4
List of bounding boxes with id.
Definition: dig_structs.h:1750
#define G_realloc(p, n)
Definition: defs/gis.h:114