mirror of
git://git.psyc.eu/libpsyc
synced 2024-08-15 03:19:02 +00:00
better psyc_dict_lookup
This commit is contained in:
parent
dbcd35102b
commit
382fd3c779
9 changed files with 156 additions and 174 deletions
|
@ -4,7 +4,7 @@ prefix = /usr
|
|||
includedir = ${prefix}/include
|
||||
|
||||
INSTALL = install
|
||||
HEADERS = method.h packet.h parse.h render.h syntax.h text.h uniform.h variable.h
|
||||
HEADERS = match.h method.h packet.h parse.h render.h syntax.h text.h uniform.h variable.h
|
||||
|
||||
install: ${HEADERS}
|
||||
|
||||
|
|
49
include/psyc/match.h
Normal file
49
include/psyc/match.h
Normal file
|
@ -0,0 +1,49 @@
|
|||
typedef struct {
|
||||
PsycString key;
|
||||
void *value;
|
||||
} PsycDict;
|
||||
|
||||
typedef struct {
|
||||
PsycString key;
|
||||
intptr_t value;
|
||||
} PsycDictInt;
|
||||
|
||||
/**
|
||||
* Checks if long keyword string inherits from short keyword string.
|
||||
*/
|
||||
int
|
||||
psyc_inherits (char *sho, size_t slen, char *lon, size_t llen);
|
||||
|
||||
/**
|
||||
* Checks if short keyword string matches long keyword string.
|
||||
*/
|
||||
int
|
||||
psyc_matches (char *sho, size_t slen, char *lon, size_t llen);
|
||||
|
||||
/**
|
||||
* Look up value associated with a key in a dictionary.
|
||||
*
|
||||
* @param dict The dictionary to search, should be ordered alphabetically.
|
||||
* @param size Size of dict.
|
||||
* @param key Key to look for.
|
||||
* @param keylen Length of key.
|
||||
* @param inherit If true, also look for anything inheriting from key,
|
||||
* otherwise only exact matches are returned.
|
||||
*
|
||||
* @return The value of the entry if found, or NULL if not found.
|
||||
*/
|
||||
|
||||
void *
|
||||
psyc_dict_lookup (const PsycDict *dict, size_t size,
|
||||
const char *key, size_t keylen, PsycBool inherit);
|
||||
|
||||
/**
|
||||
* Look up value associated with a key in a dictionary of integers.
|
||||
* @see psyc_dict_lookup
|
||||
*/
|
||||
static inline intptr_t
|
||||
psyc_dict_lookup_int (const PsycDictInt * dict, size_t size,
|
||||
const char *key, size_t keylen, PsycBool inherit)
|
||||
{
|
||||
return (intptr_t) psyc_dict_lookup((PsycDict *) dict, size, key, keylen, inherit);
|
||||
}
|
|
@ -8,7 +8,8 @@
|
|||
#include "packet.h"
|
||||
|
||||
/// Routing variables in alphabetical order.
|
||||
extern const PsycString psyc_routing_vars[];
|
||||
//extern const PsycString psyc_routing_vars[];
|
||||
extern const PsycDictInt psyc_routing_vars[];
|
||||
|
||||
// Variable types in alphabetical order.
|
||||
extern const PsycDictInt psyc_var_types[];
|
||||
|
@ -23,14 +24,22 @@ extern const size_t psyc_methods_num;
|
|||
/**
|
||||
* Is this a routing variable name?
|
||||
*/
|
||||
PsycBool
|
||||
psyc_var_is_routing (const char *name, size_t len);
|
||||
static inline PsycBool
|
||||
psyc_var_is_routing (const char *name, size_t len)
|
||||
{
|
||||
return (PsycBool) psyc_dict_lookup((PsycDict *)psyc_routing_vars,
|
||||
psyc_routing_vars_num, name, len, PSYC_NO);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the type of variable name.
|
||||
*/
|
||||
PsycType
|
||||
psyc_var_type (const char *name, size_t len);
|
||||
static inline PsycType
|
||||
psyc_var_type (const char *name, size_t len)
|
||||
{
|
||||
return (PsycType) psyc_dict_lookup((PsycDict *)psyc_var_types,
|
||||
psyc_var_types_num, name, len, PSYC_YES);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this a list variable name?
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue