xbot/lib/db.h

53 lines
1.1 KiB
C
Raw Normal View History

2024-03-04 19:37:24 +00:00
#ifndef DB_H
#define DB_H
2024-03-06 09:45:01 +00:00
#include "util.h"
2024-03-06 02:12:10 +00:00
#define DB_MAGIC 0xdeadbeef
#define DB_VER 0x10
2024-03-06 04:53:00 +00:00
enum db_type
{
DB_TYPE_CHAR,
DB_TYPE_INT,
DB_TYPE_FLOAT
2024-03-06 04:53:00 +00:00
};
2024-03-04 19:37:24 +00:00
struct db_hash
{
2024-03-06 02:12:10 +00:00
int key_len;
int value_len;
2024-03-06 04:53:00 +00:00
int type;
2024-03-06 02:12:10 +00:00
char *key;
2024-03-06 04:53:00 +00:00
void *value;
2024-03-04 19:37:24 +00:00
};
struct db_table
{
int db_magic;
int db_ver;
int count;
struct db_hash *hashes;
};
2024-03-06 09:45:01 +00:00
MY_API int db_write(struct db_table *db, char *fname);
MY_API struct db_table *db_read(char *fname);
2024-03-06 04:53:00 +00:00
2024-03-06 09:45:01 +00:00
MY_API int db_set_hash(struct db_table *db, char *key, void *value);
MY_API int db_set_hash_char(struct db_table *db, char *key, char *value);
MY_API int db_set_hash_int(struct db_table *db, char *key, int value);
MY_API int db_set_hash_float(struct db_table *db, char *key, float value);
2024-03-06 04:53:00 +00:00
2024-03-06 09:45:01 +00:00
MY_API int db_del_hash(struct db_table *db, char *key);
2024-03-06 04:53:00 +00:00
2024-03-06 09:45:01 +00:00
MY_API void *db_get_hash(struct db_table *db, char *key);
MY_API int db_get_hash_type(struct db_table *db, char *key);
2024-03-06 09:45:01 +00:00
MY_API char *db_get_hash_char(struct db_table *db, char *key);
MY_API int db_get_hash_int(struct db_table *db, char *key);
MY_API float db_get_hash_float(struct db_table *db, char *key);
2024-03-04 19:37:24 +00:00
#endif