[glibmm] Variant: Add a VariantStringBase and a VariantContainerBase class.



commit 2eff97b849a744ad07531f23969abf738edfd99a
Author: José Alburquerque <jaalburqu svn gnome org>
Date:   Mon Dec 20 01:43:55 2010 -0500

    	Variant: Add a VariantStringBase and a VariantContainerBase class.
    
    	* glib/src/variant.{ccg,hg} (VariantStringBase): Implement a new class
    	from which the Glib::Variant<> string class (like
    	Glib::Variant<Glib::ustring>) now derive.  The new class has methods
    	for determining/creating object paths and signatures.  The new
    	instances are created by setting output parameters.
    	(VaraintContainerBase): Implement this new class from which variant
    	containers should derive.
    	(VariantContainerBase::get_n_children, get, get_maybe): Moved from
    	Variant<VariantBase>
    	(castitem constructors): Corrected all GVariant* castitem constructors
    	to accept a 'take_a_reference' bool parameter.
    	(Variant< std::vector<T> >::create, get, get_iter): Re-wrote these
    	methods to use the Glib::VariantType class to get variant types
    	instead of using strings.  Also Re-wrote to work specifically with
    	fixed arrays (see g_variant_get_fixed_array).  This means that this
    	class will not work with vectors of strings because
    	g_variant_get_strv() and g_variant_get_bytestring_array() need to be
    	used in those cases.
    	(std::vector<T> get): Re-wrote to use an output parameter.
    
    	* glib/src/variant_basictypes.h.m4: Corrected the castitem
    	constructors as above.
    
    	* tests/Makefile.am:
    	* tests/glibmm_variant/main.cc: Added a small test for the
    	Variant< std::vector<T> > methods.
    
    	* gio/src/dbuserror.hg:
    	* gio/src/error.hg: Wrap the GDBusError enum as a GError, moving its
    	declaration to error.hg.

 ChangeLog                        |   35 +++++
 gio/src/dbuserror.hg             |    2 -
 gio/src/error.hg                 |    1 +
 glib/src/variant.ccg             |   57 +++++---
 glib/src/variant.hg              |  276 ++++++++++++++++++++++++++-----------
 glib/src/variant_basictypes.h.m4 |    4 +-
 tests/Makefile.am                |    5 +-
 tests/glibmm_variant/main.cc     |   40 ++++++
 8 files changed, 313 insertions(+), 107 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index fd368e1..a7c1fe3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,38 @@
+2010-12-20  José Alburquerque  <jaalburqu svn gnome org>
+
+	Variant: Add a VariantStringBase and a VariantContainerBase class.
+
+	* glib/src/variant.{ccg,hg} (VariantStringBase): Implement a new class
+	from which the Glib::Variant<> string class (like
+	Glib::Variant<Glib::ustring>) now derive.  The new class has methods
+	for determining/creating object paths and signatures.  The new
+	instances are created by setting output parameters.
+	(VaraintContainerBase): Implement this new class from which variant
+	containers should derive.
+	(VariantContainerBase::get_n_children, get, get_maybe): Moved from
+	Variant<VariantBase>
+	(castitem constructors): Corrected all GVariant* castitem constructors
+	to accept a 'take_a_reference' bool parameter.
+	(Variant< std::vector<T> >::create, get, get_iter): Re-wrote these
+	methods to use the Glib::VariantType class to get variant types
+	instead of using strings.  Also Re-wrote to work specifically with
+	fixed arrays (see g_variant_get_fixed_array).  This means that this
+	class will not work with vectors of strings because
+	g_variant_get_strv() and g_variant_get_bytestring_array() need to be
+	used in those cases.
+	(std::vector<T> get): Re-wrote to use an output parameter.
+
+	* glib/src/variant_basictypes.h.m4: Corrected the castitem
+	constructors as above.
+
+	* tests/Makefile.am:
+	* tests/glibmm_variant/main.cc: Added a small test for the
+	Variant< std::vector<T> > methods.
+
+	* gio/src/dbuserror.hg:
+	* gio/src/error.hg: Wrap the GDBusError enum as a GError, moving its
+	declaration to error.hg.
+
 2010-12-16  José Alburquerque  <jaalburqu svn gnome org>
 
 	Added a new Glib::Variant<> specialization to deal with arrays.
