Move sourcecode into 'senf/' directory
[senf.git] / senf / 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 KeyType_, class ContainerType_>
41 prefix_ ContainerType_ const &
42 senf::ppi::module::MultiConnectorMixin<Self_,ConnectorType_,KeyType_,ContainerType_>::
43 connectors()
44     const
45 {
46     return connectors_;
47 }
48
49 template <class Self_, class ConnectorType_, class ContainerType_>
50 prefix_ ContainerType_ &
51 senf::ppi::module::MultiConnectorMixin<Self_,ConnectorType_,void,ContainerType_>::connectors()
52 {
53     return connectors_;
54 }
55
56 #ifdef DOXYGEN
57
58 // Only for exposition
59 // Other implementations with 0..SENF_MULTI_CONNECTOR_MAX_ARGS arguments accordingly
60
61 template <class Self_, class ConnectorType_, class KeyType_, class ContainerType_>
62 template <class A1>
63 prefix_ ConnectorType_ &
64 senf::ppi::module::MultiConnectorMixin<Self_,ConnectorType_,KeyType_,ContainerType_>::
65 newConnector(A1 const & a1)
66 {
67     std::auto_ptr<ConnectorType_> conn (new ConnectorType_);
68     KeyType_ key (static_cast<Self_*>(this)->connectorSetup(*conn, a1));
69     return * connectors_.insert(key, conn).first->second;
70 }
71
72 template <class Self_, class ConnectorType_, class ContainerType_>
73 template <class A1>
74 prefix_ ConnectorType_ &
75 senf::ppi::module::MultiConnectorMixin<Self_,ConnectorType_,void,ContainerType_>::
76 newConnector(A1 const & a1)
77 {
78     connectors_.push_back(new ConnectorType_);
79     ConnectorType_ & conn (connectors_.back());
80     try { static_cast<Self_*>(this)->connectorSetup(conn , a1); }
81     catch (...) { connectors_.pop_back(); throw; }
82     return conn;
83 }
84
85 template <class Source, class Target , class A1>
86 typename boost::enable_if<
87     boost::is_base_of<senf::ppi::connector::OutputConnector, typename Source::ConnectorType>,
88     typename Source::ConnectorType & >::type
89 senf::ppi::connect(Source & source, Target & target , A1 const & a1)
90 {
91     connect(source.newConnector(a1), target);
92 }
93
94 template <class Source, class Target , class A1>
95 typename boost::enable_if<
96     boost::is_base_of<senf::ppi::connector::InputConnector, typename Target::ConnectorType>,
97     typename Target::ConnectorType & >::type
98 senf::ppi::connect(Source & source, Target & target , A1 const & a1)
99 {
100     connect(source, target.newConnector(a1));
101 }
102
103 #else
104
105 // Include 'Implementation' from MultiConnectorMixin.mpp
106 #define BOOST_PP_ITERATION_PARAMS_1 (4, ( \
107             0, \
108             SENF_MULTI_CONNECTOR_MAX_ARGS, \
109             SENF_ABSOLUTE_INCLUDE_PATH(PPI/MultiConnectorMixin.mpp), \
110             3 ))
111 #include BOOST_PP_ITERATE()
112
113 #endif
114
115 ///////////////////////////////cti.e///////////////////////////////////////
116 #undef prefix_
117
118 \f
119 // Local Variables:
120 // mode: c++
121 // fill-column: 100
122 // comment-column: 40
123 // c-file-style: "senf"
124 // indent-tabs-mode: nil
125 // ispell-local-dictionary: "american"
126 // compile-command: "scons -u test"
127 // End: