summaryrefslogtreecommitdiff
path: root/glib/src
diff options
context:
space:
mode:
authorJosé Alburquerque <jaalburqu@svn.gnome.org>2012-11-06 15:20:20 -0500
committerJosé Alburquerque <jaalburqu@svn.gnome.org>2012-11-06 15:29:24 -0500
commit5222ee56a371eabe123afe208641ae76355d3588 (patch)
tree4273c36db442dbf2478f844a2d73f10446f61f11 /glib/src
parent8544ed1d4665521c7eb25e3e851f333fec91e2e1 (diff)
downloadglibmm-5222ee56a371eabe123afe208641ae76355d3588.tar.gz
Variant< std::vector<std::string> >: Add create_from_object_paths().
* glib/src/variant.hg: Add the new method that creates a variant of vector of strings out of object paths. This is so the type of the variant is rightly set to G_VARIANT_TYPE_OBJECT_PATH_ARRAY and not G_VARIANT_TYPE_BYTESTRING in case some application needs to make a distinction. Also _IGNORE the g_variant_get_objv() and g_variant_dup_objv() functions because it's possible to get object paths from a variant of vector of strings if it contains them with the existing getter methods because object paths are merely strings. * glib/src/variantiter.hg: Add an _IGNORE. * glib/src/checksum.ccg: * glib/src/convert.ccg: Whitespace.
Diffstat (limited to 'glib/src')
-rw-r--r--glib/src/checksum.ccg2
-rw-r--r--glib/src/convert.ccg1
-rw-r--r--glib/src/variant.ccg31
-rw-r--r--glib/src/variant.hg12
-rw-r--r--glib/src/variantiter.hg4
5 files changed, 44 insertions, 6 deletions
diff --git a/glib/src/checksum.ccg b/glib/src/checksum.ccg
index 19cdc280..e6e78618 100644
--- a/glib/src/checksum.ccg
+++ b/glib/src/checksum.ccg
@@ -47,5 +47,3 @@ void Checksum::update(const std::string& data)
}
} // Glib namespace
-
-
diff --git a/glib/src/convert.ccg b/glib/src/convert.ccg
index b216f932..295088b1 100644
--- a/glib/src/convert.ccg
+++ b/glib/src/convert.ccg
@@ -287,4 +287,3 @@ Glib::ustring filename_display_name(const std::string& filename)
}
} // namespace Glib
-
diff --git a/glib/src/variant.ccg b/glib/src/variant.ccg
index ded44d5d..e75a17e5 100644
--- a/glib/src/variant.ccg
+++ b/glib/src/variant.ccg
@@ -486,7 +486,8 @@ Variant<type_vec_string>::create(const type_vec_string& data)
// Terminate the string array.
str_array[data.size()] = NULL;
- // Create the variant using the builder.
+ // Create the variant using g_variant_new_bytestring_array() (passing the
+ // newly constructed array.
Variant<type_vec_string> result =
Variant<type_vec_string>(g_variant_new_bytestring_array(str_array,
data.size()));
@@ -499,6 +500,34 @@ Variant<type_vec_string>::create(const type_vec_string& data)
return result;
}
+Variant<type_vec_string>
+Variant<type_vec_string>::create_from_object_paths(const type_vec_string& data)
+{
+ // Create a string array to add the strings of the vector to.
+ char** str_array = g_new(char*, data.size() + 1);
+
+ // Add the elements of the vector into the string array.
+ for(type_vec_string::size_type i = 0; i < data.size(); i++)
+ {
+ str_array[i] = g_strdup(data[i].c_str());
+ }
+
+ // Terminate the string array.
+ str_array[data.size()] = NULL;
+
+ // Create the variant using g_variant_new_objv() (passing the
+ // newly constructed array.
+ Variant<type_vec_string> result =
+ Variant<type_vec_string>(g_variant_new_objv(str_array, data.size()));
+
+ g_strfreev(str_array);
+
+ // Remove the floating reference (since it is newly created).
+ g_variant_ref_sink(result.gobj());
+
+ return result;
+}
+
std::string Variant<type_vec_string>::get_child(gsize index) const
{
gsize n_elements = 0;
diff --git a/glib/src/variant.hg b/glib/src/variant.hg
index 110bbe5c..2caa689c 100644
--- a/glib/src/variant.hg
+++ b/glib/src/variant.hg
@@ -718,6 +718,14 @@ public:
static Variant< std::vector<std::string> >
create(const std::vector<std::string>& data);
+ /** Creates a new Variant from an array of D-Bus object paths.
+ * @param data The array to use for creation.
+ * @return The new Variant.
+ * @newin{2,36}
+ */
+ static Variant< std::vector<std::string> >
+ create_from_object_paths(const std::vector<std::string>& paths);
+
/** Gets a specific element of the string array. It is an error if @a index
* is greater than the number of child items in the container. See
* VariantContainerBase::get_n_children().
@@ -738,6 +746,10 @@ public:
std::vector<std::string> get() const;
_IGNORE(g_variant_get_bytestring_array, g_variant_dup_bytestring_array)
+ // Object paths are merely strings so it is possible to get them already with
+ // the existing get() methods in this class.
+ _IGNORE(g_variant_get_objv, g_variant_dup_objv)
+
/** Gets a VariantIter of the Variant.
* @return the VaraintIter.
* @newin{2,28}
diff --git a/glib/src/variantiter.hg b/glib/src/variantiter.hg
index 8382ab4e..e72b75ce 100644
--- a/glib/src/variantiter.hg
+++ b/glib/src/variantiter.hg
@@ -50,8 +50,8 @@ public:
bool next_value(VariantBase& value);
_IGNORE(g_variant_iter_next_value)
- // Ignore varargs function
- _IGNORE(g_variant_iter_next)
+ // Ignore varargs functions
+ _IGNORE(g_variant_iter_loop, g_variant_iter_next)
};
} // namespace Glib