1、common头文件
#ifndef TYPEDEF_H
#define TYPEDEF_H
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
typedef enum
{
RET_OK,
RET_FAILED,
RET_OOM, //out of memory
RET_INVALIDPARM,
}Ret;
#define return_if_fail(p) if(!(p))\
{printf("%d, %s,Warning: "#p" failed.\n",\
__LINE__, __FUNCTION__); return;}
#define return_val_if_fail(p, ret) if(!(p))\
{printf("%d, %s, Warning: "#p" failed.\n",\
__LINE__, __FUNCTION__); return (ret);}
#endif
2、slist头文件
#ifndef SList_H
#define SList_H
#include "typedef.h"
struct _SList;//隐藏数据结构,实现在内部,是封装的常用做法
typedef struct _SList SList;
#ifdef __cplusplus
extern "C" {
#endif
typedef void (*SlistDataDestroyFunc) (void *ctx, void* data);
typedef int (*SlistDataCmpFunc) (void* ctx, void* data);
typedef void (*SlistDataVisitFunc)(void* ctx, void* data);
SList* slist_create(SlistDataDestroyFunc data_destroy, void* data_destroy_ctx);
Ret slist_prepend(SList* this, void* data);
Ret slist_append(SList* this, void *data);
Ret slist_insert(SList* this, size_t index, void* data);
Ret slist_delete(SList* this, size_t index);
Ret slist_get_by_index(SList* this, size_t index, void** data);
Ret slist_set_by_index(SList* this, size_t index, void* data);
size_t slist_find(SList* this, SlistDataCmpFunc cmp, void* data);
size_t slist_length(SList* this);
void slist_destroy(SList* this);
Ret slist_foreach(SList* this, SlistDataVisitFunc visit, void* data);
SList* slist_reverse(SList* this);
#ifdef __cplusplus
}
#endif
#endif