Update of /cvsroot/boost-sandbox/boost-sandbox/libs/thread_safe_signals/test
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv20359/libs/thread_safe_signals/test
Modified Files:
signal_n_test.cpp signal_test.cpp track_test.cpp
Log Message:
Made slots throw bad_weak_ptr when called with expired tracked
objects. Combiners now have to catch bad_weak_ptr exceptions
thrown on slot iterator dereference. Tracking works automatically
now for slots that call other slots.
Index: signal_test.cpp
===================================================================
RCS file: /cvsroot/boost-sandbox/boost-sandbox/libs/thread_safe_signals/test/signal_test.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- signal_test.cpp 28 Feb 2007 19:44:09 -0000 1.2
+++ signal_test.cpp 2 Mar 2007 22:04:47 -0000 1.3
@@ -7,6 +7,7 @@
// For more information, see http://www.boost.org
+#include <boost/optional.hpp>
#include <boost/test/minimal.hpp>
#include <boost/thread_safe_signal.hpp>
#include <functional>
@@ -19,14 +20,19 @@
typename InputIterator::value_type
operator()(InputIterator first, InputIterator last) const
{
- if (first == last)
- return T();
-
- T max = *first++;
+ boost::optional<T> max;
for (; first != last; ++first)
- max = (*first > max)? *first : max;
-
- return max;
+ {
+ try
+ {
+ if(max == false) max = *first;
+ else max = (*first > max.get())? *first : max;
+ }
+ catch(const boost::bad_weak_ptr &)
+ {}
+ }
+ if(max) return max.get();
+ return T();
}
};
Index: signal_n_test.cpp
===================================================================
RCS file: /cvsroot/boost-sandbox/boost-sandbox/libs/thread_safe_signals/test/signal_n_test.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- signal_n_test.cpp 28 Feb 2007 19:44:09 -0000 1.2
+++ signal_n_test.cpp 2 Mar 2007 22:04:46 -0000 1.3
@@ -7,6 +7,7 @@
// For more information, see http://www.boost.org
+#include <boost/optional.hpp>
#include <boost/test/minimal.hpp>
#include <boost/thread_safe_signal.hpp>
#include <functional>
@@ -18,14 +19,19 @@
typename InputIterator::value_type
operator()(InputIterator first, InputIterator last) const
{
- if (first == last)
- return T();
-
- T max = *first++;
+ boost::optional<T> max;
for (; first != last; ++first)
- max = (*first > max)? *first : max;
-
- return max;
+ {
+ try
+ {
+ if(max == false) max = *first;
+ else max = (*first > max.get())? *first : max;
+ }
+ catch(const boost::bad_weak_ptr &)
+ {}
+ }
+ if(max) return max.get();
+ return T();
}
};
Index: track_test.cpp
===================================================================
RCS file: /cvsroot/boost-sandbox/boost-sandbox/libs/thread_safe_signals/test/track_test.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- track_test.cpp 28 Feb 2007 17:08:12 -0000 1.5
+++ track_test.cpp 2 Mar 2007 22:04:47 -0000 1.6
@@ -77,7 +77,7 @@
boost::shared_ptr<int> shorty(new int(2));
boost::slot<int (double)> other_slot(&myfunc, boost::cref(*shorty.get()), _1);
other_slot.track(shorty);
- s1.connect(sig_type::slot_type(other_slot, 0.5).track(other_slot));
+ s1.connect(sig_type::slot_type(other_slot, 0.5));
BOOST_CHECK(s1(3) == 2);
}
BOOST_CHECK(s1(3) == 0);
|