GRASS 8 Programmer's Manual 8.6.0dev(2026)-4bb960b182
Loading...
Searching...
No Matches
ilist.c
Go to the documentation of this file.
1/*
2 ****************************************************************************
3 *
4 * MODULE: gis 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 and manipulating integer list
10 *
11 * SPDX-FileCopyrightText: 2001 GRASS Development Team
12 * SPDX-License-Identifier: GPL-2.0-or-later
13 *
14 *****************************************************************************/
15#include <stdlib.h>
16#include <grass/gis.h>
17
18/**
19 * \brief Free allocated memory of an integer list
20 *
21 * \param list The pointer to an integer list
22 *
23 * */
24void G_free_ilist(struct ilist *list)
25{
26 if (list->value)
27 G_free(list->value);
28 G_free(list);
29}
30
31/**
32 * \brief Return a new integer list.
33 *
34 * G_fatal_error() will be invoked by the
35 * allocation function.
36 *
37 * \return list The pointer to a new allocated integer list
38 *
39 * */
40struct ilist *G_new_ilist(void)
41{
42 struct ilist *l = G_malloc(sizeof(struct ilist));
43
44 l->value = NULL;
46 return l;
47}
48
49/**
50 * \brief Init an integer list and free allocated memory
51 *
52 * \param list The pointer to an integer list
53 *
54 * */
55void G_init_ilist(struct ilist *list)
56{
57 if (list->value)
58 G_free(list->value);
59 list->value = NULL;
60 list->n_values = 0;
61 list->alloc_values = 0;
62}
63
64/**
65 * \brief Add item to ilist
66 *
67 * This function adds an integer to the list but does not check for duplicates.
68 * In case reallocation fails, G_fatal_error() will be invoked by the
69 * allocation function.
70 *
71 * \param list The ilist pointer
72 * \param val The value to attach
73 *
74 * */
75void G_ilist_add(struct ilist *list, int val)
76{
77 if (list->n_values == list->alloc_values) {
78 size_t size = (list->n_values + 1000) * sizeof(int);
79 void *p = G_realloc((void *)list->value, size);
80
81 list->value = (int *)p;
82 list->alloc_values = list->n_values + 1000;
83 }
84
85 list->value[list->n_values] = val;
86 list->n_values++;
87}
#define NULL
Definition ccmath.h:32
void G_free(void *)
Free allocated memory.
Definition gis/alloc.c:145
#define G_realloc(p, n)
Definition defs/gis.h:138
#define G_malloc(n)
Definition defs/gis.h:136
struct ilist * G_new_ilist(void)
Return a new integer list.
Definition ilist.c:40
void G_init_ilist(struct ilist *list)
Init an integer list and free allocated memory.
Definition ilist.c:55
void G_ilist_add(struct ilist *list, int val)
Add item to ilist.
Definition ilist.c:75
void G_free_ilist(struct ilist *list)
Free allocated memory of an integer list.
Definition ilist.c:24
double l
Definition r_raster.c:37
List of integers.
Definition gis.h:712
Definition manage.h:4