diff options
author | Kjell Ahlstedt <kjellahlstedt@gmail.com> | 2019-03-18 16:33:11 +0100 |
---|---|---|
committer | Kjell Ahlstedt <kjellahlstedt@gmail.com> | 2019-03-18 16:33:11 +0100 |
commit | 68c3e73996ee747c5ca777d67a87b1781d33f236 (patch) | |
tree | 38559519e0de2beda0c1da50ad48fe8d291aff3d | |
parent | 2b96b961c36e4db7d731d580f24512abe064bdbc (diff) | |
download | glibmm-68c3e73996ee747c5ca777d67a87b1781d33f236.tar.gz |
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.
-rw-r--r-- | glib/glibmm/value.cc | 39 | ||||
-rw-r--r-- | glib/glibmm/value.h | 31 |
2 files changed, 70 insertions, 0 deletions
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 <glibmm/value.h> #include <glibmm/objectbase.h> #include <glibmm/utility.h> +#include <glibmm/vectorutils.h> #include <glibmm/wrap.h> #include <cstring> // std::memset() @@ -324,4 +325,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 0ab4407a..688e773d 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 { @@ -320,6 +321,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 */ |