GRASS 8 Programmer's Manual 8.6.0dev(2026)-1d1e47ad9d
Loading...
Searching...
No Matches
vector/diglib/list.c
Go to the documentation of this file.
1/*****************************************************************************
2 *
3 * MODULE: Vector library
4 *
5 * AUTHOR(S): Original author CERL, probably Dave Gerdes.
6 * Update to GRASS 5.7 Radim Blazek.
7 *
8 * PURPOSE: Lower level functions for reading/writing/manipulating vectors.
9 *
10 * COPYRIGHT: (C) 2001 by the GRASS Development Team
11 *
12 * This program is free software under the GNU General Public
13 * License (>=v2). Read the file COPYING that comes with GRASS
14 * for details.
15 *
16 *****************************************************************************/
17
18#include <stdlib.h>
19#include <grass/vector.h>
20
21/* Init box list */
22int 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 */
34int 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}
#define NULL
Definition ccmath.h:32
#define G_realloc(p, n)
Definition defs/gis.h:141
Bounding box.
Definition dig_structs.h:62
List of bounding boxes with id.
Definition manage.h:4
int dig_init_boxlist(struct boxlist *list, int have_boxes)
int dig_boxlist_add(struct boxlist *list, int id, const struct bound_box *box)