Implement convenience functions for looking up the implemented entries.

Este commit está contenido en:
Danila Fedorin 2018-02-11 23:00:07 -08:00
padre 8b13b9a735
commit ee19f55058
Se han modificado 2 ficheros con 32 adiciones y 0 borrados

Ver fichero

@ -68,6 +68,22 @@ void libab_table_init(libab_table* table);
* @return the table entry, or NULL if an entry was not found.
*/
libab_table_entry* libab_table_search(libab_table* table, const char* string);
/**
* Searches for the given string in the table, returning a value only
* if it is an operator.
* @param table the table to search.
* @param string the string to search for.
* @return the found operator, or NULL if it was not found.
*/
libab_operator* libab_table_search_operator(libab_table* table, const char* string);
/**
* Searches for the given string in the table, returning a value only
* if it is a function.
* @param table the table to search.
* @param string the string to search for.
* @return the found function, or NULL if it was not found.
*/
libab_function* libab_table_search_function(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.

Ver fichero

@ -14,6 +14,22 @@ libab_table_entry* table_search(libab_table* table, const char* string) {
} while(table && to_return == NULL);
return to_return;
}
libab_operator* libab_table_search_operator(libab_table* table, const char* string) {
libab_table_entry* entry = table_search(table, string);
libab_operator* to_return = NULL;
if(entry && entry->variant == ENTRY_OPERATOR) {
to_return = &entry->data_u.op;
}
return to_return;
}
libab_function* libab_table_search_function(libab_table* table, const char* string) {
libab_table_entry* entry = table_search(table, string);
libab_function* to_return = NULL;
if(entry && entry->variant == ENTRY_FUNCTION) {
to_return = &entry->data_u.function;
}
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));
}