Gromacs  2025.0-dev-20241009-5c23d5f
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Typedefs | Functions
symtab.h File Reference
#include <cstdio>
#include <functional>
#include <string>
#include <unordered_map>
#include <vector>
#include "gromacs/utility/basedefinitions.h"
#include "gromacs/utility/gmxassert.h"
+ Include dependency graph for symtab.h:
+ This graph shows which files directly or indirectly include this file:

Description

Declares modern and legacy symbol table used to store strings of characters.

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

Classes

class  StringTable
 A class to store strings for lookup. More...
 
class  StringTableEntry
 Helper class to access members in StringTable. More...
 
class  StringTableBuilder
 Builds a memory efficient storage for strings of characters. More...
 
struct  t_symbuf
 Legacy symbol table entry as linked list. More...
 

Typedefs

using StringTablePair = std::pair< std::string, int >
 Convenience typedef for pair stored in map.
 
using StringReference = std::reference_wrapper< const std::string >
 Convenience typedef for string reference wrapper.
 

Functions

StringTableEntry readStringTableEntry (gmx::ISerializer *serializer, const StringTable &table)
 De-serialize StringTableEntry using the index into the 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 free_symtab (t_symtab *symtab)
 Frees the space allocated by the symbol table itself.
 
void done_symtab (t_symtab *symtab)
 Frees the space allocated by the symbol table, including all entries in it.
 
char ** put_symtab (t_symtab *symtab, const char *name)
 Enters a string into the symbol table. More...
 
int lookup_symtab (t_symtab *symtab, char **name)
 Returns unique handle for name. More...
 
char ** get_symtab_handle (t_symtab *symtab, int index)
 Returns text string corresponding to index. More...
 
void pr_symtab (FILE *fp, int indent, const char *title, t_symtab *symtab)
 Prints human readable form of symtab. More...
 

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.
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.