Nux

Merge lp:~loic.molinari/nux/nux-sigc-trackable-base-class into lp:nux

Proposed by Loïc Molinari
Status: Merged
Merged at revision: 194
Proposed branch: lp:~loic.molinari/nux/nux-sigc-trackable-base-class
Merge into: lp:nux
Diff against target: 226 lines (+36/-16)
10 files modified
Nux/Area.cpp (+0/-1)
Nux/Area.h (+1/-7)
Nux/InputArea.h (+1/-1)
Nux/RadioButtonGroup.h (+1/-1)
Nux/View.h (+1/-1)
NuxCore/Object.cpp (+1/-1)
NuxCore/Object.h (+7/-1)
NuxCore/nux-core.pc.in (+1/-1)
configure.ac (+4/-1)
tests/test-object.cpp (+19/-1)
To merge this branch: bzr merge lp:~loic.molinari/nux/nux-sigc-trackable-base-class
Reviewer Review Type Date Requested Status
Jay Taoko (community) Approve
Review via email: mp+47779@code.launchpad.net

Description of the change

This branch makes nux::Trackable inherit from sigc::trackable which allows users to easily define new signal all along the class hierarchy. Based on that, it adds a new OnDestroyed signal in the nux::Trackable class that's implemented by nux::Object.

Fixes lp:703054 and invalidates lp:706891.

To post a comment you must log in.
Revision history for this message
Jay Taoko (jaytaoko) wrote :

