1 | /* gtktreemodelrefcount.h |
2 | * Copyright (C) 2011 Kristian Rietveld <kris@gtk.org> |
3 | * |
4 | * This library is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU Library General Public |
6 | * License as published by the Free Software Foundation; either |
7 | * version 2 of the License, or (at your option) any later version. |
8 | * |
9 | * This library is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | * Library General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU Library General Public |
15 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. |
16 | */ |
17 | |
18 | #ifndef __GTK_TREE_MODEL_REF_COUNT_H__ |
19 | #define __GTK_TREE_MODEL_REF_COUNT_H__ |
20 | |
21 | #include <gtk/gtk.h> |
22 | |
23 | G_BEGIN_DECLS |
24 | |
25 | #define GTK_TYPE_TREE_MODEL_REF_COUNT (gtk_tree_model_ref_count_get_type ()) |
26 | #define GTK_TREE_MODEL_REF_COUNT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_TREE_MODEL_REF_COUNT, GtkTreeModelRefCount)) |
27 | #define GTK_TREE_MODEL_REF_COUNT_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST ((vtable), GTK_TYPE_TREE_MODEL_REF_COUNT, GtkTreeModelRefCountClass)) |
28 | #define GTK_IS_TREE_MODEL_REF_COUNT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_TREE_MODEL_REF_COUNT)) |
29 | #define GTK_IS_TREE_MODEL_REF_COUNT_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), GTK_TYPE_TREE_MODEL_REF_COUNT)) |
30 | #define GTK_TREE_MODEL_REF_COUNT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_TREE_MODEL_REF_COUNT, GtkTreeModelRefCountClass)) |
31 | |
32 | |
33 | typedef struct _GtkTreeModelRefCount GtkTreeModelRefCount; |
34 | typedef struct _GtkTreeModelRefCountClass GtkTreeModelRefCountClass; |
35 | typedef struct _GtkTreeModelRefCountPrivate GtkTreeModelRefCountPrivate; |
36 | |
37 | struct _GtkTreeModelRefCount |
38 | { |
39 | GtkTreeStore parent; |
40 | |
41 | /* < private > */ |
42 | GtkTreeModelRefCountPrivate *priv; |
43 | }; |
44 | |
45 | struct _GtkTreeModelRefCountClass |
46 | { |
47 | GtkTreeStoreClass parent_class; |
48 | }; |
49 | |
50 | |
51 | GType gtk_tree_model_ref_count_get_type (void) G_GNUC_CONST; |
52 | GtkTreeModel *gtk_tree_model_ref_count_new (void); |
53 | |
54 | void gtk_tree_model_ref_count_dump (GtkTreeModelRefCount *ref_model); |
55 | gboolean gtk_tree_model_ref_count_check_level (GtkTreeModelRefCount *ref_model, |
56 | GtkTreeIter *parent, |
57 | int expected_ref_count, |
58 | gboolean recurse, |
59 | gboolean may_assert); |
60 | gboolean gtk_tree_model_ref_count_check_node (GtkTreeModelRefCount *ref_model, |
61 | GtkTreeIter *iter, |
62 | int expected_ref_count, |
63 | gboolean may_assert); |
64 | |
65 | /* A couple of helpers for the tests. Since this model will never be used |
66 | * outside of unit tests anyway, it is probably fine to have these here |
67 | * without namespacing. |
68 | */ |
69 | |
70 | static inline void |
71 | assert_entire_model_unreferenced (GtkTreeModelRefCount *ref_model) |
72 | { |
73 | gtk_tree_model_ref_count_check_level (ref_model, NULL, expected_ref_count: 0, TRUE, TRUE); |
74 | } |
75 | |
76 | static inline void |
77 | assert_root_level_unreferenced (GtkTreeModelRefCount *ref_model) |
78 | { |
79 | gtk_tree_model_ref_count_check_level (ref_model, NULL, expected_ref_count: 0, FALSE, TRUE); |
80 | } |
81 | |
82 | static inline void |
83 | assert_level_unreferenced (GtkTreeModelRefCount *ref_model, |
84 | GtkTreeIter *iter) |
85 | { |
86 | gtk_tree_model_ref_count_check_level (ref_model, parent: iter, expected_ref_count: 0, FALSE, TRUE); |
87 | } |
88 | |
89 | static inline void |
90 | assert_entire_model_referenced (GtkTreeModelRefCount *ref_model, |
91 | int ref_count) |
92 | { |
93 | gtk_tree_model_ref_count_check_level (ref_model, NULL, expected_ref_count: ref_count, TRUE, TRUE); |
94 | } |
95 | |
96 | static inline void |
97 | assert_not_entire_model_referenced (GtkTreeModelRefCount *ref_model, |
98 | int ref_count) |
99 | { |
100 | g_assert_cmpint (gtk_tree_model_ref_count_check_level (ref_model, NULL, |
101 | ref_count, |
102 | TRUE, FALSE), |
103 | ==, FALSE); |
104 | } |
105 | |
106 | static inline void |
107 | assert_root_level_referenced (GtkTreeModelRefCount *ref_model, |
108 | int ref_count) |
109 | { |
110 | gtk_tree_model_ref_count_check_level (ref_model, NULL, expected_ref_count: ref_count, |
111 | FALSE, TRUE); |
112 | } |
113 | |
114 | static inline void |
115 | assert_level_referenced (GtkTreeModelRefCount *ref_model, |
116 | int ref_count, |
117 | GtkTreeIter *iter) |
118 | { |
119 | gtk_tree_model_ref_count_check_level (ref_model, parent: iter, expected_ref_count: ref_count, |
120 | FALSE, TRUE); |
121 | } |
122 | |
123 | static inline void |
124 | assert_node_ref_count (GtkTreeModelRefCount *ref_model, |
125 | GtkTreeIter *iter, |
126 | int ref_count) |
127 | { |
128 | gtk_tree_model_ref_count_check_node (ref_model, iter, expected_ref_count: ref_count, TRUE); |
129 | } |
130 | |
131 | |
132 | #endif /* __GTK_TREE_MODEL_REF_COUNT_H__ */ |
133 | |