From 68c3e73996ee747c5ca777d67a87b1781d33f236 Mon Sep 17 00:00:00 2001 From: Kjell Ahlstedt Date: Mon, 18 Mar 2019 16:33:11 +0100 Subject: Glib::Value: Add Value> specializations Add Value> and Value>. One of them is needed in _WRAP_PROPERTY("names", std::vector) 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 1c01338b..664d33c0 100644 --- a/glib/glibmm/value.cc +++ b/glib/glibmm/value.cc @@ -17,6 +17,7 @@ #include #include #include +#include #include #include // std::memset() @@ -324,4 +325,42 @@ Value::set(const Glib::ustring& data) g_value_set_string(&gobject_, data.c_str()); } +/**** Glib::Value> ********************************/ + +// static +GType Value>::value_type() +{ + return G_TYPE_STRV; +} + +void Value>::set(const CppType& data) +{ + set_boxed(Glib::ArrayHandler::vector_to_array(data).data()); +} + +std::vector Value>::get() const +{ + return Glib::ArrayHandler::array_to_vector( + static_cast(get_boxed()), Glib::OWNERSHIP_NONE); +} + +/**** Glib::Value> ********************************/ + +// static +GType Value>::value_type() +{ + return G_TYPE_STRV; +} + +void Value>::set(const CppType& data) +{ + set_boxed(Glib::ArrayHandler::vector_to_array(data).data()); +} + +std::vector Value>::get() const +{ + return Glib::ArrayHandler::array_to_vector( + static_cast(get_boxed()), Glib::OWNERSHIP_NONE); +} + } // namespace Glib diff --git a/glib/glibmm/value.h b/glib/glibmm/value.h index 0ab4407a..688e773d 100644 --- a/glib/glibmm/value.h +++ b/glib/glibmm/value.h @@ -22,6 +22,7 @@ #include #include #include +#include namespace Glib { @@ -320,6 +321,36 @@ public: Glib::ustring get() const { return get_cstring(); } }; +/** Specialization for vectors of strings. + * @ingroup glibmmValue + */ +template <> +class Value> : public ValueBase_Boxed +{ +public: + using CppType = std::vector; + + static GType value_type(); + + void set(const CppType& data); + CppType get() const; +}; + +/** Specialization for vectors of UTF-8 strings. + * @ingroup glibmmValue + */ +template <> +class Value> : public ValueBase_Boxed +{ +public: + using CppType = std::vector; + + static GType value_type(); + + void set(const CppType& data); + CppType get() const; +}; + /** Base class of Glib::Value specializations for enum types. * @ingroup glibmmValue */ -- cgit v1.2.1