1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
3 * Copyright (c) 2005,2006,2007 INRIA
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation;
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
22 #ifndef EVENT_TRACE_SOURCE_H
23 #define EVENT_TRACE_SOURCE_H
31 * \brief log arbitrary number of parameters to a matching ns3::Callback
34 * Whenever operator () is invoked on this class, the call and its arguments
35 * are forwarded to the internal matching ns3::Callback.
37 template<typename T1 = empty, typename T2 = empty,
38 typename T3 = empty, typename T4 = empty>
39 class EventTraceSource
43 void Connect (const CallbackBase & callback);
44 void Disconnect (const CallbackBase & callback);
45 void operator() (void) const;
46 void operator() (T1 a1) const;
47 void operator() (T1 a1, T2 a2) const;
48 void operator() (T1 a1, T2 a2, T3 a3) const;
49 void operator() (T1 a1, T2 a2, T3 a3, T4 a4) const;
52 typedef std::list<Callback<void,T1,T2,T3,T4> > CallbackList;
53 CallbackList m_callbackList;
58 // implementation below.
63 template<typename T1, typename T2,
64 typename T3, typename T4>
65 EventTraceSource<T1,T2,T3,T4>::EventTraceSource ()
68 template<typename T1, typename T2,
69 typename T3, typename T4>
71 EventTraceSource<T1,T2,T3,T4>::Connect (const CallbackBase & callback)
73 Callback<void,T1,T2,T3,T4> cb;
75 m_callbackList.push_back (cb);
77 template<typename T1, typename T2,
78 typename T3, typename T4>
80 EventTraceSource<T1,T2,T3,T4>::Disconnect (const CallbackBase & callback)
82 for (typename CallbackList::iterator i = m_callbackList.begin ();
83 i != m_callbackList.end (); /* empty */)
85 if ((*i).IsEqual (callback))
87 i = m_callbackList.erase (i);
95 template<typename T1, typename T2,
96 typename T3, typename T4>
98 EventTraceSource<T1,T2,T3,T4>::operator() (void) const
100 for (typename CallbackList::const_iterator i = m_callbackList.begin ();
101 i != m_callbackList.end (); i++)
106 template<typename T1, typename T2,
107 typename T3, typename T4>
109 EventTraceSource<T1,T2,T3,T4>::operator() (T1 a1) const
111 for (typename CallbackList::const_iterator i = m_callbackList.begin ();
112 i != m_callbackList.end (); i++)
117 template<typename T1, typename T2,
118 typename T3, typename T4>
120 EventTraceSource<T1,T2,T3,T4>::operator() (T1 a1, T2 a2) const
122 for (typename CallbackList::const_iterator i = m_callbackList.begin ();
123 i != m_callbackList.end (); i++)
128 template<typename T1, typename T2,
129 typename T3, typename T4>
131 EventTraceSource<T1,T2,T3,T4>::operator() (T1 a1, T2 a2, T3 a3) const
133 for (typename CallbackList::const_iterator i = m_callbackList.begin ();
134 i != m_callbackList.end (); i++)
139 template<typename T1, typename T2,
140 typename T3, typename T4>
142 EventTraceSource<T1,T2,T3,T4>::operator() (T1 a1, T2 a2, T3 a3, T4 a4) const
144 for (typename CallbackList::const_iterator i = m_callbackList.begin ();
145 i != m_callbackList.end (); i++)
147 (*i) (a1, a2, a3, a4);
153 #endif /* CALLBACK_TRACE_H */