1 #ifndef __CS_MAP_H__
2 #define __CS_MAP_H__
3 
4 /*============================================================================
5  * Map helper structures
6  *============================================================================*/
7 
8 /*
9   This file is part of Code_Saturne, a general-purpose CFD tool.
10 
11   Copyright (C) 1998-2021 EDF S.A.
12 
13   This program is free software; you can redistribute it and/or modify it under
14   the terms of the GNU General Public License as published by the Free Software
15   Foundation; either version 2 of the License, or (at your option) any later
16   version.
17 
18   This program is distributed in the hope that it will be useful, but WITHOUT
19   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20   FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
21   details.
22 
23   You should have received a copy of the GNU General Public License along with
24   this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
25   Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 */
27 
28 /*----------------------------------------------------------------------------*/
29 
30 /*----------------------------------------------------------------------------
31  *  Local headers
32  *----------------------------------------------------------------------------*/
33 
34 #include "cs_base.h"
35 
36 /*----------------------------------------------------------------------------*/
37 
38 BEGIN_C_DECLS
39 
40 /*============================================================================
41  * Macro definitions
42  *============================================================================*/
43 
44 /*============================================================================
45  * Type definitions
46  *============================================================================*/
47 
48 typedef struct _cs_map_name_to_id_t  cs_map_name_to_id_t;
49 
50 /*============================================================================
51  *  Global variables
52  *============================================================================*/
53 
54 /*=============================================================================
55  * Public function prototypes for Fortran API
56  *============================================================================*/
57 
58 /*=============================================================================
59  * Public function prototypes
60  *============================================================================*/
61 
62 /*----------------------------------------------------------------------------
63  * Create empty name to id map.
64  *
65  * returns:
66  *   pointer to newly initialized map structure.
67  *----------------------------------------------------------------------------*/
68 
69 cs_map_name_to_id_t *
70 cs_map_name_to_id_create(void);
71 
72 /*----------------------------------------------------------------------------
73  * Destroy name to id map structure.
74  *
75  * parameters:
76  *   m <-> pointer to map structure.
77  *----------------------------------------------------------------------------*/
78 
79 void
80 cs_map_name_to_id_destroy(cs_map_name_to_id_t **m);
81 
82 /*----------------------------------------------------------------------------
83  * Find id matching a key, inserting key if not already present.
84  *
85  * parameters:
86  *   m     <-> pointer to map structure
87  *   key   <-- character string (key)
88  *
89  * returns:
90  *   id matching key (already present or newly inserted)
91  *----------------------------------------------------------------------------*/
92 
93 int
94 cs_map_name_to_id(cs_map_name_to_id_t  *m,
95                   const char           *key);
96 
97 /*----------------------------------------------------------------------------
98  * Return id matching a key, or -1 if not present.
99  *
100  * parameters:
101  *   m      <-- pointer to map structure
102  *   key    <-- character string (key)
103  *
104  * returns:
105  *   id matching key, or -1.
106  *----------------------------------------------------------------------------*/
107 
108 int
109 cs_map_name_to_id_try(const cs_map_name_to_id_t  *m,
110                       const char                 *key);
111 
112 /*----------------------------------------------------------------------------
113  * Return a key name in a map matching a given id.
114  *
115  * parameters:
116  *   m  <-- pointer to map structure.
117  *   id <-- key id
118  *
119  * returns:
120  *   pointer to key.
121  *----------------------------------------------------------------------------*/
122 
123 const char *
124 cs_map_name_to_id_reverse(const cs_map_name_to_id_t  *m,
125                           size_t                      id);
126 
127 /*----------------------------------------------------------------------------
128  * Return the size of a map.
129  *
130  * parameters:
131  *   m <-- pointer to map structure.
132  *
133  * returns:
134  *   number of entries in map.
135  *----------------------------------------------------------------------------*/
136 
137 size_t
138 cs_map_name_to_id_size(const cs_map_name_to_id_t *m);
139 
140 /*----------------------------------------------------------------------------
141  * Return key in a map for a given index position.
142  *
143  * parameters:
144  *   m     <-- pointer to map structure.
145  *   index <-- key index
146  *
147  * returns:
148  *   pointer to key.
149  *----------------------------------------------------------------------------*/
150 
151 const char *
152 cs_map_name_to_id_key(const cs_map_name_to_id_t  *m,
153                       size_t                      index);
154 
155 /*----------------------------------------------------------------------------*/
156 
157 END_C_DECLS
158 
159 #endif /* __CS_MAP_H__ */
160