|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r84006 - in trunk: boost/signals2 boost/signals2/detail libs/signals2/doc/reference libs/signals2/test
From: fmhess_at_[hidden]
Date: 2013-04-21 23:22:08
Author: fmhess
Date: 2013-04-21 23:22:06 EDT (Sun, 21 Apr 2013)
New Revision: 84006
URL: http://svn.boost.org/trac/boost/changeset/84006
Log:
Added swap to signal classes. Fixes #8449
Text files modified:
trunk/boost/signals2/detail/signal_template.hpp | 14 +++++++++++
trunk/boost/signals2/preprocessed_signal.hpp | 15 ++++++++++++
trunk/libs/signals2/doc/reference/connection.xml | 2
trunk/libs/signals2/doc/reference/signal_header.xml | 39 ++++++++++++++++++++++++++++++++
trunk/libs/signals2/test/signal_n_test.cpp | 48 ++++++++++++++++++++++++++++++++++++++++
trunk/libs/signals2/test/signal_test.cpp | 20 ++++++++++++++++
6 files changed, 137 insertions(+), 1 deletions(-)
Modified: trunk/boost/signals2/detail/signal_template.hpp
==============================================================================
--- trunk/boost/signals2/detail/signal_template.hpp (original)
+++ trunk/boost/signals2/detail/signal_template.hpp 2013-04-21 23:22:06 EDT (Sun, 21 Apr 2013)
@@ -714,6 +714,11 @@
{
return (*_pimpl).set_combiner(combiner_arg);
}
+ void swap(BOOST_SIGNALS2_SIGNAL_CLASS_NAME(BOOST_SIGNALS2_NUM_ARGS) & other)
+ {
+ using std::swap;
+ swap(_pimpl, other._pimpl);
+ }
protected:
virtual shared_ptr<void> lock_pimpl() const
{
@@ -724,6 +729,15 @@
_pimpl;
};
+ // free swap function, findable by ADL
+ template<BOOST_SIGNALS2_SIGNAL_TEMPLATE_SPECIALIZATION_DECL(BOOST_SIGNALS2_NUM_ARGS)>
+ void swap(
+ BOOST_SIGNALS2_SIGNAL_CLASS_NAME(BOOST_SIGNALS2_NUM_ARGS) <BOOST_SIGNALS2_SIGNAL_TEMPLATE_INSTANTIATION> &sig1,
+ BOOST_SIGNALS2_SIGNAL_CLASS_NAME(BOOST_SIGNALS2_NUM_ARGS) <BOOST_SIGNALS2_SIGNAL_TEMPLATE_INSTANTIATION> &sig2 )
+ {
+ sig1.swap(sig2);
+ };
+
namespace detail
{
// wrapper class for storing other signals as slots with automatic lifetime tracking
Modified: trunk/boost/signals2/preprocessed_signal.hpp
==============================================================================
--- trunk/boost/signals2/preprocessed_signal.hpp (original)
+++ trunk/boost/signals2/preprocessed_signal.hpp 2013-04-21 23:22:06 EDT (Sun, 21 Apr 2013)
@@ -49,6 +49,21 @@
base_type(combiner_arg, group_compare)
{}
};
+
+ // free swap function, findable by ADL
+ template<typename Signature,
+ typename Combiner,
+ typename Group,
+ typename GroupCompare,
+ typename SlotFunction,
+ typename ExtendedSlotFunction,
+ typename Mutex>
+ void swap(
+ signal<Signature, Combiner, Group, GroupCompare, SlotFunction, ExtendedSlotFunction, Mutex> &sig1,
+ signal<Signature, Combiner, Group, GroupCompare, SlotFunction, ExtendedSlotFunction, Mutex> &sig2)
+ {
+ sig1.swap(sig2);
+ };
}
}
Modified: trunk/libs/signals2/doc/reference/connection.xml
==============================================================================
--- trunk/libs/signals2/doc/reference/connection.xml (original)
+++ trunk/libs/signals2/doc/reference/connection.xml 2013-04-21 23:22:06 EDT (Sun, 21 Apr 2013)
@@ -104,7 +104,7 @@
<method name="swap">
<type>void</type>
<parameter name="other">
- <paramtype>const <classname alt="signals2::connection">connection</classname>&</paramtype>
+ <paramtype><classname alt="signals2::connection">connection</classname>&</paramtype>
</parameter>
<effects><para>Swaps the connections referenced in
<computeroutput>this</computeroutput> and
Modified: trunk/libs/signals2/doc/reference/signal_header.xml
==============================================================================
--- trunk/libs/signals2/doc/reference/signal_header.xml (original)
+++ trunk/libs/signals2/doc/reference/signal_header.xml 2013-04-21 23:22:06 EDT (Sun, 21 Apr 2013)
@@ -397,6 +397,45 @@
<throws><para>Will not throw.</para></throws>
</method>
</method-group>
+
+ <method-group name="modifiers">
+ <method name="swap">
+ <type>void</type>
+ <parameter name="other">
+ <paramtype><classname alt="signals2::signal">signal</classname>&</paramtype>
+ </parameter>
+ <effects><para>Swaps the signal referenced in
+ <computeroutput>this</computeroutput> and
+ <computeroutput>other</computeroutput>.</para></effects>
+
+ <throws><para>Will not throw.</para></throws>
+ </method>
+ </method-group>
+
+ <free-function-group name="specialized algorithms">
+ <function name="swap">
+ <template>
+ <template-type-parameter name="Combiner"/>
+ <template-type-parameter name="Group"/>
+ <template-type-parameter name="GroupCompare"/>
+ <template-type-parameter name="SlotFunction"/>
+ <template-type-parameter name="ExtendedSlotFunction"/>
+ <template-type-parameter name="Mutex"/>
+ <template-type-parameter name="R"/>
+ <template-type-parameter name="Args..."/>
+ </template>
+ <type>void</type>
+ <parameter name="x">
+ <paramtype><classname alt="signals2::signal">signal</classname><R (Args...), Combiner, Group, GroupCompare, SlotFunction, ExtendedSlotFunction, Mutex>&</paramtype>
+ </parameter>
+ <parameter name="y">
+ <paramtype><classname alt="signals2::signal">signal</classname><R (Args...), Combiner, Group, GroupCompare, SlotFunction, ExtendedSlotFunction, Mutex>&</paramtype>
+ </parameter>
+
+ <effects><para><computeroutput>x.swap(y)</computeroutput></para></effects>
+ <throws><para>Will not throw.</para></throws>
+ </function>
+ </free-function-group>
</class>
</namespace>
</namespace>
Modified: trunk/libs/signals2/test/signal_n_test.cpp
==============================================================================
--- trunk/libs/signals2/test/signal_n_test.cpp (original)
+++ trunk/libs/signals2/test/signal_n_test.cpp 2013-04-21 23:22:06 EDT (Sun, 21 Apr 2013)
@@ -286,6 +286,52 @@
BOOST_CHECK(sig.num_slots() == 0);
}
}
+class dummy_combiner
+{
+public:
+ typedef int result_type;
+
+ dummy_combiner(result_type return_value): _return_value(return_value)
+ {}
+ template<typename SlotIterator>
+ result_type operator()(SlotIterator, SlotIterator)
+ {
+ return _return_value;
+ }
+private:
+ result_type _return_value;
+};
+
+static void
+test_set_combiner()
+{
+ typedef boost::signals2::signal0<int, dummy_combiner> signal_type;
+ signal_type sig(dummy_combiner(0));
+ BOOST_CHECK(sig() == 0);
+ BOOST_CHECK(sig.combiner()(0,0) == 0);
+ sig.set_combiner(dummy_combiner(1));
+ BOOST_CHECK(sig() == 1);
+ BOOST_CHECK(sig.combiner()(0,0) == 1);
+}
+
+static void
+test_swap()
+{
+ typedef boost::signals2::signal0<int, dummy_combiner> signal_type;
+ signal_type sig1(dummy_combiner(1));
+ BOOST_CHECK(sig1() == 1);
+ signal_type sig2(dummy_combiner(2));
+ BOOST_CHECK(sig2() == 2);
+
+ sig1.swap(sig2);
+ BOOST_CHECK(sig1() == 2);
+ BOOST_CHECK(sig2() == 1);
+
+ using std::swap;
+ swap(sig1, sig2);
+ BOOST_CHECK(sig1() == 1);
+ BOOST_CHECK(sig2() == 2);
+}
int
test_main(int, char* [])
@@ -297,6 +343,8 @@
test_default_combiner();
test_extended_slot<void>();
test_extended_slot<int>();
+ test_set_combiner();
+ test_swap();
return 0;
}
Modified: trunk/libs/signals2/test/signal_test.cpp
==============================================================================
--- trunk/libs/signals2/test/signal_test.cpp (original)
+++ trunk/libs/signals2/test/signal_test.cpp 2013-04-21 23:22:06 EDT (Sun, 21 Apr 2013)
@@ -293,6 +293,25 @@
BOOST_CHECK(sig.combiner()(0,0) == 1);
}
+static void
+test_swap()
+{
+ typedef boost::signals2::signal<int (), dummy_combiner> signal_type;
+ signal_type sig1(dummy_combiner(1));
+ BOOST_CHECK(sig1() == 1);
+ signal_type sig2(dummy_combiner(2));
+ BOOST_CHECK(sig2() == 2);
+
+ sig1.swap(sig2);
+ BOOST_CHECK(sig1() == 2);
+ BOOST_CHECK(sig2() == 1);
+
+ using std::swap;
+ swap(sig1, sig2);
+ BOOST_CHECK(sig1() == 1);
+ BOOST_CHECK(sig2() == 2);
+}
+
int
test_main(int, char* [])
{
@@ -304,5 +323,6 @@
test_reference_args();
test_typedefs_etc();
test_set_combiner();
+ test_swap();
return 0;
}
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk