3 * $Id: atom.h,v 1.1 2001/01/20 11:50:16 mdw Exp $
7 * (c) 2000 Straylight/Edgeware
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of the mLib utilities library.
14 * mLib is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU Library General Public License as
16 * published by the Free Software Foundation; either version 2 of the
17 * License, or (at your option) any later version.
19 * mLib is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Library General Public License for more details.
24 * You should have received a copy of the GNU Library General Public
25 * License along with mLib; if not, write to the Free
26 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
30 /*----- Revision history --------------------------------------------------*
33 * Revision 1.1 2001/01/20 11:50:16 mdw
34 * Implementation of atom tables (for example, as found in X11).
45 /*----- Header files ------------------------------------------------------*/
51 /*----- Data structures ---------------------------------------------------*/
53 typedef struct atom_table {
54 sym_table t; /* Symbol table of interned atoms */
55 hash_base *g; /* List of uninterned atoms */
56 unsigned long gseq; /* Sequence number for @gensym@ */
60 sym_base b; /* Base structure for symbol table */
61 unsigned f; /* Various useful flags */
64 #define ATOMF_GENSYM 1u /* Atom is uninterned */
66 typedef struct { sym_iter i; } atom_iter;
68 /*----- Global magic ------------------------------------------------------*/
72 /*----- Functions provided ------------------------------------------------*/
74 /* --- @atom_createtable@ --- *
76 * Arguments: @atom_table *t@ = pointer to an atom table
80 * Use: Initializes an atom table.
83 extern void atom_createtable(atom_table */*t*/);
85 /* --- @atom_destroytable@ --- *
87 * Arguments: @atom_table *t@ = pointer to an atom table
91 * Use: Destroys all of the atoms in an atom table. All of the atoms
92 * (including uninterned atoms) are freed. Any references to
93 * atoms from the table become invalid, and any association
94 * tables dependent on the atom table are unusable, except that
95 * they may be destroyed safely.
98 extern void atom_destroytable(atom_table */*t*/);
100 /* --- @atom_intern@ --- *
102 * Arguments: @atom_table *t@ = pointer to an atom table
103 * @const char *p@ = pointer to the string to intern
105 * Returns: A pointer to the atom block for the given symbol string.
107 * Use: Interns an atom, returning the atom block. The string can be
108 * extracted from the atom by means of the @ATOM_NAME@ macro.
111 #define INTERN(p) atom_intern(ATOM_GLOBAL, (p))
113 extern atom *atom_intern(atom_table */*t*/, const char */*p*/);
115 /* --- @atom_gensym@ --- *
117 * Arguments: @atom_table *t@ = pointer to a symbol table
119 * Returns: A pointer to a new atom block, not previously interned.
121 * Use: Creates a new, uninterned atom. This atom will never be
122 * returned by either @atom_intern@ or any other call to
123 * @atom_gensym@, while the symbol table exists.
126 #define GENSYM atom_gensym(ATOM_GLOBAL)
128 extern atom *atom_gensym(atom_table */*t*/);
130 /* --- @atom_name@ --- *
132 * Arguments: @atom *a@ = pointer to an atom
134 * Returns: The atom's textual name.
136 * Use: Given an atom, returns the name with which it was interned
137 * (or a made-up name if it was created using @gensym@.
140 #define ATOM_NAME(a) SYM_NAME(a)
142 extern const char *atom_name(const atom */*a*/);
144 /* --- @atom_len@ --- *
146 * Arguments: @atom *a@ = pointer to an atom
148 * Returns: The atom string's length.
150 * Use: Given an atom, return the length of its textual
154 #define ATOM_LEN(a) (SYM_LEN(a) - 1)
156 extern size_t atom_len(const atom */*a*/);
158 /* --- @atom_hash@ --- *
160 * Arguments: @atom *a@ = pointer to an atom
162 * Returns: The atom's hash.
164 * Use: Given an atom, returns its hash.
167 #define ATOM_HASH(a) SYM_HASH(a)
169 extern uint32 atom_hash(const atom */*a*/);
171 /* --- @atom_mkiter@ , @atom_next@ --- *
173 * Arguments: @atom_table *t@ = pointer to an atom table
174 * @atom_iter *i@ = pointer to an iterator structure
176 * Returns: Next atom, for @atom_next@; nothing for @atom_mkiter@.
178 * Use: Iterates over atoms (both interned and uninterned).
181 extern void atom_mkiter(atom_iter */*i*/, atom_table */*t*/);
182 extern atom *atom_next(atom_iter */*i*/);
184 /*----- That's all, folks -------------------------------------------------*/