[glibmm] Glib::Value: Add Value<std::vector<string>> specializations



commit ce5bd4795f9ab7bdae2d2584cfc19d3cbf4a1ace
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date:   Sun Jan 27 18:11:51 2019 +0100

    Glib::Value: Add Value<std::vector<string>> specializations
    
    Add Value<std::vector<std::string>> and Value<std::vector<Glib::ustring>>.
    One of them is needed in _WRAP_PROPERTY("names", std::vector<Glib::ustring>)
    in Gio::ThemedIcon and in _WRAP_PROPERTYs in gtkmm.

 glib/glibmm/value.cc | 39 +++++++++++++++++++++++++++++++++++++++
 glib/glibmm/value.h  | 31 +++++++++++++++++++++++++++++++
 2 files changed, 70 insertions(+)
---
diff --git a/glib/glibmm/value.cc b/glib/glibmm/value.cc
index d111b184..6f8eee21 100644
--- a/glib/glibmm/value.cc
+++ b/glib/glibmm/value.cc
@@ -17,6 +17,7 @@
 #include <glibmm/value.h>
 #include <glibmm/objectbase.h>
 #include <glibmm/utility.h>
+#include <glibmm/vectorutils.h>
 #include <glibmm/wrap.h>
 #include <cstring> // std::memset()
 
@@ -289,4 +290,42 @@ Value<Glib::ustring>::set(const Glib::ustring& data)
   g_value_set_string(&gobject_, data.c_str());
 }
 
+/**** Glib::Value<std::vector<std::string>> ********************************/
+
+// static
+GType Value<std::vector<std::string>>::value_type()
+{
+  return G_TYPE_STRV;
+}
+
+void Value<std::vector<std::string>>::set(const CppType& data)
+{
+  set_boxed(Glib::ArrayHandler<std::string>::vector_to_array(data).data());
+}
+
+std::vector<std::string> Value<std::vector<std::string>>::get() const
+{
+  return Glib::ArrayHandler<std::string>::array_to_vector(
+    static_cast<const char* const*>(get_boxed()), Glib::OWNERSHIP_NONE);
+}
+
+/**** Glib::Value<std::vector<Glib::ustring>> ********************************/
+
+// static
+GType Value<std::vector<Glib::ustring>>::value_type()
+{
+  return G_TYPE_STRV;
+}
+
+void Value<std::vector<Glib::ustring>>::set(const CppType& data)
+{
+  set_boxed(Glib::ArrayHandler<Glib::ustring>::vector_to_array(data).data());
+}
+
+std::vector<Glib::ustring> Value<std::vector<Glib::ustring>>::get() const
+{
+  return Glib::ArrayHandler<Glib::ustring>::array_to_vector(
+    static_cast<const char* const*>(get_boxed()), Glib::OWNERSHIP_NONE);
+}
+
 } // namespace Glib
diff --git a/glib/glibmm/value.h b/glib/glibmm/value.h
index fb504342..b5a435b7 100644
--- a/glib/glibmm/value.h
+++ b/glib/glibmm/value.h
@@ -22,6 +22,7 @@
 #include <glibmm/ustring.h>
 #include <glibmm/enums.h>
 #include <glib-object.h>
+#include <vector>
 
 namespace Glib
 {
@@ -331,6 +332,36 @@ public:
   Glib::ustring get() const { return get_cstring(); }
 };
 
+/** Specialization for vectors of strings.
+ * @ingroup glibmmValue
+ */
+template <>
+class Value<std::vector<std::string>> : public ValueBase_Boxed
+{
+public:
+  using CppType = std::vector<std::string>;
+
+  static GType value_type();
+
+  void set(const CppType& data);
+  CppType get() const;
+};
+
+/** Specialization for vectors of UTF-8 strings.
+ * @ingroup glibmmValue
+ */
+template <>
+class Value<std::vector<Glib::ustring>> : public ValueBase_Boxed
+{
+public:
+  using CppType = std::vector<Glib::ustring>;
+
+  static GType value_type();
+
+  void set(const CppType& data);
+  CppType get() const;
+};
+
 /** Base class of Glib::Value<T> specializations for enum types.
  * @ingroup glibmmValue
  */


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