GRASS 8 Programmer's Manual 8.6.0dev(2026)-4bb960b182
Loading...
Searching...
No Matches
db/dbmi_base/token.c
Go to the documentation of this file.
1/*!
2 \file db/dbmi_base/token.c
3
4 \brief DBMI Library (base) - tokens management
5
6 SPDX-FileCopyrightText: 1999-2009 GRASS Development Team
7 SPDX-License-Identifier: GPL-2.0-or-later
8
9 \author Joel Jones (CERL/UIUC), Radim Blazek
10 */
11#include <grass/dbmi.h>
12
13/* these routines manage a mapping between tokens (ints) and memory addresses */
14#define NONE ((dbAddress)NULL)
15
16static dbAddress *list = NONE;
17static dbToken count = 0;
18
19/*!
20 \brief Find token
21
22 \param token pointer to dbToken
23
24 \return dbAddress
25 \return NULL if no token found
26 */
28{
29 if (token >= 0 && token < count)
30 return list[token];
31 return (NONE);
32}
33
34/*!
35 \brief Drop token
36
37 \param token pointer to dbToken
38 */
40{
41 if (token >= 0 && token < count)
42 list[token] = NONE;
43}
44
45/*!
46 \brief Add new token
47
48 \param address dbAddress of token to be added
49
50 \return dbToken
51 */
53{
54 dbToken token;
55 dbAddress *p;
56
57 for (token = 0; token < count; token++)
58 if (list[token] == NONE) {
59 list[token] = address;
60 return token;
61 }
62
63 p = (dbAddress *)db_realloc((void *)list, sizeof(*list) * (count + 1));
64 if (p == NULL)
65 return -1;
66
67 list = p;
68 token = count++;
69 list[token] = address;
70 return (token);
71}
#define NULL
Definition ccmath.h:32
#define NONE
dbToken db_new_token(dbAddress address)
Add new token.
dbAddress db_find_token(dbToken token)
Find token.
void db_drop_token(dbToken token)
Drop token.
Main header of GRASS DataBase Management Interface.
int dbToken
Definition dbmi.h:143
void * dbAddress
Definition dbmi.h:142
void * db_realloc(void *, int)
Reallocate memory.
Definition manage.h:4