GRASS 8 Programmer's Manual 8.6.0dev(2026)-4bb960b182
Loading...
Searching...
No Matches
map_list.c
Go to the documentation of this file.
1/*****************************************************************************
2 *
3 * MODULE: gis 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 and manipulating integer list
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/gis.h>
17#include <grass/temporal.h>
18
19/**
20 * \brief Free allocated memory of an integer list
21 *
22 * \param list The pointer to an integer list
23 *
24 * */
26{
27 if (list->values) {
28 int i;
29
30 for (i = 0; i < list->n_values; i++) {
31 if (list->values[i]->name)
32 G_free(list->values[i]->name);
33 if (list->values[i]->mapset)
34 G_free(list->values[i]->mapset);
35 G_free(list->values[i]);
36 }
37 G_free(list->values);
38 }
39 G_free(list);
40}
41
42/**
43 * \brief Return a new integer list.
44 *
45 * G_fatal_error() will be invoked by the
46 * allocation function.
47 *
48 * \return list The pointer to a new allocated integer list
49 *
50 * */
52{
54
55 list->values = NULL;
57 return list;
58}
59
60/**
61 * \brief Init a tgisMapList and free allocated memory
62 *
63 * \param list The pointer to a tgisMapList
64 *
65 * */
67{
68 if (list->values) {
69 int i;
70
71 for (i = 0; i < list->n_values; i++) {
72 if (list->values[i]->name)
73 G_free(list->values[i]->name);
74 if (list->values[i]->mapset)
75 G_free(list->values[i]->mapset);
76 G_free(list->values[i]);
77 }
78 G_free(list->values);
79 }
80
81 list->values = NULL;
82 list->n_values = 0;
83 list->alloc_values = 0;
84}
85
86/**
87 * \brief Add a map to tgisMapList
88 *
89 * This function adds a tgisMap to the list but does not check for duplicates.
90 * In case reallocation fails, G_fatal_error() will be invoked by the
91 * allocation function.
92 *
93 * The content of the map will not be copied, the pointer
94 *to the map will be stored.
95 *
96 * \param list The tgisMapList pointer
97 * \param map A pointer to a tgisMap struct that should be added
98 *
99 * */
101{
102 if (list->n_values == list->alloc_values) {
103 size_t size = (list->n_values + 1000) * sizeof(tgisMap *);
104 void *p = G_realloc((void *)list->values, size);
105
106 list->values = (tgisMap **)p;
107 list->alloc_values = list->n_values + 1000;
108 }
109
110 list->values[list->n_values] = map;
111 list->n_values++;
112}
113
114/**
115 * \brief Insert map information into tgisMapList
116 *
117 * This function allocates a tgisMap, fills it with the provided information
118 * and adds it to the list.
119 * In case allocation fails, G_fatal_error() will be invoked by the
120 * allocation function.
121 *
122 * All arguments are deep copied to the new allocated tgisMap struct.
123 *
124 * \param list The tgisMapList pointer
125 * \param name The name of the map
126 * \param mapset The name of the mapset
127 * \param ts A pointer to the timestamp of the map
128 *
129 * */
130void tgis_map_list_insert(tgisMapList *list, char *name, char *mapset,
131 struct TimeStamp *ts)
132{
133 tgisMap *map = G_calloc(1, sizeof(tgisMap));
134
135 map->name = G_store(name);
136 map->mapset = G_store(mapset);
137
138 if (ts->count == 1)
139 G_set_timestamp(&(map->ts), &(ts->dt[0]));
140 if (ts->count == 2)
141 G_set_timestamp_range(&(map->ts), &(ts->dt[0]), &(ts->dt[1]));
142
144}
#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
void G_set_timestamp(struct TimeStamp *, const struct DateTime *)
#define G_calloc(m, n)
Definition defs/gis.h:137
#define G_malloc(n)
Definition defs/gis.h:136
void G_set_timestamp_range(struct TimeStamp *, const struct DateTime *, const struct DateTime *)
char * G_store(const char *)
Copy string to allocated memory.
Definition strings.c:85
tgisMapList * tgis_new_map_list(void)
Return a new integer list.
Definition map_list.c:51
void tgis_free_map_list(tgisMapList *list)
Free allocated memory of an integer list.
Definition map_list.c:25
void tgis_init_map_list(tgisMapList *list)
Init a tgisMapList and free allocated memory.
Definition map_list.c:66
void tgis_map_list_add(tgisMapList *list, tgisMap *map)
Add a map to tgisMapList.
Definition map_list.c:100
void tgis_map_list_insert(tgisMapList *list, char *name, char *mapset, struct TimeStamp *ts)
Insert map information into tgisMapList.
Definition map_list.c:130
const char * name
Definition named_colr.c:6
DateTime dt[2]
Definition gis.h:618
int count
Definition gis.h:619
List of tgisMap struct's.
Definition temporal.h:54
char * mapset
Definition temporal.h:44
char * name
Definition temporal.h:43
struct TimeStamp ts
Definition temporal.h:45
Definition manage.h:4