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
|
/* Copyright (C) 2002-2009 The gtkmm 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, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glibmm/exceptionhandler.h>
static int
ValueArray_Compare_glibmm_callback(gconstpointer a, gconstpointer b, gpointer user_data)
{
Glib::ValueArray::SlotCompare* the_slot = static_cast<Glib::ValueArray::SlotCompare*>(user_data);
try
{
return (*the_slot)(
*reinterpret_cast<const Glib::ValueBase*>(a), *reinterpret_cast<const Glib::ValueBase*>(b));
}
catch (...)
{
Glib::exception_handlers_invoke();
}
return 0;
}
namespace Glib
{
ValueArray::ValueArray() : gobject_(g_value_array_new(0))
{
}
ValueArray::ValueArray(guint n_preallocated) : gobject_(g_value_array_new(n_preallocated))
{
}
bool
ValueArray::get_nth(guint index, Glib::ValueBase& value)
{
const auto g_value = g_value_array_get_nth(gobj(), index);
if (g_value)
{
value.init(g_value);
return true;
}
else
return false;
}
Glib::ValueArray&
ValueArray::append(const Glib::ValueBase& value)
{
g_value_array_append(gobj(), value.gobj());
return *this;
}
Glib::ValueArray&
ValueArray::prepend(const Glib::ValueBase& value)
{
g_value_array_prepend(gobj(), value.gobj());
return *this;
}
Glib::ValueArray&
ValueArray::insert(guint index, const Glib::ValueBase& value)
{
g_value_array_insert(gobj(), index, value.gobj());
return *this;
}
Glib::ValueArray&
ValueArray::remove(guint index)
{
g_value_array_remove(gobj(), index);
return *this;
}
Glib::ValueArray&
ValueArray::sort(const SlotCompare& compare_func)
{
SlotCompare slot_copy(compare_func);
g_value_array_sort_with_data(gobj(), &ValueArray_Compare_glibmm_callback, &slot_copy);
return *this;
}
} // Glib namespace
|