ZE-Standard-Libraries/src/list/list_expand_get.c

93 lines
2.4 KiB
C
Raw Normal View History

2018-08-24 00:57:38 +08:00
#include <type.h>
#include <list/list.h>
#include <list/list_expand.h>
2019-01-04 18:16:16 +08:00
//长链表模式可能启用则包含以下头文件
2018-08-24 00:57:38 +08:00
#ifdef list_quick_enable
#include <list/list_quick.h>
2018-12-21 17:36:57 +08:00
#endif
2019-01-06 22:50:06 +08:00
/**
@param p_node
@return 0
*/
int getByIntForNode(Node *p_node) {
if (p_node->type == INT) return *(int *)(p_node->value);
else return 0;
}
/**
@param p_node
@return 0
*/
unsigned int getByUIntForNode(Node *p_node){
if (p_node->type == UINT) return *(unsigned int *)(p_node->value);
else return 0;
}
2019-01-04 18:16:16 +08:00
/**
@param p_node
@return
*/
2018-12-21 17:36:57 +08:00
char *getByStringForNode(Node *p_node) {
if (p_node->type == STRING) return (char *)(p_node->value);
else return NULL;
}
2019-01-04 18:16:16 +08:00
/**
@param p_node
@return
*/
2018-12-21 17:36:57 +08:00
double getByDoubleForNode(Node *p_node) {
if (p_node->type == DOUBLE) return *(double *)(p_node->value);
2019-01-04 18:16:16 +08:00
else return -1.0;
2018-12-21 17:36:57 +08:00
}
2019-01-04 18:16:16 +08:00
/**
@param p_node
@return
*/
2018-12-21 17:36:57 +08:00
void *getByPointerForNode(Node *p_node) {
return (void *)(p_node->value);
}
2019-01-04 18:16:16 +08:00
/**
@param p_list
@param p_node
@return 0
*/
2018-08-24 00:57:38 +08:00
unsigned long long getIndexByNode(List *p_list, Node *p_node) {
2019-01-04 18:16:16 +08:00
// 长链表模式可能启用则编译以下代码
2018-08-24 00:57:38 +08:00
#ifdef list_quick_enable
if (p_list->p_lq != NULL){
register Node **p_fn_node = p_list->p_lq->fn_node;
register Node *rp_node = p_node;
for (register int i = 0; i < p_list->length; i++) if (p_fn_node[i] == rp_node) return i;
}
2018-12-21 17:36:57 +08:00
#endif
register Node *t_node = p_list->head;
register unsigned long long index = 0;
2018-08-24 00:57:38 +08:00
while (t_node != NULL) {
2019-01-04 18:16:16 +08:00
// id模块可能启用的时候则编译以下代码
2018-12-21 17:36:57 +08:00
#ifdef id_enable
2018-08-24 00:57:38 +08:00
if (p_node->s_id == t_node->s_id) return index;
2018-12-21 17:36:57 +08:00
#endif
index++;
t_node = t_node->next;
}
return 0;
2018-08-24 00:57:38 +08:00
}