diff options
author | Daniel Boles <dboles@src.gnome.org> | 2017-05-29 23:03:34 +0100 |
---|---|---|
committer | Daniel Boles <dboles@src.gnome.org> | 2017-05-29 23:07:53 +0100 |
commit | 53384fc8c4c1de4ca518052866fdd17311332468 (patch) | |
tree | 0c511090d4c1b6d2f7044924c142a85206cfdf1c | |
parent | 62fcbed3b28ef9388c046c488f2442a95ba59222 (diff) | |
download | glibmm-53384fc8c4c1de4ca518052866fdd17311332468.tar.gz |
Variant: Use own get_n_children() instead of C API
This looks much less ugly.
-rw-r--r-- | glib/src/variant.ccg | 14 | ||||
-rw-r--r-- | 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 da0587c4..9e59319b 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 1ca472dc..74a14f71 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; |