Commit ce5bd479 authored by Kjell Ahlstedt's avatar Kjell Ahlstedt

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.
parent 51f7915c
......@@ -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
......@@ -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
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment