A Discrete-Event Network Simulator
API
make-event.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2008 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  */
19 
20 #ifndef MAKE_EVENT_H
21 #define MAKE_EVENT_H
22 
29 namespace ns3 {
30 
31 class EventImpl;
32 
54 template <typename MEM, typename OBJ>
55 EventImpl * MakeEvent (MEM mem_ptr, OBJ obj);
56 
67 template <typename MEM, typename OBJ,
68  typename T1>
69 EventImpl * MakeEvent (MEM mem_ptr, OBJ obj, T1 a1);
70 
83 template <typename MEM, typename OBJ,
84  typename T1, typename T2>
85 EventImpl * MakeEvent (MEM mem_ptr, OBJ obj, T1 a1, T2 a2);
86 
101 template <typename MEM, typename OBJ,
102  typename T1, typename T2, typename T3>
103 EventImpl * MakeEvent (MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3);
104 
121 template <typename MEM, typename OBJ,
122  typename T1, typename T2, typename T3, typename T4>
123 EventImpl * MakeEvent (MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3, T4 a4);
124 
143 template <typename MEM, typename OBJ,
144  typename T1, typename T2, typename T3, typename T4, typename T5>
145 EventImpl * MakeEvent (MEM mem_ptr, OBJ obj,
146  T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
165 EventImpl * MakeEvent (void (*f)(void));
166 
175 template <typename U1,
176  typename T1>
177 EventImpl * MakeEvent (void (*f)(U1), T1 a1);
178 
190 template <typename U1, typename U2,
191  typename T1, typename T2>
192 EventImpl * MakeEvent (void (*f)(U1,U2), T1 a1, T2 a2);
193 
208 template <typename U1, typename U2, typename U3,
209  typename T1, typename T2, typename T3>
210 EventImpl * MakeEvent (void (*f)(U1,U2,U3), T1 a1, T2 a2, T3 a3);
211 
229 template <typename U1, typename U2, typename U3, typename U4,
230  typename T1, typename T2, typename T3, typename T4>
231 EventImpl * MakeEvent (void (*f)(U1,U2,U3,U4), T1 a1, T2 a2, T3 a3, T4 a4);
232 
253 template <typename U1, typename U2, typename U3, typename U4, typename U5,
254  typename T1, typename T2, typename T3, typename T4, typename T5>
255 EventImpl * MakeEvent (void (*f)(U1,U2,U3,U4,U5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
258 } // namespace ns3
259 
260 /********************************************************************
261  * Implementation of the templates declared above.
262  ********************************************************************/
263 
264 #include "event-impl.h"
265 #include "type-traits.h"
266 
267 namespace ns3 {
268 
279 template <typename T>
281 
292 template <typename T>
294 {
299  static T &GetReference (T *p)
300  {
301  return *p;
302  }
303 };
304 
305 template <typename MEM, typename OBJ>
306 EventImpl * MakeEvent (MEM mem_ptr, OBJ obj)
307 {
308  // zero argument version
309  class EventMemberImpl0 : public EventImpl
310  {
311 public:
312  EventMemberImpl0 (OBJ obj, MEM function)
313  : m_obj (obj),
314  m_function (function)
315  {
316  }
317  virtual ~EventMemberImpl0 ()
318  {
319  }
320 private:
321  virtual void Notify (void)
322  {
323  (EventMemberImplObjTraits<OBJ>::GetReference (m_obj).*m_function)();
324  }
325  OBJ m_obj;
326  MEM m_function;
327  } *ev = new EventMemberImpl0 (obj, mem_ptr);
328  return ev;
329 }
330 
331 
332 template <typename MEM, typename OBJ,
333  typename T1>
334 EventImpl * MakeEvent (MEM mem_ptr, OBJ obj, T1 a1)
335 {
336  // one argument version
337  class EventMemberImpl1 : public EventImpl
338  {
339 public:
340  EventMemberImpl1 (OBJ obj, MEM function, T1 a1)
341  : m_obj (obj),
342  m_function (function),
343  m_a1 (a1)
344  {
345  }
346 protected:
347  virtual ~EventMemberImpl1 ()
348  {
349  }
350 private:
351  virtual void Notify (void)
352  {
353  (EventMemberImplObjTraits<OBJ>::GetReference (m_obj).*m_function)(m_a1);
354  }
355  OBJ m_obj;
356  MEM m_function;
357  typename TypeTraits<T1>::ReferencedType m_a1;
358  } *ev = new EventMemberImpl1 (obj, mem_ptr, a1);
359  return ev;
360 }
361 
362 template <typename MEM, typename OBJ,
363  typename T1, typename T2>
364 EventImpl * MakeEvent (MEM mem_ptr, OBJ obj, T1 a1, T2 a2)
365 {
366  // two argument version
367  class EventMemberImpl2 : public EventImpl
368  {
369 public:
370  EventMemberImpl2 (OBJ obj, MEM function, T1 a1, T2 a2)
371  : m_obj (obj),
372  m_function (function),
373  m_a1 (a1),
374  m_a2 (a2)
375  {
376  }
377 protected:
378  virtual ~EventMemberImpl2 ()
379  {
380  }
381 private:
382  virtual void Notify (void)
383  {
384  (EventMemberImplObjTraits<OBJ>::GetReference (m_obj).*m_function)(m_a1, m_a2);
385  }
386  OBJ m_obj;
387  MEM m_function;
388  typename TypeTraits<T1>::ReferencedType m_a1;
389  typename TypeTraits<T2>::ReferencedType m_a2;
390  } *ev = new EventMemberImpl2 (obj, mem_ptr, a1, a2);
391  return ev;
392 }
393 
394 template <typename MEM, typename OBJ,
395  typename T1, typename T2, typename T3>
396 EventImpl * MakeEvent (MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3)
397 {
398  // three argument version
399  class EventMemberImpl3 : public EventImpl
400  {
401 public:
402  EventMemberImpl3 (OBJ obj, MEM function, T1 a1, T2 a2, T3 a3)
403  : m_obj (obj),
404  m_function (function),
405  m_a1 (a1),
406  m_a2 (a2),
407  m_a3 (a3)
408  {
409  }
410 protected:
411  virtual ~EventMemberImpl3 ()
412  {
413  }
414 private:
415  virtual void Notify (void)
416  {
417  (EventMemberImplObjTraits<OBJ>::GetReference (m_obj).*m_function)(m_a1, m_a2, m_a3);
418  }
419  OBJ m_obj;
420  MEM m_function;
421  typename TypeTraits<T1>::ReferencedType m_a1;
422  typename TypeTraits<T2>::ReferencedType m_a2;
423  typename TypeTraits<T3>::ReferencedType m_a3;
424  } *ev = new EventMemberImpl3 (obj, mem_ptr, a1, a2, a3);
425  return ev;
426 }
427 
428 template <typename MEM, typename OBJ,
429  typename T1, typename T2, typename T3, typename T4>
430 EventImpl * MakeEvent (MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3, T4 a4)
431 {
432  // four argument version
433  class EventMemberImpl4 : public EventImpl
434  {
435 public:
436  EventMemberImpl4 (OBJ obj, MEM function, T1 a1, T2 a2, T3 a3, T4 a4)
437  : m_obj (obj),
438  m_function (function),
439  m_a1 (a1),
440  m_a2 (a2),
441  m_a3 (a3),
442  m_a4 (a4)
443  {
444  }
445 protected:
446  virtual ~EventMemberImpl4 ()
447  {
448  }
449 private:
450  virtual void Notify (void)
451  {
452  (EventMemberImplObjTraits<OBJ>::GetReference (m_obj).*m_function)(m_a1, m_a2, m_a3, m_a4);
453  }
454  OBJ m_obj;
455  MEM m_function;
456  typename TypeTraits<T1>::ReferencedType m_a1;
457  typename TypeTraits<T2>::ReferencedType m_a2;
458  typename TypeTraits<T3>::ReferencedType m_a3;
459  typename TypeTraits<T4>::ReferencedType m_a4;
460  } *ev = new EventMemberImpl4 (obj, mem_ptr, a1, a2, a3, a4);
461  return ev;
462 }
463 
464 template <typename MEM, typename OBJ,
465  typename T1, typename T2, typename T3, typename T4, typename T5>
466 EventImpl * MakeEvent (MEM mem_ptr, OBJ obj,
467  T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
468 {
469  // five argument version
470  class EventMemberImpl5 : public EventImpl
471  {
472 public:
473  EventMemberImpl5 (OBJ obj, MEM function, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
474  : m_obj (obj),
475  m_function (function),
476  m_a1 (a1),
477  m_a2 (a2),
478  m_a3 (a3),
479  m_a4 (a4),
480  m_a5 (a5)
481  {
482  }
483 protected:
484  virtual ~EventMemberImpl5 ()
485  {
486  }
487 private:
488  virtual void Notify (void)
489  {
490  (EventMemberImplObjTraits<OBJ>::GetReference (m_obj).*m_function)(m_a1, m_a2, m_a3, m_a4, m_a5);
491  }
492  OBJ m_obj;
493  MEM m_function;
494  typename TypeTraits<T1>::ReferencedType m_a1;
495  typename TypeTraits<T2>::ReferencedType m_a2;
496  typename TypeTraits<T3>::ReferencedType m_a3;
497  typename TypeTraits<T4>::ReferencedType m_a4;
498  typename TypeTraits<T5>::ReferencedType m_a5;
499  } *ev = new EventMemberImpl5 (obj, mem_ptr, a1, a2, a3, a4, a5);
500  return ev;
501 }
502 
503 template <typename U1, typename T1>
504 EventImpl * MakeEvent (void (*f)(U1), T1 a1)
505 {
506  // one arg version
507  class EventFunctionImpl1 : public EventImpl
508  {
509 public:
510  typedef void (*F)(U1);
511 
512  EventFunctionImpl1 (F function, T1 a1)
513  : m_function (function),
514  m_a1 (a1)
515  {
516  }
517 protected:
518  virtual ~EventFunctionImpl1 ()
519  {
520  }
521 private:
522  virtual void Notify (void)
523  {
524  (*m_function)(m_a1);
525  }
526  F m_function;
527  typename TypeTraits<T1>::ReferencedType m_a1;
528  } *ev = new EventFunctionImpl1 (f, a1);
529  return ev;
530 }
531 
532 template <typename U1, typename U2, typename T1, typename T2>
533 EventImpl * MakeEvent (void (*f)(U1,U2), T1 a1, T2 a2)
534 {
535  // two arg version
536  class EventFunctionImpl2 : public EventImpl
537  {
538 public:
539  typedef void (*F)(U1, U2);
540 
541  EventFunctionImpl2 (F function, T1 a1, T2 a2)
542  : m_function (function),
543  m_a1 (a1),
544  m_a2 (a2)
545  {
546  }
547 protected:
548  virtual ~EventFunctionImpl2 ()
549  {
550  }
551 private:
552  virtual void Notify (void)
553  {
554  (*m_function)(m_a1, m_a2);
555  }
556  F m_function;
557  typename TypeTraits<T1>::ReferencedType m_a1;
558  typename TypeTraits<T2>::ReferencedType m_a2;
559  } *ev = new EventFunctionImpl2 (f, a1, a2);
560  return ev;
561 }
562 
563 template <typename U1, typename U2, typename U3,
564  typename T1, typename T2, typename T3>
565 EventImpl * MakeEvent (void (*f)(U1,U2,U3), T1 a1, T2 a2, T3 a3)
566 {
567  // three arg version
568  class EventFunctionImpl3 : public EventImpl
569  {
570 public:
571  typedef void (*F)(U1, U2, U3);
572 
573  EventFunctionImpl3 (F function, T1 a1, T2 a2, T3 a3)
574  : m_function (function),
575  m_a1 (a1),
576  m_a2 (a2),
577  m_a3 (a3)
578  {
579  }
580 protected:
581  virtual ~EventFunctionImpl3 ()
582  {
583  }
584 private:
585  virtual void Notify (void)
586  {
587  (*m_function)(m_a1, m_a2, m_a3);
588  }
589  F m_function;
590  typename TypeTraits<T1>::ReferencedType m_a1;
591  typename TypeTraits<T2>::ReferencedType m_a2;
592  typename TypeTraits<T3>::ReferencedType m_a3;
593  } *ev = new EventFunctionImpl3 (f, a1, a2, a3);
594  return ev;
595 }
596 
597 template <typename U1, typename U2, typename U3, typename U4,
598  typename T1, typename T2, typename T3, typename T4>
599 EventImpl * MakeEvent (void (*f)(U1,U2,U3,U4), T1 a1, T2 a2, T3 a3, T4 a4)
600 {
601  // four arg version
602  class EventFunctionImpl4 : public EventImpl
603  {
604 public:
605  typedef void (*F)(U1, U2, U3, U4);
606 
607  EventFunctionImpl4 (F function, T1 a1, T2 a2, T3 a3, T4 a4)
608  : m_function (function),
609  m_a1 (a1),
610  m_a2 (a2),
611  m_a3 (a3),
612  m_a4 (a4)
613  {
614  }
615 protected:
616  virtual ~EventFunctionImpl4 ()
617  {
618  }
619 private:
620  virtual void Notify (void)
621  {
622  (*m_function)(m_a1, m_a2, m_a3, m_a4);
623  }
624  F m_function;
625  typename TypeTraits<T1>::ReferencedType m_a1;
626  typename TypeTraits<T2>::ReferencedType m_a2;
627  typename TypeTraits<T3>::ReferencedType m_a3;
628  typename TypeTraits<T4>::ReferencedType m_a4;
629  } *ev = new EventFunctionImpl4 (f, a1, a2, a3, a4);
630  return ev;
631 }
632 
633 template <typename U1, typename U2, typename U3, typename U4, typename U5,
634  typename T1, typename T2, typename T3, typename T4, typename T5>
635 EventImpl * MakeEvent (void (*f)(U1,U2,U3,U4,U5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
636 {
637  // five arg version
638  class EventFunctionImpl5 : public EventImpl
639  {
640 public:
641  typedef void (*F)(U1,U2,U3,U4,U5);
642 
643  EventFunctionImpl5 (F function, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
644  : m_function (function),
645  m_a1 (a1),
646  m_a2 (a2),
647  m_a3 (a3),
648  m_a4 (a4),
649  m_a5 (a5)
650  {
651  }
652 protected:
653  virtual ~EventFunctionImpl5 ()
654  {
655  }
656 private:
657  virtual void Notify (void)
658  {
659  (*m_function)(m_a1, m_a2, m_a3, m_a4, m_a5);
660  }
661  F m_function;
662  typename TypeTraits<T1>::ReferencedType m_a1;
663  typename TypeTraits<T2>::ReferencedType m_a2;
664  typename TypeTraits<T3>::ReferencedType m_a3;
665  typename TypeTraits<T4>::ReferencedType m_a4;
666  typename TypeTraits<T5>::ReferencedType m_a5;
667  } *ev = new EventFunctionImpl5 (f, a1, a2, a3, a4, a5);
668  return ev;
669 }
670 
671 } // namespace ns3
672 
673 #endif /* MAKE_EVENT_H */
ns3::EventImpl declarations.
Helper for the MakeEvent functions which take a class method.
Definition: make-event.h:280
double f(double x, void *params)
Definition: 80211b.c:60
Every class exported by the ns3 library is enclosed in the ns3 namespace.
A simulation event.
Definition: event-impl.h:44
Inspect a type to deduce its features.
Definition: type-traits.h:37
TypeTraits introspection template.
EventImpl * MakeEvent(void(*f)(void))
Make an EventImpl from a function pointer taking varying numbers of arguments.
Definition: make-event.cc:34