GRASS GIS 8 Programmer's Manual  8.2.2dev(2023)-3d2c704037
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  (C) 1999-2009 by the GRASS Development Team
7 
8  This program is free software under the GNU General Public
9  License (>=v2). Read the file COPYING that comes with GRASS
10  for details.
11 
12  \author Joel Jones (CERL/UIUC), Radim Blazek
13 */
14 #include <grass/dbmi.h>
15 
16 /* these routines manage a mapping between tokens (ints) and memory addresses */
17 #define NONE ( (dbAddress) NULL )
18 
19 static dbAddress *list = NONE;
20 static dbToken count = 0;
21 
22 /*!
23  \brief Find token
24 
25  \param token pointer to dbToken
26 
27  \return dbAddress
28  \return NULL if no token found
29 */
31 {
32  if (token >= 0 && token < count)
33  return list[token];
34  return (NONE);
35 }
36 
37 /*!
38  \brief Drop token
39 
40  \param token pointer to dbToken
41 */
43 {
44  if (token >= 0 && token < count)
45  list[token] = NONE;
46 }
47 
48 /*!
49  \brief Add new token
50 
51  \param address dbAddress of token to be added
52 
53  \return dbToken
54  */
56 {
57  dbToken token;
58  dbAddress *p;
59 
60  for (token = 0; token < count; token++)
61  if (list[token] == NONE) {
62  list[token] = address;
63  return token;
64  }
65 
66  p = (dbAddress *) db_realloc((void *)list, sizeof(*list) * (count + 1));
67  if (p == NULL)
68  return -1;
69 
70  list = p;
71  token = count++;
72  list[token] = address;
73  return (token);
74 }
void * db_realloc(void *, int)
Reallocate memory.
dbAddress db_find_token(dbToken token)
Find token.
void db_drop_token(dbToken token)
Drop token.
int count
char * address
Definition: la.h:50
int dbToken
Definition: dbmi.h:145
#define NULL
Definition: ccmath.h:32
void * dbAddress
Definition: dbmi.h:144
struct list * list
Definition: read_list.c:24
dbToken db_new_token(dbAddress address)
Add new token.
Definition: manage.h:4
#define NONE