[glibmm] Variant: Use own get_n_children() instead of C API
- From: Daniel Boles <dboles src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glibmm] Variant: Use own get_n_children() instead of C API
- Date: Mon, 29 May 2017 22:11:35 +0000 (UTC)
commit 53384fc8c4c1de4ca518052866fdd17311332468
Author: Daniel Boles <dboles src gnome org>
Date: Mon May 29 23:03:34 2017 +0100
Variant: Use own get_n_children() instead of C API
This looks much less ugly.
glib/src/variant.ccg | 14 +++++---------
glib/src/variant.hg | 6 ++----
2 files changed, 7 insertions(+), 13 deletions(-)
---
diff --git a/glib/src/variant.ccg b/glib/src/variant.ccg
index da0587c..9e59319 100644
--- a/glib/src/variant.ccg
+++ b/glib/src/variant.ccg
@@ -184,7 +184,7 @@ VariantContainerBase::create_maybe(const VariantType& child_type, const VariantB
void
VariantContainerBase::get_child(VariantBase& child, gsize index) const
{
- if (index >= g_variant_n_children(gobject_))
+ if (index >= get_n_children())
throw std::out_of_range("VariantContainerBase::get_child(): Index out of bounds.");
GVariant* const gvariant = g_variant_get_child_value(gobject_, index);
@@ -411,7 +411,7 @@ Variant<type_vec_ustring>::create(const type_vec_ustring& data)
Glib::ustring
Variant<type_vec_ustring>::get_child(gsize index) const
{
- if (index >= g_variant_n_children(const_cast<GVariant*>(gobj())))
+ if (index >= get_n_children())
throw std::out_of_range(
"Variant< std::vector<Glib::ustring> >::get_child(): Index out of bounds.");
@@ -427,9 +427,7 @@ Variant<type_vec_ustring>::get() const
// but the Variant can alternatively hold an array of object paths or DBus type signatures.
type_vec_ustring result;
- gsize n_children = g_variant_n_children(const_cast<GVariant*>(gobj()));
-
- for (gsize i = 0; i < n_children; i++)
+ for (gsize i = 0, n_children = get_n_children(); i < n_children; ++i)
{
GVariant* gvariant = g_variant_get_child_value(const_cast<GVariant*>(gobj()), i);
result.emplace_back(Glib::Variant<Glib::ustring>(gvariant).get());
@@ -509,7 +507,7 @@ Variant<type_vec_string>::create_from_object_paths(const type_vec_string& data)
std::string
Variant<type_vec_string>::get_child(gsize index) const
{
- if (index >= g_variant_n_children(const_cast<GVariant*>(gobj())))
+ if (index >= get_n_children())
throw std::out_of_range(
"Variant< std::vector<std::string> >::get_child(): Index out of bounds.");
@@ -526,9 +524,7 @@ Variant<type_vec_string>::get() const
// signatures.
type_vec_string result;
- gsize n_children = g_variant_n_children(const_cast<GVariant*>(gobj()));
-
- for (gsize i = 0; i < n_children; i++)
+ for (gsize i = 0, n_children = get_n_children(); i < n_children; ++i)
{
GVariant* gvariant = g_variant_get_child_value(const_cast<GVariant*>(gobj()), i);
result.emplace_back(Glib::Variant<std::string>(gvariant).get());
diff --git a/glib/src/variant.hg b/glib/src/variant.hg
index 1ca472d..74a14f7 100644
--- a/glib/src/variant.hg
+++ b/glib/src/variant.hg
@@ -1157,7 +1157,7 @@ Variant< std::vector<T> >::create(const std::vector<T>& data)
template<class T>
T Variant< std::vector<T> >::get_child(gsize index) const
{
- if(index >= g_variant_n_children(const_cast<GVariant*>(gobj())))
+ if (index >= get_n_children())
throw std::out_of_range(
"Variant< std::vector<T> >::get_child(): Index out of bounds.");
@@ -1175,9 +1175,7 @@ std::vector<T> Variant< std::vector<T> >::get() const
{
std::vector<T> result;
- gsize n_children = g_variant_n_children(const_cast<GVariant*>(gobj()));
-
- for(gsize i = 0; i < n_children; i++)
+ for (gsize i = 0, n_children = get_n_children(); i < n_children; ++i)
{
Glib::Variant<T> variant;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]