Add more specific lookup functions.
This commit is contained in:
parent
450d12dc43
commit
d7ef8e236d
|
@ -94,6 +94,17 @@ libab_table_entry* libab_table_search(libab_table* table, const char* string);
|
||||||
*/
|
*/
|
||||||
libab_operator* libab_table_search_operator(libab_table* table,
|
libab_operator* libab_table_search_operator(libab_table* table,
|
||||||
const char* string, int type);
|
const char* string, int type);
|
||||||
|
/**
|
||||||
|
* Searches for a given string in the table,
|
||||||
|
* returning the entry that holds it only if it is an operator.
|
||||||
|
* @param table the table to search.
|
||||||
|
* @param string the string to search for.
|
||||||
|
* @param type the type of operator to search for (infix, prefix, postfix)
|
||||||
|
* @return the entry, or NULL if it was not found.
|
||||||
|
*/
|
||||||
|
libab_table_entry* libab_table_search_entry_operator(libab_table* table,
|
||||||
|
const char* string,
|
||||||
|
int type);
|
||||||
/**
|
/**
|
||||||
* Searches for the given basetype in the table, returning a value
|
* Searches for the given basetype in the table, returning a value
|
||||||
* only if it's a basetype.
|
* only if it's a basetype.
|
||||||
|
@ -103,6 +114,15 @@ libab_operator* libab_table_search_operator(libab_table* table,
|
||||||
*/
|
*/
|
||||||
libab_basetype* libab_table_search_basetype(libab_table* table,
|
libab_basetype* libab_table_search_basetype(libab_table* table,
|
||||||
const char* string);
|
const char* string);
|
||||||
|
/**
|
||||||
|
* Searches for the given basetype in the table, returning a table
|
||||||
|
* entry only if it holds a basetype.
|
||||||
|
* @param table to table to search.
|
||||||
|
* @param string the string to search for.
|
||||||
|
* @return the entry holding the basetype, or NULL if it was not found.
|
||||||
|
*/
|
||||||
|
libab_table_entry* libab_table_search_entry_basetype(libab_table* table,
|
||||||
|
const char* string);
|
||||||
/**
|
/**
|
||||||
* Searches for the given value in the table.
|
* Searches for the given value in the table.
|
||||||
* @param table the table to search.
|
* @param table the table to search.
|
||||||
|
@ -112,13 +132,30 @@ libab_basetype* libab_table_search_basetype(libab_table* table,
|
||||||
void libab_table_search_value(libab_table* table, const char* string,
|
void libab_table_search_value(libab_table* table, const char* string,
|
||||||
libab_ref* ref);
|
libab_ref* ref);
|
||||||
/**
|
/**
|
||||||
* Searches for the given type parameter in the talb.e
|
* Searches for a value with the given name in the table,
|
||||||
|
* and returns an entry that holds it.
|
||||||
|
* @param table the table to search.
|
||||||
|
* @param string the tabe entry key.
|
||||||
|
* @return the table entry holding the value, or NULL if it was not found.
|
||||||
|
*/
|
||||||
|
libab_table_entry* libab_table_search_entry_value(libab_table* table,
|
||||||
|
const char* string);
|
||||||
|
/**
|
||||||
|
* Searches for the given type parameter in the table.
|
||||||
* @param table the table to search in.
|
* @param table the table to search in.
|
||||||
* @param string the key ot search for.
|
* @param string the key to search for.
|
||||||
* @param ref the reference to store the type into.
|
* @param ref the reference to store the type into.
|
||||||
*/
|
*/
|
||||||
void libab_table_search_type_param(libab_table* table, const char* string,
|
void libab_table_search_type_param(libab_table* table, const char* string,
|
||||||
libab_ref* ref);
|
libab_ref* ref);
|
||||||
|
/**
|
||||||
|
* Searches for the given type parameter in the table.
|
||||||
|
* @param table the table to search in.
|
||||||
|
* @param string the key to search for.
|
||||||
|
* @return the table entry holding the type parameter, or NULL.
|
||||||
|
*/
|
||||||
|
libab_table_entry* libab_table_search_entry_type_param(libab_table* table,
|
||||||
|
const char* string);
|
||||||
/**
|
/**
|
||||||
* Stores the given entry in the table under the given key.
|
* Stores the given entry in the table under the given key.
|
||||||
* @param table the table to store the entry into.
|
* @param table the table to store the entry into.
|
||||||
|
|
35
src/table.c
35
src/table.c
|
@ -54,6 +54,12 @@ int libab_table_compare_type_param(const void* left, const void* right) {
|
||||||
|
|
||||||
libab_operator* libab_table_search_operator(libab_table* table,
|
libab_operator* libab_table_search_operator(libab_table* table,
|
||||||
const char* string, int type) {
|
const char* string, int type) {
|
||||||
|
libab_table_entry* entry =
|
||||||
|
libab_table_search_entry_operator(table, string, type);
|
||||||
|
return entry ? &entry->data_u.op : NULL;
|
||||||
|
}
|
||||||
|
libab_table_entry* libab_table_search_entry_operator(libab_table* table,
|
||||||
|
const char* string, int type) {
|
||||||
libab_table_entry* entry = NULL;
|
libab_table_entry* entry = NULL;
|
||||||
if (type == OPERATOR_PREFIX) {
|
if (type == OPERATOR_PREFIX) {
|
||||||
entry = libab_table_search_filter(table, string, NULL,
|
entry = libab_table_search_filter(table, string, NULL,
|
||||||
|
@ -65,37 +71,52 @@ libab_operator* libab_table_search_operator(libab_table* table,
|
||||||
entry = libab_table_search_filter(table, string, NULL,
|
entry = libab_table_search_filter(table, string, NULL,
|
||||||
libab_table_compare_op_postfix);
|
libab_table_compare_op_postfix);
|
||||||
}
|
}
|
||||||
return entry ? &entry->data_u.op : NULL;
|
return entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
libab_basetype* libab_table_search_basetype(libab_table* table,
|
libab_basetype* libab_table_search_basetype(libab_table* table,
|
||||||
const char* string) {
|
const char* string) {
|
||||||
libab_table_entry* entry = libab_table_search_filter(
|
libab_table_entry* entry =
|
||||||
table, string, NULL, libab_table_compare_basetype);
|
libab_table_search_entry_basetype(table, string);
|
||||||
return entry ? entry->data_u.basetype : NULL;
|
return entry ? entry->data_u.basetype : NULL;
|
||||||
}
|
}
|
||||||
|
libab_table_entry* libab_table_search_entry_basetype(libab_table* table,
|
||||||
|
const char* string) {
|
||||||
|
return libab_table_search_filter(table, string, NULL,
|
||||||
|
libab_table_compare_basetype);
|
||||||
|
}
|
||||||
|
|
||||||
void libab_table_search_value(libab_table* table, const char* string,
|
void libab_table_search_value(libab_table* table, const char* string,
|
||||||
libab_ref* ref) {
|
libab_ref* ref) {
|
||||||
libab_table_entry* entry = libab_table_search_filter(
|
libab_table_entry* entry =
|
||||||
table, string, NULL, libab_table_compare_value);
|
libab_table_search_entry_value(table, string);
|
||||||
if (entry) {
|
if (entry) {
|
||||||
libab_ref_copy(&entry->data_u.value, ref);
|
libab_ref_copy(&entry->data_u.value, ref);
|
||||||
} else {
|
} else {
|
||||||
libab_ref_null(ref);
|
libab_ref_null(ref);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
libab_table_entry* libab_table_search_entry_value(libab_table* table,
|
||||||
|
const char* string) {
|
||||||
|
return libab_table_search_filter(table, string, NULL,
|
||||||
|
libab_table_compare_value);
|
||||||
|
}
|
||||||
|
|
||||||
void libab_table_search_type_param(libab_table* table, const char* string,
|
void libab_table_search_type_param(libab_table* table, const char* string,
|
||||||
libab_ref* ref) {
|
libab_ref* ref) {
|
||||||
libab_table_entry* entry = libab_table_search_filter(
|
libab_table_entry* entry =
|
||||||
table, string, NULL, libab_table_compare_type_param);
|
libab_table_search_entry_type_param(table, string);
|
||||||
if (entry) {
|
if (entry) {
|
||||||
libab_ref_copy(&entry->data_u.type_param, ref);
|
libab_ref_copy(&entry->data_u.type_param, ref);
|
||||||
} else {
|
} else {
|
||||||
libab_ref_null(ref);
|
libab_ref_null(ref);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
libab_table_entry* libab_table_search_entry_type_param(libab_table* table,
|
||||||
|
const char* string) {
|
||||||
|
return libab_table_search_filter(
|
||||||
|
table, string, NULL, libab_table_compare_type_param);
|
||||||
|
}
|
||||||
|
|
||||||
libab_result libab_table_put(libab_table* table, const char* string,
|
libab_result libab_table_put(libab_table* table, const char* string,
|
||||||
libab_table_entry* entry) {
|
libab_table_entry* entry) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user