From 7acaffa8418bb9adc6ccde986f000f4b6ce2fea6 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 19 Jul 2007 15:10:59 +0200 Subject: [PATCH] fix testcase --- SConstruct | 1 + src/core/type-traits.h | 26 ++++ src/simulator/simulator.h | 245 ++++++++++++++++++++------------------ 3 files changed, 157 insertions(+), 115 deletions(-) create mode 100644 src/core/type-traits.h diff --git a/SConstruct b/SConstruct index 6d2a8c0b9..d23612623 100644 --- a/SConstruct +++ b/SConstruct @@ -93,6 +93,7 @@ core.add_inst_headers([ 'default-value.h', 'command-line.h', 'type-name.h', + 'type-traits.h', 'component-manager.h', ]) diff --git a/src/core/type-traits.h b/src/core/type-traits.h new file mode 100644 index 000000000..4a65404ad --- /dev/null +++ b/src/core/type-traits.h @@ -0,0 +1,26 @@ +#ifndef TYPE_TRAITS_H +#define TYPE_TRAITS_H + +template +struct TypeTraits; + +template +struct TypeTraits +{ + typedef T ReferencedType; +}; + +template +struct TypeTraits +{ + typedef T ReferencedType; +}; + +template +struct TypeTraits +{ + typedef T ReferencedType; +}; + + +#endif /* TYPE_TRAITS_H */ diff --git a/src/simulator/simulator.h b/src/simulator/simulator.h index 1a3675c66..59a888459 100644 --- a/src/simulator/simulator.h +++ b/src/simulator/simulator.h @@ -26,6 +26,7 @@ #include "event-id.h" #include "event-impl.h" #include "nstime.h" +#include "ns3/type-traits.h" namespace ns3 { @@ -232,8 +233,8 @@ public: * @param a1 the first argument to pass to the function to invoke * @returns an id for the scheduled event. */ - template - static EventId Schedule (Time const &time, void (*f) (T1), T1 a1); + template + static EventId Schedule (Time const &time, void (*f) (U1), T1 a1); /** * @param time the relative expiration time of the event. * @param f the function to invoke @@ -241,8 +242,8 @@ public: * @param a2 the second argument to pass to the function to invoke * @returns an id for the scheduled event. */ - template - static EventId Schedule (Time const &time, void (*f) (T1,T2), T1 a1, T2 a2); + template + static EventId Schedule (Time const &time, void (*f) (U1,U2), T1 a1, T2 a2); /** * @param time the relative expiration time of the event. * @param f the function to invoke @@ -251,8 +252,8 @@ public: * @param a3 the third argument to pass to the function to invoke * @returns an id for the scheduled event. */ - template - static EventId Schedule (Time const &time, void (*f) (T1,T2,T3), T1 a1, T2 a2, T3 a3); + template + static EventId Schedule (Time const &time, void (*f) (U1,U2,U3), T1 a1, T2 a2, T3 a3); /** * @param time the relative expiration time of the event. * @param f the function to invoke @@ -262,8 +263,9 @@ public: * @param a4 the fourth argument to pass to the function to invoke * @returns an id for the scheduled event. */ - template - static EventId Schedule (Time const &time, void (*f) (T1,T2,T3,T4), T1 a1, T2 a2, T3 a3, T4 a4); + template + static EventId Schedule (Time const &time, void (*f) (U1,U2,U3,U4), T1 a1, T2 a2, T3 a3, T4 a4); /** * @param time the relative expiration time of the event. * @param f the function to invoke @@ -274,8 +276,9 @@ public: * @param a5 the fifth argument to pass to the function to invoke * @returns an id for the scheduled event. */ - template - static EventId Schedule (Time const &time, void (*f) (T1,T2,T3,T4,T5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5); + template + static EventId Schedule (Time const &time, void (*f) (U1,U2,U3,U4,U5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5); /** @@ -529,6 +532,7 @@ public: private: Simulator (); ~Simulator (); + template static EventImpl *MakeEvent (void (T::*mem_ptr) (void), OBJ obj); template @@ -543,16 +547,20 @@ private: static EventImpl *MakeEvent (void (T::*mem_ptr) (T1,T2,T3,T4,T5), OBJ obj, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5); static EventImpl *MakeEvent (void (*f) (void)); - template - static EventImpl *MakeEvent (void (*f) (T1), T1 a1); - template - static EventImpl *MakeEvent (void (*f) (T1,T2), T1 a1, T2 a2); - template - static EventImpl *MakeEvent (void (*f) (T1,T2,T3), T1 a1, T2 a2, T3 a3); - template - static EventImpl *MakeEvent (void (*f) (T1,T2,T3,T4), T1 a1, T2 a2, T3 a3, T4 a4); - template - static EventImpl *MakeEvent (void (*f) (T1,T2,T3,T4,T5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5); + template + static EventImpl *MakeEvent (void (*f) (U1), T1 a1); + template + static EventImpl *MakeEvent (void (*f) (U1,U2), T1 a1, T2 a2); + template + static EventImpl *MakeEvent (void (*f) (U1,U2,U3), T1 a1, T2 a2, T3 a3); + template + static EventImpl *MakeEvent (void (*f) (U1,U2,U3,U4), T1 a1, T2 a2, T3 a3, T4 a4); + template + static EventImpl *MakeEvent (void (*f) (U1,U2,U3,U4,U5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5); static SimulatorPrivate *GetPriv (void); static EventId Schedule (Time const &time, EventImpl *event); @@ -767,142 +775,145 @@ EventImpl *Simulator::MakeEvent (void (T::*mem_ptr) (T1,T2,T3,T4,T5), OBJ obj, return ev; } -template -EventImpl *Simulator::MakeEvent (void (*f) (T1), T1 a1) +template +EventImpl *Simulator::MakeEvent (void (*f) (U1), T1 a1) { // one arg version class EventFunctionImpl1 : public EventImpl { public: - typedef void (*F)(T1); + typedef void (*F)(U1); - EventFunctionImpl1 (F function, T1 a1) - : m_function (function), - m_a1 (a1) - { } + EventFunctionImpl1 (F function, T1 a1) + : m_function (function), + m_a1 (a1) + { } protected: - virtual ~EventFunctionImpl1 () {} + virtual ~EventFunctionImpl1 () {} private: - virtual void Notify (void) { - (*m_function) (m_a1); - } - F m_function; - T1 m_a1; + virtual void Notify (void) { + (*m_function) (m_a1); + } + F m_function; + typename TypeTraits::ReferencedType m_a1; } *ev = new EventFunctionImpl1(f, a1); return ev; } -template -EventImpl *Simulator::MakeEvent (void (*f) (T1,T2), T1 a1, T2 a2) +template +EventImpl *Simulator::MakeEvent (void (*f) (U1,U2), T1 a1, T2 a2) { // two arg version class EventFunctionImpl2 : public EventImpl { public: - typedef void (*F)(T1, T2); + typedef void (*F)(U1, U2); - EventFunctionImpl2 (F function, T1 a1, T2 a2) - : m_function (function), - m_a1 (a1), - m_a2 (a2) - { } + EventFunctionImpl2 (F function, T1 a1, T2 a2) + : m_function (function), + m_a1 (a1), + m_a2 (a2) + {} protected: - virtual ~EventFunctionImpl2 () {} + virtual ~EventFunctionImpl2 () {} private: - virtual void Notify (void) { - (*m_function) (m_a1, m_a2); - } - F m_function; - T1 m_a1; - T2 m_a2; + virtual void Notify (void) { + (*m_function) (m_a1, m_a2); + } + F m_function; + typename TypeTraits::ReferencedType m_a1; + typename TypeTraits::ReferencedType m_a2; } *ev = new EventFunctionImpl2 (f, a1, a2); return ev; } -template -EventImpl *Simulator::MakeEvent (void (*f) (T1,T2,T3), T1 a1, T2 a2, T3 a3) +template +EventImpl *Simulator::MakeEvent (void (*f) (U1,U2,U3), T1 a1, T2 a2, T3 a3) { // three arg version class EventFunctionImpl3 : public EventImpl { public: - typedef void (*F)(T1, T2, T3); + typedef void (*F)(U1, U2, U3); - EventFunctionImpl3 (F function, T1 a1, T2 a2, T3 a3) - : m_function (function), - m_a1 (a1), - m_a2 (a2), - m_a3 (a3) - { } + EventFunctionImpl3 (F function, T1 a1, T2 a2, T3 a3) + : m_function (function), + m_a1 (a1), + m_a2 (a2), + m_a3 (a3) + { } protected: - virtual ~EventFunctionImpl3 () {} + virtual ~EventFunctionImpl3 () {} private: - virtual void Notify (void) { - (*m_function) (m_a1, m_a2, m_a3); - } - F m_function; - T1 m_a1; - T2 m_a2; - T3 m_a3; + virtual void Notify (void) { + (*m_function) (m_a1, m_a2, m_a3); + } + F m_function; + typename TypeTraits::ReferencedType m_a1; + typename TypeTraits::ReferencedType m_a2; + typename TypeTraits::ReferencedType m_a3; } *ev = new EventFunctionImpl3 (f, a1, a2, a3); return ev; } -template -EventImpl *Simulator::MakeEvent (void (*f) (T1,T2,T3,T4), T1 a1, T2 a2, T3 a3, T4 a4) +template +EventImpl *Simulator::MakeEvent (void (*f) (U1,U2,U3,U4), T1 a1, T2 a2, T3 a3, T4 a4) { // four arg version class EventFunctionImpl4 : public EventImpl { public: - typedef void (*F)(T1, T2, T3, T4); + typedef void (*F)(U1, U2, U3, U4); - EventFunctionImpl4 (F function, T1 a1, T2 a2, T3 a3, T4 a4) - : m_function (function), - m_a1 (a1), - m_a2 (a2), - m_a3 (a3), - m_a4 (a4) - { } + EventFunctionImpl4 (F function, T1 a1, T2 a2, T3 a3, T4 a4) + : m_function (function), + m_a1 (a1), + m_a2 (a2), + m_a3 (a3), + m_a4 (a4) + { } protected: - virtual ~EventFunctionImpl4 () {} + virtual ~EventFunctionImpl4 () {} private: - virtual void Notify (void) { - (*m_function) (m_a1, m_a2, m_a3, m_a4); - } - F m_function; - T1 m_a1; - T2 m_a2; - T3 m_a3; - T4 m_a4; + virtual void Notify (void) { + (*m_function) (m_a1, m_a2, m_a3, m_a4); + } + F m_function; + typename TypeTraits::ReferencedType m_a1; + typename TypeTraits::ReferencedType m_a2; + typename TypeTraits::ReferencedType m_a3; + typename TypeTraits::ReferencedType m_a4; } *ev = new EventFunctionImpl4 (f, a1, a2, a3, a4); return ev; } -template -EventImpl *Simulator::MakeEvent (void (*f) (T1,T2,T3,T4,T5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) +template +EventImpl *Simulator::MakeEvent (void (*f) (U1,U2,U3,U4,U5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) { // five arg version class EventFunctionImpl5 : public EventImpl { public: - typedef void (*F)(T1, T2, T3, T4, T5); + typedef void (*F)(U1,U2,U3,U4,U5); - EventFunctionImpl5 (F function, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) - : m_function (function), - m_a1 (a1), - m_a2 (a2), - m_a3 (a3), - m_a4 (a4), - m_a5 (a5) - { } + EventFunctionImpl5 (F function, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) + : m_function (function), + m_a1 (a1), + m_a2 (a2), + m_a3 (a3), + m_a4 (a4), + m_a5 (a5) + {} protected: - virtual ~EventFunctionImpl5 () {} + virtual ~EventFunctionImpl5 () {} private: - virtual void Notify (void) { - (*m_function) (m_a1, m_a2, m_a3, m_a4, m_a5); - } - F m_function; - T1 m_a1; - T2 m_a2; - T3 m_a3; - T4 m_a4; - T5 m_a5; + virtual void Notify (void) { + (*m_function) (m_a1, m_a2, m_a3, m_a4, m_a5); + } + F m_function; + typename TypeTraits::ReferencedType m_a1; + typename TypeTraits::ReferencedType m_a2; + typename TypeTraits::ReferencedType m_a3; + typename TypeTraits::ReferencedType m_a4; + typename TypeTraits::ReferencedType m_a5; } *ev = new EventFunctionImpl5 (f, a1, a2, a3, a4, a5); return ev; } @@ -945,32 +956,36 @@ EventId Simulator::Schedule (Time const &time, void (T::*mem_ptr) (T1,T2,T3,T4,T return Schedule (time, MakeEvent (mem_ptr, obj, a1, a2, a3, a4, a5)); } -template -EventId Simulator::Schedule (Time const &time, void (*f) (T1), T1 a1) +template +EventId Simulator::Schedule (Time const &time, void (*f) (U1), T1 a1) { return Schedule (time, MakeEvent (f, a1)); } -template -EventId Simulator::Schedule (Time const &time, void (*f) (T1,T2), T1 a1, T2 a2) +template +EventId Simulator::Schedule (Time const &time, void (*f) (U1,U2), T1 a1, T2 a2) { return Schedule (time, MakeEvent (f, a1, a2)); } -template -EventId Simulator::Schedule (Time const &time, void (*f) (T1,T2,T3), T1 a1, T2 a2, T3 a3) +template +EventId Simulator::Schedule (Time const &time, void (*f) (U1,U2,U3), T1 a1, T2 a2, T3 a3) { return Schedule (time, MakeEvent (f, a1, a2, a3)); } -template -EventId Simulator::Schedule (Time const &time, void (*f) (T1,T2,T3,T4), T1 a1, T2 a2, T3 a3, T4 a4) +template +EventId Simulator::Schedule (Time const &time, void (*f) (U1,U2,U3,U4), T1 a1, T2 a2, T3 a3, T4 a4) { return Schedule (time, MakeEvent (f, a1, a2, a3, a4)); } -template -EventId Simulator::Schedule (Time const &time, void (*f) (T1,T2,T3,T4,T5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) +template +EventId Simulator::Schedule (Time const &time, void (*f) (U1,U2,U3,U4,U5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) { return Schedule (time, MakeEvent (f, a1, a2, a3, a4, a5)); }