A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
traced-callback.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2005,2006,2007 INRIA
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 
21 #ifndef TRACED_CALLBACK_H
22 #define TRACED_CALLBACK_H
23 
24 #include <list>
25 #include "callback.h"
26 
27 namespace ns3 {
28 
39 template<typename T1 = empty, typename T2 = empty,
40  typename T3 = empty, typename T4 = empty,
41  typename T5 = empty, typename T6 = empty,
42  typename T7 = empty, typename T8 = empty>
44 {
45 public:
46  TracedCallback ();
53  void ConnectWithoutContext (const CallbackBase & callback);
63  void Connect (const CallbackBase & callback, std::string path);
71  void DisconnectWithoutContext (const CallbackBase & callback);
80  void Disconnect (const CallbackBase & callback, std::string path);
81  void operator() (void) const;
82  void operator() (T1 a1) const;
83  void operator() (T1 a1, T2 a2) const;
84  void operator() (T1 a1, T2 a2, T3 a3) const;
85  void operator() (T1 a1, T2 a2, T3 a3, T4 a4) const;
86  void operator() (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) const;
87  void operator() (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6) const;
88  void operator() (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7) const;
89  void operator() (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7, T8 a8) const;
90 
91 private:
92  typedef std::list<Callback<void,T1,T2,T3,T4,T5,T6,T7,T8> > CallbackList;
94 };
95 
96 } // namespace ns3
97 
98 // implementation below.
99 
100 namespace ns3 {
101 
102 template<typename T1, typename T2,
103  typename T3, typename T4,
104  typename T5, typename T6,
105  typename T7, typename T8>
107  : m_callbackList ()
108 {
109 }
110 template<typename T1, typename T2,
111  typename T3, typename T4,
112  typename T5, typename T6,
113  typename T7, typename T8>
114 void
116 {
118  cb.Assign (callback);
119  m_callbackList.push_back (cb);
120 }
121 template<typename T1, typename T2,
122  typename T3, typename T4,
123  typename T5, typename T6,
124  typename T7, typename T8>
125 void
127 {
129  cb.Assign (callback);
130  Callback<void,T1,T2,T3,T4,T5,T6,T7,T8> realCb = cb.Bind (path);
131  m_callbackList.push_back (realCb);
132 }
133 template<typename T1, typename T2,
134  typename T3, typename T4,
135  typename T5, typename T6,
136  typename T7, typename T8>
137 void
139 {
140  for (typename CallbackList::iterator i = m_callbackList.begin ();
141  i != m_callbackList.end (); /* empty */)
142  {
143  if ((*i).IsEqual (callback))
144  {
145  i = m_callbackList.erase (i);
146  }
147  else
148  {
149  i++;
150  }
151  }
152 }
153 template<typename T1, typename T2,
154  typename T3, typename T4,
155  typename T5, typename T6,
156  typename T7, typename T8>
157 void
159 {
161  cb.Assign (callback);
162  Callback<void,T1,T2,T3,T4,T5,T6,T7,T8> realCb = cb.Bind (path);
163  DisconnectWithoutContext (realCb);
164 }
165 template<typename T1, typename T2,
166  typename T3, typename T4,
167  typename T5, typename T6,
168  typename T7, typename T8>
169 void
171 {
172  for (typename CallbackList::const_iterator i = m_callbackList.begin ();
173  i != m_callbackList.end (); i++)
174  {
175  (*i)();
176  }
177 }
178 template<typename T1, typename T2,
179  typename T3, typename T4,
180  typename T5, typename T6,
181  typename T7, typename T8>
182 void
184 {
185  for (typename CallbackList::const_iterator i = m_callbackList.begin ();
186  i != m_callbackList.end (); i++)
187  {
188  (*i)(a1);
189  }
190 }
191 template<typename T1, typename T2,
192  typename T3, typename T4,
193  typename T5, typename T6,
194  typename T7, typename T8>
195 void
197 {
198  for (typename CallbackList::const_iterator i = m_callbackList.begin ();
199  i != m_callbackList.end (); i++)
200  {
201  (*i)(a1, a2);
202  }
203 }
204 template<typename T1, typename T2,
205  typename T3, typename T4,
206  typename T5, typename T6,
207  typename T7, typename T8>
208 void
210 {
211  for (typename CallbackList::const_iterator i = m_callbackList.begin ();
212  i != m_callbackList.end (); i++)
213  {
214  (*i)(a1, a2, a3);
215  }
216 }
217 template<typename T1, typename T2,
218  typename T3, typename T4,
219  typename T5, typename T6,
220  typename T7, typename T8>
221 void
223 {
224  for (typename CallbackList::const_iterator i = m_callbackList.begin ();
225  i != m_callbackList.end (); i++)
226  {
227  (*i)(a1, a2, a3, a4);
228  }
229 }
230 template<typename T1, typename T2,
231  typename T3, typename T4,
232  typename T5, typename T6,
233  typename T7, typename T8>
234 void
235 TracedCallback<T1,T2,T3,T4,T5,T6,T7,T8>::operator() (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) const
236 {
237  for (typename CallbackList::const_iterator i = m_callbackList.begin ();
238  i != m_callbackList.end (); i++)
239  {
240  (*i)(a1, a2, a3, a4, a5);
241  }
242 }
243 template<typename T1, typename T2,
244  typename T3, typename T4,
245  typename T5, typename T6,
246  typename T7, typename T8>
247 void
248 TracedCallback<T1,T2,T3,T4,T5,T6,T7,T8>::operator() (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6) const
249 {
250  for (typename CallbackList::const_iterator i = m_callbackList.begin ();
251  i != m_callbackList.end (); i++)
252  {
253  (*i)(a1, a2, a3, a4, a5, a6);
254  }
255 }
256 template<typename T1, typename T2,
257  typename T3, typename T4,
258  typename T5, typename T6,
259  typename T7, typename T8>
260 void
261 TracedCallback<T1,T2,T3,T4,T5,T6,T7,T8>::operator() (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7) const
262 {
263  for (typename CallbackList::const_iterator i = m_callbackList.begin ();
264  i != m_callbackList.end (); i++)
265  {
266  (*i)(a1, a2, a3, a4, a5, a6, a7);
267  }
268 }
269 template<typename T1, typename T2,
270  typename T3, typename T4,
271  typename T5, typename T6,
272  typename T7, typename T8>
273 void
274 TracedCallback<T1,T2,T3,T4,T5,T6,T7,T8>::operator() (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7, T8 a8) const
275 {
276  for (typename CallbackList::const_iterator i = m_callbackList.begin ();
277  i != m_callbackList.end (); i++)
278  {
279  (*i)(a1, a2, a3, a4, a5, a6, a7, a8);
280  }
281 }
282 
283 } // namespace ns3
284 
285 #endif /* TRACED_CALLBACK_H */
forward calls to a chain of CallbackAn ns3::TracedCallback has almost exactly the same API as a norma...
void operator()(void) const
void Assign(const CallbackBase &other)
Adopt the other's implementation, if type compatible.
Definition: callback.h:1155
Callback< R, T2, T3, T4, T5, T6, T7, T8, T9 > Bind(T a)
Bind the first arguments.
Definition: callback.h:965
Base class for Callback class.
Definition: callback.h:844
void DisconnectWithoutContext(const CallbackBase &callback)
void Disconnect(const CallbackBase &callback, std::string path)
void Connect(const CallbackBase &callback, std::string path)
CallbackList m_callbackList
void ConnectWithoutContext(const CallbackBase &callback)
void DisconnectWithoutContext(std::string path, const CallbackBase &cb)
Definition: config.cc:722
std::list< Callback< void, T1, T2, T3, T4, T5, T6, T7, T8 > > CallbackList