|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r50747 - in sandbox/thread_safe_signals/trunk: boost/signals2 libs/signals2/test
From: fmhess_at_[hidden]
Date: 2009-01-23 11:14:15
Author: fmhess
Date: 2009-01-23 11:14:14 EST (Fri, 23 Jan 2009)
New Revision: 50747
URL: http://svn.boost.org/trac/boost/changeset/50747
Log:
Added signal_type metafunction which uses Boost.Parameter
to enable named template type parameters when
declarng signals.
Added:
sandbox/thread_safe_signals/trunk/boost/signals2/signal_type.hpp (contents, props changed)
sandbox/thread_safe_signals/trunk/libs/signals2/test/signal_type_test.cpp (contents, props changed)
Added: sandbox/thread_safe_signals/trunk/boost/signals2/signal_type.hpp
==============================================================================
--- (empty file)
+++ sandbox/thread_safe_signals/trunk/boost/signals2/signal_type.hpp 2009-01-23 11:14:14 EST (Fri, 23 Jan 2009)
@@ -0,0 +1,142 @@
+/*
+ A meta function which supports using named template type parameters
+ via Boost.Parameter to specify the template type parameters for
+ the boost::signals2::signal class.
+
+ Author: Frank Mori Hess <fmhess_at_[hidden]>
+ Begin: 2009-01-22
+*/
+// Copyright Frank Mori Hess 2009
+// Use, modification and
+// distribution is subject to the Boost Software License, Version
+// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+// For more information, see http://www.boost.org
+
+#ifndef BOOST_SIGNALS2_SIGNAL_TYPE_HPP
+#define BOOST_SIGNALS2_SIGNAL_TYPE_HPP
+
+// support for function types is currently broken in Boost.Parameter
+// #define NAMED_SIGNATURE_PARAMETER
+
+#include <boost/signals2/signal.hpp>
+
+#if !defined(BOOST_PARAMETER_MAX_ARITY)
+#define BOOST_PARAMETER_MAX_ARITY 7
+#else
+#if BOOST_PARAMETER_MAX_ARITY < 7
+#error This header requires BOOST_PARAMETER_MAX_ARITY to be defined as 7 or greater prior to including Boost.Parameter headers
+#endif // BOOST_PARAMETER_MAX_ARITY < 7
+#endif // !defined(BOOST_PARAMETER_MAX_ARITY)
+#include <boost/parameter.hpp>
+
+namespace boost
+{
+ namespace signals2
+ {
+ namespace keywords
+ {
+#ifdef NAMED_SIGNATURE_PARAMETER
+ BOOST_PARAMETER_TEMPLATE_KEYWORD(signature_type)
+#endif
+ BOOST_PARAMETER_TEMPLATE_KEYWORD(combiner_type)
+ BOOST_PARAMETER_TEMPLATE_KEYWORD(group_type)
+ BOOST_PARAMETER_TEMPLATE_KEYWORD(group_compare_type)
+ BOOST_PARAMETER_TEMPLATE_KEYWORD(slot_function_type)
+ BOOST_PARAMETER_TEMPLATE_KEYWORD(extended_slot_function_type)
+ BOOST_PARAMETER_TEMPLATE_KEYWORD(mutex_type)
+ } // namespace keywords
+
+ template <
+#ifdef NAMED_SIGNATURE_PARAMETER
+ typename A0,
+#else
+ typename Signature,
+#endif
+ typename A1 = parameter::void_,
+ typename A2 = parameter::void_,
+ typename A3 = parameter::void_,
+ typename A4 = parameter::void_,
+ typename A5 = parameter::void_,
+ typename A6 = parameter::void_
+ >
+ class signal_type
+ {
+ typedef parameter::parameters<
+#ifdef NAMED_SIGNATURE_PARAMETER
+ parameter::required<keywords::tag::signature_type>,
+#endif
+ parameter::optional<keywords::tag::combiner_type>,
+ parameter::optional<keywords::tag::group_type>,
+ parameter::optional<keywords::tag::group_compare_type>,
+ parameter::optional<keywords::tag::slot_function_type>,
+ parameter::optional<keywords::tag::extended_slot_function_type>,
+ parameter::optional<keywords::tag::mutex_type>
+ > parameter_spec;
+
+ public:
+ // ArgumentPack
+ typedef typename
+ parameter_spec::bind<
+#ifdef NAMED_SIGNATURE_PARAMETER
+ A0,
+#endif
+ A1, A2, A3, A4, A5, A6>::type
+ args;
+
+#ifdef NAMED_SIGNATURE_PARAMETER
+ typedef typename parameter::binding<args, keywords::tag::signature_type>::type
+ signature_type;
+#else
+ typedef Signature signature_type;
+#endif
+
+ typedef typename parameter::binding
+ <
+ args,
+ keywords::tag::combiner_type,
+ optional_last_value
+ <
+ typename boost::function_traits<signature_type>::result_type
+ >
+ >::type combiner_type;
+
+ typedef typename
+ parameter::binding<args, keywords::tag::group_type, int>::type group_type;
+
+ typedef typename
+ parameter::binding<args, keywords::tag::group_compare_type, std::less<group_type> >::type
+ group_compare_type;
+
+ typedef typename
+ parameter::binding<args, keywords::tag::slot_function_type, function<signature_type> >::type
+ slot_function_type;
+
+ typedef typename
+ parameter::binding
+ <
+ args,
+ keywords::tag::extended_slot_function_type,
+ typename detail::extended_signature<function_traits<signature_type>::arity, signature_type>::function_type
+ >::type
+ extended_slot_function_type;
+
+ typedef typename
+ parameter::binding<args, keywords::tag::mutex_type, mutex>::type mutex_type;
+
+ typedef signal
+ <
+ signature_type,
+ combiner_type,
+ group_type,
+ group_compare_type,
+ slot_function_type,
+ extended_slot_function_type,
+ mutex_type
+ > type;
+ };
+ } // namespace signals2
+} // namespace boost
+
+#endif // BOOST_SIGNALS2_SIGNAL_TYPE_HPP
Added: sandbox/thread_safe_signals/trunk/libs/signals2/test/signal_type_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/thread_safe_signals/trunk/libs/signals2/test/signal_type_test.cpp 2009-01-23 11:14:14 EST (Fri, 23 Jan 2009)
@@ -0,0 +1,32 @@
+// Tests for boost::signals2::signal_type
+
+// Copyright Frank Mori Hess 2009.
+// Distributed under the Boost Software License, Version
+// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+// See http://www.boost.org/libs/signals2 for library home page.
+
+#include <boost/signals2/signal_type.hpp>
+
+#include <boost/test/minimal.hpp>
+
+namespace bs2 = boost::signals2;
+
+int test_main(int, char*[])
+{
+ {
+ using namespace bs2::keywords;
+ bs2::signal_type<void ()>::type mysig;
+ bs2::signal<void ()> mysig2;
+ BOOST_CHECK(typeid(mysig) == typeid(mysig2));
+ }
+
+ {
+ using namespace bs2::keywords;
+ bs2::signal_type<double (int), group_compare_type<std::less<float> >, group_type<float> >::type mysig;
+ bs2::signal<double (int), bs2::optional_last_value<double>, float, std::less<float> > mysig2;
+ BOOST_CHECK(typeid(mysig) == typeid(mysig2));
+ }
+ 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