Commit 9d894e30 authored by Kjell Ahlstedt's avatar Kjell Ahlstedt

Glib::Value: Add ValueBase_Variant

Nice to have as a base class for Value<VariantBase> and possibly for future
Glib::Value specializations.
parent 1078af30
......@@ -244,6 +244,35 @@ ValueBase_String::create_param_spec(const Glib::ustring& name,
get_cstring(), static_cast<GParamFlags>(flags));
}
/**** Glib::ValueBase_Variant ************************************************/
// static
GType ValueBase_Variant::value_type()
{
return G_TYPE_VARIANT;
}
void ValueBase_Variant::set_variant(GVariant* data)
{
g_value_set_variant(&gobject_, data);
}
GVariant* ValueBase_Variant::get_variant() const
{
return g_value_get_variant(&gobject_);
}
GParamSpec* ValueBase_Variant::create_param_spec(const Glib::ustring& name,
const Glib::ustring& nick, const Glib::ustring& blurb, Glib::ParamFlags flags) const
{
GVariant* gvariant = g_value_get_variant(&gobject_);
const GVariantType* gvariant_type = gvariant ? g_variant_get_type(gvariant) : G_VARIANT_TYPE_ANY;
return g_param_spec_variant(
name.c_str(), c_str_or_nullptr(nick), c_str_or_nullptr(blurb),
gvariant_type, gvariant, static_cast<GParamFlags>(flags));
}
/**** Glib::Value<std::string> *********************************************/
void
......
......@@ -184,9 +184,28 @@ protected:
const char* get_cstring() const; // never returns nullptr
};
/**
* @ingroup glibmmValue
*/
class ValueBase_Variant : public ValueBase
{
public:
static GType value_type() G_GNUC_CONST;
#ifndef DOXYGEN_SHOULD_SKIP_THIS
GParamSpec* create_param_spec(const Glib::ustring& name, const Glib::ustring& nick,
const Glib::ustring& blurb, Glib::ParamFlags flags) const;
#endif
protected:
void set_variant(GVariant* data);
GVariant* get_variant() const; // doesn't copy, may return nullptr
};
} // namespace Glib
/* Include generic Glib::Value<> template, before any specializations:
/* Include primary Glib::Value<> template, before any specializations:
*/
#define _GLIBMM_VALUE_H_INCLUDE_VALUE_CUSTOM_H
#include <glibmm/value_custom.h>
......
......@@ -694,31 +694,14 @@ Variant<type_vec_string>::get_iter() const
/*---------------------Value<Glib::VariantBase>---------------------*/
// static
GType Value<VariantBase>::value_type()
{
return G_TYPE_VARIANT;
}
void Value<VariantBase>::set(CppType data)
{
g_value_set_variant(&gobject_, data.gobj());
set_variant(data.gobj());
}
Value<VariantBase>::CppType Value<VariantBase>::get() const
{
return CppType(g_value_get_variant(&gobject_), true);
}
GParamSpec* Value<VariantBase>::create_param_spec(const Glib::ustring& name,
const Glib::ustring& nick, const Glib::ustring& blurb, Glib::ParamFlags flags) const
{
GVariant* gvariant = g_value_get_variant(&gobject_);
const GVariantType* gvariant_type = gvariant ? g_variant_get_type(gvariant) : G_VARIANT_TYPE_ANY;
return g_param_spec_variant(
name.c_str(), c_str_or_nullptr(nick), c_str_or_nullptr(blurb),
gvariant_type, gvariant, static_cast<GParamFlags>(flags));
return CppType(get_variant(), true);
}
} // namespace Glib
......@@ -1588,26 +1588,18 @@ VariantIter Variant<std::tuple<Types...>>::get_iter() const
return VariantContainerBase::get_iter(type);
}
/*---------------------Value<Glib::VariantBase>---------------------*/
#ifndef DOXYGEN_SHOULD_SKIP_THIS
// This is needed so Glib::VariantBase can be used with
// Glib::Value and _WRAP_PROPERTY in Gio::Action and elsewhere.
template <>
class Value<Glib::VariantBase> : public ValueBase
class Value<Glib::VariantBase> : public ValueBase_Variant
{
public:
using CppType = Glib::VariantBase;
using CType = GVariant*;
static GType value_type() G_GNUC_CONST;
void set(CppType data);
CppType get() const;
#ifndef DOXYGEN_SHOULD_SKIP_THIS
GParamSpec* create_param_spec(const Glib::ustring& name, const Glib::ustring& nick,
const Glib::ustring& blurb, Glib::ParamFlags flags) const;
#endif
};
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
} // namespace Glib
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