Approved

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'Nux/Area.cpp'
--- Nux/Area.cpp 2011-01-16 23:25:28 +0000
+++ Nux/Area.cpp 2011-01-28 10:08:16 +0000
@@ -47,7 +47,6 @@
4747
48 Area::~Area()48 Area::~Area()
49 {49 {
50 OnDelete.emit (this);
51 }50 }
5251
53 const NString &Area::GetBaseString() const52 const NString &Area::GetBaseString() const
5453
=== modified file 'Nux/Area.h'
--- Nux/Area.h 2011-01-19 04:39:26 +0000
+++ Nux/Area.h 2011-01-28 10:08:16 +0000
@@ -23,11 +23,6 @@
23#ifndef BASEOBJECT_H23#ifndef BASEOBJECT_H
24#define BASEOBJECT_H24#define BASEOBJECT_H
2525
26#include <sigc++/trackable.h>
27#include <sigc++/signal.h>
28#include <sigc++/functors/ptr_fun.h>
29#include <sigc++/functors/mem_fun.h>
30
31#include "NuxCore/InitiallyUnownedObject.h"26#include "NuxCore/InitiallyUnownedObject.h"
3227
33#include "Utils.h"28#include "Utils.h"
@@ -125,7 +120,7 @@
125 class Area;120 class Area;
126121
127122
128 class Area: public InitiallyUnownedObject, public sigc::trackable123 class Area: public InitiallyUnownedObject
129 {124 {
130 public:125 public:
131 NUX_DECLARE_OBJECT_TYPE (Area, InitiallyUnownedObject);126 NUX_DECLARE_OBJECT_TYPE (Area, InitiallyUnownedObject);
@@ -374,7 +369,6 @@
374 outofbound = b;369 outofbound = b;
375 }370 }
376371
377 sigc::signal<void, Area*> OnDelete; //!< Signal emitted when an area is destroyed.
378 sigc::signal<void, int, int, int, int> OnResize; //!< Signal emitted when an area is resized.372 sigc::signal<void, int, int, int, int> OnResize; //!< Signal emitted when an area is resized.
379373
380 unsigned int m_stretchfactor;374 unsigned int m_stretchfactor;
381375
=== modified file 'Nux/InputArea.h'
--- Nux/InputArea.h 2011-01-26 06:08:18 +0000
+++ Nux/InputArea.h 2011-01-28 10:08:16 +0000
@@ -45,7 +45,7 @@
45 class InputArea;45 class InputArea;
46 typedef InputArea CoreArea;46 typedef InputArea CoreArea;
4747
48 class InputArea : public Area //public sigc::trackable48 class InputArea : public Area
49 {49 {
50 public:50 public:
51 NUX_DECLARE_OBJECT_TYPE (InputArea, Area);51 NUX_DECLARE_OBJECT_TYPE (InputArea, Area);
5252
=== modified file 'Nux/RadioButtonGroup.h'
--- Nux/RadioButtonGroup.h 2010-12-06 06:09:44 +0000
+++ Nux/RadioButtonGroup.h 2011-01-28 10:08:16 +0000
@@ -32,7 +32,7 @@
32 /*!32 /*!
33 RadioButtonGroup does not hold reference on radio buttons.33 RadioButtonGroup does not hold reference on radio buttons.
34 */34 */
35 class RadioButtonGroup: public Object, public sigc::trackable35 class RadioButtonGroup: public Object
36 {36 {
37 public:37 public:
38 RadioButtonGroup (NUX_FILE_LINE_PROTO);38 RadioButtonGroup (NUX_FILE_LINE_PROTO);
3939
=== modified file 'Nux/View.h'
--- Nux/View.h 2011-01-19 04:39:26 +0000
+++ Nux/View.h 2011-01-28 10:08:16 +0000
@@ -38,7 +38,7 @@
38 ePopupBox38 ePopupBox
39 };39 };
4040
41 class View: public InputArea //Area //public sigc::trackable41 class View: public InputArea //Area
42 {42 {
43 NUX_DECLARE_OBJECT_TYPE (View, InputArea);43 NUX_DECLARE_OBJECT_TYPE (View, InputArea);
44 public:44 public:
4545
=== modified file 'NuxCore/Object.cpp'
--- NuxCore/Object.cpp 2011-01-06 06:43:42 +0000
+++ NuxCore/Object.cpp 2011-01-28 10:08:16 +0000
@@ -80,7 +80,6 @@
8080
81 Trackable::~Trackable()81 Trackable::~Trackable()
82 {82 {
83
84 }83 }
8584
86 bool Trackable::Reference()85 bool Trackable::Reference()
@@ -420,6 +419,7 @@
420 //nuxDebugMsg (TEXT("[Object::Destroy] There are weak references pending on this object. This is OK!"));419 //nuxDebugMsg (TEXT("[Object::Destroy] There are weak references pending on this object. This is OK!"));
421 }420 }
422421
422 OnDestroyed.emit ();
423 delete this;423 delete this;
424 }424 }
425425
426426
=== modified file 'NuxCore/Object.h'
--- NuxCore/Object.h 2010-12-12 20:46:29 +0000
+++ NuxCore/Object.h 2011-01-28 10:08:16 +0000
@@ -23,6 +23,9 @@
23#ifndef NUXOBJECT_H23#ifndef NUXOBJECT_H
24#define NUXOBJECT_H24#define NUXOBJECT_H
2525
26#include <sigc++/trackable.h>
27#include <sigc++/signal.h>
28
26namespace nux29namespace nux
27{30{
2831
@@ -66,7 +69,7 @@
66 Trackable does not implement reference counting. It only defines the API. It is up69 Trackable does not implement reference counting. It only defines the API. It is up
67 to the class that inherit from Trackable to implement the reference counting.70 to the class that inherit from Trackable to implement the reference counting.
68 */71 */
69 class Trackable72 class Trackable : public sigc::trackable
70 {73 {
71 public:74 public:
72 NUX_DECLARE_ROOT_OBJECT_TYPE (Trackable);75 NUX_DECLARE_ROOT_OBJECT_TYPE (Trackable);
@@ -88,6 +91,9 @@
88 */91 */
89 bool IsDynamic() const;92 bool IsDynamic() const;
9093
94 //! Signal emitted immediately before the object is destroyed.
95 sigc::signal<void> OnDestroyed;
96
91 //! Increase the reference count.97 //! Increase the reference count.
92 /*98 /*
93 Widget are typically created and added to containers. It is decided that when widgets are created, they should have a floating reference99 Widget are typically created and added to containers. It is decided that when widgets are created, they should have a floating reference
94100
=== modified file 'NuxCore/nux-core.pc.in'
--- NuxCore/nux-core.pc.in 2010-09-01 19:40:43 +0000
+++ NuxCore/nux-core.pc.in 2011-01-28 10:08:16 +0000
@@ -8,4 +8,4 @@
8Version: @VERSION@8Version: @VERSION@
9Libs: -L${libdir} -lnux-core-@NUX_API_VERSION@9Libs: -L${libdir} -lnux-core-@NUX_API_VERSION@
10Cflags: -I${includedir}/Nux-@NUX_API_VERSION@10Cflags: -I${includedir}/Nux-@NUX_API_VERSION@
11Requires: glib-2.011Requires: glib-2.0 sigc++-2.0
1212
=== modified file 'configure.ac'
--- configure.ac 2011-01-27 11:44:31 +0000
+++ configure.ac 2011-01-28 10:08:16 +0000
@@ -109,7 +109,7 @@
109109
110dnl ===========================================================================110dnl ===========================================================================
111111
112PKG_CHECK_MODULES(NUX_CORE, glib-2.0 >= 2.25.14 gthread-2.0)112PKG_CHECK_MODULES(NUX_CORE, glib-2.0 >= 2.25.14 gthread-2.0 sigc++-2.0)
113AC_SUBST(NUX_CORE_CFLAGS)113AC_SUBST(NUX_CORE_CFLAGS)
114AC_SUBST(NUX_CORE_LIBS)114AC_SUBST(NUX_CORE_LIBS)
115115
@@ -118,6 +118,7 @@
118 gdk-pixbuf-2.0118 gdk-pixbuf-2.0
119 cairo >= 1.9.14119 cairo >= 1.9.14
120 libpng >= 1.2.44120 libpng >= 1.2.44
121 sigc++-2.0
121 )122 )
122AC_SUBST(NUX_IMAGE_CFLAGS)123AC_SUBST(NUX_IMAGE_CFLAGS)
123AC_SUBST(NUX_IMAGE_LIBS)124AC_SUBST(NUX_IMAGE_LIBS)
@@ -127,6 +128,7 @@
127 gdk-pixbuf-2.0128 gdk-pixbuf-2.0
128 glew129 glew
129 glewmx130 glewmx
131 sigc++-2.0
130 )132 )
131AC_SUBST(NUX_MESH_CFLAGS)133AC_SUBST(NUX_MESH_CFLAGS)
132AC_SUBST(NUX_MESH_LIBS)134AC_SUBST(NUX_MESH_LIBS)
@@ -138,6 +140,7 @@
138 glew140 glew
139 glewmx141 glewmx
140 xxf86vm142 xxf86vm
143 sigc++-2.0
141 )144 )
142AC_SUBST(NUX_GRAPHICS_CFLAGS)145AC_SUBST(NUX_GRAPHICS_CFLAGS)
143AC_SUBST(NUX_GRAPHICS_LIBS)146AC_SUBST(NUX_GRAPHICS_LIBS)
144147
=== modified file 'tests/test-object.cpp'
--- tests/test-object.cpp 2010-12-19 02:57:54 +0000
+++ tests/test-object.cpp 2011-01-28 10:08:16 +0000
@@ -28,6 +28,7 @@
28static void TestObjectPtr (void);28static void TestObjectPtr (void);
29static void TestObjectPtr1 (void);29static void TestObjectPtr1 (void);
30static void TestObjectPtr2 (void);30static void TestObjectPtr2 (void);
31static void TestObjectSignal (void);
3132
32void33void
33TestObjectSuite (void)34TestObjectSuite (void)
@@ -39,6 +40,7 @@
39 g_test_add_func (TESTDOMAIN"/TestObjectPtr", TestObjectPtr);40 g_test_add_func (TESTDOMAIN"/TestObjectPtr", TestObjectPtr);
40 g_test_add_func (TESTDOMAIN"/TestObjectPtr1", TestObjectPtr1);41 g_test_add_func (TESTDOMAIN"/TestObjectPtr1", TestObjectPtr1);
41 g_test_add_func (TESTDOMAIN"/TestObjectPtr2", TestObjectPtr2);42 g_test_add_func (TESTDOMAIN"/TestObjectPtr2", TestObjectPtr2);
43 g_test_add_func (TESTDOMAIN"/TestObjectSignal", TestObjectSignal);
42}44}
4345
44static const int ARRAY_SIZE = 1000;46static const int ARRAY_SIZE = 1000;
@@ -224,4 +226,20 @@
224226
225 g_assert (object_ptr2.GetWeakReferenceCount () == 1);227 g_assert (object_ptr2.GetWeakReferenceCount () == 1);
226 g_assert (object_ptr2.Release () == true);228 g_assert (object_ptr2.Release () == true);
227}
228\ No newline at end of file229\ No newline at end of file
230}
231
232static bool g_signal_called = false;
233
234static void on_destroyed_cb () {
235 g_signal_called = true;
236}
237
238static void
239TestObjectSignal (void)
240{
241 nux::Object *obj = new nux::Object ();
242 obj->OnDestroyed.connect (sigc::ptr_fun (on_destroyed_cb));
243 g_assert (g_signal_called == false);
244 obj->UnReference ();
245 g_assert (g_signal_called == true);
246}

Subscribers

People subscribed via source and target branches