PPI: MultiConnectorMixin documentation
[senf.git] / PPI / MultiConnectorMixin.cti
1 // $Id$
2 //
3 // Copyright (C) 2009 
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.de>
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23 /** \file
24     \brief MultiConnectorMixin inline template implementation */
25
26 //#include "MultiConnectorMixin.ih"
27
28 // Custom includes
29
30 #define prefix_ inline
31 ///////////////////////////////cti.p///////////////////////////////////////
32
33 template <class Self_, class ConnectorType_, class KeyType_, class ContainerType_>
34 prefix_ ContainerType_ &
35 senf::ppi::module::MultiConnectorMixin<Self_,ConnectorType_,KeyType_,ContainerType_>::connectors()
36 {
37     return connectors_;
38 }
39
40 template <class Self_, class ConnectorType_, class ContainerType_>
41 prefix_ ContainerType_ &
42 senf::ppi::module::MultiConnectorMixin<Self_,ConnectorType_,void,ContainerType_>::connectors()
43 {
44     return connectors_;
45 }
46
47 #ifdef DOXYGEN
48
49 // Only for exposition
50 // Other implementations with 0..SENF_MULTI_CONNECTOR_MAX_ARGS arguments accordingly
51
52 template <class Self_, class ConnectorType_, class KeyType_, class ContainerType_>
53 template <class A1>
54 prefix_ ConnectorType_ &
55 senf::ppi::module::MultiConnectorMixin<Self_,ConnectorType_,KeyType_,ContainerType_>::
56 newConnector(A1 const & a1)
57 {
58     std::auto_ptr<ConnectorType_> conn (new ConnectorType_);
59     KeyType_ key (static_cast<Self_*>(this)->connectorSetup(*conn, a1));
60     return * connectors_.insert(key, conn).first->second;
61 }
62
63 template <class Self_, class ConnectorType_, class ContainerType_>
64 template <class A1>
65 prefix_ ConnectorType_ &
66 senf::ppi::module::MultiConnectorMixin<Self_,ConnectorType_,void,ContainerType_>::
67 newConnector(A1 const & a1)
68 {
69     connectors_.push_back(new ConnectorType_);
70     ConnectorType_ & conn (connectors_.back());
71     try { static_cast<Self_*>(this)->connectorSetup(conn , a1); }
72     catch (...) { connectors_.pop_back(); throw; }
73     return conn;
74 }
75
76 template <class Source, class Target , class A1>
77 typename boost::enable_if<
78     boost::is_base_of<senf::ppi::connector::OutputConnector, typename Source::ConnectorType>,
79     typename Source::ConnectorType & >::type
80 senf::ppi::connect(Source & source, Target & target , A1 const & a1)
81 {
82     connect(source.newConnector(a1), target);
83 }
84
85 template <class Source, class Target , class A1>
86 typename boost::enable_if<
87     boost::is_base_of<senf::ppi::connector::InputConnector, typename Target::ConnectorType>,
88     typename Target::ConnectorType & >::type
89 senf::ppi::connect(Source & source, Target & target , A1 const & a1)
90 {
91     connect(source, target.newConnector(a1));
92 }
93
94 #endif
95
96 // Include 'Implementation' from MultiConnectorMixin.mpp
97 #define BOOST_PP_ITERATION_PARAMS_1 (4, ( \
98             0, \
99             SENF_MULTI_CONNECTOR_MAX_ARGS, \
100             SENF_ABSOLUTE_INCLUDE_PATH(PPI/MultiConnectorMixin.mpp), \
101             3 ))
102 #include BOOST_PP_ITERATE()
103
104 ///////////////////////////////cti.e///////////////////////////////////////
105 #undef prefix_
106
107 \f
108 // Local Variables:
109 // mode: c++
110 // fill-column: 100
111 // comment-column: 40
112 // c-file-style: "senf"
113 // indent-tabs-mode: nil
114 // ispell-local-dictionary: "american"
115 // compile-command: "scons -u test"
116 // End: