summaryrefslogtreecommitdiff
path: root/hieroglyph/hgdict.h
blob: a0acb28f5474a3543d41c2fbac2466925b07df40 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/* 
 * hgdict.h
 * Copyright (C) 2005-2011 Akira TAGOH
 * 
 * Authors:
 *   Akira TAGOH  <akira@tagoh.org>
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */
#if !defined (__HG_H_INSIDE__) && !defined (HG_COMPILATION)
#error "Only <hieroglyph/hg.h> can be included directly."
#endif

#ifndef __HIEROGLYPH_HGDICT_H__
#define __HIEROGLYPH_HGDICT_H__

#include <hieroglyph/hgobject.h>

HG_BEGIN_DECLS

#define HG_DICT_INIT							\
	HG_STMT_START {							\
		hg_object_register(HG_TYPE_DICT,			\
				   hg_object_dict_get_vtable());	\
		hg_object_register(HG_TYPE_DICT_NODE,			\
				   hg_object_dict_node_get_vtable());	\
	} HG_STMT_END

#define HG_IS_QDICT(_v_)				\
	(hg_quark_get_type(_v_) == HG_TYPE_DICT)
#define HG_IS_QDICT_NODE(_v_)				\
	(hg_quark_get_type(_v_) == HG_TYPE_DICT_NODE)

typedef struct _hg_dict_t		hg_dict_t;
typedef struct _hg_dict_node_t		hg_dict_node_t;
typedef hg_cb_BOOL__QUARK_QUARK_t	hg_dict_traverse_func_t;

struct _hg_dict_t {
	hg_object_t o;
	hg_quark_t  qroot;
	hg_usize_t  length;
	hg_usize_t  allocated_size;
	hg_bool_t   raise_dictfull:1;
};


hg_object_vtable_t *hg_object_dict_get_vtable     (void) HG_GNUC_CONST;
hg_object_vtable_t *hg_object_dict_node_get_vtable(void) HG_GNUC_CONST;
hg_quark_t          hg_dict_new                   (hg_mem_t                *mem,
                                                   hg_usize_t               size,
                                                   hg_bool_t                raise_dictfull,
                                                   hg_pointer_t            *ret);
hg_quark_t          hg_dict_dup                   (hg_dict_t               *dict,
						   hg_pointer_t            *ret);
hg_bool_t           hg_dict_add                   (hg_dict_t               *dict,
                                                   hg_quark_t               qkey,
                                                   hg_quark_t               qval,
                                                   hg_bool_t                force);
hg_bool_t           hg_dict_remove                (hg_dict_t               *dict,
                                                   hg_quark_t               qkey);
hg_bool_t           hg_dict_clear                 (hg_dict_t               *dict);
hg_quark_t          hg_dict_lookup                (hg_dict_t               *dict,
                                                   hg_quark_t               qkey);
hg_usize_t          hg_dict_length                (hg_dict_t               *dict);
hg_usize_t          hg_dict_maxlength             (hg_dict_t               *dict);
void                hg_dict_foreach               (hg_dict_t               *dict,
                                                   hg_dict_traverse_func_t  func,
                                                   hg_pointer_t             data);
hg_bool_t           hg_dict_first_item            (hg_dict_t               *dict,
                                                   hg_quark_t              *qkey,
                                                   hg_quark_t              *qval);


HG_END_DECLS

#endif /* __HIEROGLYPH_HGDICT_H__ */