Gromacs  2021.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Functions | Variables
symtab.cpp File Reference
#include "gmxpre.h"
#include "symtab.h"
#include <cstdio>
#include <cstring>
#include <algorithm>
#include "gromacs/utility/basedefinitions.h"
#include "gromacs/utility/cstringutil.h"
#include "gromacs/utility/exceptions.h"
#include "gromacs/utility/fatalerror.h"
#include "gromacs/utility/iserializer.h"
#include "gromacs/utility/smalloc.h"
#include "gromacs/utility/stringutil.h"
#include "gromacs/utility/txtdump.h"
+ Include dependency graph for symtab.cpp:

Description

Implements new and legacy symbol table routines.

Author
David van der Spoel david.nosp@m..van.nosp@m.dersp.nosp@m.oel@.nosp@m.icm.u.nosp@m.u.se
Paul Bauer paul..nosp@m.baue.nosp@m.r.q@g.nosp@m.mail.nosp@m..com

Functions

StringTableEntry readStringTableEntry (gmx::ISerializer *serializer, const StringTable &table)
 De-serialize StringTableEntry using the index into the table. More...
 
static char * trim_string (const char *s, char *out, int maxlen)
 Remove leading and trailing whitespace from string and enforce maximum length. More...
 
int lookup_symtab (t_symtab *symtab, char **name)
 Returns unique handle for name. More...
 
char ** get_symtab_handle (t_symtab *symtab, int name)
 Returns text string corresponding to index. More...
 
static t_symbufnew_symbuf ()
 Returns a new initialized entry into the symtab linked list.
 
static char ** enter_buf (t_symtab *symtab, char *name)
 Low level function to enter new string into legacy symtab. More...
 
char ** put_symtab (t_symtab *symtab, const char *name)
 Enters a string into the symbol table. More...
 
void open_symtab (t_symtab *symtab)
 Initialises the symbol table symtab.
 
void close_symtab (t_symtab *symtab)
 Undoes the effect of open_symtab() More...
 
t_symtab * duplicateSymtab (const t_symtab *symtab)
 Returns a deep copy of symtab.
 
void done_symtab (t_symtab *symtab)
 Frees the space allocated by the symbol table, including all entries in it.
 
void free_symtab (t_symtab *symtab)
 Frees the space allocated by the symbol table itself.
 
void pr_symtab (FILE *fp, int indent, const char *title, t_symtab *symtab)
 Prints human readable form of symtab. More...
 

Variables

constexpr int c_trimSize = 1024
 Maximum size of character string in table.
 
constexpr int c_maxBufSize = 5
 Maximum number of entries in each element of the linked list.
 

Function Documentation

void close_symtab ( t_symtab *  symtab)

Undoes the effect of open_symtab()

After invoking this function, no value can be added to the symbol table, only values can be retrieved using get_symtab_handle().

Note that this does no work.

Parameters
[in,out]symtabSymbol table to close.
static char** enter_buf ( t_symtab *  symtab,
char *  name 
)
static

Low level function to enter new string into legacy symtab.

Parameters
[in,out]symtabSymbol table to add entry to.
[in]nameNew string to add to symtab.
Returns
Pointer to new entry in the legacy symbol table, or to existing entry if it already existed.
char** get_symtab_handle ( t_symtab *  symtab,
int  index 
)

Returns text string corresponding to index.

index needs to be value obtained from call to lookup_symtab(). get_symtab_handle() and lookup_symtab() are inverse functions.

Parameters
[in]symtabSymbol table to search.
[in]indexEntry to find in table.
Returns
String pointer into symtab corresponding to the entry.
int lookup_symtab ( t_symtab *  symtab,
char **  name 
)

Returns unique handle for name.

Looks up the string pointer name in the symbol table and returns the index in it to the matching entry. Gives fatal error if name is not found. name has to be entered first using put_symtab().

Parameters
[in]symtabSymbol table to search.
[in]nameString pointer into symtab.
Returns
Unique index to position in symbol table.
void pr_symtab ( FILE *  fp,
int  indent,
const char *  title,
t_symtab *  symtab 
)

Prints human readable form of symtab.

Parameters
[in]fpFile to print to.
[in]indentNumber of spaces to use for indentation.
[in]titleName for header text.
[in]symtabSymbol table to print out.
char** put_symtab ( t_symtab *  symtab,
const char *  name 
)

Enters a string into the symbol table.

If the string name was not present before, a reference to a copy is returned, else a reference to the earlier entered value is returned. Strings are trimmed of spaces.

Parameters
[in,out]symtabSymbol table to add string to.
[in]nameString to add.
Returns
Pointer to entry of string in symtab.
StringTableEntry readStringTableEntry ( gmx::ISerializer serializer,
const StringTable table 
)

De-serialize StringTableEntry using the index into the table.

Parameters
[in]serializerThe object containing the serialized index.
[in]tableThe storage object holding all strings.
Returns
The entry into the Table as StringTableEntry.
static char* trim_string ( const char *  s,
char *  out,
int  maxlen 
)
static

Remove leading and trailing whitespace from string and enforce maximum length.

Parameters
[in]sString to trim.
[in,out]outString to return.
[in]maxlenMaximum string length to use.
Returns
New pruned string.