ds: dict: convert to new object system
This commit is contained in:
@@ -1,16 +1,23 @@
|
||||
#ifndef BLUELIB_DICT_H_
|
||||
#define BLUELIB_DICT_H_
|
||||
#ifndef BLUE_DS_DICT_H_
|
||||
#define BLUE_DS_DICT_H_
|
||||
|
||||
#include <blue/core/btree.h>
|
||||
#include <blue/core/macros.h>
|
||||
#include <blue/core/misc.h>
|
||||
#include <blue/core/queue.h>
|
||||
#include <blue/core/status.h>
|
||||
#include <blue/ds/object.h>
|
||||
#include <blue/ds/type.h>
|
||||
#include <blue/ds/string.h>
|
||||
|
||||
struct b_string;
|
||||
B_DECLS_BEGIN;
|
||||
|
||||
#define B_DICT(p) ((b_dict *)(p))
|
||||
#define B_TYPE_DICT (b_dict_get_type())
|
||||
|
||||
struct b_dict_p;
|
||||
|
||||
B_DECLARE_TYPE(b_dict);
|
||||
|
||||
B_TYPE_CLASS_DECLARATION_BEGIN(b_dict)
|
||||
B_TYPE_CLASS_DECLARATION_END(b_dict)
|
||||
|
||||
#define B_DICT_ITEM(k, v) {.key = (k), .value = (v)}
|
||||
#define B_DICT_ITEM_END {.key = NULL, .value = NULL}
|
||||
@@ -19,46 +26,38 @@ struct b_string;
|
||||
for (int z__b_unique_name() = b_dict_iterator_begin(dict, it); \
|
||||
(it)->key != NULL; b_dict_iterator_next(it))
|
||||
|
||||
typedef struct b_dict b_dict;
|
||||
|
||||
typedef struct b_dict_iterator {
|
||||
b_iterator _base;
|
||||
size_t i;
|
||||
const struct b_string *key;
|
||||
b_dsref *value;
|
||||
const b_string *key;
|
||||
b_object *value;
|
||||
|
||||
b_dict *_d;
|
||||
struct b_dict_p *_d_p;
|
||||
b_btree_node *_cbn;
|
||||
b_queue_entry *_cqe;
|
||||
} b_dict_iterator;
|
||||
|
||||
typedef struct b_dict_item {
|
||||
const char *key;
|
||||
b_dsref *value;
|
||||
b_object *value;
|
||||
} b_dict_item;
|
||||
|
||||
BLUE_API b_dict *b_dict_create(void);
|
||||
BLUE_API b_type b_dict_get_type(void);
|
||||
|
||||
B_TYPE_DEFAULT_CONSTRUCTOR(b_dict, B_TYPE_DICT);
|
||||
|
||||
BLUE_API b_dict *b_dict_create_with_items(const b_dict_item *items);
|
||||
|
||||
static inline b_dict *b_dict_retain(b_dict *dict)
|
||||
{
|
||||
return B_DICT(b_retain(B_DSREF(dict)));
|
||||
}
|
||||
static inline void b_dict_release(b_dict *dict)
|
||||
{
|
||||
b_release(B_DSREF(dict));
|
||||
}
|
||||
|
||||
BLUE_API b_status b_dict_put(b_dict *dict, const char *key, b_dsref *value);
|
||||
BLUE_API b_status b_dict_put_sk(
|
||||
b_dict *dict, const struct b_string *key, b_dsref *value);
|
||||
BLUE_API b_dsref *b_dict_at(const b_dict *dict, const char *key);
|
||||
BLUE_API b_dsref *b_dict_at_sk(const b_dict *dict, const struct b_string *key);
|
||||
BLUE_API b_dsref *b_dict_get(b_dict *dict, const char *key);
|
||||
BLUE_API b_dsref *b_dict_get_sk(b_dict *dict, const struct b_string *key);
|
||||
BLUE_API b_status b_dict_put(b_dict *dict, const char *key, b_object *value);
|
||||
BLUE_API b_status b_dict_put_sk(b_dict *dict, const b_string *key, b_object *value);
|
||||
BLUE_API b_object *b_dict_at(const b_dict *dict, const char *key);
|
||||
BLUE_API b_object *b_dict_at_sk(const b_dict *dict, const b_string *key);
|
||||
BLUE_API b_object *b_dict_get(b_dict *dict, const char *key);
|
||||
BLUE_API b_object *b_dict_get_sk(b_dict *dict, const b_string *key);
|
||||
|
||||
BLUE_API bool b_dict_has_key(const b_dict *dict, const char *key);
|
||||
BLUE_API bool b_dict_has_skey(const b_dict *dict, const struct b_string *key);
|
||||
BLUE_API bool b_dict_has_skey(const b_dict *dict, const b_string *key);
|
||||
BLUE_API size_t b_dict_get_size(const b_dict *dict);
|
||||
BLUE_API bool b_dict_is_empty(const b_dict *dict);
|
||||
|
||||
@@ -67,4 +66,6 @@ BLUE_API bool b_dict_iterator_next(b_dict_iterator *it);
|
||||
BLUE_API b_status b_dict_iterator_erase(b_dict_iterator *it);
|
||||
BLUE_API bool b_dict_iterator_is_valid(const b_dict_iterator *it);
|
||||
|
||||
B_DECLS_END;
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user