diff options
author | Kjell Ahlstedt <kjellahlstedt@gmail.com> | 2019-01-20 16:29:30 +0100 |
---|---|---|
committer | Kjell Ahlstedt <kjellahlstedt@gmail.com> | 2019-01-20 16:29:30 +0100 |
commit | 9d894e30007c54622c73ed7619c3d868e3351b35 (patch) | |
tree | e212e6a7829750e9c05bd542bcd65be010a3ea5f | |
parent | 1078af3089d3807874d1d9e095eae5279078ea63 (diff) | |
download | glibmm-9d894e30007c54622c73ed7619c3d868e3351b35.tar.gz |
Glib::Value: Add ValueBase_Variant
Nice to have as a base class for Value<VariantBase> and possibly for future
Glib::Value specializations.
-rw-r--r-- | glib/glibmm/value.cc | 29 | ||||
-rw-r--r-- | glib/glibmm/value.h | 21 | ||||
-rw-r--r-- | glib/src/variant.ccg | 21 | ||||
-rw-r--r-- | glib/src/variant.hg | 14 |
4 files changed, 54 insertions, 31 deletions
diff --git a/glib/glibmm/value.cc b/glib/glibmm/value.cc index 75685fda..d111b184 100644 --- a/glib/glibmm/value.cc +++ b/glib/glibmm/value.cc @@ -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 diff --git a/glib/glibmm/value.h b/glib/glibmm/value.h index 6882db4c..fb504342 100644 --- a/glib/glibmm/value.h +++ b/glib/glibmm/value.h @@ -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> diff --git a/glib/src/variant.ccg b/glib/src/variant.ccg index ec3fc94a..299a9393 100644 --- a/glib/src/variant.ccg +++ b/glib/src/variant.ccg @@ -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 diff --git a/glib/src/variant.hg b/glib/src/variant.hg index be42eb83..d570dcb8 100644 --- a/glib/src/variant.hg +++ b/glib/src/variant.hg @@ -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 |