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
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/* ctktreemodelrefcount.h
 * Copyright (C) 2011  Kristian Rietveld <kris@gtk.org>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef __CTK_TREE_MODEL_REF_COUNT_H__
#define __CTK_TREE_MODEL_REF_COUNT_H__

#include <ctk/ctk.h>

G_BEGIN_DECLS

#define CTK_TYPE_TREE_MODEL_REF_COUNT              (ctk_tree_model_ref_count_get_type ())
#define CTK_TREE_MODEL_REF_COUNT(obj)              (G_TYPE_CHECK_INSTANCE_CAST ((obj), CTK_TYPE_TREE_MODEL_REF_COUNT, CtkTreeModelRefCount))
#define CTK_TREE_MODEL_REF_COUNT_CLASS(vtable)     (G_TYPE_CHECK_CLASS_CAST ((vtable), CTK_TYPE_TREE_MODEL_REF_COUNT, CtkTreeModelRefCountClass))
#define CTK_IS_TREE_MODEL_REF_COUNT(obj)           (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CTK_TYPE_TREE_MODEL_REF_COUNT))
#define CTK_IS_TREE_MODEL_REF_COUNT_CLASS(vtable)  (G_TYPE_CHECK_CLASS_TYPE ((vtable), CTK_TYPE_TREE_MODEL_REF_COUNT))
#define CTK_TREE_MODEL_REF_COUNT_GET_CLASS(obj)    (G_TYPE_INSTANCE_GET_CLASS ((obj), CTK_TYPE_TREE_MODEL_REF_COUNT, CtkTreeModelRefCountClass))


typedef struct _CtkTreeModelRefCount        CtkTreeModelRefCount;
typedef struct _CtkTreeModelRefCountClass   CtkTreeModelRefCountClass;
typedef struct _CtkTreeModelRefCountPrivate CtkTreeModelRefCountPrivate;

struct _CtkTreeModelRefCount
{
  CtkTreeStore parent;

  /* < private > */
  CtkTreeModelRefCountPrivate *priv;
};

struct _CtkTreeModelRefCountClass
{
  CtkTreeStoreClass parent_class;
};


GType         ctk_tree_model_ref_count_get_type    (void) G_GNUC_CONST;
CtkTreeModel *ctk_tree_model_ref_count_new         (void);

void          ctk_tree_model_ref_count_dump        (CtkTreeModelRefCount *ref_model);
gboolean      ctk_tree_model_ref_count_check_level (CtkTreeModelRefCount *ref_model,
                                                    CtkTreeIter          *parent,
                                                    gint                  expected_ref_count,
                                                    gboolean              recurse,
                                                    gboolean              may_assert);
gboolean      ctk_tree_model_ref_count_check_node  (CtkTreeModelRefCount *ref_model,
                                                    CtkTreeIter          *iter,
                                                    gint                  expected_ref_count,
                                                    gboolean              may_assert);

/* A couple of helpers for the tests.  Since this model will never be used
 * outside of unit tests anyway, it is probably fine to have these here
 * without namespacing.
 */

static inline void
assert_entire_model_unreferenced (CtkTreeModelRefCount *ref_model)
{
  ctk_tree_model_ref_count_check_level (ref_model, NULL, 0, TRUE, TRUE);
}

static inline void
assert_root_level_unreferenced (CtkTreeModelRefCount *ref_model)
{
  ctk_tree_model_ref_count_check_level (ref_model, NULL, 0, FALSE, TRUE);
}

static inline void
assert_level_unreferenced (CtkTreeModelRefCount *ref_model,
                           CtkTreeIter          *iter)
{
  ctk_tree_model_ref_count_check_level (ref_model, iter, 0, FALSE, TRUE);
}

static inline void
assert_entire_model_referenced (CtkTreeModelRefCount *ref_model,
                                gint                  ref_count)
{
  ctk_tree_model_ref_count_check_level (ref_model, NULL, ref_count, TRUE, TRUE);
}

static inline void
assert_not_entire_model_referenced (CtkTreeModelRefCount *ref_model,
                                    gint                  ref_count)
{
  g_assert_cmpint (ctk_tree_model_ref_count_check_level (ref_model, NULL,
                                                         ref_count,
                                                         TRUE, FALSE),<--- syntax error
                   ==, FALSE);
}

static inline void
assert_root_level_referenced (CtkTreeModelRefCount *ref_model,
                              gint                  ref_count)
{
  ctk_tree_model_ref_count_check_level (ref_model, NULL, ref_count,
                                        FALSE, TRUE);
}

static inline void
assert_level_referenced (CtkTreeModelRefCount *ref_model,
                         gint                  ref_count,
                         CtkTreeIter          *iter)
{
  ctk_tree_model_ref_count_check_level (ref_model, iter, ref_count,
                                        FALSE, TRUE);
}

static inline void
assert_node_ref_count (CtkTreeModelRefCount *ref_model,
                       CtkTreeIter          *iter,
                       gint                  ref_count)
{
  ctk_tree_model_ref_count_check_node (ref_model, iter, ref_count, TRUE);
}


#endif /* __CTK_TREE_MODEL_REF_COUNT_H__ */