[gtkmm] Gdk::TimeCoord: Make it the owner of the wrapped GdkTimeCoord
- From: Kjell Ahlstedt <kjellahl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtkmm] Gdk::TimeCoord: Make it the owner of the wrapped GdkTimeCoord
- Date: Mon, 24 Jul 2017 12:51:03 +0000 (UTC)
commit 83c499d8f936dfb71a7e3a2bb89b99a8fb7957eb
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date: Mon Jul 24 14:49:27 2017 +0200
Gdk::TimeCoord: Make it the owner of the wrapped GdkTimeCoord
Add destructor and copy operations. Add a make_a_copy parameter in the
constructor. Correct the move operations. Bug 784955
gdk/src/timecoord.ccg | 41 ++++++++++++++++++++++++++++++++++++-----
gdk/src/timecoord.hg | 7 +++++--
2 files changed, 41 insertions(+), 7 deletions(-)
---
diff --git a/gdk/src/timecoord.ccg b/gdk/src/timecoord.ccg
index 47586ef..d90b43c 100644
--- a/gdk/src/timecoord.ccg
+++ b/gdk/src/timecoord.ccg
@@ -17,27 +17,58 @@
#include <gdk/gdk.h>
+namespace
+{
+
+inline GdkTimeCoord* time_coord_copy(const GdkTimeCoord* gobject)
+{
+ // If gobject == nullptr, g_memdup() returns nullptr.
+ return static_cast<GdkTimeCoord*>(g_memdup(gobject, sizeof(GdkTimeCoord)));
+}
+
+} // anonymous namespace
+
namespace Gdk
{
-TimeCoord::TimeCoord(GdkTimeCoord* castitem)
-: gobject_(castitem)
+TimeCoord::TimeCoord(GdkTimeCoord* gobject, bool make_a_copy)
+:
+ gobject_((make_a_copy && gobject) ? time_coord_copy(gobject) : gobject)
+{}
+
+TimeCoord::TimeCoord(const TimeCoord& other)
+:
+ gobject_(time_coord_copy(other.gobject_))
{}
+TimeCoord& TimeCoord::operator=(const TimeCoord& other)
+{
+ g_free(gobject_);
+ gobject_ = time_coord_copy(other.gobject_);
+ return *this;
+}
+
TimeCoord::TimeCoord(TimeCoord&& other) noexcept
-: gobject_(std::move(other.gobject_))
+:
+ gobject_(std::move(other.gobject_))
{
+ other.gobject_ = nullptr;
}
TimeCoord& TimeCoord::operator=(TimeCoord&& other) noexcept
{
+ g_free(gobject_);
gobject_ = std::move(other.gobject_);
-
other.gobject_ = nullptr;
-
return *this;
}
+TimeCoord::~TimeCoord() noexcept
+{
+ // If gobject_ == nullptr, g_free() does nothing.
+ g_free(gobject_);
+}
+
double TimeCoord::get_value_at_axis(guint index) const
{
if (gobject_)
diff --git a/gdk/src/timecoord.hg b/gdk/src/timecoord.hg
index 6944e48..dd27b6f 100644
--- a/gdk/src/timecoord.hg
+++ b/gdk/src/timecoord.hg
@@ -29,13 +29,16 @@ class TimeCoord
{
_CLASS_GENERIC(TimeCoord, GdkTimeCoord)
public:
- explicit TimeCoord(GdkTimeCoord* castitem);
+ explicit TimeCoord(GdkTimeCoord* gobject, bool make_a_copy = true);
- //TODO: = delete the copy operations?
+ TimeCoord(const TimeCoord& other);
+ TimeCoord& operator=(const TimeCoord& other);
TimeCoord(TimeCoord&& other) noexcept;
TimeCoord& operator=(TimeCoord&& other) noexcept;
+ ~TimeCoord() noexcept;
+
_MEMBER_GET(time, time, guint32, guint32);
/** Gets value at @a index axis.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]