2a7b59b4ac9024c83866f7856c5800b4fb2d26cf
[alexxy/gromacs.git] / include / symtab.h
1 /*
2  * 
3  *                This source code is part of
4  * 
5  *                 G   R   O   M   A   C   S
6  * 
7  *          GROningen MAchine for Chemical Simulations
8  * 
9  *                        VERSION 3.2.0
10  * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
11  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
12  * Copyright (c) 2001-2004, The GROMACS development team,
13  * check out http://www.gromacs.org for more information.
14
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * as published by the Free Software Foundation; either version 2
18  * of the License, or (at your option) any later version.
19  * 
20  * If you want to redistribute modifications, please consider that
21  * scientific software is very special. Version control is crucial -
22  * bugs must be traceable. We will be happy to consider code for
23  * inclusion in the official distribution, but derived work must not
24  * be called official GROMACS. Details are found in the README & COPYING
25  * files - if they are missing, get the official version at www.gromacs.org.
26  * 
27  * To help us fund GROMACS development, we humbly ask that you cite
28  * the papers on the package - you can find them in the top README file.
29  * 
30  * For more info, check our website at http://www.gromacs.org
31  * 
32  * And Hey:
33  * Gromacs Runs On Most of All Computer Systems
34  */
35
36 #ifndef _symtab_h
37 #define _symtab_h
38
39 #include <stdio.h>
40 #include "visibility.h"
41 #include "typedefs.h"
42
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46
47 /*
48  * This module handles symbol table manipulation. All text strings 
49  * needed by an application are allocated only once. All references
50  * to these text strings use handles returned from the put_symtab()
51  * routine. These handles can easily be converted to address independent
52  * values by invoking lookup_symtab(). So when writing structures to
53  * a file which contains text strings, this value can be written in stead
54  * of the text string or its address. This value can easily be converted
55  * back to a text string handle by get_symtab_handle().
56  */
57
58 GMX_LIBGMX_EXPORT
59 void open_symtab(t_symtab *symtab);
60      /* Initialises the symbol table symtab.
61       */
62
63 GMX_LIBGMX_EXPORT
64 void close_symtab(t_symtab *symtab);
65      /* Undoes the effect of open_symtab(), after invoking this function, 
66       * no value can be added to the symbol table, only values can be 
67       * retrieved using get_symtab().
68       */
69
70 void free_symtab(t_symtab *symtab);
71      /* Frees the space allocated by the symbol table itself */
72
73 GMX_LIBGMX_EXPORT
74 void done_symtab(t_symtab *symtab);
75      /* Frees the space allocated by the symbol table, including all
76       * entries in it */
77
78 GMX_LIBGMX_EXPORT
79 char **put_symtab(t_symtab *symtab,const char *name);
80      /* Enters a string into the symbol table symtab, if it was not
81       * available, a reference to a copy is returned else a reference 
82       * to the earlier entered value is returned. Strings are trimmed
83       * of spaces.
84       */
85
86 int lookup_symtab(t_symtab *symtab,char **name);
87      /* Returns a unique handle for **name, without a memory reference.
88       * It is a failure when name cannot be found in the symbol table,
89       * it should be entered before with put_symtab().
90       */
91
92 char **get_symtab_handle(t_symtab *symtab,int name);
93      /* Returns a text string handle for name. Name should be a value
94       * returned from lookup_symtab(). So get_symtab_handle() and 
95       * lookup_symtab() are inverse functions.
96       */
97
98 long wr_symtab(FILE *fp,t_symtab *symtab);
99      /* Writes the symbol table symtab to the file, specified by fp.
100       * The function returns the number of bytes written.
101       */
102
103 long rd_symtab(FILE *fp,t_symtab *symtab);
104      /* Reads the symbol table symtab from the file, specified by fp.
105       * This will include allocating the needed space. The function 
106       * returns the number of bytes read. The symtab is in the closed
107       * state afterwards, so no strings can be added to it.
108       */
109
110 GMX_LIBGMX_EXPORT
111 void pr_symtab(FILE *fp,int indent,const char *title,t_symtab *symtab);
112      /* This routine prints out a (human) readable representation of 
113       * the symbol table symtab to the file fp. Ident specifies the
114       * number of spaces the text should be indented. Title is used
115       * to print a header text.
116       */
117
118 #ifdef __cplusplus
119 }
120 #endif
121
122 #endif  /* _symtab_h */