portability fixes
[rrq/rrqmisc.git] / logic / BindingTable.h
1 #ifndef BindingTable_H
2 #define BindingTable_H
3
4 #include <HashVector.h>
5 #include <TupleSchema.h>
6 #include <Binding.h>
7
8 /**
9  * A BindingTable is a chain of \ref HashVector "HashVectors" of
10  * Binding items that associate a (char*) name with a (void*) value.
11  */
12 typedef HashVector/*<Binding>*/ BindingTable;
13
14 /**
15  * \brief Allocate a new \ref BindingTable.
16  *
17  * \returns the allocated \ref bandingtable.
18  *
19  * \related BindingTable
20  */
21 extern BindingTable *BindingTable_create();
22
23 /**
24  * \brief Reclaim a \ref BindingTable with all its bindings.
25  *
26  * \param bt is the \ref BindingTable to reclaim.
27  *
28  * \related BindingTable
29  */
30 extern void BindingTable_release(BindingTable *bt);
31
32 /**
33  * \brief Set a Binding in a \ref BindingTable.
34  *
35  * \param bt is the \ref BindingTable concerned.
36  *
37  * \param name is the Binding name.
38  *
39  * \param value is the Binding value.
40  *
41  * \note Binding names are equal or not by means of strcmp, and each
42  * name has a at most single Binding.
43  *
44  * The name and the value are held as given with all memory management
45  * the callers responsibility. This function will however create new
46  * Binding objects and reclaim the old ones as needed.
47  *
48  * A value of \b 0 indicates "unbound".
49  *
50  * \related BindingTable
51  */
52 extern void BindingTable_set(BindingTable *bt,char *name,void *value);
53
54 /**
55  * \brief Get a Binding from a BindingTable chain.
56  *
57  * \param bt is the first BindingTable concerned.
58  *
59  * \param name is the Binding variable name.
60  *
61  * \returns the value of the found Binding, or \b 0 if none is found.
62  *
63  * \note Binding names are equal or not by means of strcmp, and each
64  * name has a at most single Binding.
65  *
66  * \note Not also that a name can be made unbound on top of being
67  * bound by setting it to \b 0.
68  *
69  * \related BindingTable
70  */
71 extern void *BindingTable_get(BindingTable *bt,char *name);
72
73 /**
74  * \brief Replace all names with their values.
75  *
76  * \param bt is the BindingTable concerned.
77  *
78  * \param t is the tuple of (char*) names to dereference.
79  */
80 extern void BindingTable_deref(BindingTable *bt,Tuple *t);
81
82 /**
83  * \brief Set values for names, optionally unbinding names as well.
84  *
85  * \param bt is the bindingtable concerned.
86  *
87  * \param nm is the Tuple of names to bind.
88  *
89  * \param vs is the Tuple of values.
90  *
91  * \param all is a flag to assign all (1) or only non-zero (0) values.
92  *
93  * \note The values tuple must be as wide as the names tuple.
94  */
95 extern void BindingTable_set_all(BindingTable *bt,Tuple *nm,Tuple *vs,int all);
96
97 #endif