diff --git a/gio/src/dbuserror.hg b/gio/src/dbuserror.hg
index 8753692..f7f8707 100644
--- a/gio/src/dbuserror.hg
+++ b/gio/src/dbuserror.hg
@@ -28,8 +28,6 @@ namespace DBus
 namespace Error
 {
 
-_WRAP_ENUM(DBusError, GDBusError, NO_GTYPE)
-
 /** Checks if @a error represents an error received via D-Bus from a remote
  * peer.  If so, use get_remote_error() to get the name of the error.
  *
diff --git a/gio/src/error.hg b/gio/src/error.hg
index 970b59b..8bc9b1b 100644
--- a/gio/src/error.hg
+++ b/gio/src/error.hg
@@ -40,6 +40,7 @@ namespace Gio
 
 /** Exception class for giomm errors.
  */
+_WRAP_GERROR(DBusError, GDBusError, G_DBUS_ERROR, NO_GTYPE)
 _WRAP_GERROR(Error, GIOErrorEnum, G_IO_ERROR, NO_GTYPE)
 _WRAP_GERROR(ResolverError, GResolverError, G_RESOLVER_ERROR, NO_GTYPE)
 
diff --git a/glib/src/variant.ccg b/glib/src/variant.ccg
index 22b0d1e..1590c25 100644
--- a/glib/src/variant.ccg
+++ b/glib/src/variant.ccg
@@ -38,6 +38,43 @@ void VariantBase::byteswap(VariantBase& result) const
   result.init(g_value); // g_value is already referenced.
 }
 
+//static
+void VariantStringBase::create_object_path(VariantStringBase& output,
+  const std::string& object_path)
+{
+  GVariant* result = 0;
+  result = g_variant_new_object_path(object_path.c_str());
+  output.init(result);
+}
+
+//static
+void VariantStringBase::create_signature(VariantStringBase& output,
+  const std::string& signature)
+{
+  GVariant* result = 0;
+  result = g_variant_new_signature(signature.c_str());
+  output.init(result);
+}
+
+void VariantContainerBase::get(VariantBase& child, gsize index) const
+{
+  GVariant* const gvariant = g_variant_get_child_value(gobject_, index);
+  child.init(gvariant);
+}
+
+bool VariantContainerBase::get_maybe(Glib::VariantBase& maybe) const
+{
+  GVariant* const g_value =
+    g_variant_get_maybe(const_cast<GVariant*>(gobj()));
+
+  if(g_value)
+  {
+    maybe.init(g_value); // g_value is already referenced.
+    return true;
+  }
+  else
+    return false;
+}
 
 /****************** Specializations ***********************************/
 
@@ -68,26 +105,6 @@ Variant<VariantBase> Variant<VariantBase>::create(const VariantBase& data)
   return result;
 }
 
