From 10d607afe1ade71a232f05b2d398693a4a26b964 Mon Sep 17 00:00:00 2001 From: Murray Cumming Date: Tue, 9 May 2006 12:57:26 +0000 Subject: Added init(const GValue*), so that we can copy GValue instances of any 2006-05-09 Murray Cumming * glib/glibmm/value.cc: * glib/glibmm/value.h: Added init(const GValue*), so that we can copy GValue instances of any type at runtime. Needed by libgdamm, which returns const GValue* instances. --- ChangeLog | 6 ++++++ glib/glibmm/value.cc | 8 ++++++++ glib/glibmm/value.h | 12 ++++++++++++ 3 files changed, 26 insertions(+) diff --git a/ChangeLog b/ChangeLog index 7c0f068e..b2722d9b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2006-05-09 Murray Cumming + + * glib/glibmm/value.cc: + * glib/glibmm/value.h: Added init(const GValue*), so that we can copy GValue instances + of any type at runtime. Needed by libgdamm, which returns const GValue* instances. + This is the HEAD branch, for API additions. See also the glibmm-2-10 branch. 2.10.1: diff --git a/glib/glibmm/value.cc b/glib/glibmm/value.cc index adb3e902..12ba6fc9 100644 --- a/glib/glibmm/value.cc +++ b/glib/glibmm/value.cc @@ -39,6 +39,14 @@ void ValueBase::init(GType type) g_value_init(&gobject_, type); } +void ValueBase::init(const GValue* value) +{ + g_value_init(&gobject_, G_VALUE_TYPE(value)); + + if(value) + g_value_copy(value, &gobject_); +} + ValueBase::ValueBase(const ValueBase& other) { GLIBMM_INITIALIZE_STRUCT(gobject_, GValue); diff --git a/glib/glibmm/value.h b/glib/glibmm/value.h index 94203a32..a891418c 100644 --- a/glib/glibmm/value.h +++ b/glib/glibmm/value.h @@ -69,9 +69,21 @@ public: * * init() is not implemented as constructor, to avoid the necessity * to implement a forward constructor in each derived class. + * + * @param type The type that the Value should hold. */ void init(GType type); + /** Setup the GValue storing the type and value of the specified @a value. + * Note that init() should never be called twice. + * + * init() is not implemented as constructor, to avoid the necessity + * to implement a forward constructor in each derived class. + * + * @param value The existing GValue. + */ + void init(const GValue* value); + /** Reset contents to the default value of its type. */ void reset(); -- cgit v1.2.1