InterfaceDecorator.cti
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
6 //
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
11 //
12 
13 
14 /** \file
15  \brief InterfaceDecorator inline template implementation */
16 
17 //#include "InterfaceDecorator.ih"
18 
19 // Custom includes
20 
21 #define prefix_ inline
22 //-/////////////////////////////////////////////////////////////////////////////////////////////////
23 
24 //-/////////////////////////////////////////////////////////////////////////////////////////////////
25 // senf::emu::ReceiverDecorator
26 
27 template <class Connector>
28 prefix_ senf::emu::ReceiverDecorator::ReceiverDecorator(Connector & connector)
29  : output (connector)
30 {}
31 
32 //-/////////////////////////////////////////////////////////////////////////////////////////////////
33 // senf::emu::TransmitterDecorator
34 
35 template <class Connector>
36 prefix_ senf::emu::TransmitterDecorator::TransmitterDecorator(Connector & connector)
37  : input (connector)
38 {}
39 
40 //-/////////////////////////////////////////////////////////////////////////////////////////////////
41 // senf::emu::TypedInterfaceDecorator<InterfaceType,Base>
42 
43 template <class InterfaceType, class Base>
44 prefix_ InterfaceType & senf::emu::TypedInterfaceDecorator<InterfaceType,Base>::interface()
45 {
46  return dynamic_cast<InterfaceType &>(Base::interface());
47 }
48 
49 template <class InterfaceType, class Base>
50 prefix_ InterfaceType const &
51 senf::emu::TypedInterfaceDecorator<InterfaceType,Base>::interface()
52  const
53 {
54  return dynamic_cast<InterfaceType const &>(Base::interface());
55 }
56 
57 template <class InterfaceType, class Base>
58 prefix_ senf::emu::TypedInterfaceDecorator<InterfaceType,Base>::
59 TypedInterfaceDecorator(InterfaceType & interface)
60  : Base (interface)
61 {}
62 
63 //-/////////////////////////////////////////////////////////////////////////////////////////////////
64 // senf::emu::ReceiverDecoratorImplementation<DecoratorType,ReceiveModule>
65 
66 template <class ReceiveModule>
67 template <class Interface>
68 prefix_
69 senf::emu::ReceiverDecoratorImplementation<ReceiveModule>::
70 ReceiverDecoratorImplementation(Interface & interface)
71  : ModuleMember (boost::ref(interface)), ReceiverDecorator (ModuleMember::member.output)
72 {
73  ppi::connect(interface, ModuleMember::member);
74 }
75 
76 template <class ReceiveModule>
77 prefix_ ReceiveModule &
78 senf::emu::ReceiverDecoratorImplementation<ReceiveModule>::receiveModule()
79 {
80  return ModuleMember::member;
81 }
82 
83 template <class ReceiveModule>
84 prefix_ ReceiveModule const &
85 senf::emu::ReceiverDecoratorImplementation<ReceiveModule>::receiveModule()
86  const
87 {
88  return ModuleMember::member;
89 }
90 
91 //-/////////////////////////////////////////////////////////////////////////////////////////////////
92 // senf::emu::ReceiverDecoratorImplementation<DecoratorType, senf::mpl::nil>
93 
94 template <class Interface>
95 prefix_
96 senf::emu::ReceiverDecoratorImplementation<senf::mpl::nil>::
97 ReceiverDecoratorImplementation(Interface & interface)
98  : ReceiverDecorator (interface.output)
99 {}
100 
101 //-/////////////////////////////////////////////////////////////////////////////////////////////////
102 // senf::emu::TransmitterDecoratorImplementation<DecoratorType,TransmitModule>
103 
104 template <class TransmitModule>
105 template <class Interface>
106 prefix_
107 senf::emu::TransmitterDecoratorImplementation<TransmitModule>::
108 TransmitterDecoratorImplementation(Interface & interface)
109  : ModuleMember (boost::ref(interface)), TransmitterDecorator (ModuleMember::member.input)
110 {
111  ppi::connect(ModuleMember::member, interface);
112 }
113 
114 template <class TransmitModule>
115 prefix_ TransmitModule &
116 senf::emu::TransmitterDecoratorImplementation<TransmitModule>::transmitModule()
117 {
118  return ModuleMember::member;
119 }
120 
121 template <class TransmitModule>
122 prefix_ TransmitModule const &
123 senf::emu::TransmitterDecoratorImplementation<TransmitModule>::transmitModule()
124  const
125 {
126  return ModuleMember::member;
127 }
128 
129 //-/////////////////////////////////////////////////////////////////////////////////////////////////
130 // senf::emu::TransmitterDecoratorImplementation<DecoratorType, senf::mpl::nil>
131 
132 template <class Interface>
133 prefix_
134 senf::emu::TransmitterDecoratorImplementation<senf::mpl::nil>::
135 TransmitterDecoratorImplementation(Interface & interface)
136  : TransmitterDecorator(interface.input)
137 {}
138 
139 //-/////////////////////////////////////////////////////////////////////////////////////////////////
140 // senf::emu::detail::NoDecorator
141 
142 template <class Interface>
143 prefix_ senf::emu::detail::NoDecorator::NoDecorator(Interface & interface)
144 {}
145 
146 //-/////////////////////////////////////////////////////////////////////////////////////////////////
147 // senf::emu::InterfaceDecoratorImplementation<InterfaceType,ReceiveModule,TransmitModule>
148 
149 template <class InterfaceType, class ReceiveModule, class TransmitModule>
150 prefix_
151 senf::emu::InterfaceDecoratorImplementation<InterfaceType,ReceiveModule,TransmitModule>::
152 InterfaceDecoratorImplementation()
153  : InterfaceType::Decorator (InterfaceBase::member),
154  ReceiverDecoratorBase (InterfaceBase::member),
155  TransmitterDecoratorBase (InterfaceBase::member)
156 {}
157 
158 template <class InterfaceType, class ReceiveModule, class TransmitModule>
159 template <class A1>
160 prefix_
161 senf::emu::InterfaceDecoratorImplementation<InterfaceType,ReceiveModule,TransmitModule>::
162 InterfaceDecoratorImplementation(A1 const & a1)
163  : InterfaceBase(a1),
164  InterfaceType::Decorator (InterfaceBase::member),
165  ReceiverDecoratorBase (InterfaceBase::member),
166  TransmitterDecoratorBase (InterfaceBase::member)
167 {}
168 
169 template <class InterfaceType, class ReceiveModule, class TransmitModule>
170 template <class A1, class A2>
171 prefix_
172 senf::emu::InterfaceDecoratorImplementation<InterfaceType,ReceiveModule,TransmitModule>::
173 InterfaceDecoratorImplementation(A1 const & a1, A2 const & a2)
174  : InterfaceBase(a1, a2),
175  InterfaceType::Decorator (InterfaceBase::member),
176  ReceiverDecoratorBase (InterfaceBase::member),
177  TransmitterDecoratorBase (InterfaceBase::member)
178 {}
179 
180 //-/////////////////////////////////////////////////////////////////////////////////////////////////
181 // senf::emu::ApplyInterfaceDecorator<ReceiveModule,TransmitModule>
182 
183 template <class ReceiveModule, class TransmitModule>
184 prefix_ ReceiveModule &
185 senf::emu::ApplyInterfaceDecorator<ReceiveModule,TransmitModule>::
186 receiveModule(InterfaceDecorator & interface)
187 {
188  try {
189  return dynamic_cast<ReceiverDecoratorImplementation<ReceiveModule>&>(
190  interface.receiverDecorator()).receiveModule();
191  }
192  SENF_WRAP_EXC_MSG(std::bad_cast, "in (ReceiveModule &). Type is " + senf::prettyName(typeid(const_cast<InterfaceDecorator &>(interface))))
193 }
194 
195 template <class ReceiveModule, class TransmitModule>
196 prefix_ ReceiveModule const &
197 senf::emu::ApplyInterfaceDecorator<ReceiveModule,TransmitModule>::
198 receiveModule(InterfaceDecorator const & interface)
199 {
200  try {
201  return dynamic_cast<ReceiverDecoratorImplementation<ReceiveModule> const &>(
202  interface.receiverDecorator()).receiveModule();
203  }
204  SENF_WRAP_EXC_MSG(std::bad_cast, "in (ReceiveModule const &). Type is " + senf::prettyName(typeid(const_cast<InterfaceDecorator &>(interface))))
205 }
206 
207 template <class ReceiveModule, class TransmitModule>
208 prefix_ TransmitModule &
209 senf::emu::ApplyInterfaceDecorator<ReceiveModule,TransmitModule>::
210 transmitModule(InterfaceDecorator & interface)
211 {
212  try {
213  return dynamic_cast<TransmitterDecoratorImplementation<TransmitModule> &>(
214  interface.transmitterDecorator()).transmitModule();
215  }
216  SENF_WRAP_EXC_MSG(std::bad_cast, "in (TransmitModule &). Type is " + senf::prettyName(typeid(const_cast<InterfaceDecorator &>(interface))))
217 }
218 
219 template <class ReceiveModule, class TransmitModule>
220 prefix_ TransmitModule const &
221 senf::emu::ApplyInterfaceDecorator<ReceiveModule,TransmitModule>::
222 transmitModule(InterfaceDecorator const & interface)
223 {
224  try {
225  return dynamic_cast<TransmitterDecoratorImplementation<TransmitModule> const &>(
226  interface.transmitterDecorator()).transmitModule();
227  }
228  SENF_WRAP_EXC_MSG(std::bad_cast, "in (TransmitModule const &). Type is " + senf::prettyName(typeid(const_cast<InterfaceDecorator &>(interface))))
229 }
230 
231 //-/////////////////////////////////////////////////////////////////////////////////////////////////
232 #undef prefix_
233 
234 
235 // Local Variables:
236 // mode: c++
237 // fill-column: 100
238 // comment-column: 40
239 // c-file-style: "senf"
240 // indent-tabs-mode: nil
241 // ispell-local-dictionary: "american"
242 // compile-command: "scons -u test"
243 // End: