Implement two entry types and a function to store entries in table.
This commit is contained in:
parent
3de3f1ec00
commit
72be209f0f
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include "ht.h"
|
#include "ht.h"
|
||||||
#include "result.h"
|
#include "result.h"
|
||||||
|
#include "custom.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A struct that represents a structure
|
* A struct that represents a structure
|
||||||
|
@ -29,6 +30,7 @@ struct libab_table_s {
|
||||||
enum libab_table_entry_variant_e {
|
enum libab_table_entry_variant_e {
|
||||||
ENTRY_VALUE,
|
ENTRY_VALUE,
|
||||||
ENTRY_TYPE,
|
ENTRY_TYPE,
|
||||||
|
ENTRY_OPERATOR,
|
||||||
ENTRY_FUNCTION
|
ENTRY_FUNCTION
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -40,6 +42,14 @@ struct libab_table_entry_s {
|
||||||
* The type of this entry.
|
* The type of this entry.
|
||||||
*/
|
*/
|
||||||
enum libab_table_entry_variant_e variant;
|
enum libab_table_entry_variant_e variant;
|
||||||
|
/**
|
||||||
|
* Union that holds the various types of
|
||||||
|
* data that this entry could hold.
|
||||||
|
*/
|
||||||
|
union {
|
||||||
|
libab_operator op;
|
||||||
|
libab_function function;
|
||||||
|
} data_u;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct libab_table_s libab_table;
|
typedef struct libab_table_s libab_table;
|
||||||
|
@ -58,6 +68,14 @@ void libab_table_init(libab_table* table);
|
||||||
* @return the table entry, or NULL if an entry was not found.
|
* @return the table entry, or NULL if an entry was not found.
|
||||||
*/
|
*/
|
||||||
libab_table_entry* libab_table_search(libab_table* table, const char* string);
|
libab_table_entry* libab_table_search(libab_table* table, const char* string);
|
||||||
|
/**
|
||||||
|
* Stores the given entry in the table under the given key.
|
||||||
|
* @param table the table to store the entry into.
|
||||||
|
* @param string the string to use as the key.
|
||||||
|
* @param entry the new entry to put into the table.
|
||||||
|
* @return the result of the insertion, which could be LIBAB_MALLOC.
|
||||||
|
*/
|
||||||
|
libab_result libab_table_put(libab_table* table, const char* string, libab_table_entry* entry);
|
||||||
/**
|
/**
|
||||||
* Frees the resources allocated by the
|
* Frees the resources allocated by the
|
||||||
* given table.
|
* given table.
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "table.h"
|
#include "table.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
void table_init(libab_table* table) {
|
void table_init(libab_table* table) {
|
||||||
ht_init(&table->table);
|
ht_init(&table->table);
|
||||||
|
@ -13,6 +14,9 @@ libab_table_entry* table_search(libab_table* table, const char* string) {
|
||||||
} while(table && to_return == NULL);
|
} while(table && to_return == NULL);
|
||||||
return to_return;
|
return to_return;
|
||||||
}
|
}
|
||||||
|
libab_result libab_table_put(libab_table* table, const char* string, libab_table_entry* entry) {
|
||||||
|
return libab_convert_ds_result(ht_put(&table->table, string, entry));
|
||||||
|
}
|
||||||
void table_free(libab_table* table) {
|
void table_free(libab_table* table) {
|
||||||
ht_free(&table->table);
|
ht_free(&table->table);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user