[glibmm] VariantContainerBase: Add a create() method from an array of variants.



commit d7f620fb20eb57c917a4f3c6c51b964b72ca1455
Author: José Alburquerque <jaalburqu svn gnome org>
Date:   Thu Dec 30 00:45:13 2010 -0500

    VariantContainerBase: Add a create() method from an array of variants.
    
    	* glib/src/variant.{ccg,hg}: (VariantContainerBase::create): Add this
    	method that accepts a VariantType (describing what kind of container
    	should be created), and a vector of VariantBase.  Theoretically, this
    	method should make creation of tuples possible.  There is no tuple
    	class in standard C++ so something like this would be necessary in
    	cases where tuples need to be created (to be returned, for example,
    	from some method call).  The future server/client D-Bus example should
    	put this method to the test.
    	(VariantStringBase::create_*_path): Sink the variant after creation in
    	these methods which was forgotten.
    	* gio/src/dbusconnection.hg: Typos.

 ChangeLog                 |   16 ++++++++++++++++
 gio/src/dbusconnection.hg |    4 ++--
 glib/src/variant.ccg      |   28 ++++++++++++++++++++++++++++
 glib/src/variant.hg       |   15 +++++++++++++--
 4 files changed, 59 insertions(+), 4 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index f4235bb..45f407f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2010-12-30  José Alburquerque  <jaalburqu svn gnome org>
+
+	VariantContainerBase: Add a create() method from an array of variants.
+
+	* glib/src/variant.{ccg,hg}: (VariantContainerBase::create): Add this
+	method that accepts a VariantType (describing what kind of container
+	should be created), and a vector of VariantBase.  Theoretically, this
+	method should make creation of tuples possible.  There is no tuple
+	class in standard C++ so something like this would be necessary in
+	cases where tuples need to be created (to be returned, for example,
+	from some method call).  The future server/client D-Bus example should
+	put this method to the test.
+	(VariantStringBase::create_*_path): Sink the variant after creation in
+	these methods which was forgotten.
+	* gio/src/dbusconnection.hg: Typos.
+
 2010-12-28  José Alburquerque  <jaalburqu svn gnome org>
 
 	Variant test: Use the dictionary variant classes in the test.
diff --git a/gio/src/dbusconnection.hg b/gio/src/dbusconnection.hg
index f703fcb..5bb5210 100644
--- a/gio/src/dbusconnection.hg
+++ b/gio/src/dbusconnection.hg
@@ -44,7 +44,7 @@ class DBusInterfaceInfo;
 class DBusInterfaceVTable;
 class DBusMethodInvocation;
 
-/// @defgroup DBus D-Bus Access Functionality
+/// @defgroup DBus D-Bus API
 
 //TODO: Add example from C API in class docs.
 /** DBusConnection - D-Bus Connections.
@@ -869,7 +869,7 @@ public:
    * connection, const Glib::ustring& sender, const Glib::ustring&
    * object_path, const Glib::ustring& interface_name, const Glib::ustring&
    * method_name, const Glib::VariantBase& parameters, const
-   * Glib::RefPtr<Gio::DBusInvocation>& invocation);
+   * Glib::RefPtr<Gio::DBusMethodInvocation>& invocation);
    * @encode
    */
   typedef sigc::slot<
diff --git a/glib/src/variant.ccg b/glib/src/variant.ccg
index e58246e..b6babe8 100644
--- a/glib/src/variant.ccg
+++ b/glib/src/variant.ccg
@@ -44,6 +44,7 @@ void VariantStringBase::create_object_path(VariantStringBase& output,
 {
   GVariant* result = 0;
   result = g_variant_new_object_path(object_path.c_str());
+  g_variant_ref_sink(result);
   output.init(result);
 }
 
@@ -53,6 +54,33 @@ void VariantStringBase::create_signature(VariantStringBase& output,
 {
   GVariant* result = 0;
   result = g_variant_new_signature(signature.c_str());
+  g_variant_ref_sink(result);
+  output.init(result);
+}
+
+//static
+void VariantContainerBase::create(VariantContainerBase& output,
+  const Glib::VariantType& container_type,
+  const std::vector<const VariantBase*>& children)
+{
+  g_return_if_fail(container_type.is_container());
+
+  // Create a builder to create the container (as is done in the
+  // Variant< std::map<K, V> >::create() method.
+  GVariantBuilder* builder = g_variant_builder_new(container_type.gobj());
+
+  for(std::vector<const VariantBase*>::const_iterator iter = children.begin();
+    iter < children.end(); iter++)
+  {
+    g_variant_builder_add_value(builder,
+      const_cast<GVariant*>((*iter)->gobj()));
+  }
+
+  GVariant* result = g_variant_new(
+    reinterpret_cast<char*>(const_cast<GVariantType*>(container_type.gobj())),
+    builder);
+
+  g_variant_ref_sink(result);
   output.init(result);
 }
 
diff --git a/glib/src/variant.hg b/glib/src/variant.hg
index d0ccdd5..80d3462 100644
--- a/glib/src/variant.hg
+++ b/glib/src/variant.hg
@@ -29,7 +29,7 @@ _DEFS(glibmm,glib)
 namespace Glib
 {
 
-/** @defgroup Variant Variant Datatype
+/** @defgroup Variant Variant Data Types
  *
  * Glib::Variant<> are specialized classes that deal with strongly typed
  * variant data.  They are used to wrap glib's GVariant API.  For more
@@ -209,6 +209,17 @@ public:
   : VariantBase(castitem, take_a_reference)
   {}
 
+  /** Create a container variant from a vector of its variant children.  Since
+   * the children are variant and can be of any variant type, it is possible
+   * to create a variant tuple with this method.
+   * @param output A location in which to store the newly created variant.
+   * @param container_type The container type to be created.
+   * @param children The vector containing the children of the container.
+   */
+  static void create(VariantContainerBase& output,
+    const Glib::VariantType& container_type,
+    const std::vector<const VariantBase*>& children);
+
   _WRAP_METHOD(gsize get_n_children() const, g_variant_n_children)
 
   /** Reads a child item out of this instance. This method is valid for
@@ -819,7 +830,7 @@ const VariantType& Variant< std::vector<T> >::variant_type()
 
 template<class T>
 Variant< std::vector<T> >
-Variant< std::vector<T> >::create(const  std::vector<T>& data)
+Variant< std::vector<T> >::create(const std::vector<T>& data)
 {
   // Get the variant type of the elements.
   VariantType element_variant_type = Variant<T>::variant_type();



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