[glibmm] Variant< std::vector<std::string> >: Add create_from_object_paths().



commit 5222ee56a371eabe123afe208641ae76355d3588
Author: Josà Alburquerque <jaalburqu svn gnome org>
Date:   Tue Nov 6 15:20:20 2012 -0500

    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.

 ChangeLog               |   20 ++++++++++++++++++++
 glib/src/checksum.ccg   |    2 --
 glib/src/convert.ccg    |    1 -
 glib/src/variant.ccg    |   31 ++++++++++++++++++++++++++++++-
 glib/src/variant.hg     |   12 ++++++++++++
 glib/src/variantiter.hg |    4 ++--
 6 files changed, 64 insertions(+), 6 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 24340ad..613ae5c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,23 @@
+2012-11-06  Josà Alburquerque  <jaalburquerque gmail com>
+
+
+2012-11-06  Josà Alburquerque  <jaalburquerque gmail com>
+
+	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.
+
 2012-11-05  Josà Alburquerque  <jaalburquerque gmail com>
 
 	Regenerate the XML docs files for glibmm and giomm.
diff --git a/glib/src/checksum.ccg b/glib/src/checksum.ccg
index 19cdc28..e6e7861 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 b216f93..295088b 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 ded44d5..e75a17e 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 110bbe5..2caa689 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 8382ab4..e72b75c 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



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]