ekiga r5938 - in trunk: . lib/engine/framework lib/engine/presence/local-roster
- From: jpuydt svn gnome org
- To: svn-commits-list gnome org
- Subject: ekiga r5938 - in trunk: . lib/engine/framework lib/engine/presence/local-roster
- Date: Sat, 26 Jan 2008 13:12:11 +0000 (GMT)
Author: jpuydt
Date: Sat Jan 26 13:12:11 2008
New Revision: 5938
URL: http://svn.gnome.org/viewvc/ekiga?rev=5938&view=rev
Log:
Simplified the Lister -- small size gain
Added:
trunk/lib/engine/framework/ptr_array.h
trunk/lib/engine/framework/ptr_array_const_iterator.h
trunk/lib/engine/framework/ptr_array_iterator.h
Removed:
trunk/lib/engine/framework/map-key-const-reference-iterator.h
trunk/lib/engine/framework/map-key-reference-iterator.h
Modified:
trunk/ChangeLog
trunk/lib/engine/framework/lister.h
trunk/lib/engine/presence/local-roster/local-heap.cpp
Modified: trunk/lib/engine/framework/lister.h
==============================================================================
--- trunk/lib/engine/framework/lister.h (original)
+++ trunk/lib/engine/framework/lister.h Sat Jan 26 13:12:11 2008
@@ -38,8 +38,9 @@
#include <sigc++/sigc++.h>
-#include "map-key-reference-iterator.h"
-#include "map-key-const-reference-iterator.h"
+#include "ptr_array.h"
+#include "ptr_array_iterator.h"
+#include "ptr_array_const_iterator.h"
namespace Ekiga
{
@@ -69,9 +70,14 @@
public:
- typedef std::list<sigc::connection> connection_set;
- typedef MapKeyReferenceIterator<ObjectType, connection_set> iterator;
- typedef MapKeyConstReferenceIterator<ObjectType, connection_set> const_iterator;
+ typedef Ekiga::ptr_array<ObjectType> container_type;
+ typedef typename Ekiga::ptr_array_iterator<ObjectType> iterator;
+ typedef typename Ekiga::ptr_array_const_iterator<ObjectType> const_iterator;
+
+
+ /** The constructor.
+ */
+ Lister ();
/** The destructor.
@@ -124,13 +130,6 @@
void remove_object (ObjectType &object);
- /** Adds a connection to an object to the Ekiga::Lister, so that when
- * said object is removed, all connections to it are correctly severed.
- * @param: The object to which the connection is linked.
- */
- void add_connection (ObjectType &object,
- sigc::connection conn);
-
/** Signals emitted by this object
*
*/
@@ -164,25 +163,36 @@
*/
void on_object_removed (ObjectType *object);
- /** Map of objects and signals.
+ /** Object store.
*/
- std::map<ObjectType *, connection_set> connections;
+ container_type objects;
+
+ /** Are we shutting done, hence not reacting to our objects saying goodbye?
+ */
+ bool shutting_down;
};
};
/* here begins the code from the template functions */
+template<typename ObjectType>
+Ekiga::Lister<ObjectType>::Lister (): shutting_down(false)
+{
+}
+
template<typename ObjectType>
Ekiga::Lister<ObjectType>::~Lister ()
{
- iterator iter = begin ();
+ shutting_down = true;
- while (iter != end ()) {
+ for (unsigned int ii = 0;
+ ii < objects.size ();
+ ii++) {
- remove_object (*iter); // here iter becomes invalid
- iter = begin ();
+ ObjectType *obj = objects[ii];
+ obj->removed.emit ();
}
}
@@ -191,8 +201,8 @@
void
Ekiga::Lister<ObjectType>::visit_objects (sigc::slot<void, ObjectType &> visitor)
{
- for (iterator iter = begin (); iter != end (); iter++)
- visitor (*iter);
+ for (unsigned int ii = 0; ii < objects.size (); ii++)
+ visitor (*objects[ii]);
}
@@ -200,7 +210,7 @@
typename Ekiga::Lister<ObjectType>::const_iterator
Ekiga::Lister<ObjectType>::begin () const
{
- return const_iterator (connections.begin ());
+ return const_iterator (objects);
}
@@ -208,7 +218,7 @@
typename Ekiga::Lister<ObjectType>::iterator
Ekiga::Lister<ObjectType>::begin ()
{
- return iterator (connections.begin ());
+ return iterator (objects);
}
@@ -216,7 +226,7 @@
typename Ekiga::Lister<ObjectType>::const_iterator
Ekiga::Lister<ObjectType>::end () const
{
- return const_iterator (connections.end ());
+ return const_iterator (objects, objects.size ());
}
@@ -224,7 +234,7 @@
typename Ekiga::Lister<ObjectType>::iterator
Ekiga::Lister<ObjectType>::end ()
{
- return iterator (connections.end ());
+ return iterator (objects, objects.size ());
}
@@ -232,12 +242,9 @@
void
Ekiga::Lister<ObjectType>::add_object (ObjectType &object)
{
- sigc::connection conn;
-
- conn = object.removed.connect (sigc::bind (sigc::mem_fun (this, &Lister::on_object_removed), &object));
- add_connection (object, conn);
- conn = object.updated.connect (sigc::bind (sigc::mem_fun (this, &Lister::on_object_updated), &object));
- add_connection (object, conn);
+ object.removed.connect (sigc::bind (sigc::mem_fun (this, &Lister::on_object_removed), &object));
+ object.updated.connect (sigc::bind (sigc::mem_fun (this, &Lister::on_object_updated), &object));
+ objects.add (&object);
object_added.emit (object);
}
@@ -247,28 +254,14 @@
Ekiga::Lister<ObjectType>::remove_object (ObjectType &object)
{
common_removal_steps (object);
- object.removed.emit ();
- delete &object;
-}
-
-template<typename ObjectType>
-void
-Ekiga::Lister<ObjectType>::add_connection (ObjectType &object, sigc::connection conn)
-{
- connections[&object].push_front (conn);
}
template<typename ObjectType>
void
Ekiga::Lister<ObjectType>::common_removal_steps (ObjectType &object)
{
- connection_set conns = connections[&object];
- for (connection_set::iterator iter = conns.begin ();
- iter != conns.end ();
- iter++)
- iter->disconnect ();
- connections.erase (&object);
object_removed.emit (object);
+ objects.remove (&object);
}
@@ -284,8 +277,8 @@
void
Ekiga::Lister<ObjectType>::on_object_removed (ObjectType *object)
{
- common_removal_steps (*object);
- delete object;
+ if ( !shutting_down)
+ common_removal_steps (*object);
}
#endif
Added: trunk/lib/engine/framework/ptr_array.h
==============================================================================
--- (empty file)
+++ trunk/lib/engine/framework/ptr_array.h Sat Jan 26 13:12:11 2008
@@ -0,0 +1,147 @@
+
+/*
+ * Ekiga -- A VoIP and Video-Conferencing application
+ * Copyright (C) 2000-2008 Damien Sandras
+
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version. This program is distributed in the hope
+ * that it will be useful, but WITHOUT ANY WARRANTY; without even the
+ * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Ekiga is licensed under the GPL license and as a special exception, you
+ * have permission to link or otherwise combine this program with the
+ * programs OPAL, OpenH323 and PWLIB, and distribute the combination, without
+ * applying the requirements of the GNU GPL to the OPAL, OpenH323 and PWLIB
+ * programs, as long as you do follow the requirements of the GNU GPL for all
+ * the rest of the software thus combined.
+ */
+
+
+/*
+ * ptr_array.h - description
+ * ------------------------------------------
+ * begin : written in 2008 by Julien Puydt
+ * copyright : (c) 2008 by Julien Puydt
+ * description : implementation of an array container for pointers
+ *
+ */
+
+#ifndef __PTR_ARRAY_H__
+#define __PTR_ARRAY_H__ 1
+
+namespace Ekiga
+{
+
+ template<typename ObjectType>
+ class ptr_array
+ {
+ public:
+
+ ptr_array();
+
+ ~ptr_array();
+
+ void add (ObjectType* obj);
+
+ void remove (unsigned int pos);
+
+ void remove (ObjectType* obj);
+
+ unsigned int size () const;
+
+ ObjectType* operator[](unsigned int pos) const;
+
+ private:
+
+ unsigned int reserved_size;
+ unsigned int used_size;
+ ObjectType **store;
+ };
+
+};
+
+template<typename ObjectType>
+Ekiga::ptr_array<ObjectType>::ptr_array ()
+{
+ reserved_size = 10;
+ used_size = 0;
+ store = new ObjectType*[reserved_size];
+}
+
+template<typename ObjectType>
+Ekiga::ptr_array<ObjectType>::~ptr_array ()
+{
+ for (unsigned int ii = 0; ii < used_size; ii++)
+ delete store[ii];
+ delete [] store;
+}
+
+template<typename ObjectType>
+void
+Ekiga::ptr_array<ObjectType>::add (ObjectType* obj)
+{
+ if (used_size >= reserved_size) {
+
+ ObjectType** new_store = new ObjectType*[reserved_size + 10];
+ for (unsigned int ii = 0 ; ii < used_size ; ii++)
+ new_store[ii] = store[ii];
+ reserved_size += 10;
+ delete [] store;
+ store = new_store;
+ }
+
+ store[used_size] = obj;
+ used_size++;
+}
+
+template<typename ObjectType>
+void
+Ekiga::ptr_array<ObjectType>::remove (unsigned int pos)
+{
+ if (pos < used_size) {
+
+ delete store[pos];
+ for (unsigned int jj = pos; jj < used_size - 1; jj++)
+ store[jj] = store[jj+1];
+ used_size--;
+ }
+}
+
+template<typename ObjectType>
+void
+Ekiga::ptr_array<ObjectType>::remove (ObjectType* obj)
+{
+ unsigned int ii;
+
+ for (ii = 0; ii < used_size; ii++)
+ if (store[ii] == obj)
+ break;
+
+ remove (ii);
+}
+
+template<typename ObjectType>
+unsigned int
+Ekiga::ptr_array<ObjectType>::size () const
+{
+ return used_size;
+}
+
+template<typename ObjectType>
+ObjectType*
+Ekiga::ptr_array<ObjectType>::operator[](unsigned int pos) const
+{
+ if (pos < used_size)
+ return store[pos];
+ else
+ return 0;
+}
+
+#endif
Added: trunk/lib/engine/framework/ptr_array_const_iterator.h
==============================================================================
--- (empty file)
+++ trunk/lib/engine/framework/ptr_array_const_iterator.h Sat Jan 26 13:12:11 2008
@@ -0,0 +1,155 @@
+
+/*
+ * Ekiga -- A VoIP and Video-Conferencing application
+ * Copyright (C) 2000-2008 Damien Sandras
+
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version. This program is distributed in the hope
+ * that it will be useful, but WITHOUT ANY WARRANTY; without even the
+ * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Ekiga is licensed under the GPL license and as a special exception, you
+ * have permission to link or otherwise combine this program with the
+ * programs OPAL, OpenH323 and PWLIB, and distribute the combination, without
+ * applying the requirements of the GNU GPL to the OPAL, OpenH323 and PWLIB
+ * programs, as long as you do follow the requirements of the GNU GPL for all
+ * the rest of the software thus combined.
+ */
+
+
+/*
+ * ptr_array_const_iterator.h - description
+ * ------------------------------------------
+ * begin : written in 2008 by Julien Puydt
+ * copyright : (c) 2008 by Julien Puydt
+ * description : implementation of const_iterator for ptr_array
+ *
+ */
+
+#ifndef __ARRAY_CONST_ITERATOR_H__
+#define __ARRAY_CONST_ITERATOR_H__ 1
+
+#include <iterator>
+
+#include "ptr_array.h"
+
+namespace Ekiga
+{
+
+ template<typename ObjectType>
+ class ptr_array_const_iterator: public std::forward_iterator_tag
+ {
+ public:
+
+ ptr_array_const_iterator (const ptr_array<ObjectType>& arr_,
+ unsigned int pos_ = 0);
+
+ ptr_array_const_iterator& operator= (const ptr_array_const_iterator &other);
+
+ bool operator== (const ptr_array_const_iterator &other);
+
+ bool operator!= (const ptr_array_const_iterator &other);
+
+ ptr_array_const_iterator &operator++ ();
+
+ ptr_array_const_iterator operator++(int);
+
+ const ObjectType& operator* ();
+
+ const ObjectType* operator-> ();
+
+ bool is_valid () const;
+
+ void set_position (unsigned int pos_);
+
+ private:
+
+ const ptr_array<ObjectType>* arr;
+ unsigned int pos;
+ };
+
+};
+
+template<typename ObjectType>
+Ekiga::ptr_array_const_iterator<ObjectType>::ptr_array_const_iterator (const ptr_array<ObjectType>& arr_, unsigned int pos_)
+ : arr(&arr_), pos(pos_)
+{
+}
+
+template<typename ObjectType>
+Ekiga::ptr_array_const_iterator<ObjectType>&
+Ekiga::ptr_array_const_iterator<ObjectType>::operator= (const ptr_array_const_iterator<ObjectType> &other)
+{
+ arr = other.arr;
+ pos = other.pos;
+ return *this;
+}
+
+
+template<typename ObjectType>
+bool
+Ekiga::ptr_array_const_iterator<ObjectType>::operator== (const ptr_array_const_iterator<ObjectType> &other)
+{
+ return (arr == other.arr && pos == other.pos);
+}
+
+template<typename ObjectType>
+bool
+Ekiga::ptr_array_const_iterator<ObjectType>::operator!= (const ptr_array_const_iterator<ObjectType> &other)
+{
+ return !(arr == other.arr && pos == other.pos);
+}
+
+template<typename ObjectType>
+Ekiga::ptr_array_const_iterator<ObjectType>&
+Ekiga::ptr_array_const_iterator<ObjectType>::operator++ ()
+{
+ pos++;
+ return *this;
+}
+
+template<typename ObjectType>
+Ekiga::ptr_array_const_iterator<ObjectType>
+Ekiga::ptr_array_const_iterator<ObjectType>::operator++(int)
+{
+ ptr_array_const_iterator<ObjectType> tmp = *this;
+ pos++;
+ return tmp;
+}
+
+template<typename ObjectType>
+const ObjectType&
+Ekiga::ptr_array_const_iterator<ObjectType>::operator* ()
+{
+ return *(*arr)[pos];
+}
+
+template<typename ObjectType>
+const ObjectType*
+Ekiga::ptr_array_const_iterator<ObjectType>::operator-> ()
+{
+ return (*arr)[pos];
+}
+
+template<typename ObjectType>
+bool
+Ekiga::ptr_array_const_iterator<ObjectType>::is_valid () const
+{
+ return (pos < arr->size());
+}
+
+template<typename ObjectType>
+void
+Ekiga::ptr_array_const_iterator<ObjectType>::set_position (unsigned int pos_)
+{
+ pos = pos_;
+}
+
+#endif
Added: trunk/lib/engine/framework/ptr_array_iterator.h
==============================================================================
--- (empty file)
+++ trunk/lib/engine/framework/ptr_array_iterator.h Sat Jan 26 13:12:11 2008
@@ -0,0 +1,155 @@
+
+/*
+ * Ekiga -- A VoIP and Video-Conferencing application
+ * Copyright (C) 2000-2008 Damien Sandras
+
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version. This program is distributed in the hope
+ * that it will be useful, but WITHOUT ANY WARRANTY; without even the
+ * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Ekiga is licensed under the GPL license and as a special exception, you
+ * have permission to link or otherwise combine this program with the
+ * programs OPAL, OpenH323 and PWLIB, and distribute the combination, without
+ * applying the requirements of the GNU GPL to the OPAL, OpenH323 and PWLIB
+ * programs, as long as you do follow the requirements of the GNU GPL for all
+ * the rest of the software thus combined.
+ */
+
+
+/*
+ * ptr_array_iterator.h - description
+ * ------------------------------------------
+ * begin : written in 2008 by Julien Puydt
+ * copyright : (c) 2008 by Julien Puydt
+ * description : implementation of iterator for ptr_array
+ *
+ */
+
+#ifndef __PTR_ARRAY_ITERATOR_H__
+#define __PTR_ARRAY_ITERATOR_H__ 1
+
+#include <iterator>
+
+#include "ptr_array.h"
+
+namespace Ekiga
+{
+
+ template<typename ObjectType>
+ class ptr_array_iterator: public std::forward_iterator_tag
+ {
+ public:
+
+ ptr_array_iterator (ptr_array<ObjectType>& arr_,
+ unsigned int pos_ = 0);
+
+ ptr_array_iterator& operator= (const ptr_array_iterator &other);
+
+ bool operator== (const ptr_array_iterator &other);
+
+ bool operator!= (const ptr_array_iterator &other);
+
+ ptr_array_iterator &operator++ ();
+
+ ptr_array_iterator operator++(int);
+
+ ObjectType& operator* ();
+
+ ObjectType* operator-> ();
+
+ bool is_valid () const;
+
+ void set_position (unsigned int pos_);
+
+ private:
+
+ ptr_array<ObjectType>* arr;
+ unsigned int pos;
+ };
+
+};
+
+template<typename ObjectType>
+Ekiga::ptr_array_iterator<ObjectType>::ptr_array_iterator (ptr_array<ObjectType>& arr_, unsigned int pos_)
+ : arr(&arr_), pos(pos_)
+{
+}
+
+template<typename ObjectType>
+Ekiga::ptr_array_iterator<ObjectType>&
+Ekiga::ptr_array_iterator<ObjectType>::operator= (const ptr_array_iterator<ObjectType> &other)
+{
+ arr = other.arr;
+ pos = other.pos;
+ return *this;
+}
+
+
+template<typename ObjectType>
+bool
+Ekiga::ptr_array_iterator<ObjectType>::operator== (const ptr_array_iterator<ObjectType> &other)
+{
+ return (arr == other.arr && pos == other.pos);
+}
+
+template<typename ObjectType>
+bool
+Ekiga::ptr_array_iterator<ObjectType>::operator!= (const ptr_array_iterator<ObjectType> &other)
+{
+ return !(arr == other.arr && pos == other.pos);
+}
+
+template<typename ObjectType>
+Ekiga::ptr_array_iterator<ObjectType>&
+Ekiga::ptr_array_iterator<ObjectType>::operator++ ()
+{
+ pos++;
+ return *this;
+}
+
+template<typename ObjectType>
+Ekiga::ptr_array_iterator<ObjectType>
+Ekiga::ptr_array_iterator<ObjectType>::operator++(int)
+{
+ ptr_array_iterator<ObjectType> tmp = *this;
+ pos++;
+ return tmp;
+}
+
+template<typename ObjectType>
+ObjectType&
+Ekiga::ptr_array_iterator<ObjectType>::operator* ()
+{
+ return *(*arr)[pos];
+}
+
+template<typename ObjectType>
+ObjectType*
+Ekiga::ptr_array_iterator<ObjectType>::operator-> ()
+{
+ return (*arr)[pos];
+}
+
+template<typename ObjectType>
+bool
+Ekiga::ptr_array_iterator<ObjectType>::is_valid () const
+{
+ return (pos < arr->size());
+}
+
+template<typename ObjectType>
+void
+Ekiga::ptr_array_iterator<ObjectType>::set_position (unsigned int pos_)
+{
+ pos = pos_;
+}
+
+#endif
Modified: trunk/lib/engine/presence/local-roster/local-heap.cpp
==============================================================================
--- trunk/lib/engine/presence/local-roster/local-heap.cpp (original)
+++ trunk/lib/engine/presence/local-roster/local-heap.cpp Sat Jan 26 13:12:11 2008
@@ -225,8 +225,7 @@
presence_core->fetch_presence (presentity.get_uri ());
// Connect the Local::Presentity signals.
- sigc::connection conn = presentity.trigger_saving.connect (sigc::mem_fun (this, &Local::Heap::save));
- add_connection (presentity, conn);
+ presentity.trigger_saving.connect (sigc::mem_fun (this, &Local::Heap::save));
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]