fix coding style

Mathieu Lacage 2006-11-01 13:11:30 +01:00
parent 5a2a57e052
commit 0fade9d7af
62 changed files with 5051 additions and 5051 deletions

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
#include "ns3/callback.h"
#include <cassert>
#include <iostream>
@ -8,51 +8,51 @@ using namespace ns3;
static double
CbOne (double a, double b)
{
std::cout << "invoke cbOne a=" << a << ", b=" << b << std::endl;
return a;
std::cout << "invoke cbOne a=" << a << ", b=" << b << std::endl;
return a;
}
class MyCb {
public:
int CbTwo (double a) {
std::cout << "invoke cbTwo a=" << a << std::endl;
return -5;
}
int CbTwo (double a) {
std::cout << "invoke cbTwo a=" << a << std::endl;
return -5;
}
};
int main (int argc, char *argv[])
{
// return type: double
// first arg type: double
// second arg type: double
Callback<double, double, double> one;
// build callback instance which points to cbOne function
one = MakeCallback (&CbOne);
// this is not a null callback
assert (!one.IsNull ());
// invoke cbOne function through callback instance
double retOne;
retOne = one (10.0, 20.0);
// return type: double
// first arg type: double
// second arg type: double
Callback<double, double, double> one;
// build callback instance which points to cbOne function
one = MakeCallback (&CbOne);
// this is not a null callback
assert (!one.IsNull ());
// invoke cbOne function through callback instance
double retOne;
retOne = one (10.0, 20.0);
// return type: int
// first arg type: double
Callback<int, double> two;
MyCb cb;
// build callback instance which points to MyCb::cbTwo
two = MakeCallback (&MyCb::CbTwo, &cb);
// this is not a null callback
assert (!two.IsNull ());
// invoke MyCb::cbTwo through callback instance
int retTwo;
retTwo = two (10.0);
// return type: int
// first arg type: double
Callback<int, double> two;
MyCb cb;
// build callback instance which points to MyCb::cbTwo
two = MakeCallback (&MyCb::CbTwo, &cb);
// this is not a null callback
assert (!two.IsNull ());
// invoke MyCb::cbTwo through callback instance
int retTwo;
retTwo = two (10.0);
two = MakeNullCallback<int, double> ();
// invoking a null callback is just like
// invoking a null function pointer:
// it will crash.
//int retTwoNull = two (20.0);
assert (two.IsNull ());
two = MakeNullCallback<int, double> ();
// invoking a null callback is just like
// invoking a null function pointer:
// it will crash.
//int retTwoNull = two (20.0);
assert (two.IsNull ());
return 0;
return 0;
}

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
#include "ns3/packet.h"
#include "ns3/header.h"
#include <iostream>
@ -9,18 +9,18 @@ using namespace ns3;
*/
class MyHeader : public Header {
public:
MyHeader ();
virtual ~MyHeader ();
MyHeader ();
virtual ~MyHeader ();
void SetData (uint16_t data);
uint16_t GetData (void) const;
void SetData (uint16_t data);
uint16_t GetData (void) const;
private:
virtual void PrintTo (std::ostream &os) const;
virtual void SerializeTo (Buffer::Iterator start) const;
virtual void DeserializeFrom (Buffer::Iterator start);
virtual uint32_t GetSerializedSize (void) const;
virtual void PrintTo (std::ostream &os) const;
virtual void SerializeTo (Buffer::Iterator start) const;
virtual void DeserializeFrom (Buffer::Iterator start);
virtual uint32_t GetSerializedSize (void) const;
uint16_t m_data;
uint16_t m_data;
};
MyHeader::MyHeader ()
@ -30,41 +30,41 @@ MyHeader::~MyHeader ()
void
MyHeader::PrintTo (std::ostream &os) const
{
os << "MyHeader data=" << m_data << std::endl;
os << "MyHeader data=" << m_data << std::endl;
}
uint32_t
MyHeader::GetSerializedSize (void) const
{
return 2;
return 2;
}
void
MyHeader::SerializeTo (Buffer::Iterator start) const
{
// serialize in head of buffer
start.WriteHtonU16 (m_data);
// serialize in head of buffer
start.WriteHtonU16 (m_data);
}
void
MyHeader::DeserializeFrom (Buffer::Iterator start)
{
// deserialize from head of buffer
m_data = start.ReadNtohU16 ();
// deserialize from head of buffer
m_data = start.ReadNtohU16 ();
}
void
MyHeader::SetData (uint16_t data)
{
m_data = data;
m_data = data;
}
uint16_t
MyHeader::GetData (void) const
{
return m_data;
return m_data;
}
/* A sample Tag implementation
*/
struct MyTag {
uint16_t m_streamId;
uint16_t m_streamId;
};
static TagRegistration<struct MyTag> g_MyTagRegistration ("ns3::MyTag", 0);
@ -73,25 +73,25 @@ static TagRegistration<struct MyTag> g_MyTagRegistration ("ns3::MyTag", 0);
static void
Receive (Packet p)
{
MyHeader my;
p.Peek (my);
p.Remove (my);
std::cout << "received data=" << my.GetData () << std::endl;
struct MyTag myTag;
p.PeekTag (myTag);
MyHeader my;
p.Peek (my);
p.Remove (my);
std::cout << "received data=" << my.GetData () << std::endl;
struct MyTag myTag;
p.PeekTag (myTag);
}
int main (int argc, char *argv[])
{
Packet p;
MyHeader my;
my.SetData (2);
std::cout << "send data=2" << std::endl;
p.Add (my);
struct MyTag myTag;
myTag.m_streamId = 5;
p.AddTag (myTag);
Receive (p);
return 0;
Packet p;
MyHeader my;
my.SetData (2);
std::cout << "send data=2" << std::endl;
p.Add (my);
struct MyTag myTag;
myTag.m_streamId = 5;
p.AddTag (myTag);
Receive (p);
return 0;
}

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
#include "ns3/simulator.h"
#include "ns3/nstime.h"
#include <iostream>
@ -7,41 +7,41 @@ using namespace ns3;
class MyModel {
public:
void Start (void);
void Start (void);
private:
void DealWithEvent (double eventValue);
void DealWithEvent (double eventValue);
};
void
MyModel::Start (void)
{
Simulator::Schedule (Now () + Seconds (10.0),
&MyModel::DealWithEvent,
this, Simulator::Now ().ApproximateToSeconds ());
Simulator::Schedule (Now () + Seconds (10.0),
&MyModel::DealWithEvent,
this, Simulator::Now ().ApproximateToSeconds ());
}
void
MyModel::DealWithEvent (double value)
{
std::cout << "Member method received event at " << Simulator::Now ().ApproximateToSeconds ()
<< "s started at " << value << "s" << std::endl;
std::cout << "Member method received event at " << Simulator::Now ().ApproximateToSeconds ()
<< "s started at " << value << "s" << std::endl;
}
static void
random_function (MyModel *model)
{
std::cout << "random function received event at " <<
Simulator::Now ().ApproximateToSeconds () << "s" << std::endl;
model->Start ();
std::cout << "random function received event at " <<
Simulator::Now ().ApproximateToSeconds () << "s" << std::endl;
model->Start ();
}
int main (int argc, char *argv[])
{
MyModel model;
MyModel model;
Simulator::Schedule (Now () + Seconds (10.0), &random_function, &model);
Simulator::Schedule (Now () + Seconds (10.0), &random_function, &model);
Simulator::Run ();
Simulator::Run ();
Simulator::Destroy ();
Simulator::Destroy ();
}

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
#include "ns3/test.h"
@ -9,24 +9,24 @@ using namespace ns3;
// declare subclass of base class Test
class MyTest : public Test {
public:
MyTest (bool ok);
virtual ~MyTest ();
virtual bool RunTests (void);
MyTest (bool ok);
virtual ~MyTest ();
virtual bool RunTests (void);
private:
bool m_ok;
bool m_ok;
};
// implement MyTest
MyTest::MyTest (bool ok)
: Test ("My"),
m_ok (ok)
: Test ("My"),
m_ok (ok)
{}
MyTest::~MyTest ()
{}
bool
MyTest::RunTests (void)
{
return m_ok;
return m_ok;
}
// instantiate MyTest once
@ -36,8 +36,8 @@ static MyTest g_my_test = MyTest (true);
int main (int argc, char *argv[])
{
// run tests
TestManager::EnableVerbose ();
TestManager::RunTests ();
return 0;
// run tests
TestManager::EnableVerbose ();
TestManager::RunTests ();
return 0;
}

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
#include "ns3/trace-container.h"
#include "ns3/ui-variable-tracer.h"
#include "ns3/callback-tracer.h"
@ -17,22 +17,22 @@ CallbackTracer<double, int> d;
void
RegisterAllTraceSources (TraceContainer *container)
{
container->RegisterCallback ("source-a", &a);
container->RegisterUiVariable ("source-b", &b);
container->RegisterStream ("source-c", &c);
container->RegisterCallback ("source-d", &d);
container->RegisterCallback ("source-a", &a);
container->RegisterUiVariable ("source-b", &b);
container->RegisterStream ("source-c", &c);
container->RegisterCallback ("source-d", &d);
}
void
GenerateTraceEvents (void)
{
// log en empty packet
a (Packet ());
b = 10;
b += 100;
b += 50;
b = (unsigned short) -20;
c << "this is a simple test b=" << b << std::endl;
d (3.1415, 3);
// log en empty packet
a (Packet ());
b = 10;
b += 100;
b += 50;
b = (unsigned short) -20;
c << "this is a simple test b=" << b << std::endl;
d (3.1415, 3);
}
void
@ -46,16 +46,16 @@ CallbackEvent (double a, int b)
int main (int argc, char *argv[])
{
TraceContainer traces;
RegisterAllTraceSources (&traces);
PcapWriter pcap;
pcap.Open ("trace-test.log");
pcap.WriteHeaderEthernet ();
traces.SetCallback ("source-a",
MakeCallback (&PcapWriter::WritePacket, &pcap));
traces.SetUiVariableCallback ("source-b", MakeCallback (&VariableEvent));
traces.SetStream ("source-c", &std::cout);
traces.SetCallback ("source-d", MakeCallback (&CallbackEvent));
GenerateTraceEvents ();
return 0;
TraceContainer traces;
RegisterAllTraceSources (&traces);
PcapWriter pcap;
pcap.Open ("trace-test.log");
pcap.WriteHeaderEthernet ();
traces.SetCallback ("source-a",
MakeCallback (&PcapWriter::WritePacket, &pcap));
traces.SetUiVariableCallback ("source-b", MakeCallback (&VariableEvent));
traces.SetStream ("source-c", &std::cout);
traces.SetCallback ("source-d", MakeCallback (&CallbackEvent));
GenerateTraceEvents ();
return 0;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005,2006 INRIA
* All rights reserved.
@ -35,54 +35,54 @@ class CallbackTracerBase {};
* are forwarded to the internal matching ns3::Callback.
*/
template<typename T1 = empty, typename T2 = empty,
typename T3 = empty, typename T4 = empty,
typename T5 = empty>
typename T3 = empty, typename T4 = empty,
typename T5 = empty>
class CallbackTracer : public CallbackTracerBase{
public:
CallbackTracer ()
: m_callback () {}
void SetCallback (Callback<void,T1,T2,T3,T4,T5> callback) {
m_callback = callback;
}
void operator() (void) {
if (!m_callback.IsNull ())
{
m_callback ();
}
}
void operator() (T1 a1) {
if (!m_callback.IsNull ())
{
m_callback (a1);
}
}
void operator() (T1 a1, T2 a2) {
if (!m_callback.IsNull ())
{
m_callback (a1,a2);
}
}
void operator() (T1 a1, T2 a2, T3 a3) {
if (!m_callback.IsNull ())
{
m_callback (a1,a2,a3);
}
}
void operator() (T1 a1, T2 a2, T3 a3, T4 a4) {
if (!m_callback.IsNull ())
{
m_callback (a1,a2,a3,a4);
}
}
void operator() (T1 a1, T2 a2, T3 a3, T4 a4,T5 a5) {
if (!m_callback.IsNull ())
{
m_callback (a1,a2,a3,a4,a5);
}
}
CallbackTracer ()
: m_callback () {}
void SetCallback (Callback<void,T1,T2,T3,T4,T5> callback) {
m_callback = callback;
}
void operator() (void) {
if (!m_callback.IsNull ())
{
m_callback ();
}
}
void operator() (T1 a1) {
if (!m_callback.IsNull ())
{
m_callback (a1);
}
}
void operator() (T1 a1, T2 a2) {
if (!m_callback.IsNull ())
{
m_callback (a1,a2);
}
}
void operator() (T1 a1, T2 a2, T3 a3) {
if (!m_callback.IsNull ())
{
m_callback (a1,a2,a3);
}
}
void operator() (T1 a1, T2 a2, T3 a3, T4 a4) {
if (!m_callback.IsNull ())
{
m_callback (a1,a2,a3,a4);
}
}
void operator() (T1 a1, T2 a2, T3 a3, T4 a4,T5 a5) {
if (!m_callback.IsNull ())
{
m_callback (a1,a2,a3,a4,a5);
}
}
private:
Callback<void,T1,T2,T3,T4,T5> m_callback;
Callback<void,T1,T2,T3,T4,T5> m_callback;
};
}; // namespace ns3

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005 INRIA
* All rights reserved.
@ -46,32 +46,32 @@ namespace ns3 {
class DataWriterPrivate {
public:
DataWriterPrivate ();
~DataWriterPrivate ();
DataWriterPrivate ();
~DataWriterPrivate ();
void open (char const *filename);
void write (uint8_t *buffer, uint32_t size);
void open (char const *filename);
void write (uint8_t *buffer, uint32_t size);
private:
uint8_t m_data[BUFFER_SIZE];
uint32_t m_current;
int m_fd;
uint8_t m_data[BUFFER_SIZE];
uint32_t m_current;
int m_fd;
};
DataWriterPrivate::DataWriterPrivate ()
: m_current (0)
: m_current (0)
{}
DataWriterPrivate::~DataWriterPrivate ()
{
::Write (m_fd, m_data, m_current);
::Close (m_fd);
::Write (m_fd, m_data, m_current);
::Close (m_fd);
}
void
DataWriterPrivate::Open (char const *filename)
{
m_fd = ::Open (filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
assert (m_fd != -1);
m_fd = ::Open (filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
assert (m_fd != -1);
}
#ifndef min
@ -81,41 +81,41 @@ DataWriterPrivate::Open (char const *filename)
void
DataWriterPrivate::Write (uint8_t *buffer, uint32_t size)
{
while (size > 0)
{
uint32_t toCopy = min (BUFFER_SIZE - m_current, size);
memcpy (m_data + m_current, buffer, toCopy);
size -= toCopy;
m_current += toCopy;
buffer += toCopy;
if (m_current == BUFFER_SIZE)
{
ssize_t written = 0;
written = ::Write (m_fd, m_data, BUFFER_SIZE);
assert (written == BUFFER_SIZE);
m_current = 0;
}
}
while (size > 0)
{
uint32_t toCopy = min (BUFFER_SIZE - m_current, size);
memcpy (m_data + m_current, buffer, toCopy);
size -= toCopy;
m_current += toCopy;
buffer += toCopy;
if (m_current == BUFFER_SIZE)
{
ssize_t written = 0;
written = ::Write (m_fd, m_data, BUFFER_SIZE);
assert (written == BUFFER_SIZE);
m_current = 0;
}
}
}
DataWriter::DataWriter ()
: m_priv (new DataWriterPrivate ())
: m_priv (new DataWriterPrivate ())
{}
DataWriter::~DataWriter ()
{
delete m_priv;
m_priv = 0;
delete m_priv;
m_priv = 0;
}
void
DataWriter::Open (char const *filename)
{
m_priv->Open (filename);
m_priv->Open (filename);
}
void
DataWriter::Write (uint8_t *buffer, uint32_t size)
{
m_priv->Write (buffer, size);
m_priv->Write (buffer, size);
}
}; // namespace

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005 INRIA
* All rights reserved.
@ -30,13 +30,13 @@ class DataWriterPrivate;
class DataWriter {
public:
DataWriter ();
~DataWriter ();
DataWriter ();
~DataWriter ();
void open (char const *filename);
void write (uint8_t *buffer, uint32_t size);
void open (char const *filename);
void write (uint8_t *buffer, uint32_t size);
private:
DataWriterPrivate *m_priv;
DataWriterPrivate *m_priv;
};
}; //namespace ns3

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2006 INRIA
* All rights reserved.
@ -29,28 +29,28 @@ namespace ns3 {
class FVariableTracerBase {
public:
typedef Callback<void,double, double> ChangeNotifyCallback;
typedef Callback<void,double, double> ChangeNotifyCallback;
FVariableTracerBase () {}
FVariableTracerBase (FVariableTracerBase const &o) {}
FVariableTracerBase &operator = (FVariableTracerBase const &o) {
return *this;
}
FVariableTracerBase () {}
FVariableTracerBase (FVariableTracerBase const &o) {}
FVariableTracerBase &operator = (FVariableTracerBase const &o) {
return *this;
}
~FVariableTracerBase () {}
~FVariableTracerBase () {}
void setCallback(ChangeNotifyCallback callback) {
m_callback = callback;
}
void setCallback(ChangeNotifyCallback callback) {
m_callback = callback;
}
protected:
void notify (double oldVal, double newVal) {
if (oldVal != newVal && !m_callback.IsNull ())
{
m_callback (oldVal, newVal);
}
}
void notify (double oldVal, double newVal) {
if (oldVal != newVal && !m_callback.IsNull ())
{
m_callback (oldVal, newVal);
}
}
private:
ChangeNotifyCallback m_callback;
ChangeNotifyCallback m_callback;
};

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005 INRIA
* All rights reserved.
@ -25,33 +25,33 @@
namespace ns3 {
Header::Header ()
: m_isDeserialized (false) {}
: m_isDeserialized (false) {}
void
Header::Print (std::ostream &os) const
{
PrintTo (os);
PrintTo (os);
}
uint32_t
Header::GetSize (void) const
{
return GetSerializedSize ();
return GetSerializedSize ();
}
void
Header::Serialize (Buffer::Iterator start) const
{
SerializeTo (start);
SerializeTo (start);
}
void
Header::Deserialize (Buffer::Iterator start)
{
DeserializeFrom (start);
m_isDeserialized = true;
DeserializeFrom (start);
m_isDeserialized = true;
}
bool
Header::IsDeserialized (void) const
{
return m_isDeserialized;
return m_isDeserialized;
}
@ -61,8 +61,8 @@ Header::~Header ()
std::ostream& operator<< (std::ostream& os, Header const& header)
{
header.Print (os);
return os;
header.Print (os);
return os;
}
}; // namespace ns3

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005 INRIA
* All rights reserved.
@ -41,40 +41,40 @@ namespace ns3 {
*/
class Header {
public:
Header ();
/**
* Derived classes must provide an explicit virtual destructor
*/
virtual ~Header () = 0;
Header ();
/**
* Derived classes must provide an explicit virtual destructor
*/
virtual ~Header () = 0;
void Print (std::ostream &os) const;
uint32_t GetSize (void) const;
void Serialize (Buffer::Iterator start) const;
void Deserialize (Buffer::Iterator start);
bool IsDeserialized (void) const;
void Print (std::ostream &os) const;
uint32_t GetSize (void) const;
void Serialize (Buffer::Iterator start) const;
void Deserialize (Buffer::Iterator start);
bool IsDeserialized (void) const;
private:
bool m_isDeserialized;
/**
* \param os the std output stream in which this
* protocol header must print itself.
*/
virtual void PrintTo (std::ostream &os) const = 0;
bool m_isDeserialized;
/**
* \param os the std output stream in which this
* protocol header must print itself.
*/
virtual void PrintTo (std::ostream &os) const = 0;
/**
* \returns the size of the serialized Header.
*/
virtual uint32_t GetSerializedSize (void) const = 0;
/**
* \returns the size of the serialized Header.
*/
virtual uint32_t GetSerializedSize (void) const = 0;
/**
* \param start the buffer iterator in which the protocol header
* must serialize itself.
*/
virtual void SerializeTo (Buffer::Iterator start) const = 0;
/**
* \param start the buffer iterator from which the protocol header must
* deserialize itself.
*/
virtual void DeserializeFrom (Buffer::Iterator start) = 0;
/**
* \param start the buffer iterator in which the protocol header
* must serialize itself.
*/
virtual void SerializeTo (Buffer::Iterator start) const = 0;
/**
* \param start the buffer iterator from which the protocol header must
* deserialize itself.
*/
virtual void DeserializeFrom (Buffer::Iterator start) = 0;
};
std::ostream& operator<< (std::ostream& os, Header const& header);

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005,2006 INRIA
* All rights reserved.
@ -26,135 +26,135 @@ namespace ns3 {
uint32_t Packet::m_global_uid = 0;
Packet::Packet ()
: m_buffer (),
m_uid (m_global_uid)
: m_buffer (),
m_uid (m_global_uid)
{
m_global_uid++;
m_global_uid++;
}
Packet::Packet (uint32_t size)
: m_buffer (size),
m_uid (m_global_uid)
: m_buffer (size),
m_uid (m_global_uid)
{
m_global_uid++;
m_global_uid++;
}
Packet::Packet (Buffer buffer, Tags tags, uint32_t uid)
: m_buffer (buffer),
m_tags (tags),
m_uid (uid)
: m_buffer (buffer),
m_tags (tags),
m_uid (uid)
{}
Packet
Packet::CreateFragment (uint32_t start, uint32_t length) const
{
Buffer tmp = m_buffer.CreateFragment (start, length);
return Packet (tmp, m_tags, m_uid);
Buffer tmp = m_buffer.CreateFragment (start, length);
return Packet (tmp, m_tags, m_uid);
}
uint32_t
Packet::GetSize (void) const
{
return m_buffer.GetSize ();
return m_buffer.GetSize ();
}
void
Packet::Add (Header const &header)
{
m_buffer.AddAtStart (header.GetSize ());
header.Serialize (m_buffer.Begin ());
m_buffer.AddAtStart (header.GetSize ());
header.Serialize (m_buffer.Begin ());
}
void
Packet::Peek (Header &header)
{
header.Deserialize (m_buffer.Begin ());
header.Deserialize (m_buffer.Begin ());
}
void
Packet::Remove (Header const &header)
{
assert (header.IsDeserialized ());
m_buffer.RemoveAtStart (header.GetSize ());
assert (header.IsDeserialized ());
m_buffer.RemoveAtStart (header.GetSize ());
}
void
Packet::Add (Trailer const &trailer)
{
m_buffer.AddAtEnd (trailer.GetSize ());
Buffer::Iterator start = m_buffer.End ();
start.Prev (trailer.GetSize ());
trailer.Serialize (start);
m_buffer.AddAtEnd (trailer.GetSize ());
Buffer::Iterator start = m_buffer.End ();
start.Prev (trailer.GetSize ());
trailer.Serialize (start);
}
void
Packet::Peek (Trailer &trailer)
{
Buffer::Iterator start = m_buffer.End ();
start.Prev (trailer.GetSize ());
trailer.Deserialize (start);
Buffer::Iterator start = m_buffer.End ();
start.Prev (trailer.GetSize ());
trailer.Deserialize (start);
}
void
Packet::Remove (Trailer const &trailer)
{
assert (trailer.IsDeserialized ());
m_buffer.RemoveAtEnd (trailer.GetSize ());
assert (trailer.IsDeserialized ());
m_buffer.RemoveAtEnd (trailer.GetSize ());
}
void
Packet::AddAtEnd (Packet packet)
{
Buffer src = packet.m_buffer;
m_buffer.AddAtEnd (src.GetSize ());
Buffer::Iterator destStart = m_buffer.End ();
destStart.Prev (src.GetSize ());
destStart.Write (src.Begin (), src.End ());
/**
* XXX: we might need to merge the tag list of the
* other packet into the current packet.
*/
Buffer src = packet.m_buffer;
m_buffer.AddAtEnd (src.GetSize ());
Buffer::Iterator destStart = m_buffer.End ();
destStart.Prev (src.GetSize ());
destStart.Write (src.Begin (), src.End ());
/**
* XXX: we might need to merge the tag list of the
* other packet into the current packet.
*/
}
void
Packet::AddAtEnd (Packet packet, uint32_t start, uint32_t size)
{
assert (packet.GetSize () <= start + size);
Buffer src = packet.m_buffer;
m_buffer.AddAtEnd (src.GetSize ());
Buffer::Iterator destStart = m_buffer.End ();
destStart.Prev (size);
Buffer::Iterator srcStart = src.Begin ();
srcStart.Next (start);
Buffer::Iterator srcEnd = srcStart;
srcEnd.Next (size);
destStart.Write (srcStart, srcEnd);
/**
* XXX: we might need to merge the tag list of the
* other packet into the current packet.
*/
assert (packet.GetSize () <= start + size);
Buffer src = packet.m_buffer;
m_buffer.AddAtEnd (src.GetSize ());
Buffer::Iterator destStart = m_buffer.End ();
destStart.Prev (size);
Buffer::Iterator srcStart = src.Begin ();
srcStart.Next (start);
Buffer::Iterator srcEnd = srcStart;
srcEnd.Next (size);
destStart.Write (srcStart, srcEnd);
/**
* XXX: we might need to merge the tag list of the
* other packet into the current packet.
*/
}
void
Packet::RemoveAtEnd (uint32_t size)
{
m_buffer.RemoveAtEnd (size);
m_buffer.RemoveAtEnd (size);
}
void
Packet::RemoveAtStart (uint32_t size)
{
m_buffer.RemoveAtStart (size);
m_buffer.RemoveAtStart (size);
}
void
Packet::RemoveAllTags (void)
{
m_tags.RemoveAll ();
m_tags.RemoveAll ();
}
uint8_t const *
Packet::PeekData (void) const
{
return m_buffer.PeekData ();
return m_buffer.PeekData ();
}
uint32_t
Packet::GetUid (void) const
{
return m_uid;
return m_uid;
}
}; // namespace ns3

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005,2006 INRIA
* All rights reserved.
@ -87,192 +87,192 @@ namespace ns3 {
*/
class Packet {
public:
/**
* Create an empty packet with a new uid (as returned
* by getUid).
*/
Packet ();
/**
* Create a packet with a zero-filled payload.
* The memory necessary for the payload is not allocated:
* it will be allocated at any later point if you attempt
* to fragment this packet or to access the zero-filled
* bytes. The packet is allocated with a new uid (as
* returned by getUid).
*
* \param size the size of the zero-filled payload
*/
Packet (uint32_t size);
/**
* Create a new packet which contains a fragment of the original
* packet. The returned packet shares the same uid as this packet.
*
* \param start offset from start of packet to start of fragment to create
* \param length length of fragment to create
* \returns a fragment of the original packet
*/
Packet CreateFragment (uint32_t start, uint32_t length) const;
/**
* \returns the size in bytes of the packet (including the zero-filled
* initial payload)
*/
uint32_t GetSize (void) const;
/**
* Add header to this packet. This method invokes the
* ns3::Header::serializeTo method to request the header to serialize
* itself in the packet buffer.
*
* \param header a reference to the header to add to this packet.
*/
void Add (Header const &header);
/**
* Deserialize header from this packet. This method invokes the
* ns3::Header::deserializeFrom method to request the header to deserialize
* itself from the packet buffer. This method does not remove
* the data from the buffer. It merely reads it.
*
* \param header a reference to the header to deserialize from the buffer
*/
void Peek (Header &header);
/**
* Remove a deserialized header from the internal buffer.
* This method removes the bytes read by Packet::peek from
* the packet buffer.
*
* \param header a reference to the header to remove from the internal buffer.
*/
void Remove (Header const &header);
/**
* Add trailer to this packet. This method invokes the
* ns3::Trailer::serializeTo method to request the trailer to serialize
* itself in the packet buffer.
*
* \param trailer a reference to the trailer to add to this packet.
*/
void Add (Trailer const &trailer);
/**
* Deserialize trailer from this packet. This method invokes the
* ns3::Trailer::deserializeFrom method to request the trailer to deserialize
* itself from the packet buffer. This method does not remove
* the data from the buffer. It merely reads it.
*
* \param trailer a reference to the trailer to deserialize from the buffer
*/
void Peek (Trailer &trailer);
/**
* Remove a deserialized trailer from the internal buffer.
* This method removes the bytes read by Packet::peek from
* the packet buffer.
*
* \param trailer a reference to the trailer to remove from the internal buffer.
*/
void Remove (Trailer const &trailer);
/**
* Attach a tag to this packet. The tag is fully copied
* in a packet-specific internal buffer. This operation
* is expected to be really fast.
*
* \param tag a pointer to the tag to attach to this packet.
*/
template <typename T>
void AddTag (T const &tag);
/**
* Remove a tag from this packet. The data stored internally
* for this tag is copied in the input tag if an instance
* of this tag type is present in the internal buffer. If this
* tag type is not present, the input tag is not modified.
*
* This operation can be potentially slow and might trigger
* unexpectedly large memory allocations. It is thus
* usually a better idea to create a copy of this packet,
* and invoke removeAllTags on the copy to remove all
* tags rather than remove the tags one by one from a packet.
*
* \param tag a pointer to the tag to remove from this packet
* \returns true if an instance of this tag type is stored
* in this packet, false otherwise.
*/
template <typename T>
bool RemoveTag (T &tag);
/**
* Copy a tag stored internally to the input tag. If no instance
* of this tag is present internally, the input tag is not modified.
*
* \param tag a pointer to the tag to read from this packet
* \returns true if an instance of this tag type is stored
* in this packet, false otherwise.
*/
template <typename T>
bool PeekTag (T &tag) const;
/**
* Remove all the tags stored in this packet. This operation is
* much much faster than invoking removeTag n times.
*/
void RemoveAllTags (void);
/**
* Concatenate the input packet at the end of the current
* packet. This does not alter the uid of either packet.
*
* \param packet packet to concatenate
*/
void AddAtEnd (Packet packet);
/**
* Concatenate the fragment of the input packet identified
* by the offset and size parameters at the end of the current
* packet. This does not alter the uid of either packet.
*
* \param packet to concatenate
* \param offset offset of fragment to copy from the start of the input packet
* \param size size of fragment of input packet to copy.
*/
void AddAtEnd (Packet packet, uint32_t offset, uint32_t size);
/**
* Remove size bytes from the end of the current packet
* It is safe to remove more bytes that what is present in
* the packet.
*
* \param size number of bytes from remove
*/
void RemoveAtEnd (uint32_t size);
/**
* Remove size bytes from the start of the current packet.
* It is safe to remove more bytes that what is present in
* the packet.
*
* \param size number of bytes from remove
*/
void RemoveAtStart (uint32_t size);
/**
* If you try to change the content of the buffer
* returned by this method, you will die.
*
* \returns a pointer to the internal buffer of the packet.
*/
uint8_t const *PeekData (void) const;
/**
* Create an empty packet with a new uid (as returned
* by getUid).
*/
Packet ();
/**
* Create a packet with a zero-filled payload.
* The memory necessary for the payload is not allocated:
* it will be allocated at any later point if you attempt
* to fragment this packet or to access the zero-filled
* bytes. The packet is allocated with a new uid (as
* returned by getUid).
*
* \param size the size of the zero-filled payload
*/
Packet (uint32_t size);
/**
* Create a new packet which contains a fragment of the original
* packet. The returned packet shares the same uid as this packet.
*
* \param start offset from start of packet to start of fragment to create
* \param length length of fragment to create
* \returns a fragment of the original packet
*/
Packet CreateFragment (uint32_t start, uint32_t length) const;
/**
* \returns the size in bytes of the packet (including the zero-filled
* initial payload)
*/
uint32_t GetSize (void) const;
/**
* Add header to this packet. This method invokes the
* ns3::Header::serializeTo method to request the header to serialize
* itself in the packet buffer.
*
* \param header a reference to the header to add to this packet.
*/
void Add (Header const &header);
/**
* Deserialize header from this packet. This method invokes the
* ns3::Header::deserializeFrom method to request the header to deserialize
* itself from the packet buffer. This method does not remove
* the data from the buffer. It merely reads it.
*
* \param header a reference to the header to deserialize from the buffer
*/
void Peek (Header &header);
/**
* Remove a deserialized header from the internal buffer.
* This method removes the bytes read by Packet::peek from
* the packet buffer.
*
* \param header a reference to the header to remove from the internal buffer.
*/
void Remove (Header const &header);
/**
* Add trailer to this packet. This method invokes the
* ns3::Trailer::serializeTo method to request the trailer to serialize
* itself in the packet buffer.
*
* \param trailer a reference to the trailer to add to this packet.
*/
void Add (Trailer const &trailer);
/**
* Deserialize trailer from this packet. This method invokes the
* ns3::Trailer::deserializeFrom method to request the trailer to deserialize
* itself from the packet buffer. This method does not remove
* the data from the buffer. It merely reads it.
*
* \param trailer a reference to the trailer to deserialize from the buffer
*/
void Peek (Trailer &trailer);
/**
* Remove a deserialized trailer from the internal buffer.
* This method removes the bytes read by Packet::peek from
* the packet buffer.
*
* \param trailer a reference to the trailer to remove from the internal buffer.
*/
void Remove (Trailer const &trailer);
/**
* Attach a tag to this packet. The tag is fully copied
* in a packet-specific internal buffer. This operation
* is expected to be really fast.
*
* \param tag a pointer to the tag to attach to this packet.
*/
template <typename T>
void AddTag (T const &tag);
/**
* Remove a tag from this packet. The data stored internally
* for this tag is copied in the input tag if an instance
* of this tag type is present in the internal buffer. If this
* tag type is not present, the input tag is not modified.
*
* This operation can be potentially slow and might trigger
* unexpectedly large memory allocations. It is thus
* usually a better idea to create a copy of this packet,
* and invoke removeAllTags on the copy to remove all
* tags rather than remove the tags one by one from a packet.
*
* \param tag a pointer to the tag to remove from this packet
* \returns true if an instance of this tag type is stored
* in this packet, false otherwise.
*/
template <typename T>
bool RemoveTag (T &tag);
/**
* Copy a tag stored internally to the input tag. If no instance
* of this tag is present internally, the input tag is not modified.
*
* \param tag a pointer to the tag to read from this packet
* \returns true if an instance of this tag type is stored
* in this packet, false otherwise.
*/
template <typename T>
bool PeekTag (T &tag) const;
/**
* Remove all the tags stored in this packet. This operation is
* much much faster than invoking removeTag n times.
*/
void RemoveAllTags (void);
/**
* Concatenate the input packet at the end of the current
* packet. This does not alter the uid of either packet.
*
* \param packet packet to concatenate
*/
void AddAtEnd (Packet packet);
/**
* Concatenate the fragment of the input packet identified
* by the offset and size parameters at the end of the current
* packet. This does not alter the uid of either packet.
*
* \param packet to concatenate
* \param offset offset of fragment to copy from the start of the input packet
* \param size size of fragment of input packet to copy.
*/
void AddAtEnd (Packet packet, uint32_t offset, uint32_t size);
/**
* Remove size bytes from the end of the current packet
* It is safe to remove more bytes that what is present in
* the packet.
*
* \param size number of bytes from remove
*/
void RemoveAtEnd (uint32_t size);
/**
* Remove size bytes from the start of the current packet.
* It is safe to remove more bytes that what is present in
* the packet.
*
* \param size number of bytes from remove
*/
void RemoveAtStart (uint32_t size);
/**
* If you try to change the content of the buffer
* returned by this method, you will die.
*
* \returns a pointer to the internal buffer of the packet.
*/
uint8_t const *PeekData (void) const;
/**
* A packet is allocated a new uid when it is created
* empty or with zero-filled payload.
*
* \returns an integer identifier which uniquely
* identifies this packet.
*/
uint32_t GetUid (void) const;
/**
* A packet is allocated a new uid when it is created
* empty or with zero-filled payload.
*
* \returns an integer identifier which uniquely
* identifies this packet.
*/
uint32_t GetUid (void) const;
private:
Packet (Buffer buffer, Tags tags, uint32_t uid);
Buffer m_buffer;
Tags m_tags;
uint32_t m_uid;
static uint32_t m_global_uid;
Packet (Buffer buffer, Tags tags, uint32_t uid);
Buffer m_buffer;
Tags m_tags;
uint32_t m_uid;
static uint32_t m_global_uid;
};
}; // namespace ns3
/**************************************************
Start of implementation of templates defined
above
Start of implementation of templates defined
above
*************************************************/
namespace ns3 {
@ -280,17 +280,17 @@ namespace ns3 {
template <typename T>
void Packet::AddTag (T const& tag)
{
m_tags.Add (tag);
m_tags.Add (tag);
}
template <typename T>
bool Packet::RemoveTag (T & tag)
{
return m_tags.Remove (tag);
return m_tags.Remove (tag);
}
template <typename T>
bool Packet::PeekTag (T & tag) const
{
return m_tags.Peek (tag);
return m_tags.Peek (tag);
}
}; // namespace ns3

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005,2006 INRIA
* All rights reserved.
@ -33,67 +33,67 @@
namespace ns3 {
enum {
PCAP_ETHERNET = 1
PCAP_ETHERNET = 1
};
PcapWriter::PcapWriter ()
{
m_writer = 0;
m_writer = 0;
}
PcapWriter::~PcapWriter ()
{
delete m_writer;
delete m_writer;
}
void
PcapWriter::Open (char const *name)
{
m_writer = new SystemFile ();
m_writer->Open (name);
m_writer = new SystemFile ();
m_writer->Open (name);
}
void
PcapWriter::WriteHeaderEthernet (void)
{
Write32 (0xa1b2c3d4);
Write16 (2);
Write16 (4);
Write32 (0);
Write32 (0);
Write32 (0xffff);
Write32 (PCAP_ETHERNET);
Write32 (0xa1b2c3d4);
Write16 (2);
Write16 (4);
Write32 (0);
Write32 (0);
Write32 (0xffff);
Write32 (PCAP_ETHERNET);
}
void
PcapWriter::WritePacket (Packet const packet)
{
if (m_writer != 0)
{
uint64_t current = Simulator::Now ().ApproximateToMicroSeconds ();
uint64_t s = current / 1000000;
uint64_t us = current % 1000000;
Write32 (s & 0xffffffff);
Write32 (us & 0xffffffff);
Write32 (packet.GetSize ());
Write32 (packet.GetSize ());
m_writer->Write (packet.PeekData (), packet.GetSize ());
}
if (m_writer != 0)
{
uint64_t current = Simulator::Now ().ApproximateToMicroSeconds ();
uint64_t s = current / 1000000;
uint64_t us = current % 1000000;
Write32 (s & 0xffffffff);
Write32 (us & 0xffffffff);
Write32 (packet.GetSize ());
Write32 (packet.GetSize ());
m_writer->Write (packet.PeekData (), packet.GetSize ());
}
}
void
PcapWriter::WriteData (uint8_t *buffer, uint32_t size)
{
m_writer->Write (buffer, size);
m_writer->Write (buffer, size);
}
void
PcapWriter::Write32 (uint32_t data)
{
m_writer->Write ((uint8_t*)&data, 4);
m_writer->Write ((uint8_t*)&data, 4);
}
void
PcapWriter::Write16 (uint16_t data)
{
m_writer->Write ((uint8_t*)&data, 2);
m_writer->Write ((uint8_t*)&data, 2);
}
}; // namespace ns3

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005,2006 INRIA
* All rights reserved.
@ -38,36 +38,36 @@ class SystemFile;
*/
class PcapWriter {
public:
PcapWriter ();
~PcapWriter ();
PcapWriter ();
~PcapWriter ();
/**
* \param name the name of the file to store packet log into.
* This method creates the file if it does not exist. If it
* exists, the file is emptied.
*/
void Open (char const *name);
/**
* \param name the name of the file to store packet log into.
* This method creates the file if it does not exist. If it
* exists, the file is emptied.
*/
void Open (char const *name);
/**
* Write a pcap header in the output file which specifies
* that the content of the file will Packets with
* Ethernet/LLC/SNAP encapsulation. This method should
* be invoked before ns3::PcapWriter::writePacket and after
* ns3::PcapWriter::open.
*/
void WriteHeaderEthernet (void);
/**
* Write a pcap header in the output file which specifies
* that the content of the file will Packets with
* Ethernet/LLC/SNAP encapsulation. This method should
* be invoked before ns3::PcapWriter::writePacket and after
* ns3::PcapWriter::open.
*/
void WriteHeaderEthernet (void);
/**
* \param packet packet to write to output file
*/
void WritePacket (Packet const packet);
/**
* \param packet packet to write to output file
*/
void WritePacket (Packet const packet);
private:
void WriteData (uint8_t *buffer, uint32_t size);
void Write32 (uint32_t data);
void Write16 (uint16_t data);
SystemFile *m_writer;
Callback<void,uint8_t *,uint32_t> m_writeCallback;
void WriteData (uint8_t *buffer, uint32_t size);
void Write32 (uint32_t data);
void Write16 (uint16_t data);
SystemFile *m_writer;
Callback<void,uint8_t *,uint32_t> m_writeCallback;
};
}; // namespace ns3

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2006 INRIA
* All rights reserved.
@ -29,28 +29,28 @@ namespace ns3 {
class SiVariableTracerBase {
public:
typedef Callback<void,int64_t, int64_t> ChangeNotifyCallback;
typedef Callback<void,int64_t, int64_t> ChangeNotifyCallback;
SiVariableTracerBase () {}
SiVariableTracerBase (SiVariableTracerBase const &o) {}
SiVariableTracerBase &operator = (SiVariableTracerBase const &o) {
return *this;
}
SiVariableTracerBase () {}
SiVariableTracerBase (SiVariableTracerBase const &o) {}
SiVariableTracerBase &operator = (SiVariableTracerBase const &o) {
return *this;
}
~SiVariableTracerBase () {}
~SiVariableTracerBase () {}
void SetCallback(ChangeNotifyCallback callback) {
m_callback = callback;
}
void SetCallback(ChangeNotifyCallback callback) {
m_callback = callback;
}
protected:
void Notify (int64_t oldVal, int64_t newVal) {
if (oldVal != newVal && !m_callback.IsNull ())
{
m_callback (oldVal, newVal);
}
}
void Notify (int64_t oldVal, int64_t newVal) {
if (oldVal != newVal && !m_callback.IsNull ())
{
m_callback (oldVal, newVal);
}
}
private:
ChangeNotifyCallback m_callback;
ChangeNotifyCallback m_callback;
};
template <typename T>
@ -84,153 +84,153 @@ class UiVariableTracer;
template <typename T>
class SiVariableTracer : public SiVariableTracerBase {
public:
SiVariableTracer ()
: m_var (0)
{}
SiVariableTracer (T const &var)
: m_var (var)
{}
SiVariableTracer ()
: m_var (0)
{}
SiVariableTracer (T const &var)
: m_var (var)
{}
SiVariableTracer &operator = (SiVariableTracer const &o) {
Assign (o.Get ());
return *this;
}
template <typename TT>
SiVariableTracer &operator = (SiVariableTracer<TT> const &o) {
Assign (o.Get ());
return *this;
}
template <typename TT>
SiVariableTracer &operator = (UiVariableTracer<TT> const &o) {
Assign (o.Get ());
return *this;
}
SiVariableTracer &operator++ () {
Assign (Get () + 1);
return *this;
}
SiVariableTracer &operator-- () {
Assign (Get () - 1);
return *this;
}
SiVariableTracer operator++ (int) {
SiVariableTracer old (*this);
++*this;
return old;
}
SiVariableTracer operator-- (int) {
SiVariableTracer old (*this);
--*this;
return old;
}
operator T () const {
return Get ();
}
SiVariableTracer &operator = (SiVariableTracer const &o) {
Assign (o.Get ());
return *this;
}
template <typename TT>
SiVariableTracer &operator = (SiVariableTracer<TT> const &o) {
Assign (o.Get ());
return *this;
}
template <typename TT>
SiVariableTracer &operator = (UiVariableTracer<TT> const &o) {
Assign (o.Get ());
return *this;
}
SiVariableTracer &operator++ () {
Assign (Get () + 1);
return *this;
}
SiVariableTracer &operator-- () {
Assign (Get () - 1);
return *this;
}
SiVariableTracer operator++ (int) {
SiVariableTracer old (*this);
++*this;
return old;
}
SiVariableTracer operator-- (int) {
SiVariableTracer old (*this);
--*this;
return old;
}
operator T () const {
return Get ();
}
void Assign (T var) {
Notify (m_var, var);
m_var = var;
}
T Get (void) const {
return m_var;
}
void Assign (T var) {
Notify (m_var, var);
m_var = var;
}
T Get (void) const {
return m_var;
}
private:
T m_var;
T m_var;
};
template <typename T>
SiVariableTracer<T> &operator += (SiVariableTracer<T> &lhs, SiVariableTracer<T> const &rhs) {
lhs.Assign (lhs.Get () + rhs.Get ());
return lhs;
lhs.Assign (lhs.Get () + rhs.Get ());
return lhs;
}
template <typename T>
SiVariableTracer<T> &operator -= (SiVariableTracer<T> &lhs, SiVariableTracer<T> const &rhs) {
lhs.Assign (lhs.Get () - rhs.Get ());
return lhs;
lhs.Assign (lhs.Get () - rhs.Get ());
return lhs;
}
template <typename T>
SiVariableTracer<T> &operator *= (SiVariableTracer<T> &lhs, SiVariableTracer<T> const &rhs) {
lhs.Assign (lhs.Get () * rhs.Get ());
return lhs;
lhs.Assign (lhs.Get () * rhs.Get ());
return lhs;
}
template <typename T>
SiVariableTracer<T> &operator /= (SiVariableTracer<T> &lhs, SiVariableTracer<T> const &rhs) {
lhs.Assign (lhs.Get () / rhs.Get ());
return lhs;
lhs.Assign (lhs.Get () / rhs.Get ());
return lhs;
}
template <typename T>
SiVariableTracer<T> &operator <<= (SiVariableTracer<T> &lhs, SiVariableTracer<T> const &rhs) {
lhs.Assign (lhs.Get () << rhs.Get ());
return lhs;
lhs.Assign (lhs.Get () << rhs.Get ());
return lhs;
}
template <typename T>
SiVariableTracer<T> &operator >>= (SiVariableTracer<T> &lhs, SiVariableTracer<T> const &rhs) {
lhs.Assign (lhs.Get () >> rhs.Get ());
return lhs;
lhs.Assign (lhs.Get () >> rhs.Get ());
return lhs;
}
template <typename T>
SiVariableTracer<T> &operator &= (SiVariableTracer<T> &lhs, SiVariableTracer<T> const &rhs) {
lhs.Assign (lhs.Get () & rhs.Get ());
return lhs;
lhs.Assign (lhs.Get () & rhs.Get ());
return lhs;
}
template <typename T>
SiVariableTracer<T> &operator |= (SiVariableTracer<T> &lhs, SiVariableTracer<T> const &rhs) {
lhs.Assign (lhs.Get () | rhs.Get ());
return lhs;
lhs.Assign (lhs.Get () | rhs.Get ());
return lhs;
}
template <typename T>
SiVariableTracer<T> &operator ^= (SiVariableTracer<T> &lhs, SiVariableTracer<T> const &rhs) {
lhs.Assign (lhs.Get () ^ rhs.Get ());
return lhs;
lhs.Assign (lhs.Get () ^ rhs.Get ());
return lhs;
}
template <typename T, typename U>
SiVariableTracer<T> &operator += (SiVariableTracer<T> &lhs, U const &rhs) {
lhs.Assign (lhs.Get () + rhs);
return lhs;
lhs.Assign (lhs.Get () + rhs);
return lhs;
}
template <typename T, typename U>
SiVariableTracer<T> &operator -= (SiVariableTracer<T> &lhs, U const &rhs) {
lhs.Assign (lhs.Get () - rhs);
return lhs;
lhs.Assign (lhs.Get () - rhs);
return lhs;
}
template <typename T, typename U>
SiVariableTracer<T> &operator *= (SiVariableTracer<T> &lhs, U const &rhs) {
lhs.Assign (lhs.Get () * rhs);
return lhs;
lhs.Assign (lhs.Get () * rhs);
return lhs;
}
template <typename T, typename U>
SiVariableTracer<T> &operator /= (SiVariableTracer<T> &lhs, U const &rhs) {
lhs.Assign (lhs.Get () / rhs);
return lhs;
lhs.Assign (lhs.Get () / rhs);
return lhs;
}
template <typename T, typename U>
SiVariableTracer<T> &operator <<= (SiVariableTracer<T> &lhs, U const &rhs) {
lhs.Assign (lhs.Get () << rhs);
return lhs;
lhs.Assign (lhs.Get () << rhs);
return lhs;
}
template <typename T, typename U>
SiVariableTracer<T> &operator >>= (SiVariableTracer<T> &lhs, U const &rhs) {
lhs.Assign (lhs.Get () >> rhs);
return lhs;
lhs.Assign (lhs.Get () >> rhs);
return lhs;
}
template <typename T, typename U>
SiVariableTracer<T> &operator &= (SiVariableTracer<T> &lhs, U const &rhs) {
lhs.Assign (lhs.Get () & rhs);
return lhs;
lhs.Assign (lhs.Get () & rhs);
return lhs;
}
template <typename T, typename U>
SiVariableTracer<T> &operator |= (SiVariableTracer<T> &lhs, U const &rhs) {
lhs.Assign (lhs.Get () | rhs);
return lhs;
lhs.Assign (lhs.Get () | rhs);
return lhs;
}
template <typename T, typename U>
SiVariableTracer<T> &operator ^= (SiVariableTracer<T> &lhs, U const &rhs) {
lhs.Assign (lhs.Get () ^ rhs);
return lhs;
lhs.Assign (lhs.Get () ^ rhs);
return lhs;
}
}; // namespace ns3

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2006 INRIA
* All rights reserved.
@ -28,38 +28,38 @@ namespace {
class TestStreamTracer : public ns3::Test {
public:
TestStreamTracer ();
virtual bool RunTests (void);
TestStreamTracer ();
virtual bool RunTests (void);
};
static TestStreamTracer gTestStream;
TestStreamTracer::TestStreamTracer ()
: Test ("StreamTracer")
: Test ("StreamTracer")
{}
bool
TestStreamTracer::RunTests (void)
{
bool ok = true;
ns3::StreamTracer trace;
//trace.setStream (&std::cout);
trace << 1;
trace << " X ";
trace << 1.0;
trace << std::endl;
trace << "test ";
trace << 1 << " test";
trace << "test "
<< 1.0 << " "
<< 0xdeadbead
<< std::endl;
trace << "0x" << std::hex
<< 0xdeadbeaf
<< std::dec << " "
<< 0xdeadbeaf
<< std::endl;
return ok;
bool ok = true;
ns3::StreamTracer trace;
//trace.setStream (&std::cout);
trace << 1;
trace << " X ";
trace << 1.0;
trace << std::endl;
trace << "test ";
trace << 1 << " test";
trace << "test "
<< 1.0 << " "
<< 0xdeadbead
<< std::endl;
trace << "0x" << std::hex
<< 0xdeadbeaf
<< std::dec << " "
<< 0xdeadbeaf
<< std::endl;
return ok;
}

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2006 INRIA
* All rights reserved.
@ -34,40 +34,40 @@ namespace ns3 {
*/
class StreamTracer {
public:
StreamTracer ()
: m_os (0) {}
template <typename T>
StreamTracer &operator << (T const&v) {
if (m_os != 0)
{
(*m_os) << v;
}
return *this;
}
template <typename T>
StreamTracer &operator << (T &v) {
if (m_os != 0)
{
(*m_os) << v;
}
return *this;
}
StreamTracer &operator << (std::ostream &(*v) (std::ostream &)) {
if (m_os != 0)
{
(*m_os) << v;
}
return *this;
}
StreamTracer ()
: m_os (0) {}
template <typename T>
StreamTracer &operator << (T const&v) {
if (m_os != 0)
{
(*m_os) << v;
}
return *this;
}
template <typename T>
StreamTracer &operator << (T &v) {
if (m_os != 0)
{
(*m_os) << v;
}
return *this;
}
StreamTracer &operator << (std::ostream &(*v) (std::ostream &)) {
if (m_os != 0)
{
(*m_os) << v;
}
return *this;
}
/**
* \param os the output stream to store
*/
void SetStream (std::ostream * os) {
m_os = os;
}
/**
* \param os the output stream to store
*/
void SetStream (std::ostream * os) {
m_os = os;
}
private:
std::ostream *m_os;
std::ostream *m_os;
};
}; // namespace ns3

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2006 INRIA
* All rights reserved.
@ -30,42 +30,42 @@ TagRegistry::TagsData TagRegistry::m_registry;
void
TagRegistry::Record (std::string uuid, PrettyPrinter prettyPrinter)
{
assert (!m_sorted);
m_registry.push_back (make_pair (uuid, prettyPrinter));
assert (!m_sorted);
m_registry.push_back (make_pair (uuid, prettyPrinter));
}
uint32_t
TagRegistry::LookupUid (std::string uuid)
{
if (!m_sorted)
{
std::sort (m_registry.begin (), m_registry.end ());
m_sorted = true;
}
assert (m_sorted);
uint32_t uid = 0;
for (TagsDataCI i = m_registry.begin (); i != m_registry.end (); i++)
{
if (i->first == uuid)
{
return uid;
}
uid++;
}
// someone asked for a uid for an unregistered uuid.
assert ("You tried to use unregistered tag: make sure you create an "
"instance of type TagRegistration<YouTagType>.");
// quiet compiler
return 0;
if (!m_sorted)
{
std::sort (m_registry.begin (), m_registry.end ());
m_sorted = true;
}
assert (m_sorted);
uint32_t uid = 0;
for (TagsDataCI i = m_registry.begin (); i != m_registry.end (); i++)
{
if (i->first == uuid)
{
return uid;
}
uid++;
}
// someone asked for a uid for an unregistered uuid.
assert ("You tried to use unregistered tag: make sure you create an "
"instance of type TagRegistration<YouTagType>.");
// quiet compiler
return 0;
}
void
TagRegistry::PrettyPrint (uint32_t uid, uint8_t buf[Tags::SIZE], std::ostream &os)
{
assert (m_registry.size () > uid);
PrettyPrinter prettyPrinter = m_registry[uid].second;
if (prettyPrinter != 0)
{
prettyPrinter (buf, os);
}
assert (m_registry.size () > uid);
PrettyPrinter prettyPrinter = m_registry[uid].second;
if (prettyPrinter != 0)
{
prettyPrinter (buf, os);
}
}
@ -77,98 +77,98 @@ uint32_t Tags::gN_free = 0;
struct Tags::TagData *
Tags::AllocData (void)
{
struct Tags::TagData *retval;
if (gFree != 0)
{
retval = gFree;
gFree = gFree->m_next;
gN_free--;
}
else
{
retval = new struct Tags::TagData ();
}
return retval;
struct Tags::TagData *retval;
if (gFree != 0)
{
retval = gFree;
gFree = gFree->m_next;
gN_free--;
}
else
{
retval = new struct Tags::TagData ();
}
return retval;
}
void
Tags::FreeData (struct TagData *data)
{
if (gN_free > 1000)
{
delete data;
return;
}
gN_free++;
data->m_next = gFree;
gFree = data;
if (gN_free > 1000)
{
delete data;
return;
}
gN_free++;
data->m_next = gFree;
gFree = data;
}
#else
struct Tags::TagData *
Tags::AllocData (void)
{
struct Tags::TagData *retval;
retval = new struct Tags::TagData ();
return retval;
struct Tags::TagData *retval;
retval = new struct Tags::TagData ();
return retval;
}
void
Tags::FreeData (struct TagData *data)
{
delete data;
delete data;
}
#endif
bool
Tags::Remove (uint32_t id)
{
bool found = false;
for (struct TagData *cur = m_next; cur != 0; cur = cur->m_next)
{
if (cur->m_id == id)
{
found = true;
}
}
if (!found)
{
return false;
}
struct TagData *start = 0;
struct TagData **prevNext = &start;
for (struct TagData *cur = m_next; cur != 0; cur = cur->m_next)
{
if (cur->m_id == id)
{
/**
* XXX
* Note: I believe that we could optimize this to
* avoid copying each TagData located after the target id
* and just link the already-copied list to the next tag.
*/
continue;
}
struct TagData *copy = AllocData ();
copy->m_id = cur->m_id;
copy->m_count = 1;
copy->m_next = 0;
memcpy (copy->m_data, cur->m_data, Tags::SIZE);
*prevNext = copy;
prevNext = &copy->m_next;
}
*prevNext = 0;
RemoveAll ();
m_next = start;
return true;
bool found = false;
for (struct TagData *cur = m_next; cur != 0; cur = cur->m_next)
{
if (cur->m_id == id)
{
found = true;
}
}
if (!found)
{
return false;
}
struct TagData *start = 0;
struct TagData **prevNext = &start;
for (struct TagData *cur = m_next; cur != 0; cur = cur->m_next)
{
if (cur->m_id == id)
{
/**
* XXX
* Note: I believe that we could optimize this to
* avoid copying each TagData located after the target id
* and just link the already-copied list to the next tag.
*/
continue;
}
struct TagData *copy = AllocData ();
copy->m_id = cur->m_id;
copy->m_count = 1;
copy->m_next = 0;
memcpy (copy->m_data, cur->m_data, Tags::SIZE);
*prevNext = copy;
prevNext = &copy->m_next;
}
*prevNext = 0;
RemoveAll ();
m_next = start;
return true;
}
void
Tags::PrettyPrint (std::ostream &os)
{
for (struct TagData *cur = m_next; cur != 0; cur = cur->m_next)
{
TagRegistry::PrettyPrint (cur->m_id, cur->m_data, os);
}
for (struct TagData *cur = m_next; cur != 0; cur = cur->m_next)
{
TagRegistry::PrettyPrint (cur->m_id, cur->m_data, os);
}
}
@ -184,38 +184,38 @@ namespace ns3 {
class TagsTest : Test {
public:
TagsTest ();
virtual ~TagsTest ();
virtual bool RunTests (void);
TagsTest ();
virtual ~TagsTest ();
virtual bool RunTests (void);
};
struct myTagA {
uint8_t a;
uint8_t a;
};
struct myTagB {
uint32_t b;
uint32_t b;
};
struct myTagC {
uint8_t c [Tags::SIZE];
uint8_t c [Tags::SIZE];
};
struct myInvalidTag {
uint8_t invalid [Tags::SIZE+1];
uint8_t invalid [Tags::SIZE+1];
};
static void
myTagAPrettyPrinterCb (struct myTagA *a, std::ostream &os)
{
os << "struct myTagA, a="<<(uint32_t)a->a<<std::endl;
os << "struct myTagA, a="<<(uint32_t)a->a<<std::endl;
}
static void
myTagBPrettyPrinterCb (struct myTagB *b, std::ostream &os)
{
os << "struct myTagB, b="<<b->b<<std::endl;
os << "struct myTagB, b="<<b->b<<std::endl;
}
static void
myTagCPrettyPrinterCb (struct myTagC *c, std::ostream &os)
{
os << "struct myTagC, c="<<(uint32_t)c->c[0]<<std::endl;
os << "struct myTagC, c="<<(uint32_t)c->c[0]<<std::endl;
}
@ -225,7 +225,7 @@ static TagRegistration<struct myTagC> gMyTagCRegistration ("C", &myTagCPrettyPri
TagsTest::TagsTest ()
: Test ("Tags")
: Test ("Tags")
{}
TagsTest::~TagsTest ()
{}
@ -233,92 +233,92 @@ TagsTest::~TagsTest ()
bool
TagsTest::RunTests (void)
{
bool ok = true;
bool ok = true;
// build initial tag.
Tags tags;
struct myTagA a;
a.a = 10;
tags.Add (a);
a.a = 0;
tags.Peek (a);
if (a.a != 10)
{
ok = false;
}
//tags.prettyPrint (std::cout);
struct myTagB b;
b.b = 0xff;
tags.Add (b);
b.b = 0;
tags.Peek (b);
if (b.b != 0xff)
{
ok = false;
}
//tags.prettyPrint (std::cout);
// build initial tag.
Tags tags;
struct myTagA a;
a.a = 10;
tags.Add (a);
a.a = 0;
tags.Peek (a);
if (a.a != 10)
{
ok = false;
}
//tags.prettyPrint (std::cout);
struct myTagB b;
b.b = 0xff;
tags.Add (b);
b.b = 0;
tags.Peek (b);
if (b.b != 0xff)
{
ok = false;
}
//tags.prettyPrint (std::cout);
// make sure copy contains copy.
Tags other = tags;
//other.prettyPrint (std::cout);
//tags.prettyPrint (std::cout);
struct myTagA oA;
oA.a = 0;
other.Peek (oA);
if (oA.a != 10)
{
ok = false;
}
struct myTagB oB;
other.Peek (oB);
if (oB.b != 0xff)
{
ok = false;
}
// remove data.
other.Remove (oA);
if (other.Peek (oA))
{
ok = false;
}
//other.prettyPrint (std::cout);
if (!tags.Peek (oA))
{
ok = false;
}
other.Remove (oB);
if (other.Peek (oB))
{
ok = false;
}
if (!tags.Peek (oB))
{
ok = false;
}
// make sure copy contains copy.
Tags other = tags;
//other.prettyPrint (std::cout);
//tags.prettyPrint (std::cout);
struct myTagA oA;
oA.a = 0;
other.Peek (oA);
if (oA.a != 10)
{
ok = false;
}
struct myTagB oB;
other.Peek (oB);
if (oB.b != 0xff)
{
ok = false;
}
// remove data.
other.Remove (oA);
if (other.Peek (oA))
{
ok = false;
}
//other.prettyPrint (std::cout);
if (!tags.Peek (oA))
{
ok = false;
}
other.Remove (oB);
if (other.Peek (oB))
{
ok = false;
}
if (!tags.Peek (oB))
{
ok = false;
}
other = tags;
Tags another = other;
struct myTagC c;
c.c[0] = 0x66;
another.Add (c);
c.c[0] = 0;
another.Peek (c);
if (!another.Peek (c))
{
ok = false;
}
if (tags.Peek (c))
{
ok = false;
}
other = tags;
Tags another = other;
struct myTagC c;
c.c[0] = 0x66;
another.Add (c);
c.c[0] = 0;
another.Peek (c);
if (!another.Peek (c))
{
ok = false;
}
if (tags.Peek (c))
{
ok = false;
}
other = other;
//other.prettyPrint (std::cout);
other = other;
//other.prettyPrint (std::cout);
//struct myInvalidTag invalid;
//tags.add (&invalid);
//struct myInvalidTag invalid;
//tags.add (&invalid);
return ok;
return ok;
}
static TagsTest gTagsTest;

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2006 INRIA
* All rights reserved.
@ -40,43 +40,43 @@ class TagPrettyPrinter;
class Tags {
public:
inline Tags ();
inline Tags (Tags const &o);
inline Tags &operator = (Tags const &o);
inline ~Tags ();
inline Tags ();
inline Tags (Tags const &o);
inline Tags &operator = (Tags const &o);
inline ~Tags ();
template <typename T>
void Add (T const&tag);
template <typename T>
void Add (T const&tag);
template <typename T>
bool Remove (T &tag);
template <typename T>
bool Remove (T &tag);
template <typename T>
bool Peek (T &tag) const;
template <typename T>
bool Peek (T &tag) const;
void PrettyPrint (std::ostream &os);
void PrettyPrint (std::ostream &os);
inline void RemoveAll (void);
inline void RemoveAll (void);
enum {
SIZE = TAGS_MAX_SIZE
};
enum {
SIZE = TAGS_MAX_SIZE
};
private:
struct TagData {
struct TagData *m_next;
uint32_t m_id;
uint32_t m_count;
uint8_t m_data[Tags::SIZE];
};
struct TagData {
struct TagData *m_next;
uint32_t m_id;
uint32_t m_count;
uint8_t m_data[Tags::SIZE];
};
bool Remove (uint32_t id);
struct Tags::TagData *AllocData (void);
void FreeData (struct TagData *data);
bool Remove (uint32_t id);
struct Tags::TagData *AllocData (void);
void FreeData (struct TagData *data);
static struct Tags::TagData *gFree;
static uint32_t gN_free;
static struct Tags::TagData *gFree;
static uint32_t gN_free;
struct TagData *m_next;
struct TagData *m_next;
};
/**
@ -91,15 +91,15 @@ private:
template <typename T>
class TagRegistration {
public:
/**
* \param uuid a uuid generated with uuidgen
* \param fn a function which can pretty-print an instance
* of type T in the output stream.
*/
TagRegistration<T> (std::string uuid, void(*fn) (T *, std::ostream &));
/**
* \param uuid a uuid generated with uuidgen
* \param fn a function which can pretty-print an instance
* of type T in the output stream.
*/
TagRegistration<T> (std::string uuid, void(*fn) (T *, std::ostream &));
private:
static void PrettyPrinterCb (uint8_t *buf, std::ostream &os);
static void(*m_prettyPrinter) (T *, std::ostream &);
static void PrettyPrinterCb (uint8_t *buf, std::ostream &os);
static void(*m_prettyPrinter) (T *, std::ostream &);
};
}; // namespace ns3
@ -107,7 +107,7 @@ private:
/**************************************************************
An implementation of the templates defined above
An implementation of the templates defined above
*************************************************************/
#include <cassert>
#include <string>
@ -116,15 +116,15 @@ namespace ns3 {
class TagRegistry {
public:
typedef void (*PrettyPrinter) (uint8_t [Tags::SIZE], std::ostream &);
static void Record (std::string uuid, PrettyPrinter prettyPrinter);
static uint32_t LookupUid (std::string uuid);
static void PrettyPrint (uint32_t uid, uint8_t buf[Tags::SIZE], std::ostream &os);
typedef void (*PrettyPrinter) (uint8_t [Tags::SIZE], std::ostream &);
static void Record (std::string uuid, PrettyPrinter prettyPrinter);
static uint32_t LookupUid (std::string uuid);
static void PrettyPrint (uint32_t uid, uint8_t buf[Tags::SIZE], std::ostream &os);
private:
typedef std::vector<std::pair<std::string,PrettyPrinter> > TagsData;
typedef std::vector<std::pair<std::string,PrettyPrinter> >::const_iterator TagsDataCI;
static bool m_sorted;
static TagsData m_registry;
typedef std::vector<std::pair<std::string,PrettyPrinter> > TagsData;
typedef std::vector<std::pair<std::string,PrettyPrinter> >::const_iterator TagsDataCI;
static bool m_sorted;
static TagsData m_registry;
};
/**
* The TypeUid class is used to create a mapping Type --> uid
@ -137,31 +137,31 @@ private:
template <typename T>
class TypeUid {
public:
static void Record (std::string uuid);
static const uint32_t GetUid (void);
static void Record (std::string uuid);
static const uint32_t GetUid (void);
private:
static std::string *GetUuid (void);
T m_realType;
static std::string *GetUuid (void);
T m_realType;
};
template <typename T>
void TypeUid<T>::Record (std::string uuid)
{
*(GetUuid ()) = uuid;
*(GetUuid ()) = uuid;
}
template <typename T>
const uint32_t TypeUid<T>::GetUid (void)
{
static const uint32_t uid = TagRegistry::LookupUid (*(GetUuid ()));
return uid;
static const uint32_t uid = TagRegistry::LookupUid (*(GetUuid ()));
return uid;
}
template <typename T>
std::string *TypeUid<T>::GetUuid (void)
{
static std::string uuid;
return &uuid;
static std::string uuid;
return &uuid;
}
@ -175,18 +175,18 @@ std::string *TypeUid<T>::GetUuid (void)
template <typename T>
TagRegistration<T>::TagRegistration (std::string uuid, void (*prettyPrinter) (T *, std::ostream &))
{
assert (sizeof (T) <= Tags::SIZE);
m_prettyPrinter = prettyPrinter;
TagRegistry::Record (uuid, &TagRegistration<T>::PrettyPrinterCb);
TypeUid<T>::Record (uuid);
assert (sizeof (T) <= Tags::SIZE);
m_prettyPrinter = prettyPrinter;
TagRegistry::Record (uuid, &TagRegistration<T>::PrettyPrinterCb);
TypeUid<T>::Record (uuid);
}
template <typename T>
void
TagRegistration<T>::PrettyPrinterCb (uint8_t *buf, std::ostream &os)
{
assert (sizeof (T) <= Tags::SIZE);
T *tag = reinterpret_cast<T *> (buf);
(*m_prettyPrinter) (tag, os);
assert (sizeof (T) <= Tags::SIZE);
T *tag = reinterpret_cast<T *> (buf);
(*m_prettyPrinter) (tag, os);
}
template <typename T>
@ -199,106 +199,106 @@ template <typename T>
void
Tags::Add (T const&tag)
{
assert (sizeof (T) <= Tags::SIZE);
uint8_t const*buf = reinterpret_cast<uint8_t const*> (&tag);
// ensure this id was not yet added
for (struct TagData *cur = m_next; cur != 0; cur = cur->m_next)
{
assert (cur->m_id != TypeUid<T>::GetUid ());
}
struct TagData *newStart = AllocData ();
newStart->m_count = 1;
newStart->m_next = 0;
newStart->m_id = TypeUid<T>::GetUid ();
memcpy (newStart->m_data, buf, sizeof (T));
newStart->m_next = m_next;
m_next = newStart;
assert (sizeof (T) <= Tags::SIZE);
uint8_t const*buf = reinterpret_cast<uint8_t const*> (&tag);
// ensure this id was not yet added
for (struct TagData *cur = m_next; cur != 0; cur = cur->m_next)
{
assert (cur->m_id != TypeUid<T>::GetUid ());
}
struct TagData *newStart = AllocData ();
newStart->m_count = 1;
newStart->m_next = 0;
newStart->m_id = TypeUid<T>::GetUid ();
memcpy (newStart->m_data, buf, sizeof (T));
newStart->m_next = m_next;
m_next = newStart;
}
template <typename T>
bool
Tags::Remove (T &tag)
{
assert (sizeof (T) <= Tags::SIZE);
return Remove (TypeUid<T>::GetUid ());
assert (sizeof (T) <= Tags::SIZE);
return Remove (TypeUid<T>::GetUid ());
}
template <typename T>
bool
Tags::Peek (T &tag) const
{
assert (sizeof (T) <= Tags::SIZE);
uint8_t *buf = reinterpret_cast<uint8_t *> (&tag);
for (struct TagData *cur = m_next; cur != 0; cur = cur->m_next)
{
if (cur->m_id == TypeUid<T>::GetUid ())
{
/* found tag */
memcpy (buf, cur->m_data, sizeof (T));
return true;
}
}
/* no tag found */
return false;
assert (sizeof (T) <= Tags::SIZE);
uint8_t *buf = reinterpret_cast<uint8_t *> (&tag);
for (struct TagData *cur = m_next; cur != 0; cur = cur->m_next)
{
if (cur->m_id == TypeUid<T>::GetUid ())
{
/* found tag */
memcpy (buf, cur->m_data, sizeof (T));
return true;
}
}
/* no tag found */
return false;
}
Tags::Tags ()
: m_next ()
: m_next ()
{}
Tags::Tags (Tags const &o)
: m_next (o.m_next)
: m_next (o.m_next)
{
if (m_next != 0)
{
m_next->m_count++;
}
if (m_next != 0)
{
m_next->m_count++;
}
}
Tags &
Tags::operator = (Tags const &o)
{
// self assignment
if (m_next == o.m_next)
{
return *this;
}
RemoveAll ();
m_next = o.m_next;
if (m_next != 0)
{
m_next->m_count++;
}
return *this;
// self assignment
if (m_next == o.m_next)
{
return *this;
}
RemoveAll ();
m_next = o.m_next;
if (m_next != 0)
{
m_next->m_count++;
}
return *this;
}
Tags::~Tags ()
{
RemoveAll ();
RemoveAll ();
}
void
Tags::RemoveAll (void)
{
struct TagData *prev = 0;
for (struct TagData *cur = m_next; cur != 0; cur = cur->m_next)
{
cur->m_count--;
if (cur->m_count > 0)
{
break;
}
if (prev != 0)
{
FreeData (prev);
}
prev = cur;
}
if (prev != 0)
{
FreeData (prev);
}
m_next = 0;
struct TagData *prev = 0;
for (struct TagData *cur = m_next; cur != 0; cur = cur->m_next)
{
cur->m_count--;
if (cur->m_count > 0)
{
break;
}
if (prev != 0)
{
FreeData (prev);
}
prev = cur;
}
if (prev != 0)
{
FreeData (prev);
}
m_next = 0;
}

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2006 INRIA
* All rights reserved.
@ -30,118 +30,118 @@ TraceContainer::TraceContainer ()
{}
TraceContainer::~TraceContainer ()
{
m_uiList.erase (m_uiList.begin (), m_uiList.end ());
m_siList.erase (m_siList.begin (), m_siList.end ());
m_fList.erase (m_fList.begin (), m_fList.end ());
m_uiList.erase (m_uiList.begin (), m_uiList.end ());
m_siList.erase (m_siList.begin (), m_siList.end ());
m_fList.erase (m_fList.begin (), m_fList.end ());
}
void
TraceContainer::SetUiVariableCallback (char const *name, Callback<void,uint64_t, uint64_t> callback)
{
for (UiListI i = m_uiList.begin (); i != m_uiList.end (); i++)
{
if ((*i).second == name)
{
(*i).first->SetCallback (callback);
return;
}
}
assert (false);
for (UiListI i = m_uiList.begin (); i != m_uiList.end (); i++)
{
if ((*i).second == name)
{
(*i).first->SetCallback (callback);
return;
}
}
assert (false);
}
void
TraceContainer::SetSiVariableCallback (char const *name, Callback<void,int64_t, int64_t> callback)
{
for (SiListI i = m_siList.begin (); i != m_siList.end (); i++)
{
if ((*i).second == name)
{
(*i).first->SetCallback (callback);
return;
}
}
assert (false);
for (SiListI i = m_siList.begin (); i != m_siList.end (); i++)
{
if ((*i).second == name)
{
(*i).first->SetCallback (callback);
return;
}
}
assert (false);
}
void
TraceContainer::SetFVariableCallback (char const *name, Callback<void,double, double> callback)
{
assert (false);
assert (false);
}
void
TraceContainer::SetStream (char const *name, std::ostream *os)
{
for (StreamTracerListI i = m_traceStreamList.begin (); i != m_traceStreamList.end (); i++)
{
if ((*i).second == name)
{
(*i).first->SetStream (os);
return;
}
}
assert (false);
for (StreamTracerListI i = m_traceStreamList.begin (); i != m_traceStreamList.end (); i++)
{
if ((*i).second == name)
{
(*i).first->SetStream (os);
return;
}
}
assert (false);
}
void
TraceContainer::RegisterUiVariable (char const *name, UiVariableTracerBase *var)
{
// ensure unicity
for (UiListI i = m_uiList.begin (); i != m_uiList.end (); i++)
{
if (i->second == name)
{
m_uiList.erase (i);
break;
}
}
m_uiList.push_back (std::make_pair (var, name));
// ensure unicity
for (UiListI i = m_uiList.begin (); i != m_uiList.end (); i++)
{
if (i->second == name)
{
m_uiList.erase (i);
break;
}
}
m_uiList.push_back (std::make_pair (var, name));
}
void
TraceContainer::RegisterSiVariable (char const *name, SiVariableTracerBase *var)
{
// ensure unicity
for (SiListI i = m_siList.begin (); i != m_siList.end (); i++)
{
if (i->second == name)
{
m_siList.erase (i);
break;
}
}
m_siList.push_back (std::make_pair (var, name));
// ensure unicity
for (SiListI i = m_siList.begin (); i != m_siList.end (); i++)
{
if (i->second == name)
{
m_siList.erase (i);
break;
}
}
m_siList.push_back (std::make_pair (var, name));
}
void
TraceContainer::RegisterFVariable (char const *name, FVariableTracerBase *var)
{
assert (false);
assert (false);
}
void
TraceContainer::RegisterStream (char const *name, StreamTracer *stream)
{
// ensure unicity
for (StreamTracerListI i = m_traceStreamList.begin (); i != m_traceStreamList.end (); i++)
{
if (i->second == name)
{
m_traceStreamList.erase (i);
break;
}
}
m_traceStreamList.push_back (std::make_pair (stream,name));
// ensure unicity
for (StreamTracerListI i = m_traceStreamList.begin (); i != m_traceStreamList.end (); i++)
{
if (i->second == name)
{
m_traceStreamList.erase (i);
break;
}
}
m_traceStreamList.push_back (std::make_pair (stream,name));
}
void
TraceContainer::RegisterCallback (char const *name, CallbackTracerBase *tracer)
{
for (CallbackListI i = m_callbackList.begin (); i != m_callbackList.end (); i++)
{
if (i->second == name)
{
m_callbackList.erase (i);
break;
}
}
m_callbackList.push_back (std::make_pair (tracer, name));
for (CallbackListI i = m_callbackList.begin (); i != m_callbackList.end (); i++)
{
if (i->second == name)
{
m_callbackList.erase (i);
break;
}
}
m_callbackList.push_back (std::make_pair (tracer, name));
}
@ -153,36 +153,36 @@ TraceContainer::RegisterCallback (char const *name, CallbackTracerBase *tracer)
void
ns3::TraceContainer::PrintDebug (void)
{
if (!m_uiList.empty ())
{
std::cout << "ui var: " << std::endl;
for (UiListI i = m_uiList.begin (); i != m_uiList.end (); i++)
{
std::cout << " \"" << (*i).second << "\""<<std::endl;
}
}
if (!m_siList.empty ())
{
std::cout << "si var: " << std::endl;
for (SiListI i = m_siList.begin (); i != m_siList.end (); i++)
{
std::cout << " \"" << (*i).second << "\""<<std::endl;
}
}
if (!m_fList.empty ())
{
std::cout << "f var: " << std::endl;
for (FListI i = m_fList.begin (); i != m_fList.end (); i++)
{
std::cout << " \"" << (*i).second << "\""<<std::endl;
}
}
if (!m_callbackList.empty ())
{
std::cout << "callback list: "<<std::endl;
for (CallbackListI i = m_callbackList.begin (); i != m_callbackList.end (); i++)
{
std::cout << " \"" << i->second << "\""<<std::endl;
}
}
if (!m_uiList.empty ())
{
std::cout << "ui var: " << std::endl;
for (UiListI i = m_uiList.begin (); i != m_uiList.end (); i++)
{
std::cout << " \"" << (*i).second << "\""<<std::endl;
}
}
if (!m_siList.empty ())
{
std::cout << "si var: " << std::endl;
for (SiListI i = m_siList.begin (); i != m_siList.end (); i++)
{
std::cout << " \"" << (*i).second << "\""<<std::endl;
}
}
if (!m_fList.empty ())
{
std::cout << "f var: " << std::endl;
for (FListI i = m_fList.begin (); i != m_fList.end (); i++)
{
std::cout << " \"" << (*i).second << "\""<<std::endl;
}
}
if (!m_callbackList.empty ())
{
std::cout << "callback list: "<<std::endl;
for (CallbackListI i = m_callbackList.begin (); i != m_callbackList.end (); i++)
{
std::cout << " \"" << i->second << "\""<<std::endl;
}
}
}

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2006 INRIA
* All rights reserved.
@ -58,140 +58,140 @@ class StreamTracer;
*/
class TraceContainer {
public:
TraceContainer ();
~TraceContainer ();
TraceContainer ();
~TraceContainer ();
/**
* \param name the name of the target event source
* \param callback the callback being connected to the target event source
*
* This method targets only event sources which are variables of any unsigned
* integer type.
*/
void SetUiVariableCallback (char const *name,
Callback<void,uint64_t, uint64_t> callback);
/**
* \param name the name of the target event source
* \param callback the callback being connected to the target event source
*
* This method targets only event sources which are variables of any signed
* integer type.
*/
void SetSiVariableCallback (char const *name, Callback<void,int64_t, int64_t> callback);
/**
* \param name the name of the target event source
* \param callback the callback being connected to the target event source
*
* This method targets only event sources which are variables of any double type.
*/
void SetFVariableCallback (char const *name, Callback<void,double, double> callback);
/**
* \param name the name of the target event source
* \param os the output stream being connected to the source trace stream
*
* This method targets only event sources which are of type StreamTracer.
*/
void SetStream (char const *name, std::ostream *os);
/**
* \param name the name of the target event source
* \param callback the callback being connected to the target event source
*
* This method targets only event sources which are variables of any unsigned
* integer type.
*/
void SetUiVariableCallback (char const *name,
Callback<void,uint64_t, uint64_t> callback);
/**
* \param name the name of the target event source
* \param callback the callback being connected to the target event source
*
* This method targets only event sources which are variables of any signed
* integer type.
*/
void SetSiVariableCallback (char const *name, Callback<void,int64_t, int64_t> callback);
/**
* \param name the name of the target event source
* \param callback the callback being connected to the target event source
*
* This method targets only event sources which are variables of any double type.
*/
void SetFVariableCallback (char const *name, Callback<void,double, double> callback);
/**
* \param name the name of the target event source
* \param os the output stream being connected to the source trace stream
*
* This method targets only event sources which are of type StreamTracer.
*/
void SetStream (char const *name, std::ostream *os);
/**
* \param name the name of the target event source
* \param callback the callback being connected to the target event source.
*
* This method targets only event sources which are of type CallbackTracer<T1>
*/
template <typename T1>
void SetCallback (char const *name, Callback<void,T1> callback);
/**
* \param name the name of the target event source
* \param callback the callback being connected to the target event source.
*
* This method targets only event sources which are of type CallbackTracer<T1,T2>
*/
template <typename T1, typename T2>
void SetCallback (char const *name, Callback<void,T1,T2> callback);
/**
* \param name the name of the target event source
* \param callback the callback being connected to the target event source.
*
* This method targets only event sources which are of type CallbackTracer<T1,T2,T3>
*/
template <typename T1, typename T2, typename T3>
void SetCallback (char const *name, Callback<void,T1,T2,T3> callback);
/**
* \param name the name of the target event source
* \param callback the callback being connected to the target event source.
*
* This method targets only event sources which are of type CallbackTracer<T1,T2,T3,T4>
*/
template <typename T1, typename T2, typename T3, typename T4>
void SetCallback (char const *name, Callback<void,T1,T2,T3,T4> callback);
/**
* \param name the name of the target event source
* \param callback the callback being connected to the target event source.
*
* This method targets only event sources which are of type CallbackTracer<T1,T2,T3,T4,T5>
*/
template <typename T1, typename T2, typename T3, typename T4, typename T5>
void SetCallback (char const *name, Callback<void,T1,T2,T3,T4,T5> callback);
/**
* \param name the name of the target event source
* \param callback the callback being connected to the target event source.
*
* This method targets only event sources which are of type CallbackTracer<T1>
*/
template <typename T1>
void SetCallback (char const *name, Callback<void,T1> callback);
/**
* \param name the name of the target event source
* \param callback the callback being connected to the target event source.
*
* This method targets only event sources which are of type CallbackTracer<T1,T2>
*/
template <typename T1, typename T2>
void SetCallback (char const *name, Callback<void,T1,T2> callback);
/**
* \param name the name of the target event source
* \param callback the callback being connected to the target event source.
*
* This method targets only event sources which are of type CallbackTracer<T1,T2,T3>
*/
template <typename T1, typename T2, typename T3>
void SetCallback (char const *name, Callback<void,T1,T2,T3> callback);
/**
* \param name the name of the target event source
* \param callback the callback being connected to the target event source.
*
* This method targets only event sources which are of type CallbackTracer<T1,T2,T3,T4>
*/
template <typename T1, typename T2, typename T3, typename T4>
void SetCallback (char const *name, Callback<void,T1,T2,T3,T4> callback);
/**
* \param name the name of the target event source
* \param callback the callback being connected to the target event source.
*
* This method targets only event sources which are of type CallbackTracer<T1,T2,T3,T4,T5>
*/
template <typename T1, typename T2, typename T3, typename T4, typename T5>
void SetCallback (char const *name, Callback<void,T1,T2,T3,T4,T5> callback);
/**
* \param name the name of the registered event source
* \param var the event source being registered
*
* This method registers only event sources of type "unsigned integer".
*/
void RegisterUiVariable (char const *name, UiVariableTracerBase *var);
/**
* \param name the name of the registered event source
* \param var the event source being registered
*
* This method registers only event sources of type "signed integer".
*/
void RegisterSiVariable (char const *name, SiVariableTracerBase *var);
/**
* \param name the name of the registered event source
* \param var the event source being registered
*
* This method registers only event sources of type "double".
*/
void RegisterFVariable (char const *name, FVariableTracerBase *var);
/**
* \param name the name of the registered event source
* \param stream the event source being registered
*
* This method registers only event sources of type StreamTracer.
*/
void RegisterStream (char const *name, StreamTracer *stream);
/**
* \param name the name of the registered event source
* \param var the event source being registered
*
* This method registers only event sources of type "unsigned integer".
*/
void RegisterUiVariable (char const *name, UiVariableTracerBase *var);
/**
* \param name the name of the registered event source
* \param var the event source being registered
*
* This method registers only event sources of type "signed integer".
*/
void RegisterSiVariable (char const *name, SiVariableTracerBase *var);
/**
* \param name the name of the registered event source
* \param var the event source being registered
*
* This method registers only event sources of type "double".
*/
void RegisterFVariable (char const *name, FVariableTracerBase *var);
/**
* \param name the name of the registered event source
* \param stream the event source being registered
*
* This method registers only event sources of type StreamTracer.
*/
void RegisterStream (char const *name, StreamTracer *stream);
/**
* \param name the name of the registeref event source
* \param tracer the callback tracer being registered.
*
* This method registers only event sources of type CallbackTracer
*/
void RegisterCallback (char const *name, CallbackTracerBase*tracer);
/**
* \param name the name of the registeref event source
* \param tracer the callback tracer being registered.
*
* This method registers only event sources of type CallbackTracer
*/
void RegisterCallback (char const *name, CallbackTracerBase*tracer);
/**
* Print the list of registered event sources in this container only.
*/
void PrintDebug (void);
/**
* Print the list of registered event sources in this container only.
*/
void PrintDebug (void);
private:
typedef std::list<std::pair<UiVariableTracerBase *, std::string> > UiList;
typedef std::list<std::pair<UiVariableTracerBase *, std::string> >::iterator UiListI;
typedef std::list<std::pair<SiVariableTracerBase *, std::string> > SiList;
typedef std::list<std::pair<SiVariableTracerBase *, std::string> >::iterator SiListI;
typedef std::list<std::pair<FVariableTracerBase *, std::string> > FList;
typedef std::list<std::pair<FVariableTracerBase *, std::string> >::iterator FListI;
typedef std::list<std::pair<StreamTracer *, std::string> > StreamTracerList;
typedef std::list<std::pair<StreamTracer *, std::string> >::iterator StreamTracerListI;
typedef std::list<std::pair<CallbackTracerBase *, std::string> > CallbackList;
typedef std::list<std::pair<CallbackTracerBase *, std::string> >::iterator CallbackListI;
typedef std::list<std::pair<UiVariableTracerBase *, std::string> > UiList;
typedef std::list<std::pair<UiVariableTracerBase *, std::string> >::iterator UiListI;
typedef std::list<std::pair<SiVariableTracerBase *, std::string> > SiList;
typedef std::list<std::pair<SiVariableTracerBase *, std::string> >::iterator SiListI;
typedef std::list<std::pair<FVariableTracerBase *, std::string> > FList;
typedef std::list<std::pair<FVariableTracerBase *, std::string> >::iterator FListI;
typedef std::list<std::pair<StreamTracer *, std::string> > StreamTracerList;
typedef std::list<std::pair<StreamTracer *, std::string> >::iterator StreamTracerListI;
typedef std::list<std::pair<CallbackTracerBase *, std::string> > CallbackList;
typedef std::list<std::pair<CallbackTracerBase *, std::string> >::iterator CallbackListI;
UiList m_uiList;
SiList m_siList;
FList m_fList;
StreamTracerList m_traceStreamList;
CallbackList m_callbackList;
UiList m_uiList;
SiList m_siList;
FList m_fList;
StreamTracerList m_traceStreamList;
CallbackList m_callbackList;
};
}; // namespace ns3
@ -206,80 +206,80 @@ template <typename T1>
void
TraceContainer::SetCallback (char const *name, Callback<void,T1> callback)
{
for (CallbackListI i = m_callbackList.begin (); i != m_callbackList.end (); i++)
{
if (i->second == name)
{
static_cast<CallbackTracer<T1> *> (i->first)->SetCallback (callback);
return;
}
}
for (CallbackListI i = m_callbackList.begin (); i != m_callbackList.end (); i++)
{
if (i->second == name)
{
static_cast<CallbackTracer<T1> *> (i->first)->SetCallback (callback);
return;
}
}
#ifndef NDEBUG
assert (false);
assert (false);
#endif
}
template <typename T1, typename T2>
void
TraceContainer::SetCallback (char const *name, Callback<void,T1,T2> callback)
{
for (CallbackListI i = m_callbackList.begin (); i != m_callbackList.end (); i++)
{
if (i->second == name)
{
static_cast<CallbackTracer<T1,T2> *> (i->first)->SetCallback (callback);
return;
}
}
for (CallbackListI i = m_callbackList.begin (); i != m_callbackList.end (); i++)
{
if (i->second == name)
{
static_cast<CallbackTracer<T1,T2> *> (i->first)->SetCallback (callback);
return;
}
}
#ifndef NDEBUG
assert (false);
assert (false);
#endif
}
template <typename T1, typename T2, typename T3>
void
TraceContainer::SetCallback (char const *name, Callback<void,T1,T2,T3> callback)
{
for (CallbackListI i = m_callbackList.begin (); i != m_callbackList.end (); i++)
{
if (i->second == name)
{
static_cast<CallbackTracer<T1,T2,T3> *> (i->first)->SetCallback (callback);
return;
}
}
for (CallbackListI i = m_callbackList.begin (); i != m_callbackList.end (); i++)
{
if (i->second == name)
{
static_cast<CallbackTracer<T1,T2,T3> *> (i->first)->SetCallback (callback);
return;
}
}
#ifndef NDEBUG
assert (false);
assert (false);
#endif
}
template <typename T1, typename T2, typename T3, typename T4>
void
TraceContainer::SetCallback (char const *name, Callback<void,T1,T2,T3,T4> callback)
{
for (CallbackListI i = m_callbackList.begin (); i != m_callbackList.end (); i++)
{
if (i->second == name)
{
static_cast<CallbackTracer<T1,T2,T3,T4> *> (i->first)->SetCallback (callback);
return;
}
}
for (CallbackListI i = m_callbackList.begin (); i != m_callbackList.end (); i++)
{
if (i->second == name)
{
static_cast<CallbackTracer<T1,T2,T3,T4> *> (i->first)->SetCallback (callback);
return;
}
}
#ifndef NDEBUG
assert (false);
assert (false);
#endif
}
template <typename T1, typename T2, typename T3, typename T4, typename T5>
void
TraceContainer::SetCallback (char const *name, Callback<void,T1,T2,T3,T4,T5> callback)
{
for (CallbackListI i = m_callbackList.begin (); i != m_callbackList.end (); i++)
{
if (i->second == name)
{
static_cast<CallbackTracer<T1,T2,T3,T4,T5> *> (i->first)->SetCallback (callback);
return;
}
}
for (CallbackListI i = m_callbackList.begin (); i != m_callbackList.end (); i++)
{
if (i->second == name)
{
static_cast<CallbackTracer<T1,T2,T3,T4,T5> *> (i->first)->SetCallback (callback);
return;
}
}
#ifndef NDEBUG
assert (false);
assert (false);
#endif
}

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005 INRIA
* All rights reserved.
@ -25,33 +25,33 @@
namespace ns3 {
Trailer::Trailer ()
: m_isDeserialized (false) {}
: m_isDeserialized (false) {}
void
Trailer::Print (std::ostream &os) const
{
PrintTo (os);
PrintTo (os);
}
uint32_t
Trailer::GetSize (void) const
{
return GetSerializedSize ();
return GetSerializedSize ();
}
void
Trailer::Serialize (Buffer::Iterator start) const
{
SerializeTo (start);
SerializeTo (start);
}
void
Trailer::Deserialize (Buffer::Iterator start)
{
DeserializeFrom (start);
m_isDeserialized = true;
DeserializeFrom (start);
m_isDeserialized = true;
}
bool
Trailer::IsDeserialized (void) const
{
return m_isDeserialized;
return m_isDeserialized;
}
@ -61,8 +61,8 @@ Trailer::~Trailer ()
std::ostream& operator<< (std::ostream& os, Trailer const& trailer)
{
trailer.Print (os);
return os;
trailer.Print (os);
return os;
}
}; // namespace ns3

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005 INRIA
* All rights reserved.
@ -41,40 +41,40 @@ namespace ns3 {
*/
class Trailer {
public:
Trailer ();
/**
* Derived classes must provide an explicit virtual destructor
*/
virtual ~Trailer () = 0;
Trailer ();
/**
* Derived classes must provide an explicit virtual destructor
*/
virtual ~Trailer () = 0;
void Print (std::ostream &os) const;
uint32_t GetSize (void) const;
void Serialize (Buffer::Iterator start) const;
void Deserialize (Buffer::Iterator start);
bool IsDeserialized (void) const;
void Print (std::ostream &os) const;
uint32_t GetSize (void) const;
void Serialize (Buffer::Iterator start) const;
void Deserialize (Buffer::Iterator start);
bool IsDeserialized (void) const;
private:
bool m_isDeserialized;
/**
* \param os the std output stream in which this
* protocol trailer must print itself.
*/
virtual void PrintTo (std::ostream &os) const = 0;
bool m_isDeserialized;
/**
* \param os the std output stream in which this
* protocol trailer must print itself.
*/
virtual void PrintTo (std::ostream &os) const = 0;
/**
* \returns the size of the serialized Trailer.
*/
virtual uint32_t GetSerializedSize (void) const = 0;
/**
* \returns the size of the serialized Trailer.
*/
virtual uint32_t GetSerializedSize (void) const = 0;
/**
* \param start the buffer iterator in which the protocol trailer
* must serialize itself.
*/
virtual void SerializeTo (Buffer::Iterator start) const = 0;
/**
* \param start the buffer iterator from which the protocol trailer must
* deserialize itself.
*/
virtual void DeserializeFrom (Buffer::Iterator start) = 0;
/**
* \param start the buffer iterator in which the protocol trailer
* must serialize itself.
*/
virtual void SerializeTo (Buffer::Iterator start) const = 0;
/**
* \param start the buffer iterator from which the protocol trailer must
* deserialize itself.
*/
virtual void DeserializeFrom (Buffer::Iterator start) = 0;
};
std::ostream& operator<< (std::ostream& os, Trailer const& trailer);

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2006 INRIA
* All rights reserved.
@ -29,31 +29,31 @@ namespace ns3 {
class UiVariableTracerBase {
public:
typedef Callback<void, uint64_t, uint64_t> ChangeNotifyCallback;
typedef Callback<void, uint64_t, uint64_t> ChangeNotifyCallback;
UiVariableTracerBase ()
: m_callback () {}
/* We don't want to copy the base callback. Only setCallback on
* a specific instance will do something to it. */
UiVariableTracerBase (UiVariableTracerBase const &o)
: m_callback () {}
UiVariableTracerBase &operator = (UiVariableTracerBase const &o) {
return *this;
}
~UiVariableTracerBase () {}
UiVariableTracerBase ()
: m_callback () {}
/* We don't want to copy the base callback. Only setCallback on
* a specific instance will do something to it. */
UiVariableTracerBase (UiVariableTracerBase const &o)
: m_callback () {}
UiVariableTracerBase &operator = (UiVariableTracerBase const &o) {
return *this;
}
~UiVariableTracerBase () {}
void SetCallback(ChangeNotifyCallback callback) {
m_callback = callback;
}
void SetCallback(ChangeNotifyCallback callback) {
m_callback = callback;
}
protected:
void Notify (uint64_t oldVal, uint64_t newVal) {
if (oldVal != newVal && !m_callback.IsNull ())
{
m_callback (oldVal, newVal);
}
}
void Notify (uint64_t oldVal, uint64_t newVal) {
if (oldVal != newVal && !m_callback.IsNull ())
{
m_callback (oldVal, newVal);
}
}
private:
ChangeNotifyCallback m_callback;
ChangeNotifyCallback m_callback;
};
template <typename T>
@ -86,153 +86,153 @@ class SiVariableTracer;
template <typename T>
class UiVariableTracer : public UiVariableTracerBase {
public:
UiVariableTracer ()
: m_var ()
{}
UiVariableTracer (T const &var)
: m_var (var)
{}
UiVariableTracer ()
: m_var ()
{}
UiVariableTracer (T const &var)
: m_var (var)
{}
UiVariableTracer &operator = (UiVariableTracer const &o) {
Assign (o.Get ());
return *this;
}
template <typename TT>
UiVariableTracer &operator = (UiVariableTracer<TT> const &o) {
Assign (o.Get ());
return *this;
}
template <typename TT>
UiVariableTracer &operator = (SiVariableTracer<TT> const &o) {
Assign (o.Get ());
return *this;
}
UiVariableTracer &operator++ () {
Assign (Get () + 1);
return *this;
}
UiVariableTracer &operator-- () {
Assign (Get () - 1);
return *this;
}
UiVariableTracer operator++ (int) {
UiVariableTracer old (*this);
++*this;
return old;
}
UiVariableTracer operator-- (int) {
UiVariableTracer old (*this);
--*this;
return old;
}
operator T () const {
return Get ();
}
UiVariableTracer &operator = (UiVariableTracer const &o) {
Assign (o.Get ());
return *this;
}
template <typename TT>
UiVariableTracer &operator = (UiVariableTracer<TT> const &o) {
Assign (o.Get ());
return *this;
}
template <typename TT>
UiVariableTracer &operator = (SiVariableTracer<TT> const &o) {
Assign (o.Get ());
return *this;
}
UiVariableTracer &operator++ () {
Assign (Get () + 1);
return *this;
}
UiVariableTracer &operator-- () {
Assign (Get () - 1);
return *this;
}
UiVariableTracer operator++ (int) {
UiVariableTracer old (*this);
++*this;
return old;
}
UiVariableTracer operator-- (int) {
UiVariableTracer old (*this);
--*this;
return old;
}
operator T () const {
return Get ();
}
void Assign (T var) {
Notify (m_var, var);
m_var = var;
}
T Get (void) const {
return m_var;
}
void Assign (T var) {
Notify (m_var, var);
m_var = var;
}
T Get (void) const {
return m_var;
}
private:
T m_var;
T m_var;
};
template <typename T>
UiVariableTracer<T> &operator += (UiVariableTracer<T> &lhs, UiVariableTracer<T> const &rhs) {
lhs.Assign (lhs.Get () + rhs.Get ());
return lhs;
lhs.Assign (lhs.Get () + rhs.Get ());
return lhs;
}
template <typename T>
UiVariableTracer<T> &operator -= (UiVariableTracer<T> &lhs, UiVariableTracer<T> const &rhs) {
lhs.Assign (lhs.Get () - rhs.Get ());
return lhs;
lhs.Assign (lhs.Get () - rhs.Get ());
return lhs;
}
template <typename T>
UiVariableTracer<T> &operator *= (UiVariableTracer<T> &lhs, UiVariableTracer<T> const &rhs) {
lhs.Assign (lhs.Get () * rhs.Get ());
return lhs;
lhs.Assign (lhs.Get () * rhs.Get ());
return lhs;
}
template <typename T>
UiVariableTracer<T> &operator /= (UiVariableTracer<T> &lhs, UiVariableTracer<T> const &rhs) {
lhs.Assign (lhs.Get () / rhs.Get ());
return lhs;
lhs.Assign (lhs.Get () / rhs.Get ());
return lhs;
}
template <typename T>
UiVariableTracer<T> &operator <<= (UiVariableTracer<T> &lhs, UiVariableTracer<T> const &rhs) {
lhs.Assign (lhs.Get () << rhs.Get ());
return lhs;
lhs.Assign (lhs.Get () << rhs.Get ());
return lhs;
}
template <typename T>
UiVariableTracer<T> &operator >>= (UiVariableTracer<T> &lhs, UiVariableTracer<T> const &rhs) {
lhs.Assign (lhs.Get () >> rhs.Get ());
return lhs;
lhs.Assign (lhs.Get () >> rhs.Get ());
return lhs;
}
template <typename T>
UiVariableTracer<T> &operator &= (UiVariableTracer<T> &lhs, UiVariableTracer<T> const &rhs) {
lhs.Assign (lhs.Get () & rhs.Get ());
return lhs;
lhs.Assign (lhs.Get () & rhs.Get ());
return lhs;
}
template <typename T>
UiVariableTracer<T> &operator |= (UiVariableTracer<T> &lhs, UiVariableTracer<T> const &rhs) {
lhs.Assign (lhs.Get () | rhs.Get ());
return lhs;
lhs.Assign (lhs.Get () | rhs.Get ());
return lhs;
}
template <typename T>
UiVariableTracer<T> &operator ^= (UiVariableTracer<T> &lhs, UiVariableTracer<T> const &rhs) {
lhs.Assign (lhs.Get () ^ rhs.Get ());
return lhs;
lhs.Assign (lhs.Get () ^ rhs.Get ());
return lhs;
}
template <typename T, typename U>
UiVariableTracer<T> &operator += (UiVariableTracer<T> &lhs, U const &rhs) {
lhs.Assign (lhs.Get () + rhs);
return lhs;
lhs.Assign (lhs.Get () + rhs);
return lhs;
}
template <typename T, typename U>
UiVariableTracer<T> &operator -= (UiVariableTracer<T> &lhs, U const &rhs) {
lhs.Assign (lhs.Get () - rhs);
return lhs;
lhs.Assign (lhs.Get () - rhs);
return lhs;
}
template <typename T, typename U>
UiVariableTracer<T> &operator *= (UiVariableTracer<T> &lhs, U const &rhs) {
lhs.Assign (lhs.Get () * rhs);
return lhs;
lhs.Assign (lhs.Get () * rhs);
return lhs;
}
template <typename T, typename U>
UiVariableTracer<T> &operator /= (UiVariableTracer<T> &lhs, U const &rhs) {
lhs.Assign (lhs.Get () / rhs);
return lhs;
lhs.Assign (lhs.Get () / rhs);
return lhs;
}
template <typename T, typename U>
UiVariableTracer<T> &operator <<= (UiVariableTracer<T> &lhs, U const &rhs) {
lhs.Assign (lhs.Get () << rhs);
return lhs;
lhs.Assign (lhs.Get () << rhs);
return lhs;
}
template <typename T, typename U>
UiVariableTracer<T> &operator >>= (UiVariableTracer<T> &lhs, U const &rhs) {
lhs.Assign (lhs.Get () >> rhs);
return lhs;
lhs.Assign (lhs.Get () >> rhs);
return lhs;
}
template <typename T, typename U>
UiVariableTracer<T> &operator &= (UiVariableTracer<T> &lhs, U const &rhs) {
lhs.Assign (lhs.Get () & rhs);
return lhs;
lhs.Assign (lhs.Get () & rhs);
return lhs;
}
template <typename T, typename U>
UiVariableTracer<T> &operator |= (UiVariableTracer<T> &lhs, U const &rhs) {
lhs.Assign (lhs.Get () | rhs);
return lhs;
lhs.Assign (lhs.Get () | rhs);
return lhs;
}
template <typename T, typename U>
UiVariableTracer<T> &operator ^= (UiVariableTracer<T> &lhs, U const &rhs) {
lhs.Assign (lhs.Get () ^ rhs);
return lhs;
lhs.Assign (lhs.Get () ^ rhs);
return lhs;
}
}; // namespace ns3

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2006 INRIA
* All rights reserved.
@ -29,238 +29,238 @@ namespace ns3 {
class Foo {
public:
void Notify (uint64_t oldVal, uint64_t newVal) {}
void Notify (uint64_t oldVal, uint64_t newVal) {}
};
class VariableTracerTest: public Test {
public:
VariableTracerTest ();
void RunUnsignedTests (void);
void RunSignedUnsignedTests (void);
virtual bool RunTests (void);
VariableTracerTest ();
void RunUnsignedTests (void);
void RunSignedUnsignedTests (void);
virtual bool RunTests (void);
};
void
VariableTracerTest::RunUnsignedTests (void)
{
UiVariableTracer<uint32_t> var, ovar, tmp;
uint32_t utmp;
Foo *foo = new Foo ();
var.SetCallback (MakeCallback (&Foo::Notify, foo));
UiVariableTracer<uint32_t> var, ovar, tmp;
uint32_t utmp;
Foo *foo = new Foo ();
var.SetCallback (MakeCallback (&Foo::Notify, foo));
var = 10;
ovar = var;
var = 10;
ovar = var;
if (var == ovar)
{
}
if (var != ovar)
{
}
if (var > ovar)
{
}
if (var >= ovar)
{
}
if (var < ovar)
{
}
if (var <= ovar)
if (var == ovar)
{
}
if (var != ovar)
{
}
if (var > ovar)
{
}
if (var >= ovar)
{
}
if (var < ovar)
{
}
if (var <= ovar)
if (var == 1)
{
}
if (var != 1)
{
}
if (var > 1)
{
}
if (var >= 1)
{
}
if (var < 1)
{
}
if (var <= 1)
{
}
if (var == 1)
{
}
if (var != 1)
{
}
if (var > 1)
{
}
if (var >= 1)
{
}
if (var < 1)
{
}
if (var <= 1)
{
}
if (1 == ovar)
{
}
if (1 != ovar)
{
}
if (1 > ovar)
{
}
if (1 >= ovar)
{
}
if (1 < ovar)
{
}
if (1 <= ovar)
{
}
if (1 == ovar)
{
}
if (1 != ovar)
{
}
if (1 > ovar)
{
}
if (1 >= ovar)
{
}
if (1 < ovar)
{
}
if (1 <= ovar)
{
}
var++;
++var;
var--;
--var;
var++;
++var;
var--;
--var;
tmp = var + ovar;
tmp = var - ovar;
tmp = var / ovar;
tmp = var * ovar;
tmp = var << ovar;
tmp = var >> ovar;
tmp = var & ovar;
tmp = var | ovar;
tmp = var ^ ovar;
tmp = var + ovar;
tmp = var - ovar;
tmp = var / ovar;
tmp = var * ovar;
tmp = var << ovar;
tmp = var >> ovar;
tmp = var & ovar;
tmp = var | ovar;
tmp = var ^ ovar;
tmp = var + 1;
tmp = var - 1;
tmp = var / 1;
tmp = var * 1;
tmp = var << 1;
tmp = var >> 1;
tmp = var & 1;
tmp = var | 1;
tmp = var ^ 1;
tmp = var + 1;
tmp = var - 1;
tmp = var / 1;
tmp = var * 1;
tmp = var << 1;
tmp = var >> 1;
tmp = var & 1;
tmp = var | 1;
tmp = var ^ 1;
tmp = 1 + ovar;
tmp = 1 - ovar;
tmp = 1 / ovar;
tmp = 1 * ovar;
tmp = 1 << ovar;
tmp = 1 >> ovar;
tmp = 1 & ovar;
tmp = 1 | ovar;
tmp = 1 ^ ovar;
tmp = 1 + ovar;
tmp = 1 - ovar;
tmp = 1 / ovar;
tmp = 1 * ovar;
tmp = 1 << ovar;
tmp = 1 >> ovar;
tmp = 1 & ovar;
tmp = 1 | ovar;
tmp = 1 ^ ovar;
tmp += var;
tmp -= var;
tmp /= var;
tmp *= var;
tmp <<= var;
tmp >>= var;
tmp &= var;
tmp |= var;
tmp ^= var;
tmp += var;
tmp -= var;
tmp /= var;
tmp *= var;
tmp <<= var;
tmp >>= var;
tmp &= var;
tmp |= var;
tmp ^= var;
tmp += 1;
tmp -= 1;
tmp /= 1;
tmp *= 1;
tmp <<= 1;
tmp >>= 1;
tmp &= 1;
tmp |= 1;
tmp ^= 1;
tmp += 1;
tmp -= 1;
tmp /= 1;
tmp *= 1;
tmp <<= 1;
tmp >>= 1;
tmp &= 1;
tmp |= 1;
tmp ^= 1;
utmp = var + ovar;
utmp = var - ovar;
utmp = var / ovar;
utmp = var * ovar;
utmp = var << ovar;
utmp = var >> ovar;
utmp = var & ovar;
utmp = var | ovar;
utmp = var ^ ovar;
utmp = var + ovar;
utmp = var - ovar;
utmp = var / ovar;
utmp = var * ovar;
utmp = var << ovar;
utmp = var >> ovar;
utmp = var & ovar;
utmp = var | ovar;
utmp = var ^ ovar;
utmp = var + 1;
utmp = var - 1;
utmp = var / 1;
utmp = var * 1;
utmp = var << 1;
utmp = var >> 1;
utmp = var & 1;
utmp = var | 1;
utmp = var ^ 1;
utmp = var + 1;
utmp = var - 1;
utmp = var / 1;
utmp = var * 1;
utmp = var << 1;
utmp = var >> 1;
utmp = var & 1;
utmp = var | 1;
utmp = var ^ 1;
utmp = 1 + ovar;
utmp = 1 - ovar;
utmp = 1 / ovar;
utmp = 1 * ovar;
utmp = 1 << ovar;
utmp = 1 >> ovar;
utmp = 1 & ovar;
utmp = 1 | ovar;
utmp = 1 ^ ovar;
utmp = 1 + ovar;
utmp = 1 - ovar;
utmp = 1 / ovar;
utmp = 1 * ovar;
utmp = 1 << ovar;
utmp = 1 >> ovar;
utmp = 1 & ovar;
utmp = 1 | ovar;
utmp = 1 ^ ovar;
utmp += var;
utmp -= var;
utmp /= var;
utmp *= var;
utmp <<= var;
utmp >>= var;
utmp &= var;
utmp |= var;
utmp ^= var;
utmp += var;
utmp -= var;
utmp /= var;
utmp *= var;
utmp <<= var;
utmp >>= var;
utmp &= var;
utmp |= var;
utmp ^= var;
utmp += 1;
utmp -= 1;
utmp /= 1;
utmp *= 1;
utmp <<= 1;
utmp >>= 1;
utmp &= 1;
utmp |= 1;
utmp ^= 1;
utmp += 1;
utmp -= 1;
utmp /= 1;
utmp *= 1;
utmp <<= 1;
utmp >>= 1;
utmp &= 1;
utmp |= 1;
utmp ^= 1;
}
void
VariableTracerTest::RunSignedUnsignedTests (void)
{
unsigned short utmp = 10;
unsigned int uitmp = 7;
short stmp = 5;
utmp = stmp;
utmp += stmp;
uitmp = utmp;
utmp = uitmp;
unsigned short utmp = 10;
unsigned int uitmp = 7;
short stmp = 5;
utmp = stmp;
utmp += stmp;
uitmp = utmp;
utmp = uitmp;
UiVariableTracer<unsigned short> uvar = 10;
UiVariableTracer<unsigned int> uivar = 5;
SiVariableTracer<short> svar = 5;
SiVariableTracer<int> sivar = 5;
uvar = svar;
svar = uvar;
uvar += svar;
svar += uvar;
UiVariableTracer<unsigned short> uvar = 10;
UiVariableTracer<unsigned int> uivar = 5;
SiVariableTracer<short> svar = 5;
SiVariableTracer<int> sivar = 5;
uvar = svar;
svar = uvar;
uvar += svar;
svar += uvar;
uvar = sivar;
sivar = uvar;
uvar += sivar;
sivar += uvar;
uvar = sivar;
sivar = uvar;
uvar += sivar;
sivar += uvar;
uivar = uvar;
uvar = uivar;
uivar += uvar;
uvar += uivar;
uivar = uvar;
uvar = uivar;
uivar += uvar;
uvar += uivar;
sivar = svar;
svar = sivar;
sivar += svar;
svar += sivar;
sivar = svar;
svar = sivar;
sivar += svar;
svar += sivar;
}
bool
VariableTracerTest::RunTests (void)
{
RunUnsignedTests ();
RunSignedUnsignedTests ();
RunUnsignedTests ();
RunSignedUnsignedTests ();
return true;
return true;
}
VariableTracerTest::VariableTracerTest ()
: Test ("VariableTracer") {}
: Test ("VariableTracer") {}
static VariableTracerTest gVariableTracerTest;

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005,2006 INRIA
* All rights reserved.
@ -33,164 +33,164 @@ static bool gTest7 = false;
void Test5 (void)
{
gTest5 = true;
gTest5 = true;
}
void Test6 (int)
{
gTest6 = true;
gTest6 = true;
}
int Test7 (int a)
{
gTest7 = true;
return a;
gTest7 = true;
return a;
}
class CallbackTest : public ns3::Test {
private:
bool m_test1;
bool m_test2;
bool m_test3;
bool m_test4;
bool m_test1;
bool m_test2;
bool m_test3;
bool m_test4;
public:
CallbackTest ();
virtual bool RunTests (void);
void Reset (void);
bool IsWrong (void);
void Test1 (void);
int Test2 (void);
void Test3 (double a);
int Test4 (double a, int b);
void Test8 (Callback<void, int> callback);
CallbackTest ();
virtual bool RunTests (void);
void Reset (void);
bool IsWrong (void);
void Test1 (void);
int Test2 (void);
void Test3 (double a);
int Test4 (double a, int b);
void Test8 (Callback<void, int> callback);
};
CallbackTest::CallbackTest ()
: ns3::Test ("Callback"),
m_test1 (false),
m_test2 (false),
m_test3 (false),
m_test4 (false)
: ns3::Test ("Callback"),
m_test1 (false),
m_test2 (false),
m_test3 (false),
m_test4 (false)
{}
void
CallbackTest::Test1 (void)
{
m_test1 = true;
m_test1 = true;
}
int
CallbackTest::Test2 (void)
{
m_test2 = true;
return 2;
m_test2 = true;
return 2;
}
void
CallbackTest::Test3 (double a)
{
m_test3 = true;
m_test3 = true;
}
int
CallbackTest::Test4 (double a, int b)
{
m_test4 = true;
return 4;
m_test4 = true;
return 4;
}
void
CallbackTest::Test8 (Callback<void,int> callback)
{
callback (3);
callback (3);
}
bool
CallbackTest::IsWrong (void)
{
if (!m_test1 ||
!m_test2 ||
!m_test3 ||
!m_test4 ||
!gTest5 ||
!gTest6 ||
!gTest7)
{
return true;
}
return false;
if (!m_test1 ||
!m_test2 ||
!m_test3 ||
!m_test4 ||
!gTest5 ||
!gTest6 ||
!gTest7)
{
return true;
}
return false;
}
void
CallbackTest::Reset (void)
{
m_test1 = false;
m_test2 = false;
m_test3 = false;
m_test4 = false;
gTest5 = false;
gTest6 = false;
gTest7 = false;
m_test1 = false;
m_test2 = false;
m_test3 = false;
m_test4 = false;
gTest5 = false;
gTest6 = false;
gTest7 = false;
}
bool
CallbackTest::RunTests (void)
{
bool ok = true;
bool ok = true;
typedef ns3::Callback<void> A;
typedef ns3::Callback<int> B;
typedef ns3::Callback<void, double> C;
typedef ns3::Callback<int, double, int> D;
typedef ns3::Callback<void> E;
typedef ns3::Callback<void,int> F;
typedef ns3::Callback<int,int> G;
A a0 (this, &CallbackTest::Test1);
B b0;
b0 = B (this, &CallbackTest::Test2);
C c0 = C (this, &CallbackTest::Test3);
D d0 = D (this, &CallbackTest::Test4);
E e0 = E (&Test5);
F f0 = F (&Test6);
G g0 = G (&Test7);
typedef ns3::Callback<void> A;
typedef ns3::Callback<int> B;
typedef ns3::Callback<void, double> C;
typedef ns3::Callback<int, double, int> D;
typedef ns3::Callback<void> E;
typedef ns3::Callback<void,int> F;
typedef ns3::Callback<int,int> G;
A a0 (this, &CallbackTest::Test1);
B b0;
b0 = B (this, &CallbackTest::Test2);
C c0 = C (this, &CallbackTest::Test3);
D d0 = D (this, &CallbackTest::Test4);
E e0 = E (&Test5);
F f0 = F (&Test6);
G g0 = G (&Test7);
a0 ();
b0 ();
c0 (0.0);
d0 (0.0, 1);
e0 ();
f0 (1);
g0 (1);
a0 ();
b0 ();
c0 (0.0);
d0 (0.0, 1);
e0 ();
f0 (1);
g0 (1);
if (IsWrong ())
{
ok = false;
}
if (IsWrong ())
{
ok = false;
}
Reset ();
Reset ();
A a1 = ns3::MakeCallback (&CallbackTest::Test1, this);
B b1 = ns3::MakeCallback (&CallbackTest::Test2, this);
C c1 = ns3::MakeCallback (&CallbackTest::Test3, this);
D d1 = ns3::MakeCallback (&CallbackTest::Test4, this);
E e1 = ns3::MakeCallback (&Test5);
F f1 = ns3::MakeCallback (&Test6);
G g1 = ns3::MakeCallback (&Test7);
a1 ();
b1 ();
c1 (0.0);
d1 (0.0, 1);
e1 ();
f1 (1);
g1 (2);
A a1 = ns3::MakeCallback (&CallbackTest::Test1, this);
B b1 = ns3::MakeCallback (&CallbackTest::Test2, this);
C c1 = ns3::MakeCallback (&CallbackTest::Test3, this);
D d1 = ns3::MakeCallback (&CallbackTest::Test4, this);
E e1 = ns3::MakeCallback (&Test5);
F f1 = ns3::MakeCallback (&Test6);
G g1 = ns3::MakeCallback (&Test7);
a1 ();
b1 ();
c1 (0.0);
d1 (0.0, 1);
e1 ();
f1 (1);
g1 (2);
Test8 (f1);
Test8 (f1);
Callback<void, int64_t,int64_t> a2;
Callback<void, int64_t,int64_t> a2;
if (IsWrong ())
{
ok = false;
}
return ok;
if (IsWrong ())
{
ok = false;
}
return ok;
}
static CallbackTest gCallbackTest;

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005,2006 INRIA
* All rights reserved.
@ -64,43 +64,43 @@ class CallbackImpl;
template <typename R>
class CallbackImpl<R,empty,empty,empty,empty,empty> {
public:
virtual ~CallbackImpl () {}
virtual R operator() (void) = 0;
virtual ~CallbackImpl () {}
virtual R operator() (void) = 0;
};
// define CallbackImpl for 1 params
template <typename R, typename T1>
class CallbackImpl<R,T1,empty,empty,empty,empty> {
public:
virtual ~CallbackImpl () {}
virtual R operator() (T1) = 0;
virtual ~CallbackImpl () {}
virtual R operator() (T1) = 0;
};
// define CallbackImpl for 2 params
template <typename R, typename T1, typename T2>
class CallbackImpl<R,T1,T2,empty,empty,empty> {
public:
virtual ~CallbackImpl () {}
virtual R operator() (T1, T2) = 0;
virtual ~CallbackImpl () {}
virtual R operator() (T1, T2) = 0;
};
// define CallbackImpl for 3 params
template <typename R, typename T1, typename T2, typename T3>
class CallbackImpl<R,T1,T2,T3,empty,empty> {
public:
virtual ~CallbackImpl () {}
virtual R operator() (T1, T2, T3) = 0;
virtual ~CallbackImpl () {}
virtual R operator() (T1, T2, T3) = 0;
};
// define CallbackImpl for 4 params
template <typename R, typename T1, typename T2, typename T3, typename T4>
class CallbackImpl<R,T1,T2,T3,T4,empty> {
public:
virtual ~CallbackImpl () {}
virtual R operator() (T1, T2, T3, T4) = 0;
virtual ~CallbackImpl () {}
virtual R operator() (T1, T2, T3, T4) = 0;
};
// define CallbackImpl for 5 params
template <typename R, typename T1, typename T2, typename T3, typename T4, typename T5>
class CallbackImpl {
public:
virtual ~CallbackImpl () {}
virtual R operator() (T1, T2, T3, T4, T5) = 0;
virtual ~CallbackImpl () {}
virtual R operator() (T1, T2, T3, T4, T5) = 0;
};
@ -108,59 +108,59 @@ public:
template <typename T, typename R, typename T1, typename T2, typename T3, typename T4,typename T5>
class FunctorCallbackImpl : public CallbackImpl<R,T1,T2,T3,T4,T5> {
public:
FunctorCallbackImpl (T const &functor)
: m_functor (functor) {}
virtual ~FunctorCallbackImpl () {}
R operator() (void) {
return m_functor ();
}
R operator() (T1 a1) {
return m_functor (a1);
}
R operator() (T1 a1,T2 a2) {
return m_functor (a1,a2);
}
R operator() (T1 a1,T2 a2,T3 a3) {
return m_functor (a1,a2,a3);
}
R operator() (T1 a1,T2 a2,T3 a3,T4 a4) {
return m_functor (a1,a2,a3,a4);
}
R operator() (T1 a1,T2 a2,T3 a3,T4 a4,T5 a5) {
return m_functor (a1,a2,a3,a4,a5);
}
FunctorCallbackImpl (T const &functor)
: m_functor (functor) {}
virtual ~FunctorCallbackImpl () {}
R operator() (void) {
return m_functor ();
}
R operator() (T1 a1) {
return m_functor (a1);
}
R operator() (T1 a1,T2 a2) {
return m_functor (a1,a2);
}
R operator() (T1 a1,T2 a2,T3 a3) {
return m_functor (a1,a2,a3);
}
R operator() (T1 a1,T2 a2,T3 a3,T4 a4) {
return m_functor (a1,a2,a3,a4);
}
R operator() (T1 a1,T2 a2,T3 a3,T4 a4,T5 a5) {
return m_functor (a1,a2,a3,a4,a5);
}
private:
T m_functor;
T m_functor;
};
// an impl for pointer to member functions
template <typename OBJ_PTR, typename MEM_PTR, typename R, typename T1, typename T2, typename T3, typename T4, typename T5>
class MemPtrCallbackImpl : public CallbackImpl<R,T1,T2,T3,T4,T5> {
public:
MemPtrCallbackImpl (OBJ_PTR const&objPtr, MEM_PTR mem_ptr)
: m_objPtr (objPtr), m_memPtr (mem_ptr) {}
virtual ~MemPtrCallbackImpl () {}
R operator() (void) {
return ((*m_objPtr).*m_memPtr) ();
}
R operator() (T1 a1) {
return ((*m_objPtr).*m_memPtr) (a1);
}
R operator() (T1 a1,T2 a2) {
return ((*m_objPtr).*m_memPtr) (a1,a2);
}
R operator() (T1 a1,T2 a2,T3 a3) {
return ((*m_objPtr).*m_memPtr) (a1,a2,a3);
}
R operator() (T1 a1,T2 a2,T3 a3,T4 a4) {
return ((*m_objPtr).*m_memPtr) (a1,a2,a3,a4);
}
R operator() (T1 a1,T2 a2,T3 a3,T4 a4,T5 a5) {
return ((*m_objPtr).*m_memPtr) (a1,a2,a3,a4,a5);
}
MemPtrCallbackImpl (OBJ_PTR const&objPtr, MEM_PTR mem_ptr)
: m_objPtr (objPtr), m_memPtr (mem_ptr) {}
virtual ~MemPtrCallbackImpl () {}
R operator() (void) {
return ((*m_objPtr).*m_memPtr) ();
}
R operator() (T1 a1) {
return ((*m_objPtr).*m_memPtr) (a1);
}
R operator() (T1 a1,T2 a2) {
return ((*m_objPtr).*m_memPtr) (a1,a2);
}
R operator() (T1 a1,T2 a2,T3 a3) {
return ((*m_objPtr).*m_memPtr) (a1,a2,a3);
}
R operator() (T1 a1,T2 a2,T3 a3,T4 a4) {
return ((*m_objPtr).*m_memPtr) (a1,a2,a3,a4);
}
R operator() (T1 a1,T2 a2,T3 a3,T4 a4,T5 a5) {
return ((*m_objPtr).*m_memPtr) (a1,a2,a3,a4,a5);
}
private:
OBJ_PTR const m_objPtr;
MEM_PTR m_memPtr;
OBJ_PTR const m_objPtr;
MEM_PTR m_memPtr;
};
/**
@ -192,50 +192,50 @@ private:
* \include samples/main-callback.cc
*/
template<typename R,
typename T1 = empty, typename T2 = empty,
typename T3 = empty, typename T4 = empty,
typename T5 = empty>
typename T1 = empty, typename T2 = empty,
typename T3 = empty, typename T4 = empty,
typename T5 = empty>
class Callback {
public:
template <typename FUNCTOR>
Callback (FUNCTOR const &functor)
: m_impl (new FunctorCallbackImpl<FUNCTOR,R,T1,T2,T3,T4,T5> (functor))
{}
template <typename FUNCTOR>
Callback (FUNCTOR const &functor)
: m_impl (new FunctorCallbackImpl<FUNCTOR,R,T1,T2,T3,T4,T5> (functor))
{}
template <typename OBJ_PTR, typename MEM_PTR>
Callback (OBJ_PTR const &objPtr, MEM_PTR mem_ptr)
: m_impl (new MemPtrCallbackImpl<OBJ_PTR,MEM_PTR,R,T1,T2,T3,T4,T5> (objPtr, mem_ptr))
{}
template <typename OBJ_PTR, typename MEM_PTR>
Callback (OBJ_PTR const &objPtr, MEM_PTR mem_ptr)
: m_impl (new MemPtrCallbackImpl<OBJ_PTR,MEM_PTR,R,T1,T2,T3,T4,T5> (objPtr, mem_ptr))
{}
Callback (ReferenceList<CallbackImpl<R,T1,T2,T3,T4,T5> *> const &impl)
: m_impl (impl)
{}
Callback (ReferenceList<CallbackImpl<R,T1,T2,T3,T4,T5> *> const &impl)
: m_impl (impl)
{}
bool IsNull (void) {
return (m_impl.Get () == 0)?true:false;
}
bool IsNull (void) {
return (m_impl.Get () == 0)?true:false;
}
Callback () : m_impl () {}
R operator() (void) {
return (*(m_impl.Get ())) ();
}
R operator() (T1 a1) {
return (*(m_impl.Get ())) (a1);
}
R operator() (T1 a1, T2 a2) {
return (*(m_impl).Get ()) (a1,a2);
}
R operator() (T1 a1, T2 a2, T3 a3) {
return (*(m_impl).Get ()) (a1,a2,a3);
}
R operator() (T1 a1, T2 a2, T3 a3, T4 a4) {
return (*(m_impl).Get ()) (a1,a2,a3,a4);
}
R operator() (T1 a1, T2 a2, T3 a3, T4 a4,T5 a5) {
return (*(m_impl).Get ()) (a1,a2,a3,a4,a5);
}
Callback () : m_impl () {}
R operator() (void) {
return (*(m_impl.Get ())) ();
}
R operator() (T1 a1) {
return (*(m_impl.Get ())) (a1);
}
R operator() (T1 a1, T2 a2) {
return (*(m_impl).Get ()) (a1,a2);
}
R operator() (T1 a1, T2 a2, T3 a3) {
return (*(m_impl).Get ()) (a1,a2,a3);
}
R operator() (T1 a1, T2 a2, T3 a3, T4 a4) {
return (*(m_impl).Get ()) (a1,a2,a3,a4);
}
R operator() (T1 a1, T2 a2, T3 a3, T4 a4,T5 a5) {
return (*(m_impl).Get ()) (a1,a2,a3,a4,a5);
}
private:
ReferenceList<CallbackImpl<R,T1,T2,T3,T4,T5>*> m_impl;
ReferenceList<CallbackImpl<R,T1,T2,T3,T4,T5>*> m_impl;
};
/**
@ -253,7 +253,7 @@ private:
*/
template <typename OBJ, typename R>
Callback<R> MakeCallback (R (OBJ::*mem_ptr) (), OBJ *const objPtr) {
return Callback<R> (objPtr, mem_ptr);
return Callback<R> (objPtr, mem_ptr);
}
/**
* \ingroup MakeCallback
@ -265,7 +265,7 @@ Callback<R> MakeCallback (R (OBJ::*mem_ptr) (), OBJ *const objPtr) {
*/
template <typename OBJ, typename R, typename T1>
Callback<R,T1> MakeCallback (R (OBJ::*mem_ptr) (T1), OBJ *const objPtr) {
return Callback<R,T1> (objPtr, mem_ptr);
return Callback<R,T1> (objPtr, mem_ptr);
}
/**
* \ingroup MakeCallback
@ -277,7 +277,7 @@ Callback<R,T1> MakeCallback (R (OBJ::*mem_ptr) (T1), OBJ *const objPtr) {
*/
template <typename OBJ, typename R, typename T1, typename T2>
Callback<R,T1,T2> MakeCallback (R (OBJ::*mem_ptr) (T1,T2), OBJ *const objPtr) {
return Callback<R,T1,T2> (objPtr, mem_ptr);
return Callback<R,T1,T2> (objPtr, mem_ptr);
}
/**
* \ingroup MakeCallback
@ -289,7 +289,7 @@ Callback<R,T1,T2> MakeCallback (R (OBJ::*mem_ptr) (T1,T2), OBJ *const objPtr) {
*/
template <typename OBJ, typename R, typename T1,typename T2, typename T3>
Callback<R,T1,T2,T3> MakeCallback (R (OBJ::*mem_ptr) (T1,T2,T3), OBJ *const objPtr) {
return Callback<R,T1,T2,T3> (objPtr, mem_ptr);
return Callback<R,T1,T2,T3> (objPtr, mem_ptr);
}
/**
* \ingroup MakeCallback
@ -301,7 +301,7 @@ Callback<R,T1,T2,T3> MakeCallback (R (OBJ::*mem_ptr) (T1,T2,T3), OBJ *const objP
*/
template <typename OBJ, typename R, typename T1, typename T2, typename T3, typename T4>
Callback<R,T1,T2,T3,T4> MakeCallback (R (OBJ::*mem_ptr) (T1,T2,T3,T4), OBJ *const objPtr) {
return Callback<R,T1,T2,T3,T4> (objPtr, mem_ptr);
return Callback<R,T1,T2,T3,T4> (objPtr, mem_ptr);
}
/**
* \ingroup MakeCallback
@ -313,7 +313,7 @@ Callback<R,T1,T2,T3,T4> MakeCallback (R (OBJ::*mem_ptr) (T1,T2,T3,T4), OBJ *cons
*/
template <typename OBJ, typename R, typename T1, typename T2, typename T3, typename T4,typename T5>
Callback<R,T1,T2,T3,T4,T5> MakeCallback (R (OBJ::*mem_ptr) (T1,T2,T3,T4,T5), OBJ *const objPtr) {
return Callback<R,T1,T2,T3,T4,T5> (objPtr, mem_ptr);
return Callback<R,T1,T2,T3,T4,T5> (objPtr, mem_ptr);
}
/**
@ -325,7 +325,7 @@ Callback<R,T1,T2,T3,T4,T5> MakeCallback (R (OBJ::*mem_ptr) (T1,T2,T3,T4,T5), OBJ
*/
template <typename R>
Callback<R> MakeCallback (R (*fnPtr) ()) {
return Callback<R> (fnPtr);
return Callback<R> (fnPtr);
}
/**
* \ingroup MakeCallback
@ -336,7 +336,7 @@ Callback<R> MakeCallback (R (*fnPtr) ()) {
*/
template <typename R, typename T1>
Callback<R,T1> MakeCallback (R (*fnPtr) (T1)) {
return Callback<R,T1> (fnPtr);
return Callback<R,T1> (fnPtr);
}
/**
* \ingroup MakeCallback
@ -347,7 +347,7 @@ Callback<R,T1> MakeCallback (R (*fnPtr) (T1)) {
*/
template <typename R, typename T1, typename T2>
Callback<R,T1,T2> MakeCallback (R (*fnPtr) (T1,T2)) {
return Callback<R,T1,T2> (fnPtr);
return Callback<R,T1,T2> (fnPtr);
}
/**
* \ingroup MakeCallback
@ -358,7 +358,7 @@ Callback<R,T1,T2> MakeCallback (R (*fnPtr) (T1,T2)) {
*/
template <typename R, typename T1, typename T2,typename T3>
Callback<R,T1,T2,T3> MakeCallback (R (*fnPtr) (T1,T2,T3)) {
return Callback<R,T1,T2,T3> (fnPtr);
return Callback<R,T1,T2,T3> (fnPtr);
}
/**
* \ingroup MakeCallback
@ -369,7 +369,7 @@ Callback<R,T1,T2,T3> MakeCallback (R (*fnPtr) (T1,T2,T3)) {
*/
template <typename R, typename T1, typename T2,typename T3,typename T4>
Callback<R,T1,T2,T3,T4> MakeCallback (R (*fnPtr) (T1,T2,T3,T4)) {
return Callback<R,T1,T2,T3,T4> (fnPtr);
return Callback<R,T1,T2,T3,T4> (fnPtr);
}
/**
* \ingroup MakeCallback
@ -380,7 +380,7 @@ Callback<R,T1,T2,T3,T4> MakeCallback (R (*fnPtr) (T1,T2,T3,T4)) {
*/
template <typename R, typename T1, typename T2,typename T3,typename T4,typename T5>
Callback<R,T1,T2,T3,T4,T5> MakeCallback (R (*fnPtr) (T1,T2,T3,T4,T5)) {
return Callback<R,T1,T2,T3,T4,T5> (fnPtr);
return Callback<R,T1,T2,T3,T4,T5> (fnPtr);
}
@ -393,7 +393,7 @@ Callback<R,T1,T2,T3,T4,T5> MakeCallback (R (*fnPtr) (T1,T2,T3,T4,T5)) {
*/
template <typename R>
Callback<R> MakeNullCallback (void) {
return Callback<R> ();
return Callback<R> ();
}
/**
* \ingroup MakeCallback
@ -403,7 +403,7 @@ Callback<R> MakeNullCallback (void) {
*/
template <typename R, typename T1>
Callback<R,T1> MakeNullCallback (void) {
return Callback<R,T1> ();
return Callback<R,T1> ();
}
/**
* \ingroup MakeCallback
@ -413,7 +413,7 @@ Callback<R,T1> MakeNullCallback (void) {
*/
template <typename R, typename T1, typename T2>
Callback<R,T1,T2> MakeNullCallback (void) {
return Callback<R,T1,T2> ();
return Callback<R,T1,T2> ();
}
/**
* \ingroup MakeCallback
@ -423,7 +423,7 @@ Callback<R,T1,T2> MakeNullCallback (void) {
*/
template <typename R, typename T1, typename T2,typename T3>
Callback<R,T1,T2,T3> MakeNullCallback (void) {
return Callback<R,T1,T2,T3> ();
return Callback<R,T1,T2,T3> ();
}
/**
* \ingroup MakeCallback
@ -433,7 +433,7 @@ Callback<R,T1,T2,T3> MakeNullCallback (void) {
*/
template <typename R, typename T1, typename T2,typename T3,typename T4>
Callback<R,T1,T2,T3,T4> MakeNullCallback (void) {
return Callback<R,T1,T2,T3,T4> ();
return Callback<R,T1,T2,T3,T4> ();
}
/**
* \ingroup MakeCallback
@ -443,7 +443,7 @@ Callback<R,T1,T2,T3,T4> MakeNullCallback (void) {
*/
template <typename R, typename T1, typename T2,typename T3,typename T4,typename T5>
Callback<R,T1,T2,T3,T4,T5> MakeNullCallback (void) {
return Callback<R,T1,T2,T3,T4,T5> ();
return Callback<R,T1,T2,T3,T4,T5> ();
}
@ -456,64 +456,64 @@ Callback<R,T1,T2,T3,T4,T5> MakeNullCallback (void) {
template <typename T, typename R, typename TX, typename T1, typename T2, typename T3, typename T4,typename T5>
class BoundFunctorCallbackImpl : public CallbackImpl<R,T1,T2,T3,T4,T5> {
public:
BoundFunctorCallbackImpl (T const &functor, TX a)
: m_functor (functor), m_a (a) {}
virtual ~BoundFunctorCallbackImpl () {}
R operator() (void) {
return m_functor (m_a);
}
R operator() (T1 a1) {
return m_functor (m_a,a1);
}
R operator() (T1 a1,T2 a2) {
return m_functor (m_a,a1,a2);
}
R operator() (T1 a1,T2 a2,T3 a3) {
return m_functor (m_a,a1,a2,a3);
}
R operator() (T1 a1,T2 a2,T3 a3,T4 a4) {
return m_functor (m_a,a1,a2,a3,a4);
}
R operator() (T1 a1,T2 a2,T3 a3,T4 a4,T5 a5) {
return m_functor (m_a,a1,a2,a3,a4,a5);
}
BoundFunctorCallbackImpl (T const &functor, TX a)
: m_functor (functor), m_a (a) {}
virtual ~BoundFunctorCallbackImpl () {}
R operator() (void) {
return m_functor (m_a);
}
R operator() (T1 a1) {
return m_functor (m_a,a1);
}
R operator() (T1 a1,T2 a2) {
return m_functor (m_a,a1,a2);
}
R operator() (T1 a1,T2 a2,T3 a3) {
return m_functor (m_a,a1,a2,a3);
}
R operator() (T1 a1,T2 a2,T3 a3,T4 a4) {
return m_functor (m_a,a1,a2,a3,a4);
}
R operator() (T1 a1,T2 a2,T3 a3,T4 a4,T5 a5) {
return m_functor (m_a,a1,a2,a3,a4,a5);
}
private:
T m_functor;
TX m_a;
T m_functor;
TX m_a;
};
template <typename R, typename TX, typename T1>
Callback<R,T1> MakeBoundCallback (R (*fnPtr) (TX,T1), TX a) {
ReferenceList<CallbackImpl<R,T1,empty,empty,empty,empty>*> impl =
ReferenceList<CallbackImpl<R,T1,empty,empty,empty,empty>*> (
new BoundFunctorCallbackImpl<R (*) (TX,T1),R,TX,T1,empty,empty,empty,empty> (fnPtr, a)
);
return Callback<R,T1> (impl);
ReferenceList<CallbackImpl<R,T1,empty,empty,empty,empty>*> impl =
ReferenceList<CallbackImpl<R,T1,empty,empty,empty,empty>*> (
new BoundFunctorCallbackImpl<R (*) (TX,T1),R,TX,T1,empty,empty,empty,empty> (fnPtr, a)
);
return Callback<R,T1> (impl);
}
template <typename R, typename TX, typename T1, typename T2>
Callback<R,T1,T2> MakeBoundCallback (R (*fnPtr) (TX,T1,T2), TX a) {
ReferenceList<CallbackImpl<R,T1,T2,empty,empty,empty>*> impl =
ReferenceList<CallbackImpl<R,T1,T2,empty,empty,empty>*> (
new BoundFunctorCallbackImpl<R (*) (TX,T1,T2),R,TX,T1,T2,empty,empty,empty> (fnPtr, a)
);
return Callback<R,T1,T2> (impl);
ReferenceList<CallbackImpl<R,T1,T2,empty,empty,empty>*> impl =
ReferenceList<CallbackImpl<R,T1,T2,empty,empty,empty>*> (
new BoundFunctorCallbackImpl<R (*) (TX,T1,T2),R,TX,T1,T2,empty,empty,empty> (fnPtr, a)
);
return Callback<R,T1,T2> (impl);
}
template <typename R, typename TX, typename T1, typename T2,typename T3,typename T4>
Callback<R,T1,T2,T3,T4> MakeBoundCallback (R (*fnPtr) (TX,T1,T2,T3,T4), TX a) {
ReferenceList<CallbackImpl<R,T1,T2,T3,T4,empty>*> impl =
ReferenceList<CallbackImpl<R,T1,T2,T3,T4,empty>*> (
new BoundFunctorCallbackImpl<R (*) (TX,T1,T2,T3,T4),R,TX,T1,T2,T3,T4,empty> (fnPtr, a)
);
return Callback<R,T1,T2,T3,T4> (impl);
ReferenceList<CallbackImpl<R,T1,T2,T3,T4,empty>*> impl =
ReferenceList<CallbackImpl<R,T1,T2,T3,T4,empty>*> (
new BoundFunctorCallbackImpl<R (*) (TX,T1,T2,T3,T4),R,TX,T1,T2,T3,T4,empty> (fnPtr, a)
);
return Callback<R,T1,T2,T3,T4> (impl);
}
template <typename R, typename TX, typename T1, typename T2,typename T3,typename T4,typename T5>
Callback<R,T1,T2,T3,T4,T5> MakeBoundCallback (R (*fnPtr) (TX,T1,T2,T3,T4,T5), TX a) {
ReferenceList<CallbackImpl<R,T1,T2,T3,T4,T5>*> impl =
ReferenceList<CallbackImpl<R,T1,T2,T3,T4,T5>*> (
new BoundFunctorCallbackImpl<R (*) (TX,T1,T2,T3,T4,T5),R,TX,T1,T2,T3,T4,T5> (fnPtr, a)
);
return Callback<R,T1,T2,T3,T4,T5> (impl);
ReferenceList<CallbackImpl<R,T1,T2,T3,T4,T5>*> impl =
ReferenceList<CallbackImpl<R,T1,T2,T3,T4,T5>*> (
new BoundFunctorCallbackImpl<R (*) (TX,T1,T2,T3,T4,T5),R,TX,T1,T2,T3,T4,T5> (fnPtr, a)
);
return Callback<R,T1,T2,T3,T4,T5> (impl);
}

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2006 INRIA
* All rights reserved.
@ -28,7 +28,7 @@
#ifdef REFTEST_DEBUG
#include <iostream>
#define TRACE(x) \
std::cout << x << std::endl;
std::cout << x << std::endl;
#else
#define TRACE(x)
#endif
@ -37,79 +37,79 @@ namespace {
class A {
public:
A () {
TRACE ("constructor");
}
~A () {
TRACE ("destructor");
}
void Trace (void) {
TRACE ("trace");
}
A () {
TRACE ("constructor");
}
~A () {
TRACE ("destructor");
}
void Trace (void) {
TRACE ("trace");
}
};
class RefTest : public ns3::Test {
public:
RefTest ();
virtual bool RunTests (void);
RefTest ();
virtual bool RunTests (void);
private:
void OneTest (ns3::ReferenceList<A *>);
void OneTest (ns3::ReferenceList<A *>);
};
RefTest::RefTest ()
: ns3::Test ("ReferenceList")
: ns3::Test ("ReferenceList")
{}
void
RefTest::OneTest (ns3::ReferenceList<A *> a)
{
a->Trace ();
a->Trace ();
}
bool
RefTest::RunTests (void)
{
bool ok = true;
bool ok = true;
{
ns3::ReferenceList<A *> tmp;
{
ns3::ReferenceList<A *> a (new A ());
OneTest (a);
tmp = a;
OneTest (tmp);
a = tmp;
OneTest (a);
TRACE ("leave inner scope");
}
OneTest (tmp);
TRACE ("leave outer scope");
}
{
ns3::ReferenceList<A *> tmp;
{
ns3::ReferenceList<A *> a (new A ());
OneTest (a);
tmp = a;
OneTest (tmp);
a = tmp;
OneTest (a);
TRACE ("leave inner scope");
}
OneTest (tmp);
TRACE ("leave outer scope");
}
{
ns3::ReferenceList<A *> tmp;
}
{
ns3::ReferenceList<A *> tmp;
}
{
ns3::ReferenceList<A *> tmp (new A ());
}
{
ns3::ReferenceList<A *> tmp (new A ());
}
{
ns3::ReferenceList<A *> tmp;
tmp.Set (new A ());
}
{
ns3::ReferenceList<A *> tmp;
tmp.Set (new A ());
}
{
TRACE ("test assignement");
ns3::ReferenceList<A *> a0 (new A ());
ns3::ReferenceList<A *> a1 (new A ());
a0 = a1;
}
{
TRACE ("test assignement");
ns3::ReferenceList<A *> a0 (new A ());
ns3::ReferenceList<A *> a1 (new A ());
a0 = a1;
}
return ok;
return ok;
}

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2006 INRIA
* All rights reserved.
@ -37,80 +37,80 @@ class ReferenceList;
template <typename OBJ_PTR>
class ReferenceList {
public:
ReferenceList ()
: m_objPtr (),
m_prev (),
m_next ()
{
m_prev = this;
m_next = this;
}
ReferenceList (ReferenceList &o)
: m_objPtr (),
m_prev (),
m_next ()
{
m_prev = this;
m_next = this;
InsertSelfInOther (o);
}
ReferenceList (ReferenceList const&o)
: m_objPtr (),
m_prev (),
m_next ()
{
m_prev = this;
m_next = this;
InsertSelfInOther (o);
}
ReferenceList (OBJ_PTR const &objPtr)
: m_objPtr (objPtr),
m_prev (),
m_next ()
{
m_prev = this;
m_next = this;
}
~ReferenceList () {
RemoveFromList ();
}
ReferenceList & operator= (ReferenceList const&o) {
RemoveFromList ();
InsertSelfInOther (o);
return *this;
}
OBJ_PTR operator-> () {
return m_objPtr;
}
void Set (OBJ_PTR objPtr) {
RemoveFromList ();
m_objPtr = objPtr;
}
OBJ_PTR Get (void) {
// explicit conversion to raw pointer type.
return m_objPtr;
}
ReferenceList ()
: m_objPtr (),
m_prev (),
m_next ()
{
m_prev = this;
m_next = this;
}
ReferenceList (ReferenceList &o)
: m_objPtr (),
m_prev (),
m_next ()
{
m_prev = this;
m_next = this;
InsertSelfInOther (o);
}
ReferenceList (ReferenceList const&o)
: m_objPtr (),
m_prev (),
m_next ()
{
m_prev = this;
m_next = this;
InsertSelfInOther (o);
}
ReferenceList (OBJ_PTR const &objPtr)
: m_objPtr (objPtr),
m_prev (),
m_next ()
{
m_prev = this;
m_next = this;
}
~ReferenceList () {
RemoveFromList ();
}
ReferenceList & operator= (ReferenceList const&o) {
RemoveFromList ();
InsertSelfInOther (o);
return *this;
}
OBJ_PTR operator-> () {
return m_objPtr;
}
void Set (OBJ_PTR objPtr) {
RemoveFromList ();
m_objPtr = objPtr;
}
OBJ_PTR Get (void) {
// explicit conversion to raw pointer type.
return m_objPtr;
}
private:
void InsertSelfInOther (ReferenceList const&o) {
m_prev = &o;
m_next = o.m_next;
m_next->m_prev = this;
o.m_next = this;
m_objPtr = o.m_objPtr;
}
void RemoveFromList (void) {
if (m_prev == this)
{
//assert (m_next == this);
delete m_objPtr;
m_objPtr = OBJ_PTR ();
}
m_prev->m_next = m_next;
m_next->m_prev = m_prev;
}
OBJ_PTR m_objPtr;
mutable ReferenceList const*m_prev;
mutable ReferenceList const*m_next;
void InsertSelfInOther (ReferenceList const&o) {
m_prev = &o;
m_next = o.m_next;
m_next->m_prev = this;
o.m_next = this;
m_objPtr = o.m_objPtr;
}
void RemoveFromList (void) {
if (m_prev == this)
{
//assert (m_next == this);
delete m_objPtr;
m_objPtr = OBJ_PTR ();
}
m_prev->m_next = m_next;
m_next->m_prev = m_prev;
}
OBJ_PTR m_objPtr;
mutable ReferenceList const*m_prev;
mutable ReferenceList const*m_next;
};
}; // namespace ns3

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005 INRIA
* All rights reserved.
@ -35,41 +35,41 @@ class SystemFilePrivate;
*/
class SystemFile {
public:
/**
* This method does not create or open any
* file on disk.
*/
SystemFile ();
/**
* If a file has been opened, it is closed by
* this destructor.
*/
~SystemFile ();
/**
* This method does not create or open any
* file on disk.
*/
SystemFile ();
/**
* If a file has been opened, it is closed by
* this destructor.
*/
~SystemFile ();
/**
* \param filename name of file to open
*
* Open a file for writing. If the file does not
* exist, it is created. If it exists, it is
* emptied first.
*/
void Open (char const *filename);
/**
* \param buffer data to write
* \param size size of data to write
*
* Write data in file on disk. This method cannot fail:
* it will write _all_ the data to disk. This method does not
* perform any data caching and forwards the data
* to the OS through a direct syscall. However,
* it is not possible to rely on the data being
* effectively written to disk after this method returns.
* To make sure the data is written to disk, destroy
* this object.
*/
void Write (uint8_t const*buffer, uint32_t size);
/**
* \param filename name of file to open
*
* Open a file for writing. If the file does not
* exist, it is created. If it exists, it is
* emptied first.
*/
void Open (char const *filename);
/**
* \param buffer data to write
* \param size size of data to write
*
* Write data in file on disk. This method cannot fail:
* it will write _all_ the data to disk. This method does not
* perform any data caching and forwards the data
* to the OS through a direct syscall. However,
* it is not possible to rely on the data being
* effectively written to disk after this method returns.
* To make sure the data is written to disk, destroy
* this object.
*/
void Write (uint8_t const*buffer, uint32_t size);
private:
SystemFilePrivate *m_priv;
SystemFilePrivate *m_priv;
};
}; //namespace ns3

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005 INRIA
* All rights reserved.
@ -29,23 +29,23 @@ namespace ns3 {
*/
class SystemWallClockMs {
public:
SystemWallClockMs ();
~SystemWallClockMs ();
SystemWallClockMs ();
~SystemWallClockMs ();
/**
* Start a measure.
*/
void Start (void);
/**
* \returns the measured elapsed wall clock time since
* ns3::SystemWallClockMs::start was invoked.
*
* It is possible to start a new measurement with ns3::SystemWallClockMs::start
* after this method returns.
*/
unsigned long long End (void);
/**
* Start a measure.
*/
void Start (void);
/**
* \returns the measured elapsed wall clock time since
* ns3::SystemWallClockMs::start was invoked.
*
* It is possible to start a new measurement with ns3::SystemWallClockMs::start
* after this method returns.
*/
unsigned long long End (void);
private:
class SystemWallClockMsPrivate *m_priv;
class SystemWallClockMsPrivate *m_priv;
};
}; // namespace ns3

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005 INRIA
* All rights reserved.
@ -29,76 +29,76 @@ namespace ns3 {
TestManager *
TestManager::Get (void)
{
static TestManager manager;
return &manager;
static TestManager manager;
return &manager;
}
TestManager::TestManager ()
: m_verbose (false)
: m_verbose (false)
{}
TestManager::~TestManager ()
{
TestsI i = m_tests.begin ();
while (i != m_tests.end ())
{
delete (*i).second;
i = m_tests.erase (i);
}
TestsI i = m_tests.begin ();
while (i != m_tests.end ())
{
delete (*i).second;
i = m_tests.erase (i);
}
}
void
TestManager::Add (Test *test, char const *name)
{
Get ()->m_tests.push_back (std::make_pair (test, new std::string (name)));
Get ()->m_tests.push_back (std::make_pair (test, new std::string (name)));
}
void
TestManager::EnableVerbose (void)
{
Get ()->m_verbose = true;
Get ()->m_verbose = true;
}
std::ostream &
TestManager::Failure (void)
{
return std::cerr;
return std::cerr;
}
bool
TestManager::RunTests (void)
{
return Get ()->RealRunTests ();
return Get ()->RealRunTests ();
}
bool
TestManager::RealRunTests (void)
{
bool isSuccess = true;
for (TestsCI i = m_tests.begin (); i != m_tests.end (); i++)
{
std::string *testName = (*i).second;
if (!(*i).first->RunTests ())
{
isSuccess = false;
if (m_verbose)
{
std::cerr << "FAIL " << *testName << std::endl;
}
}
else
{
if (m_verbose)
{
std::cerr << "PASS "<<*testName << std::endl;
}
}
}
if (!isSuccess)
{
std::cerr << "FAIL" << std::endl;
}
return isSuccess;
bool isSuccess = true;
for (TestsCI i = m_tests.begin (); i != m_tests.end (); i++)
{
std::string *testName = (*i).second;
if (!(*i).first->RunTests ())
{
isSuccess = false;
if (m_verbose)
{
std::cerr << "FAIL " << *testName << std::endl;
}
}
else
{
if (m_verbose)
{
std::cerr << "PASS "<<*testName << std::endl;
}
}
}
if (!isSuccess)
{
std::cerr << "FAIL" << std::endl;
}
return isSuccess;
}
Test::Test (char const *name)
{
TestManager::Add (this, name);
TestManager::Add (this, name);
}
Test::~Test ()
@ -107,7 +107,7 @@ Test::~Test ()
std::ostream &
Test::Failure (void)
{
return TestManager::Failure ();
return TestManager::Failure ();
}
}; // namespace ns3

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005 INRIA
* All rights reserved.
@ -46,23 +46,23 @@ class TestManager;
*/
class Test {
public:
/**
* \param name the name of the test
*/
Test (char const *name);
virtual ~Test ();
/**
* \param name the name of the test
*/
Test (char const *name);
virtual ~Test ();
/**
* \returns true if the test was successful, false otherwise.
*/
virtual bool RunTests (void) = 0;
/**
* \returns true if the test was successful, false otherwise.
*/
virtual bool RunTests (void) = 0;
protected:
/**
* \returns an output stream which base classes can write to
* to return extra information on test errors.
*/
std::ostream &Failure (void);
/**
* \returns an output stream which base classes can write to
* to return extra information on test errors.
*/
std::ostream &Failure (void);
};
/**
@ -70,34 +70,34 @@ protected:
*/
class TestManager {
public:
/**
* Enable verbose output. If you do not enable verbose output,
* nothing is printed on screen during the test runs.
*/
static void EnableVerbose (void);
/**
* \returns true if all tests passed, false otherwise.
*
* run all registered regression tests
*/
static bool RunTests (void);
/**
* Enable verbose output. If you do not enable verbose output,
* nothing is printed on screen during the test runs.
*/
static void EnableVerbose (void);
/**
* \returns true if all tests passed, false otherwise.
*
* run all registered regression tests
*/
static bool RunTests (void);
private:
friend class Test;
static void Add (Test *test, char const *name);
static std::ostream &Failure (void);
static TestManager *Get (void);
bool RealRunTests (void);
friend class Test;
static void Add (Test *test, char const *name);
static std::ostream &Failure (void);
static TestManager *Get (void);
bool RealRunTests (void);
TestManager ();
~TestManager ();
TestManager ();
~TestManager ();
typedef std::list<std::pair<Test *,std::string *> > Tests;
typedef std::list<std::pair<Test *,std::string *> >::iterator TestsI;
typedef std::list<std::pair<Test *,std::string *> >::const_iterator TestsCI;
typedef std::list<std::pair<Test *,std::string *> > Tests;
typedef std::list<std::pair<Test *,std::string *> >::iterator TestsI;
typedef std::list<std::pair<Test *,std::string *> >::const_iterator TestsCI;
Tests m_tests;
bool m_verbose;
Tests m_tests;
bool m_verbose;
};
}; // namespace ns3

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005 INRIA
* All rights reserved.
@ -46,32 +46,32 @@ namespace ns3 {
class SystemFilePrivate {
public:
SystemFilePrivate ();
~SystemFilePrivate ();
SystemFilePrivate ();
~SystemFilePrivate ();
void Open (char const *filename);
void Write (uint8_t const*buffer, uint32_t size);
void Open (char const *filename);
void Write (uint8_t const*buffer, uint32_t size);
private:
uint8_t m_data[BUFFER_SIZE];
uint32_t m_current;
int m_fd;
uint8_t m_data[BUFFER_SIZE];
uint32_t m_current;
int m_fd;
};
SystemFilePrivate::SystemFilePrivate ()
: m_current (0)
: m_current (0)
{}
SystemFilePrivate::~SystemFilePrivate ()
{
::write (m_fd, m_data, m_current);
::close (m_fd);
::write (m_fd, m_data, m_current);
::close (m_fd);
}
void
SystemFilePrivate::Open (char const *filename)
{
m_fd = ::open (filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
assert (m_fd != -1);
m_fd = ::open (filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
assert (m_fd != -1);
}
#ifndef min
@ -81,41 +81,41 @@ SystemFilePrivate::Open (char const *filename)
void
SystemFilePrivate::Write (uint8_t const*buffer, uint32_t size)
{
while (size > 0)
{
uint32_t toCopy = min (BUFFER_SIZE - m_current, size);
memcpy (m_data + m_current, buffer, toCopy);
size -= toCopy;
m_current += toCopy;
buffer += toCopy;
if (m_current == BUFFER_SIZE)
{
ssize_t written = 0;
written = ::write (m_fd, m_data, BUFFER_SIZE);
assert (written == BUFFER_SIZE);
m_current = 0;
}
}
while (size > 0)
{
uint32_t toCopy = min (BUFFER_SIZE - m_current, size);
memcpy (m_data + m_current, buffer, toCopy);
size -= toCopy;
m_current += toCopy;
buffer += toCopy;
if (m_current == BUFFER_SIZE)
{
ssize_t written = 0;
written = ::write (m_fd, m_data, BUFFER_SIZE);
assert (written == BUFFER_SIZE);
m_current = 0;
}
}
}
SystemFile::SystemFile ()
: m_priv (new SystemFilePrivate ())
: m_priv (new SystemFilePrivate ())
{}
SystemFile::~SystemFile ()
{
delete m_priv;
m_priv = 0;
delete m_priv;
m_priv = 0;
}
void
SystemFile::Open (char const *filename)
{
m_priv->Open (filename);
m_priv->Open (filename);
}
void
SystemFile::Write (uint8_t const*buffer, uint32_t size)
{
m_priv->Write (buffer, size);
m_priv->Write (buffer, size);
}
}; // namespace

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005 INRIA
* All rights reserved.
@ -26,49 +26,49 @@ namespace ns3 {
class SystemWallClockMsPrivate {
public:
void Start (void);
unsigned long long End (void);
void Start (void);
unsigned long long End (void);
private:
struct timeval m_startTv;
struct timeval m_endTv;
struct timeval m_startTv;
struct timeval m_endTv;
};
void
SystemWallClockMsPrivate::Start (void)
{
struct timezone tz;
gettimeofday (&m_startTv, &tz);
struct timezone tz;
gettimeofday (&m_startTv, &tz);
}
unsigned long long
SystemWallClockMsPrivate::End (void)
{
struct timezone tz;
gettimeofday (&m_endTv, &tz);
unsigned long long end = m_endTv.tv_sec *1000 + m_endTv.tv_usec / 1000;
unsigned long long start = m_startTv.tv_sec *1000 + m_startTv.tv_usec / 1000;
return end - start;
struct timezone tz;
gettimeofday (&m_endTv, &tz);
unsigned long long end = m_endTv.tv_sec *1000 + m_endTv.tv_usec / 1000;
unsigned long long start = m_startTv.tv_sec *1000 + m_startTv.tv_usec / 1000;
return end - start;
}
SystemWallClockMs::SystemWallClockMs ()
: m_priv (new SystemWallClockMsPrivate ())
: m_priv (new SystemWallClockMsPrivate ())
{}
SystemWallClockMs::~SystemWallClockMs ()
{
delete m_priv;
m_priv = 0;
delete m_priv;
m_priv = 0;
}
void
SystemWallClockMs::Start (void)
{
m_priv->Start ();
m_priv->Start ();
}
unsigned long long
SystemWallClockMs::End (void)
{
return m_priv->End ();
return m_priv->End ();
}
}; // namespace ns3

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005 INRIA
* All rights reserved.
@ -38,11 +38,11 @@ namespace ns3 {
class SystemFilePrivate {
public:
SystemFilePrivate ();
~SystemFilePrivate ();
SystemFilePrivate ();
~SystemFilePrivate ();
void open (char const *filename);
void write (uint8_t const*buffer, uint32_t size);
void open (char const *filename);
void write (uint8_t const*buffer, uint32_t size);
private:
};
@ -64,23 +64,23 @@ SystemFilePrivate::Write (uint8_t const*buffer, uint32_t size)
}
SystemFile::SystemFile ()
: m_priv (new SystemFilePrivate ())
: m_priv (new SystemFilePrivate ())
{}
SystemFile::~SystemFile ()
{
delete m_priv;
m_priv = 0;
delete m_priv;
m_priv = 0;
}
void
SystemFile::Open (char const *filename)
{
m_priv->Open (filename);
m_priv->Open (filename);
}
void
SystemFile::Write (uint8_t const*buffer, uint32_t size)
{
m_priv->Write (buffer, size);
m_priv->Write (buffer, size);
}
}; // namespace

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005 INRIA
* All rights reserved.
@ -25,8 +25,8 @@ namespace ns3 {
class SystemWallClockMsPrivate {
public:
void start (void);
unsigned long long end (void);
void start (void);
unsigned long long end (void);
private:
};
@ -38,28 +38,28 @@ SystemWallClockMsPrivate::Start (void)
unsigned long long
SystemWallClockMsPrivate::End (void)
{
return 0;
return 0;
}
SystemWallClockMs::SystemWallClockMs ()
: m_priv (new SystemWallClockMsPrivate ())
: m_priv (new SystemWallClockMsPrivate ())
{}
SystemWallClockMs::~SystemWallClockMs ()
{
delete m_priv;
m_priv = 0;
delete m_priv;
m_priv = 0;
}
void
SystemWallClockMs::Start (void)
{
m_priv->Start ();
m_priv->Start ();
}
unsigned long long
SystemWallClockMs::End (void)
{
return m_priv->End ();
return m_priv->End ();
}
}; // namespace ns3

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005 INRIA
* All rights reserved.
@ -24,40 +24,40 @@
namespace ns3 {
EventId::EventId ()
: m_eventImpl (0),
m_ns (0),
m_uid (0)
: m_eventImpl (0),
m_ns (0),
m_uid (0)
{}
EventId::EventId (EventImpl *impl, uint64_t ns, uint32_t uid)
: m_eventImpl (impl),
m_ns (ns),
m_uid (uid)
: m_eventImpl (impl),
m_ns (ns),
m_uid (uid)
{}
void
EventId::Cancel (void)
{
Simulator::Cancel (*this);
Simulator::Cancel (*this);
}
bool
EventId::IsExpired (void)
{
return Simulator::IsExpired (*this);
return Simulator::IsExpired (*this);
}
EventImpl *
EventId::GetEventImpl (void) const
{
return m_eventImpl;
return m_eventImpl;
}
uint64_t
EventId::GetNs (void) const
{
return m_ns;
return m_ns;
}
uint32_t
EventId::GetUid (void) const
{
return m_uid;
return m_uid;
}

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005 INRIA
* All rights reserved.
@ -32,31 +32,31 @@ class EventImpl;
*/
class EventId {
public:
EventId ();
EventId (EventImpl *impl, uint64_t ns, uint32_t uid);
/**
* This method is syntactic sugar for the ns3::Simulator::cancel
* method.
*/
void Cancel (void);
/**
* This method is syntactic sugar for the ns3::Simulator::isExpired
* method.
* \returns true if the event has expired, false otherwise.
*/
bool IsExpired (void);
EventId ();
EventId (EventImpl *impl, uint64_t ns, uint32_t uid);
/**
* This method is syntactic sugar for the ns3::Simulator::cancel
* method.
*/
void Cancel (void);
/**
* This method is syntactic sugar for the ns3::Simulator::isExpired
* method.
* \returns true if the event has expired, false otherwise.
*/
bool IsExpired (void);
public:
/* The following methods are semi-private
* they are supposed to be invoked only by
* subclasses of the Scheduler base class.
*/
EventImpl *GetEventImpl (void) const;
uint64_t GetNs (void) const;
uint32_t GetUid (void) const;
/* The following methods are semi-private
* they are supposed to be invoked only by
* subclasses of the Scheduler base class.
*/
EventImpl *GetEventImpl (void) const;
uint64_t GetNs (void) const;
uint32_t GetUid (void) const;
private:
EventImpl *m_eventImpl;
uint64_t m_ns;
uint32_t m_uid;
EventImpl *m_eventImpl;
uint64_t m_ns;
uint32_t m_uid;
};
}; // namespace ns3

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005 INRIA
* All rights reserved.
@ -29,31 +29,31 @@ EventImpl::~EventImpl ()
{}
EventImpl::EventImpl ()
: m_internalIterator (0),
m_cancel (false)
: m_internalIterator (0),
m_cancel (false)
{}
void
EventImpl::Invoke (void)
{
if (!m_cancel)
{
Notify ();
}
if (!m_cancel)
{
Notify ();
}
}
void
EventImpl::SetInternalIterator (void *tag)
{
m_internalIterator = tag;
m_internalIterator = tag;
}
void *
EventImpl::GetInternalIterator (void) const
{
return m_internalIterator;
return m_internalIterator;
}
void
EventImpl::Cancel (void)
{
m_cancel = true;
m_cancel = true;
}
}; // namespace ns3

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005,2006 INRIA
* All rights reserved.
@ -27,18 +27,18 @@ namespace ns3 {
class EventImpl {
public:
EventImpl ();
virtual ~EventImpl () = 0;
void Invoke (void);
void Cancel (void);
void SetInternalIterator (void *iterator);
void *GetInternalIterator (void) const;
EventImpl ();
virtual ~EventImpl () = 0;
void Invoke (void);
void Cancel (void);
void SetInternalIterator (void *iterator);
void *GetInternalIterator (void) const;
protected:
virtual void Notify (void) = 0;
virtual void Notify (void) = 0;
private:
friend class Event;
void *m_internalIterator;
bool m_cancel;
friend class Event;
void *m_internalIterator;
bool m_cancel;
};
}; // namespace ns3

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005,2006 INRIA
* All rights reserved.
@ -33,28 +33,28 @@ namespace ns3 {
*/
class Time {
public:
Time (Time const &o);
Time &operator = (Time const &o);
Time (Time const &o);
Time &operator = (Time const &o);
bool IsNegative (void) const;
bool IsPositive (void) const;
bool IsStrictlyNegative (void) const;
bool IsStrictlyPositive (void) const;
bool IsZero (void) const;
bool IsNegative (void) const;
bool IsPositive (void) const;
bool IsStrictlyNegative (void) const;
bool IsStrictlyPositive (void) const;
bool IsZero (void) const;
Time operator += (Time const &o);
Time operator -= (Time const &o);
Time operator += (Time const &o);
Time operator -= (Time const &o);
double ApproximateToSeconds (void) const;
int64_t ApproximateToMilliSeconds (void) const;
int64_t ApproximateToMicroSeconds (void) const;
int64_t ApproximateToNanoSeconds (void) const;
double ApproximateToSeconds (void) const;
int64_t ApproximateToMilliSeconds (void) const;
int64_t ApproximateToMicroSeconds (void) const;
int64_t ApproximateToNanoSeconds (void) const;
protected:
Time (int64_t ns);
Time (int64_t ns);
private:
Time ();
int64_t m_ns;
Time ();
int64_t m_ns;
};
Time operator + (Time const &lhs, Time const &rhs);
@ -69,28 +69,28 @@ bool operator >= (Time const &lhs, Time const &rhs);
class Now : public Time {
public:
Now ();
Now ();
};
class Seconds : public Time
{
public:
Seconds (double s);
Seconds (double s);
};
class MilliSeconds : public Time
{
public:
MilliSeconds (int32_t ms);
MilliSeconds (int32_t ms);
};
class MicroSeconds : public Time
{
public:
MicroSeconds (int32_t us);
MicroSeconds (int32_t us);
};
class NanoSeconds : public Time
{
public:
NanoSeconds (int64_t ns);
NanoSeconds (int64_t ns);
};
}; // namespace ns3

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2006 INRIA
* All rights reserved.
@ -28,7 +28,7 @@ SchedulerFactory::~SchedulerFactory ()
Scheduler *
SchedulerFactory::Create (void) const
{
return RealCreate ();
return RealCreate ();
}
}; // namespace ns3

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2006 INRIA
* All rights reserved.
@ -35,14 +35,14 @@ class Scheduler;
*/
class SchedulerFactory {
public:
virtual ~SchedulerFactory ();
Scheduler *Create (void) const;
virtual ~SchedulerFactory ();
Scheduler *Create (void) const;
private:
/**
* \returns a newly-created scheduler. The caller takes
* ownership of the returned pointer.
*/
virtual Scheduler *RealCreate (void) const = 0;
/**
* \returns a newly-created scheduler. The caller takes
* ownership of the returned pointer.
*/
virtual Scheduler *RealCreate (void) const = 0;
};
}; // namespace ns3

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2006 INRIA
* Copyright (c) 2005 Mathieu Lacage
@ -53,11 +53,11 @@ namespace ns3 {
SchedulerHeap::SchedulerHeap ()
{
// we purposedly waste an item at the start of
// the array to make sure the indexes in the
// array start at one.
Scheduler::EventKey emptyKey = {0,0};
m_heap.push_back (std::make_pair (static_cast<EventImpl *>(0), emptyKey));
// we purposedly waste an item at the start of
// the array to make sure the indexes in the
// array start at one.
Scheduler::EventKey emptyKey = {0,0};
m_heap.push_back (std::make_pair (static_cast<EventImpl *>(0), emptyKey));
}
SchedulerHeap::~SchedulerHeap ()
@ -66,186 +66,186 @@ SchedulerHeap::~SchedulerHeap ()
void
SchedulerHeap::StoreInEvent (EventImpl *ev, uint32_t index) const
{
long tmp = index;
ev->SetInternalIterator ((void *)tmp);
long tmp = index;
ev->SetInternalIterator ((void *)tmp);
}
uint32_t
SchedulerHeap::GetFromEvent (EventImpl *ev) const
{
long tmp = (long)ev->GetInternalIterator ();
return (uint32_t)tmp;
long tmp = (long)ev->GetInternalIterator ();
return (uint32_t)tmp;
}
uint32_t
SchedulerHeap::Parent (uint32_t id) const
{
return id / 2;
return id / 2;
}
uint32_t
SchedulerHeap::Sibling (uint32_t id) const
{
return id + 1;
return id + 1;
}
uint32_t
SchedulerHeap::LeftChild (uint32_t id) const
{
return id * 2;
return id * 2;
}
uint32_t
SchedulerHeap::RightChild (uint32_t id) const
{
return id * 2 + 1;
return id * 2 + 1;
}
uint32_t
SchedulerHeap::Root (void) const
{
return 1;
return 1;
}
bool
SchedulerHeap::IsRoot (uint32_t id) const
{
return (id == Root ())?true:false;
return (id == Root ())?true:false;
}
uint32_t
SchedulerHeap::Last (void) const
{
return m_heap.size () - 1;
return m_heap.size () - 1;
}
bool
SchedulerHeap::IsBottom (uint32_t id) const
{
return (id >= m_heap.size ())?true:false;
return (id >= m_heap.size ())?true:false;
}
void
SchedulerHeap::Exch (uint32_t a, uint32_t b)
{
assert (b < m_heap.size () && a < m_heap.size ());
TRACE ("Exch " << a << ", " << b);
std::pair<EventImpl*, Scheduler::EventKey> tmp (m_heap[a]);
m_heap[a] = m_heap[b];
m_heap[b] = tmp;
StoreInEvent (m_heap[a].first, a);
StoreInEvent (m_heap[b].first, b);
assert (b < m_heap.size () && a < m_heap.size ());
TRACE ("Exch " << a << ", " << b);
std::pair<EventImpl*, Scheduler::EventKey> tmp (m_heap[a]);
m_heap[a] = m_heap[b];
m_heap[b] = tmp;
StoreInEvent (m_heap[a].first, a);
StoreInEvent (m_heap[b].first, b);
}
bool
SchedulerHeap::IsLess (uint32_t a, uint32_t b)
{
Scheduler::EventKeyCompare compare;
return compare (m_heap[a].second, m_heap[b].second);
Scheduler::EventKeyCompare compare;
return compare (m_heap[a].second, m_heap[b].second);
}
uint32_t
SchedulerHeap::Smallest (uint32_t a, uint32_t b)
{
return IsLess (a,b)?a:b;
return IsLess (a,b)?a:b;
}
bool
SchedulerHeap::RealIsEmpty (void) const
{
return (m_heap.size () == 1)?true:false;
return (m_heap.size () == 1)?true:false;
}
void
SchedulerHeap::BottomUp (void)
{
uint32_t index = Last ();
while (!IsRoot (index) &&
IsLess (index, Parent (index)))
{
Exch(index, Parent (index));
index = Parent (index);
}
uint32_t index = Last ();
while (!IsRoot (index) &&
IsLess (index, Parent (index)))
{
Exch(index, Parent (index));
index = Parent (index);
}
}
void
SchedulerHeap::TopDown (void)
{
uint32_t index = Root ();
uint32_t right = RightChild (index);
while (!IsBottom (right))
{
uint32_t left = LeftChild (index);
uint32_t tmp = Smallest (left, right);
if (IsLess (index, tmp))
{
return;
}
Exch (index, tmp);
index = tmp;
right = RightChild (index);
}
if (IsBottom (index))
{
return;
}
assert (!IsBottom (index));
uint32_t left = LeftChild (index);
if (IsBottom (left))
{
return;
}
if (IsLess (index, left))
{
return;
}
Exch (index, left);
uint32_t index = Root ();
uint32_t right = RightChild (index);
while (!IsBottom (right))
{
uint32_t left = LeftChild (index);
uint32_t tmp = Smallest (left, right);
if (IsLess (index, tmp))
{
return;
}
Exch (index, tmp);
index = tmp;
right = RightChild (index);
}
if (IsBottom (index))
{
return;
}
assert (!IsBottom (index));
uint32_t left = LeftChild (index);
if (IsBottom (left))
{
return;
}
if (IsLess (index, left))
{
return;
}
Exch (index, left);
}
EventId
SchedulerHeap::RealInsert (EventImpl *event, Scheduler::EventKey key)
{
m_heap.push_back (std::make_pair (event, key));
BottomUp ();
StoreInEvent (event, Last ());
return EventId (event, key.m_ns, key.m_uid);
m_heap.push_back (std::make_pair (event, key));
BottomUp ();
StoreInEvent (event, Last ());
return EventId (event, key.m_ns, key.m_uid);
}
EventImpl *
SchedulerHeap::RealPeekNext (void) const
{
return m_heap[Root ()].first;
return m_heap[Root ()].first;
}
Scheduler::EventKey
SchedulerHeap::RealPeekNextKey (void) const
{
return m_heap[Root ()].second;
return m_heap[Root ()].second;
}
void
SchedulerHeap::RealRemoveNext (void)
{
Exch (Root (), Last ());
m_heap.pop_back ();
TopDown ();
Exch (Root (), Last ());
m_heap.pop_back ();
TopDown ();
}
EventImpl *
SchedulerHeap::RealRemove (EventId id, Scheduler::EventKey *key)
{
EventImpl *ev = id.GetEventImpl ();
uint32_t i = GetFromEvent (ev);
*key = m_heap[i].second;
Exch (i, Last ());
m_heap.pop_back ();
TopDown ();
return ev;
EventImpl *ev = id.GetEventImpl ();
uint32_t i = GetFromEvent (ev);
*key = m_heap[i].second;
Exch (i, Last ());
m_heap.pop_back ();
TopDown ();
return ev;
}
bool
SchedulerHeap::RealIsValid (EventId id)
{
EventImpl *ev = id.GetEventImpl ();
uint32_t i = GetFromEvent (ev);
Scheduler::EventKey key = m_heap[i].second;
return (key.m_ns == id.GetNs () &&
key.m_uid == id.GetUid ());
EventImpl *ev = id.GetEventImpl ();
uint32_t i = GetFromEvent (ev);
Scheduler::EventKey key = m_heap[i].second;
return (key.m_ns == id.GetNs () &&
key.m_uid == id.GetUid ());
}
}; // namespace ns3

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005 INRIA
* All rights reserved.
@ -32,38 +32,38 @@ class EventHolder;
class SchedulerHeap : public Scheduler {
public:
SchedulerHeap ();
virtual ~SchedulerHeap ();
SchedulerHeap ();
virtual ~SchedulerHeap ();
private:
virtual EventId RealInsert (EventImpl *event, Scheduler::EventKey key);
virtual bool RealIsEmpty (void) const;
virtual EventImpl *RealPeekNext (void) const;
virtual Scheduler::EventKey RealPeekNextKey (void) const;
virtual void RealRemoveNext (void);
virtual EventImpl *RealRemove (EventId ev, Scheduler::EventKey *key);
virtual bool RealIsValid (EventId id);
virtual EventId RealInsert (EventImpl *event, Scheduler::EventKey key);
virtual bool RealIsEmpty (void) const;
virtual EventImpl *RealPeekNext (void) const;
virtual Scheduler::EventKey RealPeekNextKey (void) const;
virtual void RealRemoveNext (void);
virtual EventImpl *RealRemove (EventId ev, Scheduler::EventKey *key);
virtual bool RealIsValid (EventId id);
typedef std::vector<std::pair<EventImpl *, Scheduler::EventKey> > BinaryHeap;
inline void StoreInEvent (EventImpl *ev, uint32_t index) const;
uint32_t GetFromEvent (EventImpl *ev) const;
typedef std::vector<std::pair<EventImpl *, Scheduler::EventKey> > BinaryHeap;
inline void StoreInEvent (EventImpl *ev, uint32_t index) const;
uint32_t GetFromEvent (EventImpl *ev) const;
inline uint32_t Parent (uint32_t id) const;
uint32_t Sibling (uint32_t id) const;
inline uint32_t LeftChild (uint32_t id) const;
inline uint32_t RightChild (uint32_t id) const;
inline uint32_t Root (void) const;
uint32_t Last (void) const;
inline bool IsRoot (uint32_t id) const;
inline bool IsBottom (uint32_t id) const;
inline bool IsLess (uint32_t a, uint32_t b);
inline uint32_t Smallest (uint32_t a, uint32_t b);
inline uint32_t Parent (uint32_t id) const;
uint32_t Sibling (uint32_t id) const;
inline uint32_t LeftChild (uint32_t id) const;
inline uint32_t RightChild (uint32_t id) const;
inline uint32_t Root (void) const;
uint32_t Last (void) const;
inline bool IsRoot (uint32_t id) const;
inline bool IsBottom (uint32_t id) const;
inline bool IsLess (uint32_t a, uint32_t b);
inline uint32_t Smallest (uint32_t a, uint32_t b);
inline void Exch (uint32_t a, uint32_t b);
void BottomUp (void);
void TopDown (void);
inline void Exch (uint32_t a, uint32_t b);
void BottomUp (void);
void TopDown (void);
BinaryHeap m_heap;
BinaryHeap m_heap;
};
}; // namespace ns3

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005 INRIA
* All rights reserved.
@ -40,82 +40,82 @@ SchedulerList::~SchedulerList ()
EventId
SchedulerList::GetEventId (Scheduler::EventKey key, EventsI i)
{
assert (sizeof (i) <= sizeof (void *));
void *internalIterator;
memcpy ((char *)&(internalIterator), (char *)&i, sizeof (void *));
EventImpl *ev = i->first;
ev->SetInternalIterator (internalIterator);
return EventId (ev, key.m_ns, key.m_uid);
assert (sizeof (i) <= sizeof (void *));
void *internalIterator;
memcpy ((char *)&(internalIterator), (char *)&i, sizeof (void *));
EventImpl *ev = i->first;
ev->SetInternalIterator (internalIterator);
return EventId (ev, key.m_ns, key.m_uid);
}
SchedulerList::EventsI
SchedulerList::GetIterator (EventId id)
{
SchedulerList::EventsI i;
assert (sizeof (i) <= sizeof (void *));
EventImpl *ev = id.GetEventImpl ();
void *internalIterator = ev->GetInternalIterator ();
memcpy ((char *)&i, (char *)&(internalIterator), sizeof (void *));
return i;
SchedulerList::EventsI i;
assert (sizeof (i) <= sizeof (void *));
EventImpl *ev = id.GetEventImpl ();
void *internalIterator = ev->GetInternalIterator ();
memcpy ((char *)&i, (char *)&(internalIterator), sizeof (void *));
return i;
}
EventId
SchedulerList::RealInsert (EventImpl *event, Scheduler::EventKey key)
{
Scheduler::EventKeyCompare compare;
for (EventsI i = m_events.begin (); i != m_events.end (); i++)
{
if (compare (key, i->second))
{
m_events.insert (i, std::make_pair (event, key));
return GetEventId (key, i);
}
}
m_events.push_back (std::make_pair (event, key));
return GetEventId (key, --(m_events.end ()));
Scheduler::EventKeyCompare compare;
for (EventsI i = m_events.begin (); i != m_events.end (); i++)
{
if (compare (key, i->second))
{
m_events.insert (i, std::make_pair (event, key));
return GetEventId (key, i);
}
}
m_events.push_back (std::make_pair (event, key));
return GetEventId (key, --(m_events.end ()));
}
bool
SchedulerList::RealIsEmpty (void) const
{
return m_events.empty ();
return m_events.empty ();
}
EventImpl *
SchedulerList::RealPeekNext (void) const
{
return m_events.front ().first;
return m_events.front ().first;
}
Scheduler::EventKey
SchedulerList::RealPeekNextKey (void) const
{
return m_events.front ().second;
return m_events.front ().second;
}
void
SchedulerList::RealRemoveNext (void)
{
m_events.pop_front ();
m_events.pop_front ();
}
EventImpl *
SchedulerList::RealRemove (EventId id, Scheduler::EventKey *key)
{
EventsI i = GetIterator (id);
*key = i->second;
assert (key->m_ns == id.GetNs () &&
key->m_uid == id.GetUid ());
EventImpl *ev = i->first;
m_events.erase (i);
return ev;
EventsI i = GetIterator (id);
*key = i->second;
assert (key->m_ns == id.GetNs () &&
key->m_uid == id.GetUid ());
EventImpl *ev = i->first;
m_events.erase (i);
return ev;
}
bool
SchedulerList::RealIsValid (EventId id)
{
EventsI i = GetIterator (id);
Scheduler::EventKey key = i->second;
return (key.m_ns == id.GetNs () &&
key.m_uid == id.GetUid ());
EventsI i = GetIterator (id);
Scheduler::EventKey key = i->second;
return (key.m_ns == id.GetNs () &&
key.m_uid == id.GetUid ());
}
}; // namespace ns3

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005 INRIA
* All rights reserved.
@ -34,23 +34,23 @@ class EventImpl;
class SchedulerList : public Scheduler {
public:
SchedulerList ();
virtual ~SchedulerList ();
SchedulerList ();
virtual ~SchedulerList ();
private:
virtual EventId RealInsert (EventImpl *event, EventKey key);
virtual bool RealIsEmpty (void) const;
virtual EventImpl *RealPeekNext (void) const;
virtual Scheduler::EventKey RealPeekNextKey (void) const;
virtual void RealRemoveNext (void);
virtual EventImpl *RealRemove (EventId ev, Scheduler::EventKey *key);
virtual bool RealIsValid (EventId id);
virtual EventId RealInsert (EventImpl *event, EventKey key);
virtual bool RealIsEmpty (void) const;
virtual EventImpl *RealPeekNext (void) const;
virtual Scheduler::EventKey RealPeekNextKey (void) const;
virtual void RealRemoveNext (void);
virtual EventImpl *RealRemove (EventId ev, Scheduler::EventKey *key);
virtual bool RealIsValid (EventId id);
typedef std::list<std::pair<EventImpl*, EventKey> > Events;
typedef std::list<std::pair<EventImpl*, EventKey> >::iterator EventsI;
EventId GetEventId (Scheduler::EventKey key, EventsI i);
EventsI GetIterator (EventId id);
Events m_events;
typedef std::list<std::pair<EventImpl*, EventKey> > Events;
typedef std::list<std::pair<EventImpl*, EventKey> >::iterator EventsI;
EventId GetEventId (Scheduler::EventKey key, EventsI i);
EventsI GetIterator (EventId id);
Events m_events;
};
}; // namespace ns3

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2006 INRIA
* All rights reserved.
@ -47,70 +47,70 @@ SchedulerMap::~SchedulerMap ()
void
SchedulerMap::StoreInEvent (EventImpl *ev, EventMapI i) const
{
void *tag;
memcpy (&(tag), &i, sizeof (tag));
ev->SetInternalIterator (tag);
void *tag;
memcpy (&(tag), &i, sizeof (tag));
ev->SetInternalIterator (tag);
}
SchedulerMap::EventMapI
SchedulerMap::GetFromEvent (EventImpl *ev) const
{
EventMapI i;
void *tag = ev->GetInternalIterator ();
memcpy (&i, &(tag), sizeof (i));
return i;
EventMapI i;
void *tag = ev->GetInternalIterator ();
memcpy (&i, &(tag), sizeof (i));
return i;
}
EventId
SchedulerMap::RealInsert (EventImpl *event, Scheduler::EventKey key)
{
std::pair<EventMapI,bool> result = m_list.insert (std::make_pair (key, event));
assert (result.second);
StoreInEvent (event, result.first);
return EventId (event, key.m_ns, key.m_uid);
std::pair<EventMapI,bool> result = m_list.insert (std::make_pair (key, event));
assert (result.second);
StoreInEvent (event, result.first);
return EventId (event, key.m_ns, key.m_uid);
}
bool
SchedulerMap::RealIsEmpty (void) const
{
return m_list.empty ();
return m_list.empty ();
}
EventImpl *
SchedulerMap::RealPeekNext (void) const
{
EventMapCI i = m_list.begin ();
assert (i != m_list.end ());
return (*i).second;
EventMapCI i = m_list.begin ();
assert (i != m_list.end ());
return (*i).second;
}
Scheduler::EventKey
SchedulerMap::RealPeekNextKey (void) const
{
EventMapCI i = m_list.begin ();
assert (i != m_list.end ());
return (*i).first;
EventMapCI i = m_list.begin ();
assert (i != m_list.end ());
return (*i).first;
}
void
SchedulerMap::RealRemoveNext (void)
{
m_list.erase (m_list.begin ());
m_list.erase (m_list.begin ());
}
EventImpl *
SchedulerMap::RealRemove (EventId id, Scheduler::EventKey *key)
{
EventMapI i = GetFromEvent (id.GetEventImpl ());
*key = i->first;
m_list.erase (i);
return i->second;
EventMapI i = GetFromEvent (id.GetEventImpl ());
*key = i->first;
m_list.erase (i);
return i->second;
}
bool
SchedulerMap::RealIsValid (EventId id)
{
EventMapI i = GetFromEvent (id.GetEventImpl ());
Scheduler::EventKey key = i->first;
return (key.m_ns == id.GetNs () &&
key.m_uid == id.GetUid ());
EventMapI i = GetFromEvent (id.GetEventImpl ());
Scheduler::EventKey key = i->first;
return (key.m_ns == id.GetNs () &&
key.m_uid == id.GetUid ());
}

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2006 INRIA
* All rights reserved.
@ -33,27 +33,27 @@ class EventImpl;
class SchedulerMap : public Scheduler {
public:
SchedulerMap ();
virtual ~SchedulerMap ();
SchedulerMap ();
virtual ~SchedulerMap ();
private:
virtual EventId RealInsert (EventImpl *event, Scheduler::EventKey key);
virtual bool RealIsEmpty (void) const;
virtual EventImpl *RealPeekNext (void) const;
virtual Scheduler::EventKey RealPeekNextKey (void) const;
virtual void RealRemoveNext (void);
virtual EventImpl *RealRemove (EventId ev, Scheduler::EventKey *key);
virtual bool RealIsValid (EventId id);
virtual EventId RealInsert (EventImpl *event, Scheduler::EventKey key);
virtual bool RealIsEmpty (void) const;
virtual EventImpl *RealPeekNext (void) const;
virtual Scheduler::EventKey RealPeekNextKey (void) const;
virtual void RealRemoveNext (void);
virtual EventImpl *RealRemove (EventId ev, Scheduler::EventKey *key);
virtual bool RealIsValid (EventId id);
typedef std::map<Scheduler::EventKey, EventImpl*, Scheduler::EventKeyCompare> EventMap;
typedef std::map<Scheduler::EventKey, EventImpl*, Scheduler::EventKeyCompare>::iterator EventMapI;
typedef std::map<Scheduler::EventKey, EventImpl*, Scheduler::EventKeyCompare>::const_iterator EventMapCI;
typedef std::map<Scheduler::EventKey, EventImpl*, Scheduler::EventKeyCompare> EventMap;
typedef std::map<Scheduler::EventKey, EventImpl*, Scheduler::EventKeyCompare>::iterator EventMapI;
typedef std::map<Scheduler::EventKey, EventImpl*, Scheduler::EventKeyCompare>::const_iterator EventMapCI;
void StoreInEvent (EventImpl *ev, EventMapI i) const;
SchedulerMap::EventMapI GetFromEvent (EventImpl *ev) const;
void StoreInEvent (EventImpl *ev, EventMapI i) const;
SchedulerMap::EventMapI GetFromEvent (EventImpl *ev) const;
EventMap m_list;
uint32_t m_uid;
EventMap m_list;
uint32_t m_uid;
};
}; // namespace ns3

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2006 INRIA
* All rights reserved.
@ -35,60 +35,60 @@ Scheduler::~Scheduler ()
bool
Scheduler::EventKeyCompare::operator () (struct EventKey a, struct EventKey b)
{
assert (a.m_uid != b.m_uid);
if (a.m_ns < b.m_ns)
{
return true;
}
else if (a.m_ns == b.m_ns && a.m_uid < b.m_uid)
{
return true;
}
else
{
return false;
}
assert (a.m_uid != b.m_uid);
if (a.m_ns < b.m_ns)
{
return true;
}
else if (a.m_ns == b.m_ns && a.m_uid < b.m_uid)
{
return true;
}
else
{
return false;
}
}
EventId
Scheduler::Insert (EventImpl *event, struct EventKey key)
{
return RealInsert (event, key);
return RealInsert (event, key);
}
bool
Scheduler::IsEmpty (void) const
{
return RealIsEmpty ();
return RealIsEmpty ();
}
EventImpl *
Scheduler::PeekNext (void) const
{
assert (!RealIsEmpty ());
return RealPeekNext ();
assert (!RealIsEmpty ());
return RealPeekNext ();
}
Scheduler::EventKey
Scheduler::PeekNextKey (void) const
{
assert (!RealIsEmpty ());
return RealPeekNextKey ();
assert (!RealIsEmpty ());
return RealPeekNextKey ();
}
void
Scheduler::RemoveNext (void)
{
assert (!RealIsEmpty ());
return RealRemoveNext ();
assert (!RealIsEmpty ());
return RealRemoveNext ();
}
EventImpl *
Scheduler::Remove (EventId id, EventKey *key)
{
assert (!RealIsEmpty ());
return RealRemove (id, key);
assert (!RealIsEmpty ());
return RealRemove (id, key);
}
bool
Scheduler::IsValid (EventId id)
{
return RealIsValid (id);
return RealIsValid (id);
}
}; // namespace ns3

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005 INRIA
* All rights reserved.
@ -54,71 +54,71 @@ class EventImpl;
*/
class Scheduler {
public:
struct EventKey {
uint64_t m_ns;
uint32_t m_uid;
};
class EventKeyCompare {
public:
bool operator () (struct EventKey a, struct EventKey b);
};
struct EventKey {
uint64_t m_ns;
uint32_t m_uid;
};
class EventKeyCompare {
public:
bool operator () (struct EventKey a, struct EventKey b);
};
virtual ~Scheduler () = 0;
virtual ~Scheduler () = 0;
EventId Insert (EventImpl *event, EventKey key);
bool IsEmpty (void) const;
EventImpl *PeekNext (void) const;
Scheduler::EventKey PeekNextKey (void) const ;
void RemoveNext (void);
EventImpl *Remove (EventId id, EventKey *key);
bool IsValid (EventId id);
EventId Insert (EventImpl *event, EventKey key);
bool IsEmpty (void) const;
EventImpl *PeekNext (void) const;
Scheduler::EventKey PeekNextKey (void) const ;
void RemoveNext (void);
EventImpl *Remove (EventId id, EventKey *key);
bool IsValid (EventId id);
private:
/**
* \param event event to store in the event list
* \param key timecode associated to this new event
* \returns an event id which identifies the event inserted
*
* This method takes ownership of the event pointer.
*/
virtual EventId RealInsert (EventImpl *event, EventKey key) = 0;
/**
* \returns true if the event list is empty and false otherwise.
*/
virtual bool RealIsEmpty (void) const = 0;
/**
* \returns a pointer to the next earliest event. The caller
* takes ownership of the returned pointer.
*
* This method cannot be invoked if the list is empty.
*/
virtual EventImpl *RealPeekNext (void) const = 0;
/**
* \returns the timecode associated with the next earliest event.
*
* This method cannot be invoked if the list is empty.
*/
virtual Scheduler::EventKey RealPeekNextKey (void) const = 0;
/**
* This method cannot be invoked if the list is empty.
* Remove the next earliest event from the event list.
*/
virtual void RealRemoveNext (void) = 0;
/**
* \param id the id of the event to remove
* \param key the timecode of the event removed
* \returns a pointer to the event removed. The caller
* takes ownership of the returned pointer.
*
* This methods cannot be invoked if the list is empty.
*/
virtual EventImpl *RealRemove (EventId id, EventKey *key) = 0;
/**
* \param id event id to validate
* \returns true if the event id identifies an existing valid
* event stored in the event list and false otherwise.
*/
virtual bool RealIsValid (EventId id) = 0;
/**
* \param event event to store in the event list
* \param key timecode associated to this new event
* \returns an event id which identifies the event inserted
*
* This method takes ownership of the event pointer.
*/
virtual EventId RealInsert (EventImpl *event, EventKey key) = 0;
/**
* \returns true if the event list is empty and false otherwise.
*/
virtual bool RealIsEmpty (void) const = 0;
/**
* \returns a pointer to the next earliest event. The caller
* takes ownership of the returned pointer.
*
* This method cannot be invoked if the list is empty.
*/
virtual EventImpl *RealPeekNext (void) const = 0;
/**
* \returns the timecode associated with the next earliest event.
*
* This method cannot be invoked if the list is empty.
*/
virtual Scheduler::EventKey RealPeekNextKey (void) const = 0;
/**
* This method cannot be invoked if the list is empty.
* Remove the next earliest event from the event list.
*/
virtual void RealRemoveNext (void) = 0;
/**
* \param id the id of the event to remove
* \param key the timecode of the event removed
* \returns a pointer to the event removed. The caller
* takes ownership of the returned pointer.
*
* This methods cannot be invoked if the list is empty.
*/
virtual EventImpl *RealRemove (EventId id, EventKey *key) = 0;
/**
* \param id event id to validate
* \returns true if the event id identifies an existing valid
* event stored in the event list and false otherwise.
*/
virtual bool RealIsValid (EventId id) = 0;
};
}; // namespace ns3

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005,2006 INRIA
* All rights reserved.
@ -49,39 +49,39 @@ namespace ns3 {
class SimulatorPrivate {
public:
SimulatorPrivate (Scheduler *events);
~SimulatorPrivate ();
SimulatorPrivate (Scheduler *events);
~SimulatorPrivate ();
void EnableLogTo (char const *filename);
void EnableLogTo (char const *filename);
bool IsFinished (void) const;
Time Next (void) const;
void Stop (void);
void StopAt (Time const &time);
EventId Schedule (Time const &time, EventImpl *event);
void ScheduleNow (EventImpl *event);
void ScheduleDestroy (EventImpl *event);
void Remove (EventId ev);
void Cancel (EventId ev);
bool IsExpired (EventId ev);
void Run (void);
Time Now (void) const;
bool IsFinished (void) const;
Time Next (void) const;
void Stop (void);
void StopAt (Time const &time);
EventId Schedule (Time const &time, EventImpl *event);
void ScheduleNow (EventImpl *event);
void ScheduleDestroy (EventImpl *event);
void Remove (EventId ev);
void Cancel (EventId ev);
bool IsExpired (EventId ev);
void Run (void);
Time Now (void) const;
private:
void ProcessOneEvent (void);
uint64_t NextNs (void) const;
void ProcessOneEvent (void);
uint64_t NextNs (void) const;
typedef std::list<std::pair<EventImpl *,uint32_t> > Events;
Events m_destroy;
uint64_t m_stopAt;
bool m_stop;
Scheduler *m_events;
uint32_t m_uid;
uint32_t m_currentUid;
uint64_t m_currentNs;
std::ofstream m_log;
std::ifstream m_inputLog;
bool m_logEnable;
typedef std::list<std::pair<EventImpl *,uint32_t> > Events;
Events m_destroy;
uint64_t m_stopAt;
bool m_stop;
Scheduler *m_events;
uint32_t m_uid;
uint32_t m_currentUid;
uint64_t m_currentNs;
std::ofstream m_log;
std::ifstream m_inputLog;
bool m_logEnable;
};
@ -89,69 +89,69 @@ private:
SimulatorPrivate::SimulatorPrivate (Scheduler *events)
{
m_stop = false;
m_stopAt = 0;
m_events = events;
m_uid = 0;
m_logEnable = false;
m_currentNs = 0;
m_stop = false;
m_stopAt = 0;
m_events = events;
m_uid = 0;
m_logEnable = false;
m_currentNs = 0;
}
SimulatorPrivate::~SimulatorPrivate ()
{
while (!m_destroy.empty ())
{
EventImpl *ev = m_destroy.front ().first;
m_destroy.pop_front ();
TRACE ("handle destroy " << ev);
ev->Invoke ();
delete ev;
}
delete m_events;
m_events = (Scheduler *)0xdeadbeaf;
while (!m_destroy.empty ())
{
EventImpl *ev = m_destroy.front ().first;
m_destroy.pop_front ();
TRACE ("handle destroy " << ev);
ev->Invoke ();
delete ev;
}
delete m_events;
m_events = (Scheduler *)0xdeadbeaf;
}
void
SimulatorPrivate::EnableLogTo (char const *filename)
{
m_log.open (filename);
m_logEnable = true;
m_log.open (filename);
m_logEnable = true;
}
void
SimulatorPrivate::ProcessOneEvent (void)
{
EventImpl *nextEv = m_events->PeekNext ();
Scheduler::EventKey nextKey = m_events->PeekNextKey ();
m_events->RemoveNext ();
TRACE ("handle " << nextEv);
m_currentNs = nextKey.m_ns;
m_currentUid = nextKey.m_uid;
if (m_logEnable)
{
m_log << "e "<<nextKey.m_uid << " " << nextKey.m_ns << std::endl;
}
nextEv->Invoke ();
delete nextEv;
EventImpl *nextEv = m_events->PeekNext ();
Scheduler::EventKey nextKey = m_events->PeekNextKey ();
m_events->RemoveNext ();
TRACE ("handle " << nextEv);
m_currentNs = nextKey.m_ns;
m_currentUid = nextKey.m_uid;
if (m_logEnable)
{
m_log << "e "<<nextKey.m_uid << " " << nextKey.m_ns << std::endl;
}
nextEv->Invoke ();
delete nextEv;
}
bool
SimulatorPrivate::IsFinished (void) const
{
return m_events->IsEmpty ();
return m_events->IsEmpty ();
}
uint64_t
SimulatorPrivate::NextNs (void) const
{
assert (!m_events->IsEmpty ());
Scheduler::EventKey nextKey = m_events->PeekNextKey ();
return nextKey.m_ns;
assert (!m_events->IsEmpty ());
Scheduler::EventKey nextKey = m_events->PeekNextKey ();
return nextKey.m_ns;
}
Time
SimulatorPrivate::Next (void) const
{
return NanoSeconds (NextNs ());
return NanoSeconds (NextNs ());
}
@ -159,103 +159,103 @@ void
SimulatorPrivate::Run (void)
{
while (!m_events->IsEmpty () && !m_stop &&
(m_stopAt == 0 || m_stopAt > NextNs ()))
{
ProcessOneEvent ();
}
m_log.close ();
while (!m_events->IsEmpty () && !m_stop &&
(m_stopAt == 0 || m_stopAt > NextNs ()))
{
ProcessOneEvent ();
}
m_log.close ();
}
void
SimulatorPrivate::Stop (void)
{
m_stop = true;
m_stop = true;
}
void
SimulatorPrivate::StopAt (Time const &at)
{
assert (at.IsPositive ());
m_stopAt = at.ApproximateToNanoSeconds ();
assert (at.IsPositive ());
m_stopAt = at.ApproximateToNanoSeconds ();
}
EventId
SimulatorPrivate::Schedule (Time const &time, EventImpl *event)
{
assert (time.IsPositive ());
assert (time >= NanoSeconds (m_currentNs));
uint64_t ns = (uint64_t) time.ApproximateToNanoSeconds ();
Scheduler::EventKey key = {ns, m_uid};
if (m_logEnable)
{
m_log << "i "<<m_currentUid<<" "<<m_currentNs<<" "
<<m_uid<<" "<<time.ApproximateToNanoSeconds () << std::endl;
}
m_uid++;
return m_events->Insert (event, key);
assert (time.IsPositive ());
assert (time >= NanoSeconds (m_currentNs));
uint64_t ns = (uint64_t) time.ApproximateToNanoSeconds ();
Scheduler::EventKey key = {ns, m_uid};
if (m_logEnable)
{
m_log << "i "<<m_currentUid<<" "<<m_currentNs<<" "
<<m_uid<<" "<<time.ApproximateToNanoSeconds () << std::endl;
}
m_uid++;
return m_events->Insert (event, key);
}
void
SimulatorPrivate::ScheduleNow (EventImpl *event)
{
uint64_t ns = m_currentNs;
Scheduler::EventKey key = {ns, m_uid};
if (m_logEnable)
{
m_log << "i "<<m_currentUid<<" "<<m_currentNs<<" "
<<m_uid<<" "<<ns << std::endl;
}
m_uid++;
m_events->Insert (event, key);
uint64_t ns = m_currentNs;
Scheduler::EventKey key = {ns, m_uid};
if (m_logEnable)
{
m_log << "i "<<m_currentUid<<" "<<m_currentNs<<" "
<<m_uid<<" "<<ns << std::endl;
}
m_uid++;
m_events->Insert (event, key);
}
void
SimulatorPrivate::ScheduleDestroy (EventImpl *event)
{
m_destroy.push_back (std::make_pair (event, m_uid));
if (m_logEnable)
{
m_log << "id " << m_currentUid << " " << Now ().ApproximateToNanoSeconds () << " "
<< m_uid << std::endl;
}
{
m_log << "id " << m_currentUid << " " << Now ().ApproximateToNanoSeconds () << " "
<< m_uid << std::endl;
}
m_uid++;
}
Time
SimulatorPrivate::Now (void) const
{
return NanoSeconds (m_currentNs);
return NanoSeconds (m_currentNs);
}
void
SimulatorPrivate::Remove (EventId ev)
{
Scheduler::EventKey key;
EventImpl *impl = m_events->Remove (ev, &key);
delete impl;
if (m_logEnable)
{
m_log << "r " << m_currentUid << " " << m_currentNs << " "
<< key.m_uid << " " << key.m_ns << std::endl;
}
Scheduler::EventKey key;
EventImpl *impl = m_events->Remove (ev, &key);
delete impl;
if (m_logEnable)
{
m_log << "r " << m_currentUid << " " << m_currentNs << " "
<< key.m_uid << " " << key.m_ns << std::endl;
}
}
void
SimulatorPrivate::Cancel (EventId id)
{
assert (m_events->IsValid (id));
EventImpl *ev = id.GetEventImpl ();
ev->Cancel ();
assert (m_events->IsValid (id));
EventImpl *ev = id.GetEventImpl ();
ev->Cancel ();
}
bool
SimulatorPrivate::IsExpired (EventId ev)
{
if (ev.GetEventImpl () != 0 &&
ev.GetNs () <= m_currentNs &&
ev.GetUid () < m_currentUid)
{
return false;
}
return true;
if (ev.GetEventImpl () != 0 &&
ev.GetNs () <= m_currentNs &&
ev.GetUid () < m_currentUid)
{
return false;
}
return true;
}
@ -276,168 +276,168 @@ SchedulerFactory const*Simulator::m_schedFactory = 0;
void Simulator::SetLinkedList (void)
{
m_listType = LINKED_LIST;
m_listType = LINKED_LIST;
}
void Simulator::SetBinaryHeap (void)
{
m_listType = BINARY_HEAP;
m_listType = BINARY_HEAP;
}
void Simulator::SetStdMap (void)
{
m_listType = STD_MAP;
m_listType = STD_MAP;
}
void
Simulator::SetExternal (SchedulerFactory const*factory)
{
assert (factory != 0);
m_schedFactory = factory;
m_listType = EXTERNAL;
assert (factory != 0);
m_schedFactory = factory;
m_listType = EXTERNAL;
}
void Simulator::EnableLogTo (char const *filename)
{
GetPriv ()->EnableLogTo (filename);
GetPriv ()->EnableLogTo (filename);
}
SimulatorPrivate *
Simulator::GetPriv (void)
{
if (m_priv == 0)
{
Scheduler *events;
switch (m_listType) {
case LINKED_LIST:
events = new SchedulerList ();
break;
case BINARY_HEAP:
events = new SchedulerHeap ();
break;
case STD_MAP:
events = new SchedulerMap ();
break;
case EXTERNAL:
events = m_schedFactory->Create ();
default: // not reached
events = 0;
assert (false);
break;
}
m_priv = new SimulatorPrivate (events);
if (m_priv == 0)
{
Scheduler *events;
switch (m_listType) {
case LINKED_LIST:
events = new SchedulerList ();
break;
case BINARY_HEAP:
events = new SchedulerHeap ();
break;
case STD_MAP:
events = new SchedulerMap ();
break;
case EXTERNAL:
events = m_schedFactory->Create ();
default: // not reached
events = 0;
assert (false);
break;
}
TRACE_S ("priv " << m_priv);
return m_priv;
m_priv = new SimulatorPrivate (events);
}
TRACE_S ("priv " << m_priv);
return m_priv;
}
void
Simulator::Destroy (void)
{
delete m_priv;
m_priv = 0;
delete m_priv;
m_priv = 0;
}
bool
Simulator::IsFinished (void)
{
return GetPriv ()->IsFinished ();
return GetPriv ()->IsFinished ();
}
Time
Simulator::Next (void)
{
return GetPriv ()->Next ();
return GetPriv ()->Next ();
}
void
Simulator::Run (void)
{
GetPriv ()->Run ();
GetPriv ()->Run ();
}
void
Simulator::Stop (void)
{
TRACE ("stop");
GetPriv ()->Stop ();
TRACE ("stop");
GetPriv ()->Stop ();
}
void
Simulator::StopAt (Time const &at)
{
GetPriv ()->StopAt (at);
GetPriv ()->StopAt (at);
}
Time
Simulator::Now (void)
{
return GetPriv ()->Now ();
return GetPriv ()->Now ();
}
EventImpl *
Simulator::MakeEvent (void (*f) (void))
{
// zero arg version
class EventFunctionImpl0 : public EventImpl {
public:
typedef void (*F)(void);
EventFunctionImpl0 (F function)
: m_function (function)
{}
virtual ~EventFunctionImpl0 () {}
protected:
virtual void Notify (void) {
(*m_function) ();
}
private:
F m_function;
} *ev = new EventFunctionImpl0 (f);
return ev;
// zero arg version
class EventFunctionImpl0 : public EventImpl {
public:
typedef void (*F)(void);
EventFunctionImpl0 (F function)
: m_function (function)
{}
virtual ~EventFunctionImpl0 () {}
protected:
virtual void Notify (void) {
(*m_function) ();
}
private:
F m_function;
} *ev = new EventFunctionImpl0 (f);
return ev;
}
EventId
Simulator::Schedule (Time const &time, EventImpl *ev)
{
return GetPriv ()->Schedule (time, ev);
return GetPriv ()->Schedule (time, ev);
}
void
Simulator::ScheduleNow (EventImpl *ev)
{
GetPriv ()->ScheduleNow (ev);
GetPriv ()->ScheduleNow (ev);
}
void
Simulator::ScheduleDestroy (EventImpl *ev)
{
GetPriv ()->ScheduleDestroy (ev);
GetPriv ()->ScheduleDestroy (ev);
}
EventId
Simulator::Schedule (Time const &time, void (*f) (void))
{
return Schedule (time, MakeEvent (f));
return Schedule (time, MakeEvent (f));
}
void
Simulator::ScheduleNow (void (*f) (void))
{
return ScheduleNow (MakeEvent (f));
return ScheduleNow (MakeEvent (f));
}
void
Simulator::ScheduleDestroy (void (*f) (void))
{
return ScheduleDestroy (MakeEvent (f));
return ScheduleDestroy (MakeEvent (f));
}
void
Simulator::Remove (EventId ev)
{
return GetPriv ()->Remove (ev);
return GetPriv ()->Remove (ev);
}
void
Simulator::Cancel (EventId ev)
{
return GetPriv ()->Cancel (ev);
return GetPriv ()->Cancel (ev);
}
bool
Simulator::IsExpired (EventId id)
{
return GetPriv ()->IsExpired (id);
return GetPriv ()->IsExpired (id);
}
}; // namespace ns3
@ -465,76 +465,76 @@ static void foo5 (int, int, int, int, int)
class SimulatorTests : public Test {
public:
SimulatorTests ();
virtual ~SimulatorTests ();
virtual bool RunTests (void);
SimulatorTests ();
virtual ~SimulatorTests ();
virtual bool RunTests (void);
private:
uint64_t NowUs ();
bool RunOneTest (void);
void A (int a);
void B (int b);
void C (int c);
void D (int d);
void bar0 (void);
void bar1 (int);
void bar2 (int, int);
void bar3 (int, int, int);
void bar4 (int, int, int, int);
void bar5 (int, int, int, int, int);
uint64_t NowUs ();
bool RunOneTest (void);
void A (int a);
void B (int b);
void C (int c);
void D (int d);
void bar0 (void);
void bar1 (int);
void bar2 (int, int);
void bar3 (int, int, int);
void bar4 (int, int, int, int);
void bar5 (int, int, int, int, int);
bool m_b;
bool m_a;
bool m_c;
bool m_d;
EventId m_idC;
bool m_b;
bool m_a;
bool m_c;
bool m_d;
EventId m_idC;
};
SimulatorTests::SimulatorTests ()
: Test ("Simulator")
: Test ("Simulator")
{}
SimulatorTests::~SimulatorTests ()
{}
uint64_t
SimulatorTests::NowUs (void)
{
uint64_t ns = Now ().ApproximateToNanoSeconds ();
return ns / 1000;
uint64_t ns = Now ().ApproximateToNanoSeconds ();
return ns / 1000;
}
void
SimulatorTests::A (int a)
{
m_a = false;
m_a = false;
}
void
SimulatorTests::B (int b)
{
if (b != 2 || NowUs () != 11)
{
m_b = false;
}
else
{
m_b = true;
}
Simulator::Remove (m_idC);
Simulator::Schedule (Now () + MicroSeconds (10), &SimulatorTests::D, this, 4);
if (b != 2 || NowUs () != 11)
{
m_b = false;
}
else
{
m_b = true;
}
Simulator::Remove (m_idC);
Simulator::Schedule (Now () + MicroSeconds (10), &SimulatorTests::D, this, 4);
}
void
SimulatorTests::C (int c)
{
m_c = false;
m_c = false;
}
void
SimulatorTests::D (int d)
{
if (d != 4 || NowUs () != (11+10))
{
m_d = false;
}
else
{
m_d = true;
}
if (d != 4 || NowUs () != (11+10))
{
m_d = false;
}
else
{
m_d = true;
}
}
void
SimulatorTests::bar0 (void)
@ -558,89 +558,89 @@ SimulatorTests::bar5 (int, int, int, int, int)
bool
SimulatorTests::RunOneTest (void)
{
bool ok = true;
m_a = true;
m_b = false;
m_c = true;
m_d = false;
bool ok = true;
m_a = true;
m_b = false;
m_c = true;
m_d = false;
EventId a = Simulator::Schedule (Now () + MicroSeconds (10), &SimulatorTests::A, this, 1);
Simulator::Schedule (Now () + MicroSeconds (11), &SimulatorTests::B, this, 2);
m_idC = Simulator::Schedule (Now () + MicroSeconds (12), &SimulatorTests::C, this, 3);
EventId a = Simulator::Schedule (Now () + MicroSeconds (10), &SimulatorTests::A, this, 1);
Simulator::Schedule (Now () + MicroSeconds (11), &SimulatorTests::B, this, 2);
m_idC = Simulator::Schedule (Now () + MicroSeconds (12), &SimulatorTests::C, this, 3);
Simulator::Cancel (a);
Simulator::Run ();
Simulator::Cancel (a);
Simulator::Run ();
if (!m_a || !m_b || !m_c || !m_d)
{
ok = false;
}
return ok;
if (!m_a || !m_b || !m_c || !m_d)
{
ok = false;
}
return ok;
}
bool
SimulatorTests::RunTests (void)
{
bool ok = true;
bool ok = true;
Simulator::SetLinkedList ();
if (!RunOneTest ())
{
ok = false;
}
Simulator::Destroy ();
Simulator::SetBinaryHeap ();
if (!RunOneTest ())
{
ok = false;
}
Simulator::Destroy ();
Simulator::SetStdMap ();
if (!RunOneTest ())
{
ok = false;
}
Simulator::Destroy ();
Simulator::SetLinkedList ();
if (!RunOneTest ())
{
ok = false;
}
Simulator::Destroy ();
Simulator::SetBinaryHeap ();
if (!RunOneTest ())
{
ok = false;
}
Simulator::Destroy ();
Simulator::SetStdMap ();
if (!RunOneTest ())
{
ok = false;
}
Simulator::Destroy ();
Simulator::Schedule (Seconds (0.0), &foo0);
Simulator::Schedule (Seconds (0.0), &foo1, 0);
Simulator::Schedule (Seconds (0.0), &foo2, 0, 0);
Simulator::Schedule (Seconds (0.0), &foo3, 0, 0, 0);
Simulator::Schedule (Seconds (0.0), &foo4, 0, 0, 0, 0);
Simulator::Schedule (Seconds (0.0), &foo5, 0, 0, 0, 0, 0);
Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar0, this);
Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar1, this, 0);
Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar2, this, 0, 0);
Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar3, this, 0, 0, 0);
Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar4, this, 0, 0, 0, 0);
Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar5, this, 0, 0, 0, 0, 0);
Simulator::ScheduleNow (&foo0);
Simulator::ScheduleNow (&foo1, 0);
Simulator::ScheduleNow (&foo2, 0, 0);
Simulator::ScheduleNow (&foo3, 0, 0, 0);
Simulator::ScheduleNow (&foo4, 0, 0, 0, 0);
Simulator::ScheduleNow (&foo5, 0, 0, 0, 0, 0);
Simulator::ScheduleNow (&SimulatorTests::bar0, this);
Simulator::ScheduleNow (&SimulatorTests::bar1, this, 0);
Simulator::ScheduleNow (&SimulatorTests::bar2, this, 0, 0);
Simulator::ScheduleNow (&SimulatorTests::bar3, this, 0, 0, 0);
Simulator::ScheduleNow (&SimulatorTests::bar4, this, 0, 0, 0, 0);
Simulator::ScheduleNow (&SimulatorTests::bar5, this, 0, 0, 0, 0, 0);
Simulator::ScheduleDestroy (&foo0);
Simulator::ScheduleDestroy (&foo1, 0);
Simulator::ScheduleDestroy (&foo2, 0, 0);
Simulator::ScheduleDestroy (&foo3, 0, 0, 0);
Simulator::ScheduleDestroy (&foo4, 0, 0, 0, 0);
Simulator::ScheduleDestroy (&foo5, 0, 0, 0, 0, 0);
Simulator::ScheduleDestroy (&SimulatorTests::bar0, this);
Simulator::ScheduleDestroy (&SimulatorTests::bar1, this, 0);
Simulator::ScheduleDestroy (&SimulatorTests::bar2, this, 0, 0);
Simulator::ScheduleDestroy (&SimulatorTests::bar3, this, 0, 0, 0);
Simulator::ScheduleDestroy (&SimulatorTests::bar4, this, 0, 0, 0, 0);
Simulator::ScheduleDestroy (&SimulatorTests::bar5, this, 0, 0, 0, 0, 0);
Simulator::Schedule (Seconds (0.0), &foo0);
Simulator::Schedule (Seconds (0.0), &foo1, 0);
Simulator::Schedule (Seconds (0.0), &foo2, 0, 0);
Simulator::Schedule (Seconds (0.0), &foo3, 0, 0, 0);
Simulator::Schedule (Seconds (0.0), &foo4, 0, 0, 0, 0);
Simulator::Schedule (Seconds (0.0), &foo5, 0, 0, 0, 0, 0);
Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar0, this);
Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar1, this, 0);
Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar2, this, 0, 0);
Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar3, this, 0, 0, 0);
Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar4, this, 0, 0, 0, 0);
Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar5, this, 0, 0, 0, 0, 0);
Simulator::ScheduleNow (&foo0);
Simulator::ScheduleNow (&foo1, 0);
Simulator::ScheduleNow (&foo2, 0, 0);
Simulator::ScheduleNow (&foo3, 0, 0, 0);
Simulator::ScheduleNow (&foo4, 0, 0, 0, 0);
Simulator::ScheduleNow (&foo5, 0, 0, 0, 0, 0);
Simulator::ScheduleNow (&SimulatorTests::bar0, this);
Simulator::ScheduleNow (&SimulatorTests::bar1, this, 0);
Simulator::ScheduleNow (&SimulatorTests::bar2, this, 0, 0);
Simulator::ScheduleNow (&SimulatorTests::bar3, this, 0, 0, 0);
Simulator::ScheduleNow (&SimulatorTests::bar4, this, 0, 0, 0, 0);
Simulator::ScheduleNow (&SimulatorTests::bar5, this, 0, 0, 0, 0, 0);
Simulator::ScheduleDestroy (&foo0);
Simulator::ScheduleDestroy (&foo1, 0);
Simulator::ScheduleDestroy (&foo2, 0, 0);
Simulator::ScheduleDestroy (&foo3, 0, 0, 0);
Simulator::ScheduleDestroy (&foo4, 0, 0, 0, 0);
Simulator::ScheduleDestroy (&foo5, 0, 0, 0, 0, 0);
Simulator::ScheduleDestroy (&SimulatorTests::bar0, this);
Simulator::ScheduleDestroy (&SimulatorTests::bar1, this, 0);
Simulator::ScheduleDestroy (&SimulatorTests::bar2, this, 0, 0);
Simulator::ScheduleDestroy (&SimulatorTests::bar3, this, 0, 0, 0);
Simulator::ScheduleDestroy (&SimulatorTests::bar4, this, 0, 0, 0, 0);
Simulator::ScheduleDestroy (&SimulatorTests::bar5, this, 0, 0, 0, 0, 0);
return ok;
return ok;
}
SimulatorTests gSimulatorTests;

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005,2006 INRIA
* All rights reserved.
@ -24,10 +24,10 @@
namespace ns3 {
Time::Time ()
: m_ns (0)
: m_ns (0)
{}
Time::Time (Time const &o)
: m_ns (o.m_ns)
: m_ns (o.m_ns)
{}
Time &
Time::operator = (Time const &o)
@ -36,7 +36,7 @@ Time::operator = (Time const &o)
return *this;
}
Time::Time (int64_t ns)
: m_ns (ns)
: m_ns (ns)
{}
@ -153,19 +153,19 @@ bool operator >= (Time const &lhs, Time const &rhs)
}
Now::Now ()
: Time (Simulator::Now ())
: Time (Simulator::Now ())
{}
Seconds::Seconds (double s)
: Time ((int64_t)(s * 1000000000))
: Time ((int64_t)(s * 1000000000))
{}
MilliSeconds::MilliSeconds (int32_t ms)
: Time ((int64_t)(ms * 1000000))
: Time ((int64_t)(ms * 1000000))
{}
MicroSeconds::MicroSeconds (int32_t us)
: Time ((int64_t)(us * 1000))
: Time ((int64_t)(us * 1000))
{}
NanoSeconds::NanoSeconds (int64_t ns)
: Time (ns)
: Time (ns)
{}

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2006 INRIA
* All rights reserved.
@ -30,106 +30,106 @@ using namespace ns3;
static void
benchPtrA (uint32_t n)
{
ChunkConstantData data = ChunkConstantData (2000, 1);
ChunkUdp udp;
ChunkIpv4 ipv4;
ChunkConstantData data = ChunkConstantData (2000, 1);
ChunkUdp udp;
ChunkIpv4 ipv4;
for (uint32_t i = 0; i < n; i++) {
Packet p;
p.add (&data);
p.add (&udp);
p.add (&ipv4);
Packet o = p;
o.peek (&ipv4);
o.remove (&ipv4);
o.peek (&udp);
o.remove (&udp);
o.peek (&data);
o.remove (&data);
}
for (uint32_t i = 0; i < n; i++) {
Packet p;
p.add (&data);
p.add (&udp);
p.add (&ipv4);
Packet o = p;
o.peek (&ipv4);
o.remove (&ipv4);
o.peek (&udp);
o.remove (&udp);
o.peek (&data);
o.remove (&data);
}
}
static void
benchPtrB (uint32_t n)
{
ChunkConstantData data = ChunkConstantData (2000, 1);
ChunkUdp udp;
ChunkIpv4 ipv4;
ChunkConstantData data = ChunkConstantData (2000, 1);
ChunkUdp udp;
ChunkIpv4 ipv4;
for (uint32_t i = 0; i < n; i++) {
Packet p;
p.add (&data);
p.add (&udp);
p.add (&ipv4);
}
for (uint32_t i = 0; i < n; i++) {
Packet p;
p.add (&data);
p.add (&udp);
p.add (&ipv4);
}
}
static void
ptrC2 (Packet p)
{
ChunkConstantData data = ChunkConstantData (2000, 1);
ChunkUdp udp;
ChunkConstantData data = ChunkConstantData (2000, 1);
ChunkUdp udp;
p.peek (&udp);
p.remove (&udp);
p.peek (&data);
p.remove (&data);
p.peek (&udp);
p.remove (&udp);
p.peek (&data);
p.remove (&data);
}
static void
ptrC1 (Packet p)
{
ChunkIpv4 ipv4;
p.peek (&ipv4);
p.remove (&ipv4);
ptrC2 (p);
ChunkIpv4 ipv4;
p.peek (&ipv4);
p.remove (&ipv4);
ptrC2 (p);
}
static void
benchPtrC (uint32_t n)
{
ChunkConstantData data = ChunkConstantData (2000, 1);
ChunkUdp udp;
ChunkIpv4 ipv4;
ChunkConstantData data = ChunkConstantData (2000, 1);
ChunkUdp udp;
ChunkIpv4 ipv4;
for (uint32_t i = 0; i < n; i++) {
Packet p;
p.add (&data);
p.add (&udp);
p.add (&ipv4);
ptrC1 (p);
}
for (uint32_t i = 0; i < n; i++) {
Packet p;
p.add (&data);
p.add (&udp);
p.add (&ipv4);
ptrC1 (p);
}
}
static void
runBench (void (*bench) (uint32_t), uint32_t n, char const *name)
{
WallClockMs time;
time.start ();
(*bench) (n);
unsigned long long deltaMs = time.end ();
double ps = n;
ps *= 1000;
ps /= deltaMs;
std::cout << name<<"=" << ps << " packets/s" << std::endl;
WallClockMs time;
time.start ();
(*bench) (n);
unsigned long long deltaMs = time.end ();
double ps = n;
ps *= 1000;
ps /= deltaMs;
std::cout << name<<"=" << ps << " packets/s" << std::endl;
}
int main (int argc, char *argv[])
{
uint32_t n = 0;
while (argc > 0) {
if (strncmp ("--n=", argv[0],strlen ("--n=")) == 0) {
char const *nAscii = argv[0] + strlen ("--n=");
n = atoi (nAscii);
}
argc--;
argv++;
}
uint32_t n = 0;
while (argc > 0) {
if (strncmp ("--n=", argv[0],strlen ("--n=")) == 0) {
char const *nAscii = argv[0] + strlen ("--n=");
n = atoi (nAscii);
}
argc--;
argv++;
}
runBench (&benchPtrA, n, "a");
runBench (&benchPtrB, n, "b");
runBench (&benchPtrC, n, "c");
runBench (&benchPtrA, n, "a");
runBench (&benchPtrB, n, "b");
runBench (&benchPtrC, n, "c");
return 0;
return 0;
}

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2006 INRIA
* All rights reserved.
@ -32,115 +32,115 @@ bool gDebug = false;
class Bench {
public:
void ReadDistribution (std::istream &istream);
void SetTotal (uint32_t total);
void RunBench (void);
void ReadDistribution (std::istream &istream);
void SetTotal (uint32_t total);
void RunBench (void);
private:
void Cb (void);
std::vector<uint64_t> m_distribution;
std::vector<uint64_t>::const_iterator m_current;
uint32_t m_n;
uint32_t m_total;
void Cb (void);
std::vector<uint64_t> m_distribution;
std::vector<uint64_t>::const_iterator m_current;
uint32_t m_n;
uint32_t m_total;
};
void
Bench::SetTotal (uint32_t total)
{
m_total = total;
m_total = total;
}
void
Bench::ReadDistribution (std::istream &input)
{
double data;
while (!input.eof ()) {
if (input >> data) {
uint64_t ns = (uint64_t) (data * 1000000000);
m_distribution.push_back (ns);
} else {
input.clear ();
std::string line;
input >> line;
}
}
double data;
while (!input.eof ()) {
if (input >> data) {
uint64_t ns = (uint64_t) (data * 1000000000);
m_distribution.push_back (ns);
} else {
input.clear ();
std::string line;
input >> line;
}
}
}
void
Bench::RunBench (void)
{
SystemWallClockMs time;
double init, simu;
time.Start ();
for (std::vector<uint64_t>::const_iterator i = m_distribution.begin ();
i != m_distribution.end (); i++) {
Simulator::Schedule (Now () + NanoSeconds (*i), &Bench::Cb, this);
}
init = time.End ();
SystemWallClockMs time;
double init, simu;
time.Start ();
for (std::vector<uint64_t>::const_iterator i = m_distribution.begin ();
i != m_distribution.end (); i++) {
Simulator::Schedule (Now () + NanoSeconds (*i), &Bench::Cb, this);
}
init = time.End ();
m_current = m_distribution.begin ();
m_current = m_distribution.begin ();
time.Start ();
Simulator::Run ();
simu = time.End ();
time.Start ();
Simulator::Run ();
simu = time.End ();
std::cout <<
"init n=" << m_distribution.size () << ", time=" << init << "s" << std::endl <<
"simu n=" << m_n << ", time=" <<simu << "s" << std::endl <<
"init " << ((double)m_distribution.size ()) / init << " insert/s, avg insert=" <<
init / ((double)m_distribution.size ())<< "s" << std::endl <<
"simu " << ((double)m_n) / simu<< " hold/s, avg hold=" <<
simu / ((double)m_n) << "s" << std::endl
;
std::cout <<
"init n=" << m_distribution.size () << ", time=" << init << "s" << std::endl <<
"simu n=" << m_n << ", time=" <<simu << "s" << std::endl <<
"init " << ((double)m_distribution.size ()) / init << " insert/s, avg insert=" <<
init / ((double)m_distribution.size ())<< "s" << std::endl <<
"simu " << ((double)m_n) / simu<< " hold/s, avg hold=" <<
simu / ((double)m_n) << "s" << std::endl
;
}
void
Bench::Cb (void)
{
if (m_n > m_total) {
return;
}
if (m_current == m_distribution.end ()) {
m_current = m_distribution.begin ();
}
if (gDebug) {
std::cerr << "event at " << Simulator::Now ().ApproximateToSeconds () << "s" << std::endl;
}
Simulator::Schedule (Now () + NanoSeconds (*m_current), &Bench::Cb, this);
m_current++;
m_n++;
if (m_n > m_total) {
return;
}
if (m_current == m_distribution.end ()) {
m_current = m_distribution.begin ();
}
if (gDebug) {
std::cerr << "event at " << Simulator::Now ().ApproximateToSeconds () << "s" << std::endl;
}
Simulator::Schedule (Now () + NanoSeconds (*m_current), &Bench::Cb, this);
m_current++;
m_n++;
}
int main (int argc, char *argv[])
{
char const *filename = argv[1];
std::istream *input;
argc-=2;
argv+= 2;
if (strcmp (filename, "-") == 0) {
input = &std::cin;
} else {
input = new std::ifstream (filename);
}
while (argc > 0) {
if (strcmp ("--list", argv[0]) == 0) {
Simulator::SetLinkedList ();
} else if (strcmp ("--heap", argv[0]) == 0) {
Simulator::SetBinaryHeap ();
} else if (strcmp ("--map", argv[0]) == 0) {
Simulator::SetStdMap ();
} else if (strcmp ("--debug", argv[0]) == 0) {
gDebug = true;
} else if (strncmp ("--log=", argv[0],strlen ("--log=")) == 0) {
char const *filename = argv[0] + strlen ("--log=");
Simulator::EnableLogTo (filename);
}
argc--;
argv++;
}
Bench *bench = new Bench ();
bench->ReadDistribution (*input);
bench->SetTotal (20000);
bench->RunBench ();
char const *filename = argv[1];
std::istream *input;
argc-=2;
argv+= 2;
if (strcmp (filename, "-") == 0) {
input = &std::cin;
} else {
input = new std::ifstream (filename);
}
while (argc > 0) {
if (strcmp ("--list", argv[0]) == 0) {
Simulator::SetLinkedList ();
} else if (strcmp ("--heap", argv[0]) == 0) {
Simulator::SetBinaryHeap ();
} else if (strcmp ("--map", argv[0]) == 0) {
Simulator::SetStdMap ();
} else if (strcmp ("--debug", argv[0]) == 0) {
gDebug = true;
} else if (strncmp ("--log=", argv[0],strlen ("--log=")) == 0) {
char const *filename = argv[0] + strlen ("--log=");
Simulator::EnableLogTo (filename);
}
argc--;
argv++;
}
Bench *bench = new Bench ();
bench->ReadDistribution (*input);
bench->SetTotal (20000);
bench->RunBench ();
return 0;
return 0;
}

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2006 INRIA
* All rights reserved.
@ -32,45 +32,45 @@ using namespace ns3;
class LogReader {
public:
void readFrom_filename (char const *filename);
void run (void);
void printStats (void);
void readFrom_filename (char const *filename);
void run (void);
void printStats (void);
private:
struct Command {
enum {
REMOVE,
INSERT,
INSERT_LATER,
INSERT_REMOVE
} m_type;
// uid at which this command is supposed to be executed.
uint32_t m_uid;
union {
struct {
// time at which the event is supposed to expire
uint64_t m_evUs;
} insert;
struct {
// location in the array of events to remove where
// to insert this event once it is inserted in
// the scheduler.
uint32_t m_evLoc;
// time at which the event is supposed to expire
uint64_t m_evUs;
} insertRemove;
};
};
void executeLogCommands (uint32_t uid);
struct Command {
enum {
REMOVE,
INSERT,
INSERT_LATER,
INSERT_REMOVE
} m_type;
// uid at which this command is supposed to be executed.
uint32_t m_uid;
union {
struct {
// time at which the event is supposed to expire
uint64_t m_evUs;
} insert;
struct {
// location in the array of events to remove where
// to insert this event once it is inserted in
// the scheduler.
uint32_t m_evLoc;
// time at which the event is supposed to expire
uint64_t m_evUs;
} insertRemove;
};
};
void executeLogCommands (uint32_t uid);
typedef std::deque<struct Command> Commands;
typedef std::deque<struct Command>::iterator CommandsI;
typedef std::deque<Event > RemoveEvents;
typedef std::deque<struct Command> Commands;
typedef std::deque<struct Command>::iterator CommandsI;
typedef std::deque<Event > RemoveEvents;
Commands m_commands;
CommandsI m_command;
RemoveEvents m_removeEvents;
uint32_t m_uid;
Commands m_commands;
CommandsI m_command;
RemoveEvents m_removeEvents;
uint32_t m_uid;
};
typedef std::vector<std::pair<uint32_t, uint32_t> > Removes;
@ -79,187 +79,187 @@ typedef std::vector<std::pair<uint32_t, uint32_t> >::iterator RemovesI;
void
LogReader::ReadFrom_filename (char const *filename)
{
std::ifstream log;
std::cout << "read log..." << std::endl;
Removes removes;
log.open (filename);
while (!log.eof ()) {
std::string type;
log >> type;
if (type == "i") {
uint32_t nowUid, evUid;
uint64_t nowUs, evUs;
log >> nowUid >> nowUs >> evUid >> evUs;
struct Command cmd;
cmd.m_type = Command::INSERT;
cmd.m_uid = nowUid;
cmd.insert.m_evUs = evUs;
m_commands.push_back (cmd);
} else if (type == "r") {
uint32_t nowUid, evUid;
uint64_t nowUs, evUs;
log >> nowUid >> nowUs >> evUid >> evUs;
struct Command cmd;
cmd.m_type = Command::REMOVE;
cmd.m_uid = nowUid;
m_commands.push_back (cmd);
removes.push_back (std::Make_pair (nowUid, evUid));
} else if (type == "il") {
uint32_t nowUid, evUid;
uint64_t nowUs, evUs;
log >> nowUid >> nowUs >> evUid >> evUs;
struct Command cmd;
cmd.m_type = Command::INSERT_LATER;
cmd.m_uid = nowUid;
m_commands.push_back (cmd);
}
}
log.close ();
std::ifstream log;
std::cout << "read log..." << std::endl;
Removes removes;
log.open (filename);
while (!log.eof ()) {
std::string type;
log >> type;
if (type == "i") {
uint32_t nowUid, evUid;
uint64_t nowUs, evUs;
log >> nowUid >> nowUs >> evUid >> evUs;
struct Command cmd;
cmd.m_type = Command::INSERT;
cmd.m_uid = nowUid;
cmd.insert.m_evUs = evUs;
m_commands.push_back (cmd);
} else if (type == "r") {
uint32_t nowUid, evUid;
uint64_t nowUs, evUs;
log >> nowUid >> nowUs >> evUid >> evUs;
struct Command cmd;
cmd.m_type = Command::REMOVE;
cmd.m_uid = nowUid;
m_commands.push_back (cmd);
removes.push_back (std::Make_pair (nowUid, evUid));
} else if (type == "il") {
uint32_t nowUid, evUid;
uint64_t nowUs, evUs;
log >> nowUid >> nowUs >> evUid >> evUs;
struct Command cmd;
cmd.m_type = Command::INSERT_LATER;
cmd.m_uid = nowUid;
m_commands.push_back (cmd);
}
}
log.close ();
std::cout << "gather insert removes..." << std::endl;
for (CommandsI i = m_commands.begin (); i != m_commands.end (); i++) {
if (i->m_type == Command::INSERT) {
for (RemovesI j = removes.begin (); j != removes.end (); j++) {
if (j->second == i->m_uid) {
// this insert will be removed later.
uint64_t us = i->insert.m_evUs;
uint32_t uid = i->m_uid;
i->m_type = Command::INSERT_REMOVE;
i->m_uid = uid;
i->insertRemove.m_evUs = us;
i->insertRemove.m_evLoc = j->first;
break;
}
}
}
}
std::cout << "calculate remove locations..." << std::endl;
// calculate the final insert/remove location.
for (CommandsI i = m_commands.begin (); i != m_commands.end (); i++) {
if (i->m_type == Command::INSERT_REMOVE) {
uint32_t loc = 0;
for (CommandsI tmp = i; tmp != m_commands.end (); tmp++) {
if (tmp->m_type == Command::REMOVE &&
tmp->m_uid == i->insertRemove.m_evLoc) {
i->insertRemove.m_evLoc = loc;
break;
}
loc++;
}
}
}
std::cout << "gather insert removes..." << std::endl;
for (CommandsI i = m_commands.begin (); i != m_commands.end (); i++) {
if (i->m_type == Command::INSERT) {
for (RemovesI j = removes.begin (); j != removes.end (); j++) {
if (j->second == i->m_uid) {
// this insert will be removed later.
uint64_t us = i->insert.m_evUs;
uint32_t uid = i->m_uid;
i->m_type = Command::INSERT_REMOVE;
i->m_uid = uid;
i->insertRemove.m_evUs = us;
i->insertRemove.m_evLoc = j->first;
break;
}
}
}
}
std::cout << "calculate remove locations..." << std::endl;
// calculate the final insert/remove location.
for (CommandsI i = m_commands.begin (); i != m_commands.end (); i++) {
if (i->m_type == Command::INSERT_REMOVE) {
uint32_t loc = 0;
for (CommandsI tmp = i; tmp != m_commands.end (); tmp++) {
if (tmp->m_type == Command::REMOVE &&
tmp->m_uid == i->insertRemove.m_evLoc) {
i->insertRemove.m_evLoc = loc;
break;
}
loc++;
}
}
}
}
void
LogReader::ExecuteLogCommands (uint32_t uid)
{
if (m_command == m_commands.end ()) {
return;
}
//std::cout << "one event, uid=" <<m_uid<< std::endl;
struct Command cmd = *m_command;
//std::cout << "cmd uid=" <<cmd.m_uid<< std::endl;
while (cmd.m_uid == uid) {
m_command++;
switch (cmd.m_type) {
case Command::INSERT:
//std::Cout << "exec insert now=" << Simulator::nowUs ()
//<< ", time=" << cmd.insert.m_evUs << std::endl;
Simulator::ScheduleAbsUs (cmd.insert.m_evUs,
makeEvent (&LogReader::executeLogCommands, this, m_uid));
m_uid++;
break;
case Command::INSERT_LATER:
//std::cout << "exec insert later" << std::endl;
Simulator::ScheduleNow (makeEvent (&LogReader::executeLogCommands, this, m_uid));
m_uid++;
break;
case Command::REMOVE: {
//std::cout << "exec remove" << std::endl;
Event ev = m_removeEvents.front ();
m_removeEvents.pop_front ();
Simulator::Remove (ev);
} break;
case Command::INSERT_REMOVE: {
//std::cout << "exec insert remove" << std::endl;
Event ev = makeEvent (&LogReader::executeLogCommands, this, m_uid);
Simulator::ScheduleAbsUs (cmd.insertRemove.m_evUs, ev);
m_removeEvents[cmd.insertRemove.m_evLoc] = ev;
m_uid++;
} break;
}
cmd = *m_command;
}
if (m_command == m_commands.end ()) {
return;
}
//std::cout << "one event, uid=" <<m_uid<< std::endl;
struct Command cmd = *m_command;
//std::cout << "cmd uid=" <<cmd.m_uid<< std::endl;
while (cmd.m_uid == uid) {
m_command++;
switch (cmd.m_type) {
case Command::INSERT:
//std::Cout << "exec insert now=" << Simulator::nowUs ()
//<< ", time=" << cmd.insert.m_evUs << std::endl;
Simulator::ScheduleAbsUs (cmd.insert.m_evUs,
makeEvent (&LogReader::executeLogCommands, this, m_uid));
m_uid++;
break;
case Command::INSERT_LATER:
//std::cout << "exec insert later" << std::endl;
Simulator::ScheduleNow (makeEvent (&LogReader::executeLogCommands, this, m_uid));
m_uid++;
break;
case Command::REMOVE: {
//std::cout << "exec remove" << std::endl;
Event ev = m_removeEvents.front ();
m_removeEvents.pop_front ();
Simulator::Remove (ev);
} break;
case Command::INSERT_REMOVE: {
//std::cout << "exec insert remove" << std::endl;
Event ev = makeEvent (&LogReader::executeLogCommands, this, m_uid);
Simulator::ScheduleAbsUs (cmd.insertRemove.m_evUs, ev);
m_removeEvents[cmd.insertRemove.m_evLoc] = ev;
m_uid++;
} break;
}
cmd = *m_command;
}
}
void
LogReader::PrintStats (void)
{
uint32_t nInserts = 0;
uint32_t nRemoves = 0;
for (CommandsI i = m_commands.begin (); i != m_commands.end (); i++) {
switch (i->m_type) {
case Command::INSERT:
nInserts++;
break;
case Command::INSERT_LATER:
nInserts++;
break;
case Command::INSERT_REMOVE:
nInserts++;
break;
case Command::REMOVE:
nRemoves++;
break;
}
}
std::cout << "inserts="<<nInserts<<", removes="<<nRemoves<<std::endl;
std::cout << "run simulation..."<<std::endl;
uint32_t nInserts = 0;
uint32_t nRemoves = 0;
for (CommandsI i = m_commands.begin (); i != m_commands.end (); i++) {
switch (i->m_type) {
case Command::INSERT:
nInserts++;
break;
case Command::INSERT_LATER:
nInserts++;
break;
case Command::INSERT_REMOVE:
nInserts++;
break;
case Command::REMOVE:
nRemoves++;
break;
}
}
std::cout << "inserts="<<nInserts<<", removes="<<nRemoves<<std::endl;
std::cout << "run simulation..."<<std::endl;
}
void
LogReader::Run (void)
{
m_uid = 0;
WallClockMs time;
time.start ();
m_command = m_commands.begin ();
executeLogCommands (m_uid);
Simulator::Run ();
unsigned long long delta = time.end ();
double delay = ((double)delta)/1000;
std::cout << "runtime="<<delay<<"s"<<std::endl;
m_uid = 0;
WallClockMs time;
time.start ();
m_command = m_commands.begin ();
executeLogCommands (m_uid);
Simulator::Run ();
unsigned long long delta = time.end ();
double delay = ((double)delta)/1000;
std::cout << "runtime="<<delay<<"s"<<std::endl;
}
int main (int argc, char *argv[])
{
char const *input = 0;
uint32_t n = 1;
while (argc > 0) {
if (strcmp ("--list", argv[0]) == 0) {
Simulator::SetLinkedList ();
} else if (strcmp ("--heap", argv[0]) == 0) {
Simulator::SetBinaryHeap ();
} else if (strcmp ("--map", argv[0]) == 0) {
Simulator::SetStdMap ();
} else if (strncmp ("--n=", argv[0], strlen("--n=")) == 0) {
n = atoi (argv[0]+strlen ("--n="));
} else if (strncmp ("--input=", argv[0],strlen ("--input=")) == 0) {
input = argv[0] + strlen ("--input=");
} else if (strncmp ("--log=", argv[0],strlen ("--log=")) == 0) {
char const *filename = argv[0] + strlen ("--log=");
Simulator::EnableLogTo (filename);
}
argc--;
argv++;
}
if (input == 0) {
std::cerr << "need --input=[filename] option" << std::endl;
return 1;
}
LogReader log;
log.readFrom_filename (input);
for (uint32_t i = 0; i < n; i++) {
log.run ();
}
char const *input = 0;
uint32_t n = 1;
while (argc > 0) {
if (strcmp ("--list", argv[0]) == 0) {
Simulator::SetLinkedList ();
} else if (strcmp ("--heap", argv[0]) == 0) {
Simulator::SetBinaryHeap ();
} else if (strcmp ("--map", argv[0]) == 0) {
Simulator::SetStdMap ();
} else if (strncmp ("--n=", argv[0], strlen("--n=")) == 0) {
n = atoi (argv[0]+strlen ("--n="));
} else if (strncmp ("--input=", argv[0],strlen ("--input=")) == 0) {
input = argv[0] + strlen ("--input=");
} else if (strncmp ("--log=", argv[0],strlen ("--log=")) == 0) {
char const *filename = argv[0] + strlen ("--log=");
Simulator::EnableLogTo (filename);
}
argc--;
argv++;
}
if (input == 0) {
std::cerr << "need --input=[filename] option" << std::endl;
return 1;
}
LogReader log;
log.readFrom_filename (input);
for (uint32_t i = 0; i < n; i++) {
log.run ();
}
}

View File

@ -1,4 +1,4 @@
/* -*- Mode:NS3; -*- */
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005 INRIA
* All rights reserved.
@ -24,9 +24,9 @@
int main (int argc, char *argv[])
{
#ifdef RUN_SELF_TESTS
ns3::TestManager::EnableVerbose ();
ns3::TestManager::RunTests ();
ns3::TestManager::EnableVerbose ();
ns3::TestManager::RunTests ();
#endif /* RUN_SELF_TESTS */
return 0;
return 0;
}