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
|
/* Copyright (C) 2016 The giomm Development Team
*
* 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.1 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, see <http://www.gnu.org/licenses/>.
*/
#include <gio/gio.h>
#include <memory>
namespace
{
extern "C"
{
int ListStoreBase_CompareDataFunc(gconstpointer a, gconstpointer b, gpointer user_data)
{
auto slot = static_cast<Gio::ListStoreBase::SlotCompare*>(user_data);
const Glib::RefPtr<const Glib::ObjectBase> item_a =
Glib::wrap(static_cast<Glib::Object::BaseObjectType*>(const_cast<gpointer>(a)), true);
const Glib::RefPtr<const Glib::ObjectBase> item_b =
Glib::wrap(static_cast<Glib::Object::BaseObjectType*>(const_cast<gpointer>(b)), true);
return (*slot)(item_a, item_b);
}
// gboolean is int
gboolean ListStoreBase_EqualFuncFull(gconstpointer a, gconstpointer b, gpointer user_data)
{
auto slot = static_cast<Gio::ListStoreBase::SlotEqual*>(user_data);
const Glib::RefPtr<const Glib::ObjectBase> item_a =
Glib::wrap(static_cast<Glib::Object::BaseObjectType*>(const_cast<gpointer>(a)), true);
const Glib::RefPtr<const Glib::ObjectBase> item_b =
Glib::wrap(static_cast<Glib::Object::BaseObjectType*>(const_cast<gpointer>(b)), true);
return (*slot)(item_a, item_b);
}
}
} // anonymous namespace
namespace Gio
{
void ListStoreBase::splice(guint position, guint n_removals,
const std::vector<Glib::RefPtr<Glib::ObjectBase>>& additions)
{
const std::size_t n_additions = additions.size();
std::unique_ptr<gpointer[]> g_additions{new gpointer[n_additions]};
for (std::size_t i = 0; i < n_additions; i++)
{
g_additions[i] = additions[i]->gobj();
}
g_list_store_splice(gobj(), position, n_removals, g_additions.get(), n_additions);
}
std::pair<bool, unsigned int> ListStoreBase::find(const Glib::RefPtr<const Glib::ObjectBase>& item) const
{
unsigned int position = std::numeric_limits<unsigned int>::max();
bool result = g_list_store_find(const_cast<GListStore*>(gobj()),
const_cast<GObject*>(item->gobj()), &position);
return {result, position};
}
std::pair<bool, unsigned int> ListStoreBase::find(
const Glib::RefPtr<const Glib::ObjectBase>& item, const SlotEqual& slot) const
{
// Use the original slot (not a copy).
auto slot_ptr = const_cast<SlotEqual*>(&slot);
unsigned int position = std::numeric_limits<unsigned int>::max();
bool result = g_list_store_find_with_equal_func_full(
const_cast<GListStore*>(gobj()), const_cast<GObject*>(item->gobj()),
&ListStoreBase_EqualFuncFull, slot_ptr, &position);
return {result, position};
}
} // namespace Gio
|