fix testcase

This commit is contained in:
Mathieu Lacage
2007-07-19 15:10:59 +02:00
parent ea7652677d
commit 7acaffa841
3 changed files with 157 additions and 115 deletions

View File

@@ -93,6 +93,7 @@ core.add_inst_headers([
'default-value.h',
'command-line.h',
'type-name.h',
'type-traits.h',
'component-manager.h',
])

26
src/core/type-traits.h Normal file
View File

@@ -0,0 +1,26 @@
#ifndef TYPE_TRAITS_H
#define TYPE_TRAITS_H
template <typename T>
struct TypeTraits;
template <typename T>
struct TypeTraits
{
typedef T ReferencedType;
};
template <typename T>
struct TypeTraits<const T &>
{
typedef T ReferencedType;
};
template <typename T>
struct TypeTraits<T &>
{
typedef T ReferencedType;
};
#endif /* TYPE_TRAITS_H */

View File

@@ -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 <typename T1>
static EventId Schedule (Time const &time, void (*f) (T1), T1 a1);
template <typename U1, typename T1>
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 <typename T1, typename T2>
static EventId Schedule (Time const &time, void (*f) (T1,T2), T1 a1, T2 a2);
template <typename U1, typename U2, typename T1, typename T2>
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 <typename T1, typename T2, typename T3>
static EventId Schedule (Time const &time, void (*f) (T1,T2,T3), T1 a1, T2 a2, T3 a3);
template <typename U1, typename U2, typename U3, typename T1, typename T2, typename T3>
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 <typename T1, typename T2, typename T3, typename T4>
static EventId Schedule (Time const &time, void (*f) (T1,T2,T3,T4), T1 a1, T2 a2, T3 a3, T4 a4);
template <typename U1, typename U2, typename U3, typename U4,
typename T1, typename T2, typename T3, typename T4>
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 <typename T1, typename T2, typename T3, typename T4, typename T5>
static EventId Schedule (Time const &time, void (*f) (T1,T2,T3,T4,T5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
template <typename U1, typename U2, typename U3, typename U4, typename U5,
typename T1, typename T2, typename T3, typename T4, typename T5>
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 <typename T, typename OBJ>
static EventImpl *MakeEvent (void (T::*mem_ptr) (void), OBJ obj);
template <typename T, typename OBJ, typename T1>
@@ -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 <typename T1>
static EventImpl *MakeEvent (void (*f) (T1), T1 a1);
template <typename T1, typename T2>
static EventImpl *MakeEvent (void (*f) (T1,T2), T1 a1, T2 a2);
template <typename T1, typename T2, typename T3>
static EventImpl *MakeEvent (void (*f) (T1,T2,T3), T1 a1, T2 a2, T3 a3);
template <typename T1, typename T2, typename T3, typename T4>
static EventImpl *MakeEvent (void (*f) (T1,T2,T3,T4), T1 a1, T2 a2, T3 a3, T4 a4);
template <typename T1, typename T2, typename T3, typename T4, typename T5>
static EventImpl *MakeEvent (void (*f) (T1,T2,T3,T4,T5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
template <typename U1, typename T1>
static EventImpl *MakeEvent (void (*f) (U1), T1 a1);
template <typename U1, typename U2,
typename T1, typename T2>
static EventImpl *MakeEvent (void (*f) (U1,U2), T1 a1, T2 a2);
template <typename U1, typename U2, typename U3,
typename T1, typename T2, typename T3>
static EventImpl *MakeEvent (void (*f) (U1,U2,U3), T1 a1, T2 a2, T3 a3);
template <typename U1, typename U2, typename U3, typename U4,
typename T1, typename T2, typename T3, typename T4>
static EventImpl *MakeEvent (void (*f) (U1,U2,U3,U4), T1 a1, T2 a2, T3 a3, T4 a4);
template <typename U1, typename U2, typename U3, typename U4, typename U5,
typename T1, typename T2, typename T3, typename T4, typename T5>
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 <typename T1>
EventImpl *Simulator::MakeEvent (void (*f) (T1), T1 a1)
template <typename U1, typename T1>
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<T1>::ReferencedType m_a1;
} *ev = new EventFunctionImpl1(f, a1);
return ev;
}
template <typename T1, typename T2>
EventImpl *Simulator::MakeEvent (void (*f) (T1,T2), T1 a1, T2 a2)
template <typename U1, typename U2, typename T1, typename T2>
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<T1>::ReferencedType m_a1;
typename TypeTraits<T2>::ReferencedType m_a2;
} *ev = new EventFunctionImpl2 (f, a1, a2);
return ev;
}
template <typename T1, typename T2, typename T3>
EventImpl *Simulator::MakeEvent (void (*f) (T1,T2,T3), T1 a1, T2 a2, T3 a3)
template <typename U1, typename U2, typename U3,
typename T1, typename T2, typename T3>
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<T1>::ReferencedType m_a1;
typename TypeTraits<T2>::ReferencedType m_a2;
typename TypeTraits<T3>::ReferencedType m_a3;
} *ev = new EventFunctionImpl3 (f, a1, a2, a3);
return ev;
}
template <typename T1, typename T2, typename T3, typename T4>
EventImpl *Simulator::MakeEvent (void (*f) (T1,T2,T3,T4), T1 a1, T2 a2, T3 a3, T4 a4)
template <typename U1, typename U2, typename U3, typename U4,
typename T1, typename T2, typename T3, typename T4>
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<T1>::ReferencedType m_a1;
typename TypeTraits<T2>::ReferencedType m_a2;
typename TypeTraits<T3>::ReferencedType m_a3;
typename TypeTraits<T4>::ReferencedType m_a4;
} *ev = new EventFunctionImpl4 (f, a1, a2, a3, a4);
return ev;
}
template <typename T1, typename T2, typename T3, typename T4, typename T5>
EventImpl *Simulator::MakeEvent (void (*f) (T1,T2,T3,T4,T5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
template <typename U1, typename U2, typename U3, typename U4, typename U5,
typename T1, typename T2, typename T3, typename T4, typename T5>
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<T1>::ReferencedType m_a1;
typename TypeTraits<T2>::ReferencedType m_a2;
typename TypeTraits<T3>::ReferencedType m_a3;
typename TypeTraits<T4>::ReferencedType m_a4;
typename TypeTraits<T5>::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 <typename T1>
EventId Simulator::Schedule (Time const &time, void (*f) (T1), T1 a1)
template <typename U1, typename T1>
EventId Simulator::Schedule (Time const &time, void (*f) (U1), T1 a1)
{
return Schedule (time, MakeEvent (f, a1));
}
template <typename T1, typename T2>
EventId Simulator::Schedule (Time const &time, void (*f) (T1,T2), T1 a1, T2 a2)
template <typename U1, typename U2,
typename T1, typename T2>
EventId Simulator::Schedule (Time const &time, void (*f) (U1,U2), T1 a1, T2 a2)
{
return Schedule (time, MakeEvent (f, a1, a2));
}
template <typename T1, typename T2, typename T3>
EventId Simulator::Schedule (Time const &time, void (*f) (T1,T2,T3), T1 a1, T2 a2, T3 a3)
template <typename U1, typename U2, typename U3,
typename T1, typename T2, typename T3>
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 <typename T1, typename T2, typename T3, typename T4>
EventId Simulator::Schedule (Time const &time, void (*f) (T1,T2,T3,T4), T1 a1, T2 a2, T3 a3, T4 a4)
template <typename U1, typename U2, typename U3, typename U4,
typename T1, typename T2, typename T3, typename T4>
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 <typename T1, typename T2, typename T3, typename T4, typename T5>
EventId Simulator::Schedule (Time const &time, void (*f) (T1,T2,T3,T4,T5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
template <typename U1, typename U2, typename U3, typename U4, typename U5,
typename T1, typename T2, typename T3, typename T4, typename T5>
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));
}