40213d9a5b534aa05304fa8a4a82aad863a6252b
[alexxy/gromacs.git] / src / gromacs / topology / symtab.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5  * Copyright (c) 2001-2004, The GROMACS development team.
6  * Copyright (c) 2010,2014,2017, by the GROMACS development team, led by
7  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
8  * and including many others, as listed in the AUTHORS file in the
9  * top-level source directory and at http://www.gromacs.org.
10  *
11  * GROMACS is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public License
13  * as published by the Free Software Foundation; either version 2.1
14  * of the License, or (at your option) any later version.
15  *
16  * GROMACS is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public
22  * License along with GROMACS; if not, see
23  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
24  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
25  *
26  * If you want to redistribute modifications to GROMACS, please
27  * consider that scientific software is very special. Version
28  * control is crucial - bugs must be traceable. We will be happy to
29  * consider code for inclusion in the official distribution, but
30  * derived work must not be called official GROMACS. Details are found
31  * in the README & COPYING files - if they are missing, get the
32  * official version at http://www.gromacs.org.
33  *
34  * To help us fund GROMACS development, we humbly ask that you cite
35  * the research papers on the package. Check out http://www.gromacs.org.
36  */
37 #ifndef GMX_TOPOLOGY_SYMTAB_H
38 #define GMX_TOPOLOGY_SYMTAB_H
39
40 #include <stdio.h>
41
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45
46 typedef struct t_symbuf
47 {
48     int               bufsize;
49     char            **buf;
50     struct t_symbuf  *next;
51 } t_symbuf;
52
53 typedef struct t_symtab
54 {
55     int       nr;
56     t_symbuf *symbuf;
57 } t_symtab;
58
59 /*
60  * This module handles symbol table manipulation. All text strings
61  * needed by an application are allocated only once. All references
62  * to these text strings use handles returned from the put_symtab()
63  * routine. These handles can easily be converted to address independent
64  * values by invoking lookup_symtab(). So when writing structures to
65  * a file which contains text strings, this value can be written in stead
66  * of the text string or its address. This value can easily be converted
67  * back to a text string handle by get_symtab_handle().
68  */
69
70 void open_symtab(t_symtab *symtab);
71 /* Initialises the symbol table symtab.
72  */
73
74 void close_symtab(t_symtab *symtab);
75 /* Undoes the effect of open_symtab(), after invoking this function,
76  * no value can be added to the symbol table, only values can be
77  * retrieved using get_symtab().
78  *
79  * Note that this does no work.
80  */
81
82 void free_symtab(t_symtab *symtab);
83 /* Frees the space allocated by the symbol table itself */
84
85 void done_symtab(t_symtab *symtab);
86 /* Frees the space allocated by the symbol table, including all
87  * entries in it */
88
89 char **put_symtab(t_symtab *symtab, const char *name);
90 /* Enters a string into the symbol table symtab, if it was not
91  * available, a reference to a copy is returned else a reference
92  * to the earlier entered value is returned. Strings are trimmed
93  * of spaces.
94  */
95
96 int lookup_symtab(t_symtab *symtab, char **name);
97 /* Returns a unique handle for **name, without a memory reference.
98  * It is a failure when name cannot be found in the symbol table,
99  * it should be entered before with put_symtab().
100  */
101
102 char **get_symtab_handle(t_symtab *symtab, int name);
103 /* Returns a text string handle for name. Name should be a value
104  * returned from lookup_symtab(). So get_symtab_handle() and
105  * lookup_symtab() are inverse functions.
106  */
107
108 long wr_symtab(FILE *fp, t_symtab *symtab);
109 /* Writes the symbol table symtab to the file, specified by fp.
110  * The function returns the number of bytes written.
111  */
112
113 long rd_symtab(FILE *fp, t_symtab *symtab);
114 /* Reads the symbol table symtab from the file, specified by fp.
115  * This will include allocating the needed space. The function
116  * returns the number of bytes read. The symtab is in the closed
117  * state afterwards, so no strings can be added to it.
118  */
119
120 void pr_symtab(FILE *fp, int indent, const char *title, t_symtab *symtab);
121 /* This routine prints out a (human) readable representation of
122  * the symbol table symtab to the file fp. Ident specifies the
123  * number of spaces the text should be indented. Title is used
124  * to print a header text.
125  */
126
127 #ifdef __cplusplus
128 }
129 #endif
130
131 #endif