Cleanup Tuple to allow self-typing.
[rrq/rrqmisc.git] / vector / BindingTable.h
1 #ifndef BindingTable_H
2 #define BindingTable_H
3
4 #include <HashVector.h>
5 #include <TupleSchema.h>
6
7 /**
8  * A BindingTable is a chain of \ref HashVector "HashVectors" of
9  * Binding items that associate a (char*) name with a (void*) value.
10  */
11 typedef struct _BindingTable {
12     HashVector table;
13     struct _BindingTable *next;
14 } BindingTable;
15
16 /**
17  * \brief Allocate a new \ref BindingTable and chain it to the one given.
18  *
19  * \returns the allocated \ref bandingtable.
20  *
21  * \related BindingTable
22  */
23 extern BindingTable *BindingTable_create(BindingTable *next);
24
25 /**
26  * \brief Reclaim a \ref BindingTable with all its bindings and return
27  * its chained.
28  *
29  * \param bt is the \ref BindingTable to reclaim.
30  *
31  * \returns the chained \ref BindingTable.
32  *
33  * \related BindingTable
34  */
35 extern BindingTable *BindingTable_release(BindingTable *bt);
36
37 /**
38  * \brief Set a Binding in a \ref BindingTable.
39  *
40  * \param bt is the \ref BindingTable concerned.
41  *
42  * \param name is the Binding name.
43  *
44  * \param value is the Binding value.
45  *
46  * \note Binding names are equal or not by means of strcmp, and each
47  * name has a at most single Binding.
48  *
49  * A value of \b 0 indicates "unbound".
50  *
51  * \related BindingTable
52  */
53 extern void BindingTable_set(BindingTable *bt,char *name,void *value);
54
55 /**
56  * \brief Get a Binding from a BindingTable chain.
57  *
58  * \param bt is the first BindingTable concerned.
59  *
60  * \param name is the Binding variable name.
61  *
62  * \param value is the Binding value.
63  *
64  * \note Binding names are equal or not by means of strcmp, and each
65  * name has a at most single Binding.
66  *
67  * This function scan's the \ref BindingTable chain for the first
68  * assignment, if any, of the name. Note that a name can be made
69  * unbound on top of being bound by setting it to \b 0.
70  *
71  * \related BindingTable
72  */
73 extern void *BindingTable_get(BindingTable *bt,char *name);
74
75 /**
76  * \brief Replace all names with their values.
77  *
78  * \param bt is the BindingTable concerned.
79  *
80  * \param arity is the tuple arity.
81  *
82  * \param t is the tuple of (char*) names to dereference.
83  */
84 void BindingTable_deref(BindingTable *bt,int arity,Tuple *t);
85
86 /**
87  * \brief Unify two named bindings with option equal-value callback.
88  *
89  * \param bt is the first BindingTable concerned.
90  *
91  * \param n1 is the first Binding name.
92  *
93  * \param n2 is the second Binding name.
94  *
95  * \param eq is the optional equal-value callback that returns 0 if
96  * the given values are equal.
97  *
98  * This function updates the top \ref BindingTable by assigning n1 or
99  * n2 to any value the other has (in the chain) unless they have
100  * different values (in the chain). If both are unassigned, then
101  * neither get reassigned in the to both BindingTable/
102  *
103  * \related BindingTable
104  */
105 extern int BindingTable_unify(
106     BindingTable *bt,char *n1,char *n2,int (*eq)(void*,void*));
107
108 #endif