GRASS GIS 7 Programmer's Manual
7.8.2(2019)-exported
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
* 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/gis.h>
20
21
/**
22
* \brief Free allocated memory of an integer list
23
*
24
* \param list The pointer to an integer list
25
*
26
* */
27
void
G_free_ilist
(
struct
ilist *
list
)
28
{
29
if
(
list
->value)
30
G_free
(
list
->value);
31
G_free
(
list
);
32
}
33
34
/**
35
* \brief Return a new integer list.
36
*
37
* G_fatal_error() will be invoked by the
38
* allocation function.
39
*
40
* \return list The pointer to a new allocated integer list
41
*
42
* */
43
struct
ilist *
G_new_ilist
()
44
{
45
struct
ilist *
l
= G_malloc(
sizeof
(
struct
ilist));
46
l
->value =
NULL
;
47
G_init_ilist
(
l
);
48
return
l
;
49
}
50
51
/**
52
* \brief Init an integer list and free allocated memory
53
*
54
* \param list The pointer to an integer list
55
*
56
* */
57
void
G_init_ilist
(
struct
ilist *
list
)
58
{
59
if
(
list
->value)
60
G_free
(
list
->value);
61
list
->value =
NULL
;
62
list
->n_values = 0;
63
list
->alloc_values = 0;
64
}
65
66
/**
67
* \brief Add item to ilist
68
*
69
* This function adds an integer to the list but does not check for duplicates.
70
* In case reallocation fails, G_fatal_error() will be invoked by the
71
* allocation function.
72
*
73
* \param list The ilist pointer
74
* \param val The value to attach
75
*
76
* */
77
void
G_ilist_add
(
struct
ilist *
list
,
int
val)
78
{
79
if
(
list
->n_values ==
list
->alloc_values) {
80
size_t
size = (
list
->n_values + 1000) *
sizeof
(
int
);
81
void
*p = G_realloc((
void
*)
list
->value, size);
82
83
list
->value = (
int
*)p;
84
list
->alloc_values =
list
->n_values + 1000;
85
}
86
87
list
->value[
list
->n_values] = val;
88
list
->n_values++;
89
}
list
struct list * list
Definition:
read_list.c:24
l
double l
Definition:
driver/set_window.c:5
G_free
void G_free(void *buf)
Free allocated memory.
Definition:
alloc.c:149
G_init_ilist
void G_init_ilist(struct ilist *list)
Init an integer list and free allocated memory.
Definition:
ilist.c:57
G_ilist_add
void G_ilist_add(struct ilist *list, int val)
Add item to ilist.
Definition:
ilist.c:77
NULL
#define NULL
Definition:
ccmath.h:32
G_free_ilist
void G_free_ilist(struct ilist *list)
Free allocated memory of an integer list.
Definition:
ilist.c:27
G_new_ilist
struct ilist * G_new_ilist()
Return a new integer list.
Definition:
ilist.c:43
gis
ilist.c
Generated on Tue Jan 14 2020 14:30:42 for GRASS GIS 7 Programmer's Manual by
1.8.16