X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=senf%2FPPI%2FMultiConnectorMixin.mpp;h=0de3682d7a57fc3000750fa71eeb59ee2ee094ac;hb=c505c034e5fdc932c02aa3dc3847a5551011d87e;hp=aeb5dfda4be2f916c0e2298a7e7cc086754c403c;hpb=601d1f509f5bb24df167a4dd5a20da67a0af9af8;p=senf.git diff --git a/senf/PPI/MultiConnectorMixin.mpp b/senf/PPI/MultiConnectorMixin.mpp index aeb5dfd..0de3682 100644 --- a/senf/PPI/MultiConnectorMixin.mpp +++ b/senf/PPI/MultiConnectorMixin.mpp @@ -1,6 +1,6 @@ // $Id$ // -// Copyright (C) 2009 +// Copyright (C) 2009 // Fraunhofer Institute for Open Communication Systems (FOKUS) // Competence Center NETwork research (NET), St. Augustin, GERMANY // Stefan Bund @@ -29,78 +29,124 @@ // Custom includes #include #include -#include +#include #include #include #include -#include +#include #include +#include +#include +#include // ///////////////////////////mpp.p//////////////////////////////////////// #elif BOOST_PP_IS_ITERATING // //////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////// // Local Macros +// => template #define mpp_TplParams() \ - BOOST_PP_IF( \ - BOOST_PP_ITERATION(), \ - mpp_TplParams_, \ - BOOST_PP_EMPTY)() + BOOST_PP_IF(BOOST_PP_ITERATION(), mpp_TplParams_, BOOST_PP_EMPTY)() #define mpp_TplParams_() \ template - + +// => , class A0, class A1, ... #define mpp_TplParamsKomma() \ BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_ITERATION(), class A) + +// => A0 const & a0, A1 const & a1, ... #define mpp_FnParams() \ BOOST_PP_ENUM_BINARY_PARAMS(BOOST_PP_ITERATION(), A, const & a) + +// => , A0 const & a0, A1 const & a1, ... #define mpp_FnParamsKomma() \ BOOST_PP_ENUM_TRAILING_BINARY_PARAMS(BOOST_PP_ITERATION(), A, const & a) + +// => a0, a1, ... #define mpp_CallParams() \ BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), a) + +// => , a0, a1, ... #define mpp_CallParamsKomma() \ BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_ITERATION(), a) +// Same as above but for outer iteration (in nested file iteration) +#define mpp_TplParamsKomma2() \ + BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_FRAME_ITERATION(1), class B) +#define mpp_FnParams2() \ + BOOST_PP_ENUM_BINARY_PARAMS(BOOST_PP_FRAME_ITERATION(1), B, cont & b) +#define mpp_FnParamsKomma2() \ + BOOST_PP_ENUM_TRAILING_BINARY_PARAMS(BOOST_PP_FRAME_ITERATION(1), B, const & b) +#define mpp_CallParams2() \ + BOOST_PP_ENUM_PARAMS(BOOST_PP_FRAME_ITERATION(1), b) +#define mpp_CallParamsKomma2() \ + BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_FRAME_ITERATION(1), b) + // //////////////////////////////////////////////////////////////////////// #if BOOST_PP_ITERATION_FLAGS()==1 // ////////////////////////////////////// // //////////////////////////////////////////////////////////////////////// -// MultiConnectorMixin member declaration +// senf::ppi::module::MultiConnectorMixin member declaration 1..MAX_ARGS mpp_TplParams() ConnectorType_ & newConnector( mpp_FnParams() ); -template -friend typename boost::enable_if< - boost::is_base_of, - typename Source::ConnectorType & >::type - senf::ppi::connect(Source & source, Target & target mpp_FnParamsKomma()); - -template -friend typename boost::enable_if< - boost::is_base_of, - typename Target::ConnectorType & >::type - senf::ppi::connect(Source & source, Target & target mpp_FnParamsKomma()); - // //////////////////////////////////////////////////////////////////////// #elif BOOST_PP_ITERATION_FLAGS()==2 // //////////////////////////////////// // //////////////////////////////////////////////////////////////////////// -// senf::ppi namespace member declaration +// senf::ppi namespace member declaration 1..MAX_ARGS + +// Here the reference to Source::ConnectorType / Target::ConnectorType +// works like enable_if, since only MultiConnector modules have those members template typename boost::enable_if< - boost::is_base_of, + boost::mpl::and_< + senf::ppi::module::detail::IsMulticonnectorSource, + boost::mpl::not_< senf::ppi::module::detail::IsMulticonnectorTarget > >, typename Source::ConnectorType & >::type -connect(Source & source, Target & target mpp_FnParamsKomma()); +connect(Source & source mpp_FnParamsKomma(), Target & target); template typename boost::enable_if< - boost::is_base_of, + boost::mpl::and_< + boost::mpl::not_< senf::ppi::module::detail::IsMulticonnectorSource >, + senf::ppi::module::detail::IsMulticonnectorTarget >, typename Target::ConnectorType & >::type connect(Source & source, Target & target mpp_FnParamsKomma()); +#define BOOST_PP_ITERATION_PARAMS_2 (4, (\ + 0, \ + SENF_MULTI_CONNECTOR_MAX_ARGS, \ + SENF_ABSOLUTE_INCLUDE_PATH(PPI/MultiConnectorMixin.mpp), \ + 4 )) +#include BOOST_PP_ITERATE() + +// //////////////////////////////////////////////////////////////////////// +#elif BOOST_PP_ITERATION_FLAGS()==4 // //////////////////////////////////// +// //////////////////////////////////////////////////////////////////////// +// senf::ppi namespace member declaration 1..MAX_ARGS x 1..MAX_ARGS + +template +typename boost::enable_if< + boost::mpl::and_< + boost::is_base_of, + boost::is_base_of >, + boost::tuple >::type +connect(Source & source mpp_FnParamsKomma(), Target & target mpp_FnParamsKomma2()); + +// //////////////////////////////////////////////////////////////////////// +#elif BOOST_PP_ITERATION_FLAGS()==8 // //////////////////////////////////// +// //////////////////////////////////////////////////////////////////////// +// senf::ppi::module::detail::MultiConnectorMixinAccess member declaration 1..MAX_ARGS + +template +static typename Module::ConnectorType & +newConnector(Module & module mpp_FnParamsKomma()); + // //////////////////////////////////////////////////////////////////////// #elif BOOST_PP_ITERATION_FLAGS()==3 // //////////////////////////////////// // //////////////////////////////////////////////////////////////////////// -// Implementation +// Implementation 1..MAX_ARGS //////////////////////////////////////// // Map container @@ -111,7 +157,7 @@ prefix_ ConnectorType_ & senf::ppi::module::MultiConnectorMixin:: newConnector(mpp_FnParams()) { - std::auto_ptr conn (new ConnectorType_); + std::auto_ptr conn (new detail::MultiConnectorWrapper); KeyType_ key (static_cast(this)->connectorSetup(*conn mpp_CallParamsKomma())); return * connectors_.insert(key, conn).first->second; } @@ -125,10 +171,10 @@ prefix_ ConnectorType_ & senf::ppi::module::MultiConnectorMixin:: newConnector(mpp_FnParams()) { - connectors_.push_back(new ConnectorType_); + connectors_.push_back(new detail::MultiConnectorWrapper); ConnectorType_ & conn (connectors_.back()); try { static_cast(this)->connectorSetup(conn mpp_CallParamsKomma()); } - catch (...) { connectors_.pop_back(); throw; } + catch (...) { disconnected(conn); throw; } return conn; } @@ -141,7 +187,7 @@ prefix_ ConnectorType_ & senf::ppi::module::MultiConnectorMixin:: newConnector(mpp_FnParams()) { - std::auto_ptr cp (new ConnectorType_); + std::auto_ptr cp (new detail::MultiConnectorWrapper); ConnectorType_ & cref (*cp); static_cast(this)->connectorSetup(cp mpp_CallParamsKomma()); return cref; @@ -152,31 +198,81 @@ newConnector(mpp_FnParams()) template typename boost::enable_if< - boost::is_base_of, + boost::mpl::and_< + senf::ppi::module::detail::IsMulticonnectorSource, + boost::mpl::not_< senf::ppi::module::detail::IsMulticonnectorTarget > >, typename Source::ConnectorType & >::type -senf::ppi::connect(Source & source, Target & target mpp_FnParamsKomma()) +senf::ppi::connect(Source & source mpp_FnParamsKomma(), Target & target) { - typename Source::ConnectorType & c (source.newConnector(mpp_CallParams())); + typename Source::ConnectorType & c ( + module::detail::MultiConnectorMixinAccess::newConnector(source mpp_CallParamsKomma())); connect(c, target); return c; } template typename boost::enable_if< - boost::is_base_of, + boost::mpl::and_< + boost::mpl::not_< senf::ppi::module::detail::IsMulticonnectorSource >, + senf::ppi::module::detail::IsMulticonnectorTarget >, typename Target::ConnectorType & >::type senf::ppi::connect(Source & source, Target & target mpp_FnParamsKomma()) { - typename Target::ConnectorType & c (target.newConnector(mpp_CallParams())); + typename Target::ConnectorType & c ( + module::detail::MultiConnectorMixinAccess::newConnector(target mpp_CallParamsKomma())); connect(source, c); return c; } +//////////////////////////////////////// +// senf::ppi::module::detail::MultiConnectorMixinAccess members + +template +typename Module::ConnectorType & +senf::ppi::module::detail::MultiConnectorMixinAccess::newConnector( + Module & module mpp_FnParamsKomma()) +{ + return module.newConnector(mpp_CallParams()); +} + +#define BOOST_PP_ITERATION_PARAMS_2 (4, (\ + 0, \ + SENF_MULTI_CONNECTOR_MAX_ARGS, \ + SENF_ABSOLUTE_INCLUDE_PATH(PPI/MultiConnectorMixin.mpp), \ + 5 )) +#include BOOST_PP_ITERATE() + +//////////////////////////////////////////////////////////////////////// +#elif BOOST_PP_ITERATION_FLAGS()==5 // //////////////////////////////////// +// //////////////////////////////////////////////////////////////////////// +// Implementation 1..MAX_ARGS x 1..MAX_ARGS + +template +typename boost::enable_if< + boost::mpl::and_< + boost::is_base_of, + boost::is_base_of >, + boost::tuple >::type +senf::ppi::connect(Source & source mpp_FnParamsKomma(), Target & target mpp_FnParamsKomma2()) +{ + typename Source::ConnectorType & s ( + module::detail::MultiConnectorMixinAccess::newConnector(source mpp_CallParamsKomma())); + typename Target::ConnectorType & t ( + module::detail::MultiConnectorMixinAccess::newConnector(target mpp_CallParamsKomma2())); + connect(s,t); + return boost::tie(s,t); +} + // //////////////////////////////////////////////////////////////////////// #endif // ///////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////// // Undefine local Macros +#undef mpp_CallParamsKomma2 +#undef mpp_CallParams2 +#undef mpp_FnParamsKomma2 +#undef mpp_FnParams2 +#undef mpp_TplParamsKomma2 #undef mpp_CallParamsKomma #undef mpp_CallParams #undef mpp_FnParamsKomma @@ -184,19 +280,19 @@ senf::ppi::connect(Source & source, Target & target mpp_FnParamsKomma()) #undef mpp_TplParamsKomma #undef mpp_TplParams_ #undef mpp_TplParams - + // //////////////////////////////////////////////////////////////////////// /* (save-excursion (re-search-backward "^// Undefine local Macros") (forward-line 1) (delete-region (point) (progn (search-forward "// ////") (forward-line -1) (point))) (insert "\n") (let ((b (point)) - (e (progn (insert (save-excursion (re-search-backward + (e (progn (insert (save-excursion (re-search-backward "^// Local Macros") (search-forward "#define") (beginning-of-line) (buffer-substring (point) (progn (search-forward "// ////") (search-backward "#define") (forward-line 1) (point))))) (point)))) (reverse-region b e) (shell-command-on-region b e "grep -F '#define'" nil t) (goto-char b) (while (looking-at "#define") (delete-char 7) (insert - "#undef") (skip-chars-forward " ") (re-search-forward "[^a-zA-Z_]") + "#undef") (skip-chars-forward " ") (re-search-forward "[^a-zA-Z0-9_]") (delete-region (1- (point)) (progn (end-of-line) (point))) (forward-line 1)))) */