-void Variant<VariantBase>::get(VariantBase& child) const
-{
-  GVariant* const gvariant = g_variant_get_variant(gobject_);
-  child.init(gvariant);
-}
-
-bool Variant<VariantBase>::get_maybe(Glib::VariantBase& maybe) const
-{
-  GVariant* const g_value =
-    g_variant_get_maybe(const_cast<GVariant*>(gobj()));
-
-  if(g_value)
-  {
-    maybe.init(g_value); // g_value is already referenced.
-    return true;
-  }
-  else
-    return false;
-}
-
 // static
 const VariantType& Variant<Glib::ustring>::variant_type()
 {
diff --git a/glib/src/variant.hg b/glib/src/variant.hg
index 35037b7..eaaf445 100644
--- a/glib/src/variant.hg
+++ b/glib/src/variant.hg
@@ -22,6 +22,7 @@ _DEFS(glibmm,glib)
 #include <glibmm/variantiter.h>
 #include <glibmm/ustring.h>
 #include <vector>
+#include <stdexcept>
 
 namespace Glib
 {
@@ -48,10 +49,12 @@ class VariantBase
 public:
 
   /** Replace the underlying GVariant.
-   * This is for use by methods that take a VariantBase& as an output parameter.
+   * This is for use by methods that take a VariantBase& as an output
+   * parameter.
    *
    * @param cobject The GVariant* obtained from a C function.
-   * @param take_a_reference Whether this method should take a reference, for instance if the C function has not given one.
+   * @param take_a_reference Whether this method should take a reference, for
+   * instance if the C function has not given one.
    */
   void init(const GVariant* cobject, bool take_a_reference = false);
 
@@ -117,6 +120,124 @@ public:
    _IGNORE(g_variant_byteswap)
 };
 
+/** Base class from which string variant classes derive.
+ */
+class VariantStringBase : public VariantBase
+{
+  // Trick gmmproc into thinking this is derived from GVariant to wrap a
+  // some methods.
+  _CLASS_GENERIC(VariantStringBase, GVariant)
+
+public:
+  typedef GVariant*                     CType;
+  typedef VariantStringBase             CppType;
+
+  /// Default constructor.
+  VariantStringBase()
+  : VariantBase()
+  {}
+
+  /** GVariant constructor.
+   * @param castitem The GVariant to wrap.
+   * @param take_a_reference Whether to take an extra reference of the
+   * GVariant or not (not taking one could destroy the GVariant with the
+   * wrapper).
+   */
+  explicit VariantStringBase(GVariant* castitem,
+    bool take_a_reference = false)
+  : VariantBase(castitem, take_a_reference)
+  {}
+
+  /** Creates a DBus object path variant with the contents of @a string. @a
+   * string must be a valid DBus object path. Use is_object_path() if unsure.
+   *
+   * @param output A location in which to store the new object path variant
+   * instance.
+   * @param object_path A normal nul-terminated string.
+   * @newin{2,28}
+   */
+  static void create_object_path(VariantStringBase& output,
+    const std::string& object_path);
+
+  _WRAP_METHOD(static bool is_object_path(std::string string), g_variant_is_object_path)
+
+  /** Creates a DBus type signature variant with the contents of @a string. @a
+   * string must be a valid DBus type signature. Use is_signature() if unsure.
+   *
+   * @param output A location in which to store the new signature variant
+   * instance.
+   * @param signature A normal nul-terminated string.
+   * @newin{2,28}
+   */
+    static void create_signature(VariantStringBase& output,
+      const std::string& object_path);
+
+  _WRAP_METHOD(static bool is_signature(std::string string), g_variant_is_signature)
+};
+
+/** The base class from which variant containers derive.
+ */
+class VariantContainerBase : public VariantBase
+{
+  // Trick gmmproc into thinking this is derived from GVariant to wrap a
+  // some methods.
+  _CLASS_GENERIC(VariantContainerBase, GVariant)
+
+public:
+  typedef GVariant*                     CType;
+  typedef VariantContainerBase          CppType;
+
+  /// Default constructor.
+  VariantContainerBase()
+  : VariantBase()
+  {}
+
+  /** GVariant constructor.
+   * @param castitem The GVariant to wrap.
+   * @param take_a_reference Whether to take an extra reference of the
+   * GVariant or not (not taking one could destroy the GVariant with the
+   * wrapper).
+   */
+  explicit VariantContainerBase(GVariant* castitem,
+    bool take_a_reference = false)
+  : VariantBase(castitem, take_a_reference)
+  {}
+
+  _WRAP_METHOD(gsize get_n_children() const, g_variant_n_children)
+
+  /** Reads a child item out of this instance. This method is valid for
+   * variants, maybes, arrays, tuples and dictionary entries.
+   *
+   * It is an error if @a index is greater than the number of child items in
+   * the container. See n_children().
+   *
+   * This function is O(1).
+   *
+   * @param index The index of the child to fetch.
+   * @param child A location in which to store the child at the specified
+   * index.
+   * @newin{2,28}
+   */
+  void get(Glib::VariantBase& child, gsize index = 0) const;
+  _IGNORE(g_variant_get_child, g_variant_get_child_value)
+
+  /* TODO?:
+  /// A get() method to return the contents of the variant in the container.
+  template <class DataType>
+  DataType get(gsize index = 0) const;
+  */
+
+  /** If this is a maybe-typed instance, extract its value. If the value is
+   * Nothing, then this function returns <tt>0</tt>.
+   *
+   * @param maybe A place in which to return the value (the value may be
+   * <tt>0</tt>).
+   * @newin{2,28}
+   */
+  bool get_maybe(Glib::VariantBase& maybe) const;
+  _IGNORE(g_variant_get_maybe)
+};
+
 /** Template class used for the specialization of the Glib::Variant<> classes.
  * @newin{2,28}
  * @ingroup glibmmVariant
@@ -140,12 +261,8 @@ _IGNORE(g_variant_get_type)
  * @ingroup glibmmVariant
  */
 template <>
-class Variant<VariantBase> : public VariantBase
+class Variant<VariantBase> : public VariantContainerBase
 {
-  // Trick gmmproc into thinking this is derived from GVariant to wrap a method
-  // below.
-  _CLASS_GENERIC(Variant<VariantBase>, GVariant)
-
 public:
   typedef GVariant*                     CType;
   typedef VariantBase                   CppType;
@@ -153,14 +270,18 @@ public:
 
   /// Default constructor.
   Variant<VariantBase>()
-  : VariantBase()
+  : VariantContainerBase()
   {}
 
   /** GVariant constructor.
    * @param castitem The GVariant to wrap.
+   * @param take_a_reference Whether to take an extra reference of the
+   * GVariant or not (not taking one could destroy the GVariant with the
+   * wrapper).
    */
-  explicit Variant<VariantBase>(GVariant* castitem)
-  : VariantBase(castitem)
+  explicit Variant<VariantBase>(GVariant* castitem,
+    bool take_a_reference = false)
+  : VariantContainerBase(castitem, take_a_reference)
   {}
 
   /** Gets the Glib::VariantType.
@@ -179,24 +300,8 @@ public:
   static Variant<VariantBase> create(const Glib::VariantBase& data);
   _IGNORE(g_variant_new_variant)
 
-  /** Gets the child of the Glib::Variant<VariantBase>.
-   * @param child The location in which to store the child.
-   * @newin{2,28}
-   */
-  void get(Glib::VariantBase& child) const;
+  // The parent's class get() method suffices to get the child variant.
   _IGNORE(g_variant_get_variant)
-
-  _WRAP_METHOD(gsize get_n_children() const, g_variant_n_children)
-
-  /** If this is a maybe-typed instance, extract its value. If the value is
-   * Nothing, then this function returns <tt>0</tt>.
-   *
-   * @param maybe A place in which to return the value (the value may be
-   * <tt>0</tt>).
-   * @newin{2,28}
-   */
-  bool get_maybe(Glib::VariantBase& maybe) const;
-  _IGNORE(g_variant_get_maybe)
 };
 
 /** Specialization of Glib::Variant containing a Glib::ustring.
@@ -204,21 +309,25 @@ public:
  * @ingroup glibmmVariant
  */
 template <>
-class Variant<Glib::ustring> : public VariantBase
+class Variant<Glib::ustring> : public VariantStringBase
 {
 public:
   typedef char* CType;
 
   /// Default constructor.
   Variant<Glib::ustring>()
-  : VariantBase()
+  : VariantStringBase()
   {}
 
   /** GVariant constructor.
    * @param castitem The GVariant to wrap.
+   * @param take_a_reference Whether to take an extra reference of the
+   * GVariant or not (not taking one could destroy the GVariant with the
+   * wrapper).
    */
-  explicit Variant<Glib::ustring>(GVariant* castitem)
-  : VariantBase(castitem)
+  explicit Variant<Glib::ustring>(GVariant* castitem,
+    bool take_a_reference = false)
+  : VariantStringBase(castitem, take_a_reference)
   {}
 
   /** Gets the Glib::VariantType.
@@ -247,21 +356,25 @@ public:
  * @ingroup glibmmVariant
  */
 template <>
-class Variant<std::string> : public VariantBase
+class Variant<std::string> : public VariantStringBase
 {
 public:
   typedef char* CType;
 
   /// Default constructor.
   Variant<std::string>()
-  : VariantBase()
+  : VariantStringBase()
   {}
 
   /** GVariant constructor.
    * @param castitem The GVariant to wrap.
+   * @param take_a_reference Whether to take an extra reference of the
+   * GVariant or not (not taking one could destroy the GVariant with the
+   * wrapper).
    */
-  explicit Variant<std::string>(GVariant* castitem)
-  : VariantBase(castitem)
+  explicit Variant<std::string>(GVariant* castitem,
+    bool take_a_reference = false)
+  : VariantStringBase(castitem, take_a_reference)
   {}
 
   /** Gets the Glib::VariantType.
@@ -288,7 +401,7 @@ public:
 /** Specialization of Glib::Variant containing an array of items.
  */
 template <class T>
-class Variant< std::vector<T> > : public Variant<VariantBase>
+class Variant< std::vector<T> > : public VariantContainerBase
 {
 public:
   typedef T                     CppType;
@@ -296,14 +409,18 @@ public:
 
   /// Default constructor.
   Variant< std::vector<T> >()
-  : Variant<VariantBase>()
+  : VariantContainerBase()
   {}
 
   /** GVariant constructor.
    * @param castitem The GVariant to wrap.
+   * @param take_a_reference Whether to take an extra reference of the
+   * GVariant or not (not taking one could destroy the GVariant with the
+   * wrapper).
    */
-  explicit Variant< std::vector<T> >(GVariant* castitem)
-  : Variant<VariantBase>(castitem)
+  explicit Variant< std::vector<T> >(GVariant* castitem,
+    bool take_a_reference = false)
+  : VariantContainerBase(castitem, take_a_reference)
   {}
 
   /** Gets the Glib::VariantType.
@@ -336,8 +453,8 @@ public:
    * @return The vector.
    * @newin{2,28}
    */
-  std::vector<T> get() const;
-  _IGNORE(get_variant_get_fixed_array)
+  void get(std::vector<T>& result) const;
+  _IGNORE(g_variant_get_fixed_array)
 
   /** Gets a VariantIter of the contained array.
    * @return the VaraintIter.
@@ -386,28 +503,28 @@ template<class T>
 Variant< std::vector<T> >
 Variant< std::vector<T> >::create(const  std::vector<T>& data)
 {
-  // Get the variant type of the elements as a string.
-  std::string element_variant_type =
-    static_cast<char*>(Variant<T>::variant_type().gobj());
+  // Get the variant type of the elements.
+  VariantType element_variant_type = Variant<T>::variant_type();
 
-  // Get the variant type of the array as a string.
-  std::string array_variant_type = "a" + element_variant_type;
+  // Get the variant type of the array.
+  VariantType array_variant_type =
+    VariantType::create_array(element_variant_type);
 
   // Create a GVariantBuilder to build the array.
-  GVariantBuilder* builder =
-    g_variant_builder_new(G_VARIANT_TYPE(array_variant_type.c_str()));
+  GVariantBuilder* builder = g_variant_builder_new(array_variant_type.gobj());
 
   // Add the elements of the vector into the builder.
-  for(typename std::vector<T>::iterator iter = data.begin(); iter < data.end();
-    iter++)
+  for(typename std::vector<T>::const_iterator iter = data.begin();
+   iter < data.end(); iter++)
   {
-    g_variant_builder_add(builder, element_variant_type, *iter);
+    g_variant_builder_add(builder,
+      reinterpret_cast<gchar*>(element_variant_type.gobj()), *iter);
   }
 
   // Create the variant using the builder.
   Variant< std::vector<T> > result =
-    Variant< std::vector<T> >(g_variant_new(array_variant_type.c_str(),
-    builder));
+    Variant< std::vector<T> >(g_variant_new(
+      reinterpret_cast<gchar*>(array_variant_type.gobj()), builder));
 
   // Remove the floating reference (since it is newly created).
   g_variant_ref_sink(result.gobj());
@@ -418,50 +535,45 @@ Variant< std::vector<T> >::create(const  std::vector<T>& data)
 template<class T>
 T Variant< std::vector<T> >::get(gsize index) const
 {
-  GVariant* gvariant = g_variant_get_child_value(gobj(), index);
-  Glib::Variant<T> variant(gvariant, true /* take extra ref to preserve */);
-  return variant.get();
-}
+  gsize n_elements = 0;
 
-template<class T>
-std::vector<T> Variant< std::vector<T> >::get() const
-{
-  // Get the variant type of the elements as a string.
-  std::string element_variant_type =
-    static_cast<char*>(Variant<T>::variant_type().gobj());
+  const T* array = reinterpret_cast<const T*>(
+    g_variant_get_fixed_array(const_cast<GVariant*>(gobj()), &n_elements,
+    sizeof(T)));
 
-  // Get the variant type of the array as a string.
-  std::string array_variant_type = "a" + element_variant_type;
+  if(index > n_elements)
+    throw std::runtime_error(
+      "T Variant< std::vector<T> > get(): Index out of bounds.");
 
-  // Get the GVariantIter.
-  GVariantIter* g_iter = 0;
-  g_variant_get(gobj(), array_variant_type.c_str(), &g_iter);
-
-  // Wrap the GVariantIter.
-  VariantIter iter(g_iter);
+  return array[index];
+}
 
-  std::vector<T> result;
-  Glib::Variant<T> element;
+template<class T>
+void Variant< std::vector<T> >::get(std::vector<T>& result) const
+{
+  gsize n_elements = 0;
 
-  while(iter.next_value(element))
-    result.push_back(element.get());
+  const T* array = reinterpret_cast<const T*>(
+    g_variant_get_fixed_array(const_cast<GVariant*>(gobj()), &n_elements,
+    sizeof(T)));
 
-  return result;
+  result.assign(array, array + n_elements);
 }
 
 template<class T>
 VariantIter Variant< std::vector<T> >::get_iter()
 {
-  // Get the variant type of the elements as a string.
-  std::string element_variant_type =
-    static_cast<char*>(Variant<T>::variant_type().gobj());
+  // Get the variant type of the elements.
+  VariantType element_variant_type = Variant<T>::variant_type();
 
-  // Get the variant type of the array as a string.
-  std::string array_variant_type = "a" + element_variant_type;
+  // Get the variant type of the array.
+  VariantType array_variant_type =
+    VariantType::create_array(element_variant_type);
 
   // Get the GVariantIter.
   GVariantIter* g_iter = 0;
-  g_variant_get(gobj(), array_variant_type.c_str(), &g_iter);
+  g_variant_get(const_cast<GVariant*>(gobj()),
+    reinterpret_cast<gchar*>(array_variant_type.gobj()), &g_iter);
 
   return VariantIter(g_iter);
 }
diff --git a/glib/src/variant_basictypes.h.m4 b/glib/src/variant_basictypes.h.m4
index 4a095da..aa1964e 100644
--- a/glib/src/variant_basictypes.h.m4
+++ b/glib/src/variant_basictypes.h.m4
@@ -50,8 +50,8 @@ public:
   /** GVariant constructor.
    * @param castitem The GVariant to wrap.
    */
-  explicit Variant<$1>(GVariant* castitem)
-  : VariantBase(castitem)
+  explicit Variant<$1>(GVariant* castitem, bool take_a_reference = false)
+  : VariantBase(castitem, take_a_reference)
   {}
 
   /** Gets the Glib::VariantType.
diff --git a/tests/Makefile.am b/tests/Makefile.am
index cb03236..cda5e70 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -27,7 +27,9 @@ check_PROGRAMS =			\
 	glibmm_ustring_compose/test	\
 	glibmm_ustring_format/test	\
 	glibmm_value/test		\
-	glibmm_valuearray/test
+	glibmm_value/test		\
+	glibmm_value/test		\
+	glibmm_variant/test
 
 glibmm_includes = -I$(top_builddir)/glib $(if $(srcdir:.=),-I$(top_srcdir)/glib)
 giomm_includes  = -I$(top_builddir)/gio $(if $(srcdir:.=),-I$(top_srcdir)/gio)
@@ -58,3 +60,4 @@ glibmm_ustring_compose_test_SOURCES = glibmm_ustring_compose/main.cc
 glibmm_ustring_format_test_SOURCES = glibmm_ustring_format/main.cc
 glibmm_value_test_SOURCES           = glibmm_value/glibmm_value.cc glibmm_value/main.cc
 glibmm_valuearray_test_SOURCES      = glibmm_valuearray/main.cc
+glibmm_variant_test_SOURCES         = glibmm_variant/main.cc
diff --git a/tests/glibmm_variant/main.cc b/tests/glibmm_variant/main.cc
new file mode 100644
index 0000000..75038ad
--- /dev/null
+++ b/tests/glibmm_variant/main.cc
@@ -0,0 +1,40 @@
+#include <glibmm.h>
+#include <iostream>
+
+int main(int, char**)
+{
+  Glib::init();
+
+  int int_list[] = {1, 2, 3, 4, 5, 6, 7, 8};
+
+  std::vector<int> int_vector(int_list,
+    int_list + sizeof(int_list) / sizeof(int));
+
+  std::cout << "The elements of the original vector are:" << std::endl;
+
+  for(guint i = 0; i < int_vector.size(); i++)
+    std::cout << int_vector[i] << std::endl;
+
+  Glib::Variant< std::vector<int> > integers_variant =
+    Glib::Variant< std::vector<int> >::create(int_vector);
+
+  std::vector<int> int_vector2;
+
+  integers_variant.get(int_vector2);
+
+  std::cout << "The size of the copied vector is " << int_vector2.size() <<
+    '.' << std::endl;
+
+  std::cout << "The elements of the copied vector are:" << std::endl;
+
+  for(guint i = 0; i < int_vector2.size(); i++)
+    std::cout << int_vector2[i] << std::endl;
+
+  std::cout << "The number of children in the iterator of the copy are " <<
+    integers_variant.get_iter().get_n_children() << '.' << std::endl;
+
+  std::cout << "The 5th element in the copy is " <<
+    integers_variant.get(5) << '.' << std::endl;
+
+  return 0;
+}



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