GRASS 8 Programmer's Manual 8.6.0dev(2026)-4bb960b182
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 * SPDX-FileCopyrightText: 2001 GRASS Development Team
11 * SPDX-License-Identifier: GPL-2.0-or-later
12 *
13 *****************************************************************************/
14
15#include <stdlib.h>
16#include <grass/vector.h>
17
18/* Init box list */
19int dig_init_boxlist(struct boxlist *list, int have_boxes)
20{
21 list->id = NULL;
22 list->box = NULL;
23 list->have_boxes = have_boxes != 0;
24 list->n_values = 0;
25 list->alloc_values = 0;
26
27 return 1;
28}
29
30/* Add item to box list, does not check for duplicates */
31int dig_boxlist_add(struct boxlist *list, int id, const struct bound_box *box)
32{
33 if (list->n_values == list->alloc_values) {
34 size_t size = (list->n_values + 1000) * sizeof(int);
35 void *p = G_realloc((void *)list->id, size);
36
37 if (p == NULL)
38 return 0;
39 list->id = (int *)p;
40
41 if (list->have_boxes) {
42 size = (list->n_values + 1000) * sizeof(struct bound_box);
43 p = G_realloc((void *)list->box, size);
44
45 if (p == NULL)
46 return 0;
47 list->box = (struct bound_box *)p;
48 }
49
50 list->alloc_values = list->n_values + 1000;
51 }
52
53 list->id[list->n_values] = id;
54 if (list->have_boxes)
55 list->box[list->n_values] = *box;
56 list->n_values++;
57
58 return 1;
59}
#define NULL
Definition ccmath.h:32
#define G_realloc(p, n)
Definition defs/gis.h:138
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)