summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Boles <dboles@src.gnome.org>2017-05-29 23:03:34 +0100
committerDaniel Boles <dboles.src@gmail.com>2017-05-29 23:10:25 +0100
commit79dc3e624426a2ff1bf69c09058cb9927237d617 (patch)
tree691a8c039ef6d9ac56ecd246ddf6b2cbfaa39642
parent5323542bd99fb059f242fb18dce9567678573c59 (diff)
downloadglibmm-79dc3e624426a2ff1bf69c09058cb9927237d617.tar.gz
Variant: Use own get_n_children() instead of C API
This looks much less ugly.
-rw-r--r--glib/src/variant.ccg14
-rw-r--r--glib/src/variant.hg6
2 files changed, 7 insertions, 13 deletions
diff --git a/glib/src/variant.ccg b/glib/src/variant.ccg
index 9c47dea2..ed88877f 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);
@@ -466,7 +466,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.");
@@ -482,9 +482,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());
@@ -564,7 +562,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.");
@@ -581,9 +579,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 de101954..39c63f1b 100644
--- a/glib/src/variant.hg
+++ b/glib/src/variant.hg
@@ -1125,7 +1125,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.");
@@ -1143,9 +1143,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;