[glibmm] glibmm: Add a Variant<std::string> specialization.



commit e05ceca29cd5fa2f6dea396c491fc5007c31e78a
Author: José Alburquerque <jaalburqu svn gnome org>
Date:   Wed Dec 15 22:57:52 2010 -0500

    	glibmm: Add a Variant<std::string> specialization.
    
    	* glib/src/variant.ccg:
    	* glib/src/variant.hg: Add a Variant<std::string> specialization based
    	on the already existing Variant<Glib::ustring> one.  A way has to be
    	found to create object paths and signatures (see
    	g_variant_new_object_path() and g_variant_new_signature()) which are
    	also strings and have their own GVariantType.

 ChangeLog            |   11 +++++++++++
 glib/src/variant.ccg |   23 +++++++++++++++++++++++
 glib/src/variant.hg  |   25 +++++++++++++++++++++++++
 3 files changed, 59 insertions(+), 0 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 0726341..0614956 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
 2010-12-15  José Alburquerque  <jaalburqu svn gnome org>
 
+	glibmm: Add a Variant<std::string> specialization.
+
+	* glib/src/variant.ccg:
+	* glib/src/variant.hg: Add a Variant<std::string> specialization based
+	on the already existing Variant<Glib::ustring> one.  A way has to be
+	found to create object paths and signatures (see
+	g_variant_new_object_path() and g_variant_new_signature()) which are
+	also strings and have their own GVariantType.
+
+2010-12-15  José Alburquerque  <jaalburqu svn gnome org>
+
 	Variant[Iter,Type]: Add class docs.
 
 	* glib/src/variantiter.hg:
diff --git a/glib/src/variant.ccg b/glib/src/variant.ccg
index 1b94bf6..22f9690 100644
--- a/glib/src/variant.ccg
+++ b/glib/src/variant.ccg
@@ -110,4 +110,27 @@ Glib::ustring Variant<Glib::ustring>::get() const
   return Glib::ustring(g_variant_get_string(gobject_, 0));
 }
 
+// static
+const GVariantType* Variant<std::string>::variant_type()
+{
+  return G_VARIANT_TYPE_BYTESTRING;
+}
+
+Variant<std::string>
+Variant<std::string>::create(const std::string& data)
+{
+  Variant<std::string> result =
+    Variant<std::string>(g_variant_new_bytestring(data.c_str()));
+
+  // Remove the floating reference (since it is newly created).
+  g_variant_ref_sink(result.gobj());
+
+  return result;
+}
+
+std::string Variant<std::string>::get() const
+{
+  return std::string(g_variant_get_bytestring(gobject_));
+}
+
 } // namespace Glib
diff --git a/glib/src/variant.hg b/glib/src/variant.hg
index 2535d54..1dc4c08 100644
--- a/glib/src/variant.hg
+++ b/glib/src/variant.hg
@@ -195,6 +195,31 @@ public:
   _IGNORE(g_variant_get_string, g_variant_dup_string)
 };
 
+/** Specialization of Glib::Variant containing a std::string.
+ * @newin{2,28}
+ * @ingroup glibmmVariant
+ */
+template <>
+class Variant<std::string> : public VariantBase
+{
+public:
+  typedef char* CType;
+
+  Variant<std::string>()
+  : VariantBase()
+  {}
+
+  explicit Variant<std::string>(GVariant* castitem)
+  : VariantBase(castitem)
+  {}
+
+  static const GVariantType* variant_type() G_GNUC_CONST;
+  static Variant<std::string> create(const std::string& data);
+
+  std::string get() const;
+  _IGNORE(g_variant_get_bytestring, g_variant_dup_bytestring)
+};
+
 } // namespace Glib
 
 



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