--- a/samples/main-callback.cc Wed Nov 01 13:00:34 2006 +0100
+++ b/samples/main-callback.cc Wed Nov 01 13:11:30 2006 +0100
@@ -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 @@
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;
}
--- a/samples/main-packet.cc Wed Nov 01 13:00:34 2006 +0100
+++ b/samples/main-packet.cc Wed Nov 01 13:11:30 2006 +0100
@@ -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 @@
*/
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 @@
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 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;
}
--- a/samples/main-simulator.cc Wed Nov 01 13:00:34 2006 +0100
+++ b/samples/main-simulator.cc Wed Nov 01 13:11:30 2006 +0100
@@ -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 @@
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 ();
}
--- a/samples/main-test.cc Wed Nov 01 13:00:34 2006 +0100
+++ b/samples/main-test.cc Wed Nov 01 13:11:30 2006 +0100
@@ -1,4 +1,4 @@
-/* -*- Mode:NS3; -*- */
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
#include "ns3/test.h"
@@ -9,24 +9,24 @@
// 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 @@
int main (int argc, char *argv[])
{
- // run tests
- TestManager::EnableVerbose ();
- TestManager::RunTests ();
- return 0;
+ // run tests
+ TestManager::EnableVerbose ();
+ TestManager::RunTests ();
+ return 0;
}
--- a/samples/main-trace.cc Wed Nov 01 13:00:34 2006 +0100
+++ b/samples/main-trace.cc Wed Nov 01 13:11:30 2006 +0100
@@ -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 @@
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 @@
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;
}
--- a/src/common/buffer.cc Wed Nov 01 13:00:34 2006 +0100
+++ b/src/common/buffer.cc Wed Nov 01 13:11:30 2006 +0100
@@ -1,4 +1,4 @@
-/* -*- Mode:NS3; -*- */
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005,2006 INRIA
* All rights reserved.
@@ -34,85 +34,85 @@
struct Buffer::BufferData *
Buffer::Allocate (uint32_t reqSize, uint32_t reqStart)
{
- if (reqSize == 0)
- {
- reqSize = 1;
- }
- assert (reqSize >= 1);
- uint32_t size = reqSize - 1 + sizeof (struct Buffer::BufferData);
- uint8_t *b = new uint8_t [size];
- struct BufferData *data = reinterpret_cast<struct Buffer::BufferData*>(b);
- data->m_size = reqSize;
- data->m_initialStart = reqStart;
- data->m_dirtyStart = reqStart;
- data->m_dirtySize = 0;
- data->m_count = 1;
- return data;
+ if (reqSize == 0)
+ {
+ reqSize = 1;
+ }
+ assert (reqSize >= 1);
+ uint32_t size = reqSize - 1 + sizeof (struct Buffer::BufferData);
+ uint8_t *b = new uint8_t [size];
+ struct BufferData *data = reinterpret_cast<struct Buffer::BufferData*>(b);
+ data->m_size = reqSize;
+ data->m_initialStart = reqStart;
+ data->m_dirtyStart = reqStart;
+ data->m_dirtySize = 0;
+ data->m_count = 1;
+ return data;
}
void
Buffer::Deallocate (struct Buffer::BufferData *data)
{
- uint8_t *buf = reinterpret_cast<uint8_t *> (data);
- delete [] buf;
+ uint8_t *buf = reinterpret_cast<uint8_t *> (data);
+ delete [] buf;
}
#ifdef USE_FREE_LIST
void
Buffer::Recycle (struct Buffer::BufferData *data)
{
- assert (data->m_count == 0);
- /* get rid of it if it is too small for later reuse. */
- if (data->m_size < (Buffer::m_maxTotalAddStart + Buffer::m_maxTotalAddEnd))
- {
- Buffer::Deallocate (data);
- return;
- }
- /* feed into free list */
- if (Buffer::m_freeList.size () > 1000)
- {
- Buffer::Deallocate (data);
- }
- else
- {
- Buffer::m_freeList.push_back (data);
- }
+ assert (data->m_count == 0);
+ /* get rid of it if it is too small for later reuse. */
+ if (data->m_size < (Buffer::m_maxTotalAddStart + Buffer::m_maxTotalAddEnd))
+ {
+ Buffer::Deallocate (data);
+ return;
+ }
+ /* feed into free list */
+ if (Buffer::m_freeList.size () > 1000)
+ {
+ Buffer::Deallocate (data);
+ }
+ else
+ {
+ Buffer::m_freeList.push_back (data);
+ }
}
Buffer::BufferData *
Buffer::Create (void)
{
- /* try to find a buffer correctly sized. */
- while (!Buffer::m_freeList.empty ())
- {
- struct Buffer::BufferData *data = Buffer::m_freeList.back ();
- Buffer::m_freeList.pop_back ();
- if (data->m_size >= (m_maxTotalAddStart + m_maxTotalAddEnd))
- {
- data->m_initialStart = m_maxTotalAddStart;
- data->m_dirtyStart = m_maxTotalAddStart;
- data->m_dirtySize = 0;
- data->m_count = 1;
- return data;
- }
- Buffer::Deallocate (data);
- }
- struct Buffer::BufferData *data = Buffer::Allocate (m_maxTotalAddStart+m_maxTotalAddEnd,
- m_maxTotalAddStart);
- assert (data->m_count == 1);
- return data;
+ /* try to find a buffer correctly sized. */
+ while (!Buffer::m_freeList.empty ())
+ {
+ struct Buffer::BufferData *data = Buffer::m_freeList.back ();
+ Buffer::m_freeList.pop_back ();
+ if (data->m_size >= (m_maxTotalAddStart + m_maxTotalAddEnd))
+ {
+ data->m_initialStart = m_maxTotalAddStart;
+ data->m_dirtyStart = m_maxTotalAddStart;
+ data->m_dirtySize = 0;
+ data->m_count = 1;
+ return data;
+ }
+ Buffer::Deallocate (data);
+ }
+ struct Buffer::BufferData *data = Buffer::Allocate (m_maxTotalAddStart+m_maxTotalAddEnd,
+ m_maxTotalAddStart);
+ assert (data->m_count == 1);
+ return data;
}
#else
void
Buffer::Recycle (struct Buffer::BufferData *data)
{
- Buffer::Deallocate (data);
+ Buffer::Deallocate (data);
}
Buffer::BufferData *
Buffer::Create (void)
{
- return Buffer::Allocate (m_maxTotalAddStart+m_maxTotalAddEnd,
- m_maxTotalAddStart);
+ return Buffer::Allocate (m_maxTotalAddStart+m_maxTotalAddEnd,
+ m_maxTotalAddStart);
}
#endif
@@ -127,308 +127,308 @@
void
Buffer::AddAtStart (uint32_t start)
{
- assert (m_start <= m_data->m_initialStart);
- bool isDirty = m_data->m_count > 1 && m_start > m_data->m_dirtyStart;
- if (m_start >= start && !isDirty)
- {
- /* enough space in the buffer and not dirty. */
- m_start -= start;
- m_size += start;
- }
- else if (m_size + start <= m_data->m_size && !isDirty)
- {
- /* enough space but need to move data around to fit new data */
- memmove (m_data->m_data + start, GetStart (), m_size);
- assert (start > m_start);
- m_data->m_initialStart += start;
- m_start = 0;
- m_size += start;
- }
- else if (m_start < start)
- {
- /* not enough space in buffer */
- uint32_t newSize = m_size + start;
- struct Buffer::BufferData *newData = Buffer::Allocate (newSize, 0);
- memcpy (newData->m_data + start, GetStart (), m_size);
- newData->m_initialStart = m_data->m_initialStart + start;
- m_data->m_count--;
- if (m_data->m_count == 0)
- {
- Buffer::Deallocate (m_data);
- }
- m_data = newData;
- m_start = 0;
- m_size = newSize;
- }
- else
- {
- /* enough space in the buffer but it is dirty ! */
- assert (isDirty);
- struct Buffer::BufferData *newData = Buffer::Create ();
- memcpy (newData->m_data + m_start, GetStart (), m_size);
- newData->m_initialStart = m_data->m_initialStart;
- m_data->m_count--;
- if (m_data->m_count == 0)
- {
- Recycle (m_data);
- }
- m_data = newData;
- m_start -= start;
- m_size += start;
- }
- // update dirty area
- m_data->m_dirtyStart = m_start;
- m_data->m_dirtySize = m_size;
- // update m_maxTotalAddStart
- uint32_t addedAtStart;
- if (m_data->m_initialStart > m_start)
- {
- addedAtStart = m_data->m_initialStart - m_start;
- }
- else
- {
- addedAtStart = 0;
- }
- if (addedAtStart > m_maxTotalAddStart)
- {
- m_maxTotalAddStart = addedAtStart;
- }
- TRACE ("start add="<<start<<", start="<<m_start<<", size="<<m_size<<", zero="<<m_zeroAreaSize<<
- ", real size="<<m_data->m_size<<", ini start="<<m_data->m_initialStart<<
- ", dirty start="<<m_data->m_dirtyStart<<", dirty size="<<m_data->m_dirtySize);
+ assert (m_start <= m_data->m_initialStart);
+ bool isDirty = m_data->m_count > 1 && m_start > m_data->m_dirtyStart;
+ if (m_start >= start && !isDirty)
+ {
+ /* enough space in the buffer and not dirty. */
+ m_start -= start;
+ m_size += start;
+ }
+ else if (m_size + start <= m_data->m_size && !isDirty)
+ {
+ /* enough space but need to move data around to fit new data */
+ memmove (m_data->m_data + start, GetStart (), m_size);
+ assert (start > m_start);
+ m_data->m_initialStart += start;
+ m_start = 0;
+ m_size += start;
+ }
+ else if (m_start < start)
+ {
+ /* not enough space in buffer */
+ uint32_t newSize = m_size + start;
+ struct Buffer::BufferData *newData = Buffer::Allocate (newSize, 0);
+ memcpy (newData->m_data + start, GetStart (), m_size);
+ newData->m_initialStart = m_data->m_initialStart + start;
+ m_data->m_count--;
+ if (m_data->m_count == 0)
+ {
+ Buffer::Deallocate (m_data);
+ }
+ m_data = newData;
+ m_start = 0;
+ m_size = newSize;
+ }
+ else
+ {
+ /* enough space in the buffer but it is dirty ! */
+ assert (isDirty);
+ struct Buffer::BufferData *newData = Buffer::Create ();
+ memcpy (newData->m_data + m_start, GetStart (), m_size);
+ newData->m_initialStart = m_data->m_initialStart;
+ m_data->m_count--;
+ if (m_data->m_count == 0)
+ {
+ Recycle (m_data);
+ }
+ m_data = newData;
+ m_start -= start;
+ m_size += start;
+ }
+ // update dirty area
+ m_data->m_dirtyStart = m_start;
+ m_data->m_dirtySize = m_size;
+ // update m_maxTotalAddStart
+ uint32_t addedAtStart;
+ if (m_data->m_initialStart > m_start)
+ {
+ addedAtStart = m_data->m_initialStart - m_start;
+ }
+ else
+ {
+ addedAtStart = 0;
+ }
+ if (addedAtStart > m_maxTotalAddStart)
+ {
+ m_maxTotalAddStart = addedAtStart;
+ }
+ TRACE ("start add="<<start<<", start="<<m_start<<", size="<<m_size<<", zero="<<m_zeroAreaSize<<
+ ", real size="<<m_data->m_size<<", ini start="<<m_data->m_initialStart<<
+ ", dirty start="<<m_data->m_dirtyStart<<", dirty size="<<m_data->m_dirtySize);
}
void
Buffer::AddAtEnd (uint32_t end)
{
- assert (m_start <= m_data->m_initialStart);
- bool isDirty = m_data->m_count > 1 &&
- m_start + m_size < m_data->m_dirtyStart + m_data->m_dirtySize;
- if (m_start + m_size + end <= m_data->m_size && !isDirty)
- {
- /* enough space in buffer and not dirty */
- m_size += end;
- }
- else if (m_size + end <= m_data->m_size && !isDirty)
- {
- /* enough space but need to move data around to fit the extra data */
- uint32_t newStart = m_data->m_size - (m_size + end);
- memmove (m_data->m_data + newStart, GetStart (), m_size);
- assert (newStart < m_start);
- m_data->m_initialStart -= m_start - newStart;
- m_start = newStart;
- m_size += end;
- }
- else if (m_start + m_size + end > m_data->m_size)
- {
- /* not enough space in buffer */
- uint32_t newSize = m_size + end;
- struct Buffer::BufferData *newData = Buffer::Allocate (newSize, 0);
- memcpy (newData->m_data, GetStart (), m_size);
- newData->m_initialStart = m_data->m_initialStart;
- m_data->m_count--;
- if (m_data->m_count == 0)
- {
- Buffer::Deallocate (m_data);
- }
- m_data = newData;
- m_size = newSize;
- m_start = 0;
- }
- else
- {
- /* enough space in the buffer but it is dirty ! */
- assert (isDirty);
- struct Buffer::BufferData *newData = Buffer::Create ();
- memcpy (newData->m_data + m_start, GetStart (), m_size);
- newData->m_initialStart = m_data->m_initialStart;
- m_data->m_count--;
- if (m_data->m_count == 0)
- {
- Recycle (m_data);
- }
- m_data = newData;
- m_size += end;
- }
- // update dirty area
- m_data->m_dirtyStart = m_start;
- m_data->m_dirtySize = m_size;
- // update m_maxTotalAddEnd
- uint32_t endLoc = m_start + m_size;
- uint32_t addedAtEnd;
- if (m_data->m_initialStart < endLoc)
- {
- addedAtEnd = endLoc - m_data->m_initialStart;
- }
- else
- {
- addedAtEnd = 0;
- }
- if (addedAtEnd > m_maxTotalAddEnd)
- {
- m_maxTotalAddEnd = addedAtEnd;
- }
- TRACE ("end add="<<end<<", start="<<m_start<<", size="<<m_size<<", zero="<<m_zeroAreaSize<<
- ", real size="<<m_data->m_size<<", ini start="<<m_data->m_initialStart<<
- ", dirty start="<<m_data->m_dirtyStart<<", dirty size="<<m_data->m_dirtySize);
+ assert (m_start <= m_data->m_initialStart);
+ bool isDirty = m_data->m_count > 1 &&
+ m_start + m_size < m_data->m_dirtyStart + m_data->m_dirtySize;
+ if (m_start + m_size + end <= m_data->m_size && !isDirty)
+ {
+ /* enough space in buffer and not dirty */
+ m_size += end;
+ }
+ else if (m_size + end <= m_data->m_size && !isDirty)
+ {
+ /* enough space but need to move data around to fit the extra data */
+ uint32_t newStart = m_data->m_size - (m_size + end);
+ memmove (m_data->m_data + newStart, GetStart (), m_size);
+ assert (newStart < m_start);
+ m_data->m_initialStart -= m_start - newStart;
+ m_start = newStart;
+ m_size += end;
+ }
+ else if (m_start + m_size + end > m_data->m_size)
+ {
+ /* not enough space in buffer */
+ uint32_t newSize = m_size + end;
+ struct Buffer::BufferData *newData = Buffer::Allocate (newSize, 0);
+ memcpy (newData->m_data, GetStart (), m_size);
+ newData->m_initialStart = m_data->m_initialStart;
+ m_data->m_count--;
+ if (m_data->m_count == 0)
+ {
+ Buffer::Deallocate (m_data);
+ }
+ m_data = newData;
+ m_size = newSize;
+ m_start = 0;
+ }
+ else
+ {
+ /* enough space in the buffer but it is dirty ! */
+ assert (isDirty);
+ struct Buffer::BufferData *newData = Buffer::Create ();
+ memcpy (newData->m_data + m_start, GetStart (), m_size);
+ newData->m_initialStart = m_data->m_initialStart;
+ m_data->m_count--;
+ if (m_data->m_count == 0)
+ {
+ Recycle (m_data);
+ }
+ m_data = newData;
+ m_size += end;
+ }
+ // update dirty area
+ m_data->m_dirtyStart = m_start;
+ m_data->m_dirtySize = m_size;
+ // update m_maxTotalAddEnd
+ uint32_t endLoc = m_start + m_size;
+ uint32_t addedAtEnd;
+ if (m_data->m_initialStart < endLoc)
+ {
+ addedAtEnd = endLoc - m_data->m_initialStart;
+ }
+ else
+ {
+ addedAtEnd = 0;
+ }
+ if (addedAtEnd > m_maxTotalAddEnd)
+ {
+ m_maxTotalAddEnd = addedAtEnd;
+ }
+ TRACE ("end add="<<end<<", start="<<m_start<<", size="<<m_size<<", zero="<<m_zeroAreaSize<<
+ ", real size="<<m_data->m_size<<", ini start="<<m_data->m_initialStart<<
+ ", dirty start="<<m_data->m_dirtyStart<<", dirty size="<<m_data->m_dirtySize);
}
void
Buffer::RemoveAtStart (uint32_t start)
{
- if (m_zeroAreaSize == 0)
- {
- if (m_size <= start)
- {
- m_start += m_size;
- m_size = 0;
- }
- else
- {
- m_start += start;
- m_size -= start;
- }
- }
- else
- {
- assert (m_data->m_initialStart >= m_start);
- uint32_t zeroStart = m_data->m_initialStart - m_start;
- uint32_t zeroEnd = zeroStart + m_zeroAreaSize;
- uint32_t dataEnd = m_size + m_zeroAreaSize;
- if (start <= zeroStart)
- {
- /* only remove start of buffer */
- m_start += start;
- m_size -= start;
- }
- else if (start <= zeroEnd)
- {
- /* remove start of buffer _and_ start of zero area */
- m_start += zeroStart;
- uint32_t zeroDelta = start - zeroStart;
- m_zeroAreaSize -= zeroDelta;
- assert (zeroDelta <= start);
- m_size -= zeroStart;
- }
- else if (start <= dataEnd)
- {
- /* remove start of buffer, complete zero area, and part
- * of end of buffer */
- m_start += start - m_zeroAreaSize;
- m_size -= start - m_zeroAreaSize;
- m_zeroAreaSize = 0;
- }
- else
- {
- /* remove all buffer */
- m_start += m_size;
- m_size = 0;
- m_zeroAreaSize = 0;
- }
- }
- TRACE ("start remove="<<start<<", start="<<m_start<<", size="<<m_size<<
- ", zero="<<m_zeroAreaSize<<
- ", real size="<<m_data->m_size<<", ini start="<<m_data->m_initialStart<<
- ", dirty start="<<m_data->m_dirtyStart<<", dirty size="<<m_data->m_dirtySize);
+ if (m_zeroAreaSize == 0)
+ {
+ if (m_size <= start)
+ {
+ m_start += m_size;
+ m_size = 0;
+ }
+ else
+ {
+ m_start += start;
+ m_size -= start;
+ }
+ }
+ else
+ {
+ assert (m_data->m_initialStart >= m_start);
+ uint32_t zeroStart = m_data->m_initialStart - m_start;
+ uint32_t zeroEnd = zeroStart + m_zeroAreaSize;
+ uint32_t dataEnd = m_size + m_zeroAreaSize;
+ if (start <= zeroStart)
+ {
+ /* only remove start of buffer */
+ m_start += start;
+ m_size -= start;
+ }
+ else if (start <= zeroEnd)
+ {
+ /* remove start of buffer _and_ start of zero area */
+ m_start += zeroStart;
+ uint32_t zeroDelta = start - zeroStart;
+ m_zeroAreaSize -= zeroDelta;
+ assert (zeroDelta <= start);
+ m_size -= zeroStart;
+ }
+ else if (start <= dataEnd)
+ {
+ /* remove start of buffer, complete zero area, and part
+ * of end of buffer */
+ m_start += start - m_zeroAreaSize;
+ m_size -= start - m_zeroAreaSize;
+ m_zeroAreaSize = 0;
+ }
+ else
+ {
+ /* remove all buffer */
+ m_start += m_size;
+ m_size = 0;
+ m_zeroAreaSize = 0;
+ }
+ }
+ TRACE ("start remove="<<start<<", start="<<m_start<<", size="<<m_size<<
+ ", zero="<<m_zeroAreaSize<<
+ ", real size="<<m_data->m_size<<", ini start="<<m_data->m_initialStart<<
+ ", dirty start="<<m_data->m_dirtyStart<<", dirty size="<<m_data->m_dirtySize);
}
void
Buffer::RemoveAtEnd (uint32_t end)
{
- if (m_zeroAreaSize == 0)
- {
- if (m_size <= end)
- {
- m_size = 0;
- }
- else
- {
- m_size -= end;
- }
- }
- else
- {
- assert (m_data->m_initialStart >= m_start);
- uint32_t zeroStart = m_data->m_initialStart - m_start;
- uint32_t zeroEnd = zeroStart + m_zeroAreaSize;
- uint32_t dataEnd = m_size + m_zeroAreaSize;
- assert (zeroStart <= m_size);
- assert (zeroEnd <= m_size + m_zeroAreaSize);
- if (dataEnd <= end)
- {
- /* remove all buffer */
- m_zeroAreaSize = 0;
- m_start += m_size;
- m_size = 0;
- }
- else if (dataEnd - zeroStart <= end)
- {
- /* remove end of buffer, zero area, part of start of buffer */
- assert (end >= m_zeroAreaSize);
- m_size -= end - m_zeroAreaSize;
- m_zeroAreaSize = 0;
- }
- else if (dataEnd - zeroEnd <= end)
- {
- /* remove end of buffer, part of zero area */
- uint32_t zeroDelta = end - (dataEnd - zeroEnd);
- m_zeroAreaSize -= zeroDelta;
- m_size -= end - zeroDelta;
- }
- else
- {
- /* remove part of end of buffer */
- m_size -= end;
- }
- }
- TRACE ("end remove="<<end<<", start="<<m_start<<", size="<<m_size<<", zero="<<m_zeroAreaSize<<
- ", real size="<<m_data->m_size<<", ini start="<<m_data->m_initialStart<<
- ", dirty start="<<m_data->m_dirtyStart<<", dirty size="<<m_data->m_dirtySize);
+ if (m_zeroAreaSize == 0)
+ {
+ if (m_size <= end)
+ {
+ m_size = 0;
+ }
+ else
+ {
+ m_size -= end;
+ }
+ }
+ else
+ {
+ assert (m_data->m_initialStart >= m_start);
+ uint32_t zeroStart = m_data->m_initialStart - m_start;
+ uint32_t zeroEnd = zeroStart + m_zeroAreaSize;
+ uint32_t dataEnd = m_size + m_zeroAreaSize;
+ assert (zeroStart <= m_size);
+ assert (zeroEnd <= m_size + m_zeroAreaSize);
+ if (dataEnd <= end)
+ {
+ /* remove all buffer */
+ m_zeroAreaSize = 0;
+ m_start += m_size;
+ m_size = 0;
+ }
+ else if (dataEnd - zeroStart <= end)
+ {
+ /* remove end of buffer, zero area, part of start of buffer */
+ assert (end >= m_zeroAreaSize);
+ m_size -= end - m_zeroAreaSize;
+ m_zeroAreaSize = 0;
+ }
+ else if (dataEnd - zeroEnd <= end)
+ {
+ /* remove end of buffer, part of zero area */
+ uint32_t zeroDelta = end - (dataEnd - zeroEnd);
+ m_zeroAreaSize -= zeroDelta;
+ m_size -= end - zeroDelta;
+ }
+ else
+ {
+ /* remove part of end of buffer */
+ m_size -= end;
+ }
+ }
+ TRACE ("end remove="<<end<<", start="<<m_start<<", size="<<m_size<<", zero="<<m_zeroAreaSize<<
+ ", real size="<<m_data->m_size<<", ini start="<<m_data->m_initialStart<<
+ ", dirty start="<<m_data->m_dirtyStart<<", dirty size="<<m_data->m_dirtySize);
}
Buffer
Buffer::CreateFragment (uint32_t start, uint32_t length) const
{
- uint32_t zeroStart = m_data->m_initialStart - m_start;
- uint32_t zeroEnd = zeroStart + m_zeroAreaSize;
- if (m_zeroAreaSize != 0 &&
- start + length > zeroStart &&
- start <= zeroEnd)
- {
- TransformIntoRealBuffer ();
- }
- Buffer tmp = *this;
- tmp.RemoveAtStart (start);
- tmp.RemoveAtEnd (GetSize () - (start + length));
- return tmp;
+ uint32_t zeroStart = m_data->m_initialStart - m_start;
+ uint32_t zeroEnd = zeroStart + m_zeroAreaSize;
+ if (m_zeroAreaSize != 0 &&
+ start + length > zeroStart &&
+ start <= zeroEnd)
+ {
+ TransformIntoRealBuffer ();
+ }
+ Buffer tmp = *this;
+ tmp.RemoveAtStart (start);
+ tmp.RemoveAtEnd (GetSize () - (start + length));
+ return tmp;
}
void
Buffer::TransformIntoRealBuffer (void) const
{
- if (m_zeroAreaSize != 0)
- {
- assert (m_data->m_initialStart >= m_start);
- assert (m_size >= (m_data->m_initialStart - m_start));
- Buffer tmp;
- tmp.AddAtStart (m_zeroAreaSize);
- tmp.Begin ().WriteU8 (0, m_zeroAreaSize);
- uint32_t dataStart = m_data->m_initialStart - m_start;
- tmp.AddAtStart (dataStart);
- tmp.Begin ().Write (m_data->m_data+m_start, dataStart);
- uint32_t dataEnd = m_size - (m_data->m_initialStart - m_start);
- tmp.AddAtEnd (dataEnd);
- Buffer::Iterator i = tmp.End ();
- i.Prev (dataEnd);
- i.Write (m_data->m_data+m_data->m_initialStart,dataEnd);
- *const_cast<Buffer *> (this) = tmp;
- }
+ if (m_zeroAreaSize != 0)
+ {
+ assert (m_data->m_initialStart >= m_start);
+ assert (m_size >= (m_data->m_initialStart - m_start));
+ Buffer tmp;
+ tmp.AddAtStart (m_zeroAreaSize);
+ tmp.Begin ().WriteU8 (0, m_zeroAreaSize);
+ uint32_t dataStart = m_data->m_initialStart - m_start;
+ tmp.AddAtStart (dataStart);
+ tmp.Begin ().Write (m_data->m_data+m_start, dataStart);
+ uint32_t dataEnd = m_size - (m_data->m_initialStart - m_start);
+ tmp.AddAtEnd (dataEnd);
+ Buffer::Iterator i = tmp.End ();
+ i.Prev (dataEnd);
+ i.Write (m_data->m_data+m_data->m_initialStart,dataEnd);
+ *const_cast<Buffer *> (this) = tmp;
+ }
}
uint8_t const*
Buffer::PeekData (void) const
{
- TransformIntoRealBuffer ();
- return m_data->m_data + m_start;
+ TransformIntoRealBuffer ();
+ return m_data->m_data + m_start;
}
@@ -446,50 +446,50 @@
class BufferTest: public Test {
private:
- bool EnsureWrittenBytes (Buffer b, uint32_t n, uint8_t array[]);
+ bool EnsureWrittenBytes (Buffer b, uint32_t n, uint8_t array[]);
public:
- virtual bool RunTests (void);
- BufferTest ();
+ virtual bool RunTests (void);
+ BufferTest ();
};
BufferTest::BufferTest ()
- : Test ("Buffer") {}
+ : Test ("Buffer") {}
bool
BufferTest::EnsureWrittenBytes (Buffer b, uint32_t n, uint8_t array[])
{
- bool success = true;
- uint8_t *expected = array;
- uint8_t const*got;
- got = b.PeekData ();
- for (uint32_t j = 0; j < n; j++)
- {
- if (got[j] != expected[j])
- {
- success = false;
- }
- }
- if (!success)
- {
- Failure () << "Buffer -- ";
- Failure () << "expected: n=";
- Failure () << n << ", ";
- Failure ().setf (std::ios::hex, std::ios::basefield);
- for (uint32_t j = 0; j < n; j++)
- {
- Failure () << (uint16_t)expected[j] << " ";
- }
- Failure ().setf (std::ios::dec, std::ios::basefield);
- Failure () << "got: ";
- Failure ().setf (std::ios::hex, std::ios::basefield);
- for (uint32_t j = 0; j < n; j++)
- {
- Failure () << (uint16_t)got[j] << " ";
- }
- Failure () << std::endl;
- }
- return success;
+ bool success = true;
+ uint8_t *expected = array;
+ uint8_t const*got;
+ got = b.PeekData ();
+ for (uint32_t j = 0; j < n; j++)
+ {
+ if (got[j] != expected[j])
+ {
+ success = false;
+ }
+ }
+ if (!success)
+ {
+ Failure () << "Buffer -- ";
+ Failure () << "expected: n=";
+ Failure () << n << ", ";
+ Failure ().setf (std::ios::hex, std::ios::basefield);
+ for (uint32_t j = 0; j < n; j++)
+ {
+ Failure () << (uint16_t)expected[j] << " ";
+ }
+ Failure ().setf (std::ios::dec, std::ios::basefield);
+ Failure () << "got: ";
+ Failure ().setf (std::ios::hex, std::ios::basefield);
+ for (uint32_t j = 0; j < n; j++)
+ {
+ Failure () << (uint16_t)got[j] << " ";
+ }
+ Failure () << std::endl;
+ }
+ return success;
}
/* Note: works only when variadic macros are
@@ -498,160 +498,160 @@
*/
#define ENSURE_WRITTEN_BYTES(buffer, n, ...) \
{ \
- uint8_t bytes[] = {__VA_ARGS__}; \
- if (!EnsureWrittenBytes (buffer, n , bytes)) \
- { \
- ok = false; \
- } \
+ uint8_t bytes[] = {__VA_ARGS__}; \
+ if (!EnsureWrittenBytes (buffer, n , bytes)) \
+ { \
+ ok = false; \
+ } \
}
bool
BufferTest::RunTests (void)
{
- bool ok = true;
- Buffer buffer;
- Buffer::Iterator i;
- buffer.AddAtStart (6);
- i = buffer.Begin ();
- i.WriteU8 (0x66);
- ENSURE_WRITTEN_BYTES (buffer, 1, 0x66);
- i = buffer.Begin ();
- i.WriteU8 (0x67);
- ENSURE_WRITTEN_BYTES (buffer, 1, 0x67);
- i.WriteHtonU16 (0x6568);
- i = buffer.Begin ();
- ENSURE_WRITTEN_BYTES (buffer, 3, 0x67, 0x65, 0x68);
- i.WriteHtonU16 (0x6369);
- ENSURE_WRITTEN_BYTES (buffer, 3, 0x63, 0x69, 0x68);
- i.WriteHtonU32 (0xdeadbeaf);
- ENSURE_WRITTEN_BYTES (buffer, 6, 0x63, 0x69, 0xde, 0xad, 0xbe, 0xaf);
- buffer.AddAtStart (2);
- i = buffer.Begin ();
- i.WriteU16 (0);
- ENSURE_WRITTEN_BYTES (buffer, 8, 0, 0, 0x63, 0x69, 0xde, 0xad, 0xbe, 0xaf);
- buffer.AddAtEnd (2);
- i = buffer.Begin ();
- i.Next (8);
- i.WriteU16 (0);
- ENSURE_WRITTEN_BYTES (buffer, 10, 0, 0, 0x63, 0x69, 0xde, 0xad, 0xbe, 0xaf, 0, 0);
- buffer.RemoveAtStart (3);
- i = buffer.Begin ();
- ENSURE_WRITTEN_BYTES (buffer, 7, 0x69, 0xde, 0xad, 0xbe, 0xaf, 0, 0);
- buffer.RemoveAtEnd (4);
- i = buffer.Begin ();
- ENSURE_WRITTEN_BYTES (buffer, 3, 0x69, 0xde, 0xad);
- buffer.AddAtStart (1);
- i = buffer.Begin ();
- i.WriteU8 (0xff);
- ENSURE_WRITTEN_BYTES (buffer, 4, 0xff, 0x69, 0xde, 0xad);
- buffer.AddAtEnd (1);
- i = buffer.Begin ();
- i.Next (4);
- i.WriteU8 (0xff);
- i.Prev (2);
- uint16_t saved = i.ReadU16 ();
- i.Prev (2);
- i.WriteHtonU16 (0xff00);
- i.Prev (2);
- if (i.ReadNtohU16 () != 0xff00)
- {
- ok = false;
- }
- i.Prev (2);
- i.WriteU16 (saved);
- ENSURE_WRITTEN_BYTES (buffer, 5, 0xff, 0x69, 0xde, 0xad, 0xff);
- Buffer o = buffer;
- ENSURE_WRITTEN_BYTES (o, 5, 0xff, 0x69, 0xde, 0xad, 0xff);
- o.AddAtStart (1);
- i = o.Begin ();
- i.WriteU8 (0xfe);
- ENSURE_WRITTEN_BYTES (o, 6, 0xfe, 0xff, 0x69, 0xde, 0xad, 0xff);
- buffer.AddAtStart (2);
- i = buffer.Begin ();
- i.WriteU8 (0xfd);
- i.WriteU8 (0xfd);
- ENSURE_WRITTEN_BYTES (o, 6, 0xfe, 0xff, 0x69, 0xde, 0xad, 0xff);
- ENSURE_WRITTEN_BYTES (buffer, 7, 0xfd, 0xfd, 0xff, 0x69, 0xde, 0xad, 0xff);
+ bool ok = true;
+ Buffer buffer;
+ Buffer::Iterator i;
+ buffer.AddAtStart (6);
+ i = buffer.Begin ();
+ i.WriteU8 (0x66);
+ ENSURE_WRITTEN_BYTES (buffer, 1, 0x66);
+ i = buffer.Begin ();
+ i.WriteU8 (0x67);
+ ENSURE_WRITTEN_BYTES (buffer, 1, 0x67);
+ i.WriteHtonU16 (0x6568);
+ i = buffer.Begin ();
+ ENSURE_WRITTEN_BYTES (buffer, 3, 0x67, 0x65, 0x68);
+ i.WriteHtonU16 (0x6369);
+ ENSURE_WRITTEN_BYTES (buffer, 3, 0x63, 0x69, 0x68);
+ i.WriteHtonU32 (0xdeadbeaf);
+ ENSURE_WRITTEN_BYTES (buffer, 6, 0x63, 0x69, 0xde, 0xad, 0xbe, 0xaf);
+ buffer.AddAtStart (2);
+ i = buffer.Begin ();
+ i.WriteU16 (0);
+ ENSURE_WRITTEN_BYTES (buffer, 8, 0, 0, 0x63, 0x69, 0xde, 0xad, 0xbe, 0xaf);
+ buffer.AddAtEnd (2);
+ i = buffer.Begin ();
+ i.Next (8);
+ i.WriteU16 (0);
+ ENSURE_WRITTEN_BYTES (buffer, 10, 0, 0, 0x63, 0x69, 0xde, 0xad, 0xbe, 0xaf, 0, 0);
+ buffer.RemoveAtStart (3);
+ i = buffer.Begin ();
+ ENSURE_WRITTEN_BYTES (buffer, 7, 0x69, 0xde, 0xad, 0xbe, 0xaf, 0, 0);
+ buffer.RemoveAtEnd (4);
+ i = buffer.Begin ();
+ ENSURE_WRITTEN_BYTES (buffer, 3, 0x69, 0xde, 0xad);
+ buffer.AddAtStart (1);
+ i = buffer.Begin ();
+ i.WriteU8 (0xff);
+ ENSURE_WRITTEN_BYTES (buffer, 4, 0xff, 0x69, 0xde, 0xad);
+ buffer.AddAtEnd (1);
+ i = buffer.Begin ();
+ i.Next (4);
+ i.WriteU8 (0xff);
+ i.Prev (2);
+ uint16_t saved = i.ReadU16 ();
+ i.Prev (2);
+ i.WriteHtonU16 (0xff00);
+ i.Prev (2);
+ if (i.ReadNtohU16 () != 0xff00)
+ {
+ ok = false;
+ }
+ i.Prev (2);
+ i.WriteU16 (saved);
+ ENSURE_WRITTEN_BYTES (buffer, 5, 0xff, 0x69, 0xde, 0xad, 0xff);
+ Buffer o = buffer;
+ ENSURE_WRITTEN_BYTES (o, 5, 0xff, 0x69, 0xde, 0xad, 0xff);
+ o.AddAtStart (1);
+ i = o.Begin ();
+ i.WriteU8 (0xfe);
+ ENSURE_WRITTEN_BYTES (o, 6, 0xfe, 0xff, 0x69, 0xde, 0xad, 0xff);
+ buffer.AddAtStart (2);
+ i = buffer.Begin ();
+ i.WriteU8 (0xfd);
+ i.WriteU8 (0xfd);
+ ENSURE_WRITTEN_BYTES (o, 6, 0xfe, 0xff, 0x69, 0xde, 0xad, 0xff);
+ ENSURE_WRITTEN_BYTES (buffer, 7, 0xfd, 0xfd, 0xff, 0x69, 0xde, 0xad, 0xff);
- // test self-assignment
- {
- Buffer a = o;
- a = a;
- }
+ // test self-assignment
+ {
+ Buffer a = o;
+ a = a;
+ }
- // test Remove start.
- buffer = Buffer (5);
- ENSURE_WRITTEN_BYTES (buffer, 5, 0, 0, 0, 0, 0);
- buffer.RemoveAtStart (1);
- ENSURE_WRITTEN_BYTES (buffer, 4, 0, 0, 0, 0);
- buffer.AddAtStart (1);
- buffer.Begin ().WriteU8 (0xff);
- ENSURE_WRITTEN_BYTES (buffer, 5, 0xff, 0, 0, 0, 0);
- buffer.RemoveAtStart(3);
- ENSURE_WRITTEN_BYTES (buffer, 2, 0, 0);
- buffer.AddAtStart (4);
- buffer.Begin ().WriteHtonU32 (0xdeadbeaf);
- ENSURE_WRITTEN_BYTES (buffer, 6, 0xde, 0xad, 0xbe, 0xaf, 0, 0);
- buffer.RemoveAtStart (2);
- ENSURE_WRITTEN_BYTES (buffer, 4, 0xbe, 0xaf, 0, 0);
- buffer.AddAtEnd (4);
- i = buffer.Begin ();
- i.Next (4);
- i.WriteHtonU32 (0xdeadbeaf);
- ENSURE_WRITTEN_BYTES (buffer, 8, 0xbe, 0xaf, 0, 0, 0xde, 0xad, 0xbe, 0xaf);
- buffer.RemoveAtStart (5);
- ENSURE_WRITTEN_BYTES (buffer, 3, 0xad, 0xbe, 0xaf);
- // test Remove end
- buffer = Buffer (5);
- ENSURE_WRITTEN_BYTES (buffer, 5, 0, 0, 0, 0, 0);
- buffer.RemoveAtEnd (1);
- ENSURE_WRITTEN_BYTES (buffer, 4, 0, 0, 0, 0);
- buffer.AddAtEnd (2);
- i = buffer.Begin ();
- i.Next (4);
- i.WriteU8 (0xab);
- i.WriteU8 (0xac);
- ENSURE_WRITTEN_BYTES (buffer, 6, 0, 0, 0, 0, 0xab, 0xac);
- buffer.RemoveAtEnd (1);
- ENSURE_WRITTEN_BYTES (buffer, 5, 0, 0, 0, 0, 0xab);
- buffer.RemoveAtEnd (3);
- ENSURE_WRITTEN_BYTES (buffer, 2, 0, 0);
- buffer.AddAtEnd (6);
- i = buffer.Begin ();
- i.Next (2);
- i.WriteU8 (0xac);
- i.WriteU8 (0xad);
- i.WriteU8 (0xae);
- i.WriteU8 (0xaf);
- i.WriteU8 (0xba);
- i.WriteU8 (0xbb);
- ENSURE_WRITTEN_BYTES (buffer, 8, 0, 0, 0xac, 0xad, 0xae, 0xaf, 0xba, 0xbb);
- buffer.AddAtStart (3);
- i = buffer.Begin ();
- i.WriteU8 (0x30);
- i.WriteU8 (0x31);
- i.WriteU8 (0x32);
- ENSURE_WRITTEN_BYTES (buffer, 11, 0x30, 0x31, 0x32, 0, 0, 0xac, 0xad, 0xae, 0xaf, 0xba, 0xbb);
- buffer.RemoveAtEnd (9);
- ENSURE_WRITTEN_BYTES (buffer, 2, 0x30, 0x31);
- buffer = Buffer (3);
- buffer.AddAtEnd (2);
- i = buffer.Begin ();
- i.Next (3);
- i.WriteHtonU16 (0xabcd);
- buffer.AddAtStart (1);
- buffer.Begin ().WriteU8 (0x21);
- ENSURE_WRITTEN_BYTES (buffer, 6, 0x21, 0, 0, 0, 0xab, 0xcd);
- buffer.RemoveAtEnd (8);
- if (buffer.GetSize () != 0)
- {
- ok = false;
- }
-
-
-
+ // test Remove start.
+ buffer = Buffer (5);
+ ENSURE_WRITTEN_BYTES (buffer, 5, 0, 0, 0, 0, 0);
+ buffer.RemoveAtStart (1);
+ ENSURE_WRITTEN_BYTES (buffer, 4, 0, 0, 0, 0);
+ buffer.AddAtStart (1);
+ buffer.Begin ().WriteU8 (0xff);
+ ENSURE_WRITTEN_BYTES (buffer, 5, 0xff, 0, 0, 0, 0);
+ buffer.RemoveAtStart(3);
+ ENSURE_WRITTEN_BYTES (buffer, 2, 0, 0);
+ buffer.AddAtStart (4);
+ buffer.Begin ().WriteHtonU32 (0xdeadbeaf);
+ ENSURE_WRITTEN_BYTES (buffer, 6, 0xde, 0xad, 0xbe, 0xaf, 0, 0);
+ buffer.RemoveAtStart (2);
+ ENSURE_WRITTEN_BYTES (buffer, 4, 0xbe, 0xaf, 0, 0);
+ buffer.AddAtEnd (4);
+ i = buffer.Begin ();
+ i.Next (4);
+ i.WriteHtonU32 (0xdeadbeaf);
+ ENSURE_WRITTEN_BYTES (buffer, 8, 0xbe, 0xaf, 0, 0, 0xde, 0xad, 0xbe, 0xaf);
+ buffer.RemoveAtStart (5);
+ ENSURE_WRITTEN_BYTES (buffer, 3, 0xad, 0xbe, 0xaf);
+ // test Remove end
+ buffer = Buffer (5);
+ ENSURE_WRITTEN_BYTES (buffer, 5, 0, 0, 0, 0, 0);
+ buffer.RemoveAtEnd (1);
+ ENSURE_WRITTEN_BYTES (buffer, 4, 0, 0, 0, 0);
+ buffer.AddAtEnd (2);
+ i = buffer.Begin ();
+ i.Next (4);
+ i.WriteU8 (0xab);
+ i.WriteU8 (0xac);
+ ENSURE_WRITTEN_BYTES (buffer, 6, 0, 0, 0, 0, 0xab, 0xac);
+ buffer.RemoveAtEnd (1);
+ ENSURE_WRITTEN_BYTES (buffer, 5, 0, 0, 0, 0, 0xab);
+ buffer.RemoveAtEnd (3);
+ ENSURE_WRITTEN_BYTES (buffer, 2, 0, 0);
+ buffer.AddAtEnd (6);
+ i = buffer.Begin ();
+ i.Next (2);
+ i.WriteU8 (0xac);
+ i.WriteU8 (0xad);
+ i.WriteU8 (0xae);
+ i.WriteU8 (0xaf);
+ i.WriteU8 (0xba);
+ i.WriteU8 (0xbb);
+ ENSURE_WRITTEN_BYTES (buffer, 8, 0, 0, 0xac, 0xad, 0xae, 0xaf, 0xba, 0xbb);
+ buffer.AddAtStart (3);
+ i = buffer.Begin ();
+ i.WriteU8 (0x30);
+ i.WriteU8 (0x31);
+ i.WriteU8 (0x32);
+ ENSURE_WRITTEN_BYTES (buffer, 11, 0x30, 0x31, 0x32, 0, 0, 0xac, 0xad, 0xae, 0xaf, 0xba, 0xbb);
+ buffer.RemoveAtEnd (9);
+ ENSURE_WRITTEN_BYTES (buffer, 2, 0x30, 0x31);
+ buffer = Buffer (3);
+ buffer.AddAtEnd (2);
+ i = buffer.Begin ();
+ i.Next (3);
+ i.WriteHtonU16 (0xabcd);
+ buffer.AddAtStart (1);
+ buffer.Begin ().WriteU8 (0x21);
+ ENSURE_WRITTEN_BYTES (buffer, 6, 0x21, 0, 0, 0, 0xab, 0xcd);
+ buffer.RemoveAtEnd (8);
+ if (buffer.GetSize () != 0)
+ {
+ ok = false;
+ }
+
+
+
- return ok;
+ return ok;
}
--- a/src/common/buffer.h Wed Nov 01 13:00:34 2006 +0100
+++ b/src/common/buffer.h Wed Nov 01 13:11:30 2006 +0100
@@ -1,4 +1,4 @@
-/* -*- Mode:NS3; -*- */
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005,2006 INRIA
* All rights reserved.
@@ -39,318 +39,318 @@
*/
class Buffer {
public:
- /**
- * \brief iterator in a Buffer instance
- */
- class Iterator {
- public:
- inline Iterator ();
- /**
- * go forward by one byte
- */
- inline void Next (void);
- /**
- * go backward by one byte
- */
- inline void Prev (void);
- /**
- * \param delta number of bytes to go forward
- */
- inline void Next (uint32_t delta);
- /**
- * \param delta number of bytes to go backward
- */
- inline void Prev (uint32_t delta);
- /**
- * \param o the second iterator
- * \return number of bytes included between the two iterators
- *
- * This method works only if the two iterators point
- * to the same underlying buffer. Debug builds ensure
- * this with an assert.
- */
- inline int32_t GetDistanceFrom (Iterator const &o) const;
-
- /**
- * \return true if this iterator points to the end of the byte array.
- * false otherwise.
- */
- inline bool IsEnd (void) const;
- /**
- * \return true if this iterator points to the start of the byte array.
- * false otherwise.
- */
- inline bool IsStart (void) const;
+ /**
+ * \brief iterator in a Buffer instance
+ */
+ class Iterator {
+ public:
+ inline Iterator ();
+ /**
+ * go forward by one byte
+ */
+ inline void Next (void);
+ /**
+ * go backward by one byte
+ */
+ inline void Prev (void);
+ /**
+ * \param delta number of bytes to go forward
+ */
+ inline void Next (uint32_t delta);
+ /**
+ * \param delta number of bytes to go backward
+ */
+ inline void Prev (uint32_t delta);
+ /**
+ * \param o the second iterator
+ * \return number of bytes included between the two iterators
+ *
+ * This method works only if the two iterators point
+ * to the same underlying buffer. Debug builds ensure
+ * this with an assert.
+ */
+ inline int32_t GetDistanceFrom (Iterator const &o) const;
+
+ /**
+ * \return true if this iterator points to the end of the byte array.
+ * false otherwise.
+ */
+ inline bool IsEnd (void) const;
+ /**
+ * \return true if this iterator points to the start of the byte array.
+ * false otherwise.
+ */
+ inline bool IsStart (void) const;
- /**
- * \param data data to write in buffer
- *
- * Write the data in buffer and avance the iterator position
- * by one byte.
- */
- inline void WriteU8 (uint8_t data);
- /**
- * \param data data to write in buffer
- * \param len number of times data must be written in buffer
- *
- * Write the data in buffer len times and avance the iterator position
- * by len byte.
- */
- inline void WriteU8 (uint8_t data, uint32_t len);
- /**
- * \param data data to write in buffer
- *
- * Write the data in buffer and avance the iterator position
- * by two bytes. The format of the data written in the byte
- * buffer is non-portable. We only ensure that readU16 will
- * return exactly what we wrote with writeU16 if the program
- * is run on the same machine.
- */
- inline void WriteU16 (uint16_t data);
- /**
- * \param data data to write in buffer
- *
- * Write the data in buffer and avance the iterator position
- * by four bytes. The format of the data written in the byte
- * buffer is non-portable. We only ensure that readU32 will
- * return exactly what we wrote with writeU32 if the program
- * is run on the same machine.
- */
- inline void WriteU32 (uint32_t data);
- /**
- * \param data data to write in buffer
- *
- * Write the data in buffer and avance the iterator position
- * by eight bytes. The format of the data written in the byte
- * buffer is non-portable. We only ensure that readU64 will
- * return exactly what we wrote with writeU64 if the program
- * is run on the same machine.
- */
- inline void WriteU64 (uint64_t data);
- /**
- * \param data data to write in buffer
- *
- * Write the data in buffer and avance the iterator position
- * by two bytes. The data is written in network order and the
- * input data is expected to be in host order.
- */
- inline void WriteHtonU16 (uint16_t data);
- /**
- * \param data data to write in buffer
- *
- * Write the data in buffer and avance the iterator position
- * by four bytes. The data is written in network order and the
- * input data is expected to be in host order.
- */
- inline void WriteHtonU32 (uint32_t data);
- /**
- * \param data data to write in buffer
- *
- * Write the data in buffer and avance the iterator position
- * by eight bytes. The data is written in network order and the
- * input data is expected to be in host order.
- */
- inline void WriteHtonU64 (uint64_t data);
- /**
- * \param buffer a byte buffer to copy in the internal buffer.
- * \param size number of bytes to copy.
- *
- * Write the data in buffer and avance the iterator position
- * by size bytes.
- */
- inline void Write (uint8_t const*buffer, uint16_t size);
- /**
- * \param start the start of the data to copy
- * \param end the end of the data to copy
- *
- * Write the data delimited by start and end in internal buffer
- * and avance the iterator position by the number of bytes
- * copied.
- * The input interators _must_ not point to the same Buffer as
- * we do to avoid overlapping copies. This is enforced
- * in debug builds by asserts.
- */
- inline void Write (Iterator start, Iterator end);
+ /**
+ * \param data data to write in buffer
+ *
+ * Write the data in buffer and avance the iterator position
+ * by one byte.
+ */
+ inline void WriteU8 (uint8_t data);
+ /**
+ * \param data data to write in buffer
+ * \param len number of times data must be written in buffer
+ *
+ * Write the data in buffer len times and avance the iterator position
+ * by len byte.
+ */
+ inline void WriteU8 (uint8_t data, uint32_t len);
+ /**
+ * \param data data to write in buffer
+ *
+ * Write the data in buffer and avance the iterator position
+ * by two bytes. The format of the data written in the byte
+ * buffer is non-portable. We only ensure that readU16 will
+ * return exactly what we wrote with writeU16 if the program
+ * is run on the same machine.
+ */
+ inline void WriteU16 (uint16_t data);
+ /**
+ * \param data data to write in buffer
+ *
+ * Write the data in buffer and avance the iterator position
+ * by four bytes. The format of the data written in the byte
+ * buffer is non-portable. We only ensure that readU32 will
+ * return exactly what we wrote with writeU32 if the program
+ * is run on the same machine.
+ */
+ inline void WriteU32 (uint32_t data);
+ /**
+ * \param data data to write in buffer
+ *
+ * Write the data in buffer and avance the iterator position
+ * by eight bytes. The format of the data written in the byte
+ * buffer is non-portable. We only ensure that readU64 will
+ * return exactly what we wrote with writeU64 if the program
+ * is run on the same machine.
+ */
+ inline void WriteU64 (uint64_t data);
+ /**
+ * \param data data to write in buffer
+ *
+ * Write the data in buffer and avance the iterator position
+ * by two bytes. The data is written in network order and the
+ * input data is expected to be in host order.
+ */
+ inline void WriteHtonU16 (uint16_t data);
+ /**
+ * \param data data to write in buffer
+ *
+ * Write the data in buffer and avance the iterator position
+ * by four bytes. The data is written in network order and the
+ * input data is expected to be in host order.
+ */
+ inline void WriteHtonU32 (uint32_t data);
+ /**
+ * \param data data to write in buffer
+ *
+ * Write the data in buffer and avance the iterator position
+ * by eight bytes. The data is written in network order and the
+ * input data is expected to be in host order.
+ */
+ inline void WriteHtonU64 (uint64_t data);
+ /**
+ * \param buffer a byte buffer to copy in the internal buffer.
+ * \param size number of bytes to copy.
+ *
+ * Write the data in buffer and avance the iterator position
+ * by size bytes.
+ */
+ inline void Write (uint8_t const*buffer, uint16_t size);
+ /**
+ * \param start the start of the data to copy
+ * \param end the end of the data to copy
+ *
+ * Write the data delimited by start and end in internal buffer
+ * and avance the iterator position by the number of bytes
+ * copied.
+ * The input interators _must_ not point to the same Buffer as
+ * we do to avoid overlapping copies. This is enforced
+ * in debug builds by asserts.
+ */
+ inline void Write (Iterator start, Iterator end);
- /**
- * \return the byte read in the buffer.
- *
- * Read data and advance the Iterator by the number of bytes
- * read.
- */
- inline uint8_t ReadU8 (void);
- /**
- * \return the two bytes read in the buffer.
- *
- * Read data and advance the Iterator by the number of bytes
- * read.
- * The data is read in the format written by writeU16.
- */
- inline uint16_t ReadU16 (void);
- /**
- * \return the four bytes read in the buffer.
- *
- * Read data and advance the Iterator by the number of bytes
- * read.
- * The data is read in the format written by writeU32.
- */
- inline uint32_t ReadU32 (void);
- /**
- * \return the eight bytes read in the buffer.
- *
- * Read data and advance the Iterator by the number of bytes
- * read.
- * The data is read in the format written by writeU64.
- */
- inline uint64_t ReadU64 (void);
- /**
- * \return the two bytes read in the buffer.
- *
- * Read data and advance the Iterator by the number of bytes
- * read.
- * The data is read in network format and return in host format.
- */
- inline uint16_t ReadNtohU16 (void);
- /**
- * \return the four bytes read in the buffer.
- *
- * Read data and advance the Iterator by the number of bytes
- * read.
- * The data is read in network format and return in host format.
- */
- inline uint32_t ReadNtohU32 (void);
- /**
- * \return the eight bytes read in the buffer.
- *
- * Read data and advance the Iterator by the number of bytes
- * read.
- * The data is read in network format and return in host format.
- */
- inline uint64_t ReadNtohU64 (void);
- /**
- * \param buffer buffer to copy data into
- * \param size number of bytes to copy
- *
- * Copy size bytes of data from the internal buffer to the
- * input buffer and avance the Iterator by the number of
- * bytes read.
- */
- inline void Read (uint8_t *buffer, uint16_t size);
- private:
- friend class Buffer;
- inline Iterator (Buffer const*buffer, uint32_t m_current);
- inline uint32_t GetIndex (uint32_t n);
- uint32_t m_zeroStart;
- uint32_t m_zeroEnd;
- uint32_t m_dataEnd;
- uint32_t m_current;
- uint8_t *m_data;
- };
+ /**
+ * \return the byte read in the buffer.
+ *
+ * Read data and advance the Iterator by the number of bytes
+ * read.
+ */
+ inline uint8_t ReadU8 (void);
+ /**
+ * \return the two bytes read in the buffer.
+ *
+ * Read data and advance the Iterator by the number of bytes
+ * read.
+ * The data is read in the format written by writeU16.
+ */
+ inline uint16_t ReadU16 (void);
+ /**
+ * \return the four bytes read in the buffer.
+ *
+ * Read data and advance the Iterator by the number of bytes
+ * read.
+ * The data is read in the format written by writeU32.
+ */
+ inline uint32_t ReadU32 (void);
+ /**
+ * \return the eight bytes read in the buffer.
+ *
+ * Read data and advance the Iterator by the number of bytes
+ * read.
+ * The data is read in the format written by writeU64.
+ */
+ inline uint64_t ReadU64 (void);
+ /**
+ * \return the two bytes read in the buffer.
+ *
+ * Read data and advance the Iterator by the number of bytes
+ * read.
+ * The data is read in network format and return in host format.
+ */
+ inline uint16_t ReadNtohU16 (void);
+ /**
+ * \return the four bytes read in the buffer.
+ *
+ * Read data and advance the Iterator by the number of bytes
+ * read.
+ * The data is read in network format and return in host format.
+ */
+ inline uint32_t ReadNtohU32 (void);
+ /**
+ * \return the eight bytes read in the buffer.
+ *
+ * Read data and advance the Iterator by the number of bytes
+ * read.
+ * The data is read in network format and return in host format.
+ */
+ inline uint64_t ReadNtohU64 (void);
+ /**
+ * \param buffer buffer to copy data into
+ * \param size number of bytes to copy
+ *
+ * Copy size bytes of data from the internal buffer to the
+ * input buffer and avance the Iterator by the number of
+ * bytes read.
+ */
+ inline void Read (uint8_t *buffer, uint16_t size);
+ private:
+ friend class Buffer;
+ inline Iterator (Buffer const*buffer, uint32_t m_current);
+ inline uint32_t GetIndex (uint32_t n);
+ uint32_t m_zeroStart;
+ uint32_t m_zeroEnd;
+ uint32_t m_dataEnd;
+ uint32_t m_current;
+ uint8_t *m_data;
+ };
- /**
- * \return the number of bytes stored in this buffer.
- */
- inline uint32_t GetSize (void) const;
+ /**
+ * \return the number of bytes stored in this buffer.
+ */
+ inline uint32_t GetSize (void) const;
- /**
- * \return a pointer to the start of the internal
- * byte buffer.
- *
- * The returned pointer points to an area of
- * memory which is ns3::Buffer::GetSize () bytes big.
- * Please, try to never ever use this method. It is really
- * evil and is present only for a few specific uses.
- */
- uint8_t const*PeekData (void) const;
+ /**
+ * \return a pointer to the start of the internal
+ * byte buffer.
+ *
+ * The returned pointer points to an area of
+ * memory which is ns3::Buffer::GetSize () bytes big.
+ * Please, try to never ever use this method. It is really
+ * evil and is present only for a few specific uses.
+ */
+ uint8_t const*PeekData (void) const;
- /**
- * \param start size to reserve
- *
- * Add bytes at the start of the Buffer. The
- * content of these bytes is undefined but debugging
- * builds initialize them to 0x33.
- * Any call to this method invalidates any Iterator
- * pointing to this Buffer.
- */
- void AddAtStart (uint32_t start);
- /**
- * \param end size to reserve
- *
- * Add bytes at the end of the Buffer. The
- * content of these bytes is undefined but debugging
- * builds initialize them to 0x33.
- * Any call to this method invalidates any Iterator
- * pointing to this Buffer.
- */
- void AddAtEnd (uint32_t end);
- /**
- * \param start size to remove
- *
- * Remove bytes at the start of the Buffer.
- * Any call to this method invalidates any Iterator
- * pointing to this Buffer.
- */
- void RemoveAtStart (uint32_t start);
- /**
- * \param end size to remove
- *
- * Remove bytes at the end of the Buffer.
- * Any call to this method invalidates any Iterator
- * pointing to this Buffer.
- */
- void RemoveAtEnd (uint32_t end);
+ /**
+ * \param start size to reserve
+ *
+ * Add bytes at the start of the Buffer. The
+ * content of these bytes is undefined but debugging
+ * builds initialize them to 0x33.
+ * Any call to this method invalidates any Iterator
+ * pointing to this Buffer.
+ */
+ void AddAtStart (uint32_t start);
+ /**
+ * \param end size to reserve
+ *
+ * Add bytes at the end of the Buffer. The
+ * content of these bytes is undefined but debugging
+ * builds initialize them to 0x33.
+ * Any call to this method invalidates any Iterator
+ * pointing to this Buffer.
+ */
+ void AddAtEnd (uint32_t end);
+ /**
+ * \param start size to remove
+ *
+ * Remove bytes at the start of the Buffer.
+ * Any call to this method invalidates any Iterator
+ * pointing to this Buffer.
+ */
+ void RemoveAtStart (uint32_t start);
+ /**
+ * \param end size to remove
+ *
+ * Remove bytes at the end of the Buffer.
+ * Any call to this method invalidates any Iterator
+ * pointing to this Buffer.
+ */
+ void RemoveAtEnd (uint32_t end);
- /**
- * \param start offset from start of packet
- * \param length
- *
- * \return a fragment of size length starting at offset
- * start.
- */
- Buffer CreateFragment (uint32_t start, uint32_t length) const;
+ /**
+ * \param start offset from start of packet
+ * \param length
+ *
+ * \return a fragment of size length starting at offset
+ * start.
+ */
+ Buffer CreateFragment (uint32_t start, uint32_t length) const;
- /**
- * \return an Iterator which points to the
- * start of this Buffer.
- */
- inline Buffer::Iterator Begin (void) const;
- /**
- * \return an Iterator which points to the
- * end of this Buffer.
- */
- inline Buffer::Iterator End (void) const;
+ /**
+ * \return an Iterator which points to the
+ * start of this Buffer.
+ */
+ inline Buffer::Iterator Begin (void) const;
+ /**
+ * \return an Iterator which points to the
+ * end of this Buffer.
+ */
+ inline Buffer::Iterator End (void) const;
- inline Buffer (Buffer const &o);
- inline Buffer &operator = (Buffer const &o);
- inline Buffer ();
- inline Buffer (uint32_t dataSize);
- inline ~Buffer ();
+ inline Buffer (Buffer const &o);
+ inline Buffer &operator = (Buffer const &o);
+ inline Buffer ();
+ inline Buffer (uint32_t dataSize);
+ inline ~Buffer ();
private:
- struct BufferData {
- uint32_t m_count;
- uint32_t m_size;
- uint32_t m_initialStart;
- uint32_t m_dirtyStart;
- uint32_t m_dirtySize;
- uint8_t m_data[1];
- };
- typedef std::vector<struct Buffer::BufferData*> BufferDataList;
+ struct BufferData {
+ uint32_t m_count;
+ uint32_t m_size;
+ uint32_t m_initialStart;
+ uint32_t m_dirtyStart;
+ uint32_t m_dirtySize;
+ uint8_t m_data[1];
+ };
+ typedef std::vector<struct Buffer::BufferData*> BufferDataList;
- inline uint8_t *GetStart (void) const;
- void TransformIntoRealBuffer (void) const;
- static void Recycle (struct Buffer::BufferData *data);
- static struct Buffer::BufferData *Create (void);
- static struct Buffer::BufferData *Allocate (uint32_t size, uint32_t start);
- static void Deallocate (struct Buffer::BufferData *data);
+ inline uint8_t *GetStart (void) const;
+ void TransformIntoRealBuffer (void) const;
+ static void Recycle (struct Buffer::BufferData *data);
+ static struct Buffer::BufferData *Create (void);
+ static struct Buffer::BufferData *Allocate (uint32_t size, uint32_t start);
+ static void Deallocate (struct Buffer::BufferData *data);
- static BufferDataList m_freeList;
- static uint32_t m_maxTotalAddStart;
- static uint32_t m_maxTotalAddEnd;
+ static BufferDataList m_freeList;
+ static uint32_t m_maxTotalAddStart;
+ static uint32_t m_maxTotalAddEnd;
- struct BufferData *m_data;
- uint32_t m_zeroAreaSize;
- uint32_t m_start;
- uint32_t m_size;
+ struct BufferData *m_data;
+ uint32_t m_zeroAreaSize;
+ uint32_t m_start;
+ uint32_t m_size;
};
}; // namespace ns3
@@ -366,336 +366,336 @@
namespace ns3 {
Buffer::Buffer ()
- : m_data (Buffer::Create ()),
- m_zeroAreaSize (0),
- m_start (m_maxTotalAddStart),
- m_size (0)
+ : m_data (Buffer::Create ()),
+ m_zeroAreaSize (0),
+ m_start (m_maxTotalAddStart),
+ m_size (0)
{
- if (m_start > m_data->m_size)
- {
- m_start = 0;
- }
- assert (m_start <= m_data->m_size);
+ if (m_start > m_data->m_size)
+ {
+ m_start = 0;
+ }
+ assert (m_start <= m_data->m_size);
}
Buffer::Buffer (uint32_t dataSize)
- : m_data (Buffer::Create ()),
- m_zeroAreaSize (dataSize),
- m_start (m_maxTotalAddStart),
- m_size (0)
+ : m_data (Buffer::Create ()),
+ m_zeroAreaSize (dataSize),
+ m_start (m_maxTotalAddStart),
+ m_size (0)
{
- if (m_start > m_data->m_size)
- {
- m_start = 0;
- }
- assert (m_start <= m_data->m_size);
+ if (m_start > m_data->m_size)
+ {
+ m_start = 0;
+ }
+ assert (m_start <= m_data->m_size);
}
Buffer::Buffer (Buffer const&o)
- : m_data (o.m_data),
- m_zeroAreaSize (o.m_zeroAreaSize),
- m_start (o.m_start),
- m_size (o.m_size)
+ : m_data (o.m_data),
+ m_zeroAreaSize (o.m_zeroAreaSize),
+ m_start (o.m_start),
+ m_size (o.m_size)
{
- m_data->m_count++;
- assert (m_start <= m_data->m_size);
+ m_data->m_count++;
+ assert (m_start <= m_data->m_size);
}
Buffer &
Buffer::operator = (Buffer const&o)
{
- if (m_data != o.m_data)
- {
- // not assignment to self.
- m_data->m_count--;
- if (m_data->m_count == 0)
- {
- Recycle (m_data);
- }
- m_data = o.m_data;
- m_data->m_count++;
- }
- m_zeroAreaSize = o.m_zeroAreaSize;
- m_start = o.m_start;
- m_size = o.m_size;
- assert (m_start <= m_data->m_size);
- return *this;
+ if (m_data != o.m_data)
+ {
+ // not assignment to self.
+ m_data->m_count--;
+ if (m_data->m_count == 0)
+ {
+ Recycle (m_data);
+ }
+ m_data = o.m_data;
+ m_data->m_count++;
+ }
+ m_zeroAreaSize = o.m_zeroAreaSize;
+ m_start = o.m_start;
+ m_size = o.m_size;
+ assert (m_start <= m_data->m_size);
+ return *this;
}
Buffer::~Buffer ()
{
- m_data->m_count--;
- if (m_data->m_count == 0)
- {
- Recycle (m_data);
- }
+ m_data->m_count--;
+ if (m_data->m_count == 0)
+ {
+ Recycle (m_data);
+ }
}
uint8_t *
Buffer::GetStart (void) const
{
- return m_data->m_data + m_start;
+ return m_data->m_data + m_start;
}
uint32_t
Buffer::GetSize (void) const
{
- return m_size + m_zeroAreaSize;
+ return m_size + m_zeroAreaSize;
}
Buffer::Iterator
Buffer::Begin (void) const
{
- return Buffer::Iterator (this, 0);
+ return Buffer::Iterator (this, 0);
}
Buffer::Iterator
Buffer::End (void) const
{
- return Buffer::Iterator (this, GetSize ());
+ return Buffer::Iterator (this, GetSize ());
}
Buffer::Iterator::Iterator ()
- : m_zeroStart (0),
- m_zeroEnd (0),
- m_dataEnd (0),
- m_current (0),
- m_data (0)
+ : m_zeroStart (0),
+ m_zeroEnd (0),
+ m_dataEnd (0),
+ m_current (0),
+ m_data (0)
{}
Buffer::Iterator::Iterator (Buffer const*buffer, uint32_t current)
- : m_zeroStart (buffer->m_data->m_initialStart-buffer->m_start),
- m_zeroEnd (m_zeroStart+buffer->m_zeroAreaSize),
- m_dataEnd (buffer->GetSize ()),
- m_current (current),
- m_data (buffer->m_data->m_data+buffer->m_start)
+ : m_zeroStart (buffer->m_data->m_initialStart-buffer->m_start),
+ m_zeroEnd (m_zeroStart+buffer->m_zeroAreaSize),
+ m_dataEnd (buffer->GetSize ()),
+ m_current (current),
+ m_data (buffer->m_data->m_data+buffer->m_start)
{}
void
Buffer::Iterator::Next (void)
{
- assert (m_current + 1 <= m_dataEnd);
- m_current++;
+ assert (m_current + 1 <= m_dataEnd);
+ m_current++;
}
void
Buffer::Iterator::Prev (void)
{
- assert (m_current >= 1);
- m_current--;
+ assert (m_current >= 1);
+ m_current--;
}
void
Buffer::Iterator::Next (uint32_t delta)
{
- assert (m_current + delta <= m_dataEnd);
- m_current += delta;
+ assert (m_current + delta <= m_dataEnd);
+ m_current += delta;
}
void
Buffer::Iterator::Prev (uint32_t delta)
{
- assert (m_current >= delta);
- m_current -= delta;
+ assert (m_current >= delta);
+ m_current -= delta;
}
int32_t
Buffer::Iterator::GetDistanceFrom (Iterator const &o) const
{
- assert (m_data == o.m_data);
- int32_t start = m_current;
- int32_t end = o.m_current;
- return end - start;
+ assert (m_data == o.m_data);
+ int32_t start = m_current;
+ int32_t end = o.m_current;
+ return end - start;
}
bool
Buffer::Iterator::IsEnd (void) const
{
- return m_current == m_dataEnd;
+ return m_current == m_dataEnd;
}
bool
Buffer::Iterator::IsStart (void) const
{
- return m_current == 0;
+ return m_current == 0;
}
uint32_t
Buffer::Iterator::GetIndex (uint32_t n)
{
- assert (
- (m_current + n <= m_dataEnd) &&
- ((m_current + n <= m_zeroStart) ||
- (m_current >= m_zeroEnd))
- );
- uint32_t index;
- if (m_current < m_zeroStart)
- {
- index = m_current;
- }
- else
- {
- index = m_current - (m_zeroEnd-m_zeroStart);
- }
- return index;
+ assert (
+ (m_current + n <= m_dataEnd) &&
+ ((m_current + n <= m_zeroStart) ||
+ (m_current >= m_zeroEnd))
+ );
+ uint32_t index;
+ if (m_current < m_zeroStart)
+ {
+ index = m_current;
+ }
+ else
+ {
+ index = m_current - (m_zeroEnd-m_zeroStart);
+ }
+ return index;
}
void
Buffer::Iterator::Write (Iterator start, Iterator end)
{
- assert (start.m_data == end.m_data);
- assert (start.m_current <= end.m_current);
- assert (m_data != start.m_data);
- uint32_t size = end.m_current - start.m_current;
- uint8_t *src = start.m_data + start.GetIndex (size);
- uint8_t *dest = m_data + GetIndex (size);
- memcpy (dest, src, size);
- m_current += size;
+ assert (start.m_data == end.m_data);
+ assert (start.m_current <= end.m_current);
+ assert (m_data != start.m_data);
+ uint32_t size = end.m_current - start.m_current;
+ uint8_t *src = start.m_data + start.GetIndex (size);
+ uint8_t *dest = m_data + GetIndex (size);
+ memcpy (dest, src, size);
+ m_current += size;
}
void
Buffer::Iterator::WriteU8 (uint8_t data, uint32_t len)
{
- uint8_t *current = m_data + GetIndex (len);
- memset (current, data, len);
- m_current += len;
+ uint8_t *current = m_data + GetIndex (len);
+ memset (current, data, len);
+ m_current += len;
}
void
Buffer::Iterator::WriteU8 (uint8_t data)
{
- m_data[GetIndex (1)] = data;
- m_current++;
+ m_data[GetIndex (1)] = data;
+ m_current++;
}
void
Buffer::Iterator::WriteU16 (uint16_t data)
{
- uint16_t *buffer = (uint16_t *)(m_data + GetIndex (2));
- *buffer = data;
- m_current += 2;
+ uint16_t *buffer = (uint16_t *)(m_data + GetIndex (2));
+ *buffer = data;
+ m_current += 2;
}
void
Buffer::Iterator::WriteU32 (uint32_t data)
{
- uint32_t *buffer = (uint32_t *)(m_data + GetIndex (4));
- *buffer = data;
- m_current += 4;
+ uint32_t *buffer = (uint32_t *)(m_data + GetIndex (4));
+ *buffer = data;
+ m_current += 4;
}
void
Buffer::Iterator::WriteU64 (uint64_t data)
{
- uint64_t *buffer = (uint64_t *)(m_data + GetIndex (8));
- *buffer = data;
- m_current += 8;
+ uint64_t *buffer = (uint64_t *)(m_data + GetIndex (8));
+ *buffer = data;
+ m_current += 8;
}
void
Buffer::Iterator::WriteHtonU16 (uint16_t data)
{
- uint8_t *current = m_data + GetIndex (2);
- *(current+0) = (data >> 8) & 0xff;
- *(current+1) = (data >> 0) & 0xff;
- m_current += 2;
+ uint8_t *current = m_data + GetIndex (2);
+ *(current+0) = (data >> 8) & 0xff;
+ *(current+1) = (data >> 0) & 0xff;
+ m_current += 2;
}
void
Buffer::Iterator::WriteHtonU32 (uint32_t data)
{
- uint8_t *current = m_data + GetIndex (4);
- *(current+0) = (data >> 24) & 0xff;
- *(current+1) = (data >> 16) & 0xff;
- *(current+2) = (data >> 8) & 0xff;
- *(current+3) = (data >> 0) & 0xff;
- m_current += 4;
+ uint8_t *current = m_data + GetIndex (4);
+ *(current+0) = (data >> 24) & 0xff;
+ *(current+1) = (data >> 16) & 0xff;
+ *(current+2) = (data >> 8) & 0xff;
+ *(current+3) = (data >> 0) & 0xff;
+ m_current += 4;
}
void
Buffer::Iterator::WriteHtonU64 (uint64_t data)
{
- uint8_t *current = m_data + GetIndex (8);
- *(current+0) = (data >> 56) & 0xff;
- *(current+1) = (data >> 48) & 0xff;
- *(current+2) = (data >> 40) & 0xff;
- *(current+3) = (data >> 32) & 0xff;
- *(current+4) = (data >> 24) & 0xff;
- *(current+5) = (data >> 16) & 0xff;
- *(current+6) = (data >> 8) & 0xff;
- *(current+7) = (data >> 0) & 0xff;
- m_current += 8;
+ uint8_t *current = m_data + GetIndex (8);
+ *(current+0) = (data >> 56) & 0xff;
+ *(current+1) = (data >> 48) & 0xff;
+ *(current+2) = (data >> 40) & 0xff;
+ *(current+3) = (data >> 32) & 0xff;
+ *(current+4) = (data >> 24) & 0xff;
+ *(current+5) = (data >> 16) & 0xff;
+ *(current+6) = (data >> 8) & 0xff;
+ *(current+7) = (data >> 0) & 0xff;
+ m_current += 8;
}
void
Buffer::Iterator::Write (uint8_t const*buffer, uint16_t size)
{
- uint8_t *current = m_data + GetIndex (size);
- memcpy (current, buffer, size);
- m_current += size;
+ uint8_t *current = m_data + GetIndex (size);
+ memcpy (current, buffer, size);
+ m_current += size;
}
uint8_t
Buffer::Iterator::ReadU8 (void)
{
- uint8_t data = m_data[GetIndex(1)];
- m_current++;
- return data;
+ uint8_t data = m_data[GetIndex(1)];
+ m_current++;
+ return data;
}
uint16_t
Buffer::Iterator::ReadU16 (void)
{
- uint16_t *buffer = reinterpret_cast<uint16_t *>(m_data + GetIndex (2));
- m_current += 2;
- return *buffer;
+ uint16_t *buffer = reinterpret_cast<uint16_t *>(m_data + GetIndex (2));
+ m_current += 2;
+ return *buffer;
}
uint32_t
Buffer::Iterator::ReadU32 (void)
{
- uint32_t *buffer = reinterpret_cast<uint32_t *>(m_data + GetIndex (4));
- m_current += 4;
- return *buffer;
+ uint32_t *buffer = reinterpret_cast<uint32_t *>(m_data + GetIndex (4));
+ m_current += 4;
+ return *buffer;
}
uint64_t
Buffer::Iterator::ReadU64 (void)
{
- uint64_t *buffer = reinterpret_cast<uint64_t *>(m_data + GetIndex (8));
- m_current += 8;
- return *buffer;
+ uint64_t *buffer = reinterpret_cast<uint64_t *>(m_data + GetIndex (8));
+ m_current += 8;
+ return *buffer;
}
uint16_t
Buffer::Iterator::ReadNtohU16 (void)
{
- uint8_t *current = m_data + GetIndex (2);
- uint16_t retval = 0;
- retval |= static_cast<uint16_t> (current[0]) << 8;
- retval |= static_cast<uint16_t> (current[1]) << 0;
- m_current += 2;
- return retval;
+ uint8_t *current = m_data + GetIndex (2);
+ uint16_t retval = 0;
+ retval |= static_cast<uint16_t> (current[0]) << 8;
+ retval |= static_cast<uint16_t> (current[1]) << 0;
+ m_current += 2;
+ return retval;
}
uint32_t
Buffer::Iterator::ReadNtohU32 (void)
{
- uint8_t *current = m_data + GetIndex (4);
- uint32_t retval = 0;
- retval |= static_cast<uint32_t> (current[0]) << 24;
- retval |= static_cast<uint32_t> (current[1]) << 16;
- retval |= static_cast<uint32_t> (current[2]) << 8;
- retval |= static_cast<uint32_t> (current[3]) << 0;
- m_current += 4;
- return retval;
+ uint8_t *current = m_data + GetIndex (4);
+ uint32_t retval = 0;
+ retval |= static_cast<uint32_t> (current[0]) << 24;
+ retval |= static_cast<uint32_t> (current[1]) << 16;
+ retval |= static_cast<uint32_t> (current[2]) << 8;
+ retval |= static_cast<uint32_t> (current[3]) << 0;
+ m_current += 4;
+ return retval;
}
uint64_t
Buffer::Iterator::ReadNtohU64 (void)
{
- uint8_t *current = m_data + GetIndex (8);
- uint64_t retval = 0;
- retval |= static_cast<uint64_t> (current[0]) << 56;
- retval |= static_cast<uint64_t> (current[1]) << 48;
- retval |= static_cast<uint64_t> (current[2]) << 40;
- retval |= static_cast<uint64_t> (current[3]) << 32;
- retval |= static_cast<uint64_t> (current[4]) << 24;
- retval |= static_cast<uint64_t> (current[5]) << 16;
- retval |= static_cast<uint64_t> (current[6]) << 8;
- retval |= static_cast<uint64_t> (current[7]) << 0;
- m_current += 8;
- return retval;
+ uint8_t *current = m_data + GetIndex (8);
+ uint64_t retval = 0;
+ retval |= static_cast<uint64_t> (current[0]) << 56;
+ retval |= static_cast<uint64_t> (current[1]) << 48;
+ retval |= static_cast<uint64_t> (current[2]) << 40;
+ retval |= static_cast<uint64_t> (current[3]) << 32;
+ retval |= static_cast<uint64_t> (current[4]) << 24;
+ retval |= static_cast<uint64_t> (current[5]) << 16;
+ retval |= static_cast<uint64_t> (current[6]) << 8;
+ retval |= static_cast<uint64_t> (current[7]) << 0;
+ m_current += 8;
+ return retval;
}
void
Buffer::Iterator::Read (uint8_t *buffer, uint16_t size)
{
- uint8_t *current = m_data + GetIndex (size);
- memcpy (buffer, current, size);
- m_current += size;
+ uint8_t *current = m_data + GetIndex (size);
+ memcpy (buffer, current, size);
+ m_current += size;
}
}; // namespace ns3
--- a/src/common/callback-tracer.h Wed Nov 01 13:00:34 2006 +0100
+++ b/src/common/callback-tracer.h Wed Nov 01 13:11:30 2006 +0100
@@ -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 @@
* 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
--- a/src/common/data-writer.cc Wed Nov 01 13:00:34 2006 +0100
+++ b/src/common/data-writer.cc Wed Nov 01 13:11:30 2006 +0100
@@ -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 @@
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 @@
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
--- a/src/common/data-writer.h Wed Nov 01 13:00:34 2006 +0100
+++ b/src/common/data-writer.h Wed Nov 01 13:11:30 2006 +0100
@@ -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 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
--- a/src/common/f-variable-tracer.h Wed Nov 01 13:00:34 2006 +0100
+++ b/src/common/f-variable-tracer.h Wed Nov 01 13:11:30 2006 +0100
@@ -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 @@
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;
};
--- a/src/common/header.cc Wed Nov 01 13:00:34 2006 +0100
+++ b/src/common/header.cc Wed Nov 01 13:11:30 2006 +0100
@@ -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 @@
std::ostream& operator<< (std::ostream& os, Header const& header)
{
- header.Print (os);
- return os;
+ header.Print (os);
+ return os;
}
}; // namespace ns3
--- a/src/common/header.h Wed Nov 01 13:00:34 2006 +0100
+++ b/src/common/header.h Wed Nov 01 13:11:30 2006 +0100
@@ -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 @@
*/
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);
--- a/src/common/packet.cc Wed Nov 01 13:00:34 2006 +0100
+++ b/src/common/packet.cc Wed Nov 01 13:11:30 2006 +0100
@@ -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 @@
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
--- a/src/common/packet.h Wed Nov 01 13:00:34 2006 +0100
+++ b/src/common/packet.h Wed Nov 01 13:11:30 2006 +0100
@@ -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 @@
*/
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 @@
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
--- a/src/common/pcap-writer.cc Wed Nov 01 13:00:34 2006 +0100
+++ b/src/common/pcap-writer.cc Wed Nov 01 13:11:30 2006 +0100
@@ -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
--- a/src/common/pcap-writer.h Wed Nov 01 13:00:34 2006 +0100
+++ b/src/common/pcap-writer.h Wed Nov 01 13:11:30 2006 +0100
@@ -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 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
--- a/src/common/si-variable-tracer.h Wed Nov 01 13:00:34 2006 +0100
+++ b/src/common/si-variable-tracer.h Wed Nov 01 13:11:30 2006 +0100
@@ -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 @@
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 @@
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
--- a/src/common/stream-tracer-test.cc Wed Nov 01 13:00:34 2006 +0100
+++ b/src/common/stream-tracer-test.cc Wed Nov 01 13:11:30 2006 +0100
@@ -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 @@
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;
}
--- a/src/common/stream-tracer.h Wed Nov 01 13:00:34 2006 +0100
+++ b/src/common/stream-tracer.h Wed Nov 01 13:11:30 2006 +0100
@@ -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 @@
*/
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
--- a/src/common/tags.cc Wed Nov 01 13:00:34 2006 +0100
+++ b/src/common/tags.cc Wed Nov 01 13:11:30 2006 +0100
@@ -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 @@
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 @@
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 = ©->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 = ©->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 @@
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 @@
TagsTest::TagsTest ()
- : Test ("Tags")
+ : Test ("Tags")
{}
TagsTest::~TagsTest ()
{}
@@ -233,92 +233,92 @@
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;
--- a/src/common/tags.h Wed Nov 01 13:00:34 2006 +0100
+++ b/src/common/tags.h Wed Nov 01 13:11:30 2006 +0100
@@ -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 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 @@
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 @@
/**************************************************************
- An implementation of the templates defined above
+ An implementation of the templates defined above
*************************************************************/
#include <cassert>
#include <string>
@@ -116,15 +116,15 @@
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 @@
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 @@
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 @@
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;
}
--- a/src/common/trace-container.cc Wed Nov 01 13:00:34 2006 +0100
+++ b/src/common/trace-container.cc Wed Nov 01 13:11:30 2006 +0100
@@ -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 ()
{
- 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 @@
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;
+ }
+ }
}
--- a/src/common/trace-container.h Wed Nov 01 13:00:34 2006 +0100
+++ b/src/common/trace-container.h Wed Nov 01 13:11:30 2006 +0100
@@ -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 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 @@
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
}
--- a/src/common/trailer.cc Wed Nov 01 13:00:34 2006 +0100
+++ b/src/common/trailer.cc Wed Nov 01 13:11:30 2006 +0100
@@ -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 @@
std::ostream& operator<< (std::ostream& os, Trailer const& trailer)
{
- trailer.Print (os);
- return os;
+ trailer.Print (os);
+ return os;
}
}; // namespace ns3
--- a/src/common/trailer.h Wed Nov 01 13:00:34 2006 +0100
+++ b/src/common/trailer.h Wed Nov 01 13:11:30 2006 +0100
@@ -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 @@
*/
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);
--- a/src/common/ui-variable-tracer.h Wed Nov 01 13:00:34 2006 +0100
+++ b/src/common/ui-variable-tracer.h Wed Nov 01 13:11:30 2006 +0100
@@ -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 @@
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 @@
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
--- a/src/common/variable-tracer-test.cc Wed Nov 01 13:00:34 2006 +0100
+++ b/src/common/variable-tracer-test.cc Wed Nov 01 13:11:30 2006 +0100
@@ -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 @@
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;
--- a/src/core/callback-test.cc Wed Nov 01 13:00:34 2006 +0100
+++ b/src/core/callback-test.cc Wed Nov 01 13:11:30 2006 +0100
@@ -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 @@
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;
--- a/src/core/callback.h Wed Nov 01 13:00:34 2006 +0100
+++ b/src/core/callback.h Wed Nov 01 13:11:30 2006 +0100
@@ -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 @@
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 @@
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 @@
* \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 @@
*/
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 @@
*/
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 @@
*/
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 @@
*/
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 @@
*/
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 @@
*/
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 @@
*/
template <typename R>
Callback<R> MakeCallback (R (*fnPtr) ()) {
- return Callback<R> (fnPtr);
+ return Callback<R> (fnPtr);
}
/**
* \ingroup MakeCallback
@@ -336,7 +336,7 @@
*/
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 @@
*/
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 @@
*/
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 @@
*/
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 @@
*/
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 @@
*/
template <typename R>
Callback<R> MakeNullCallback (void) {
- return Callback<R> ();
+ return Callback<R> ();
}
/**
* \ingroup MakeCallback
@@ -403,7 +403,7 @@
*/
template <typename R, typename T1>
Callback<R,T1> MakeNullCallback (void) {
- return Callback<R,T1> ();
+ return Callback<R,T1> ();
}
/**
* \ingroup MakeCallback
@@ -413,7 +413,7 @@
*/
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 @@
*/
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 @@
*/
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 @@
*/
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 @@
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);
}
--- a/src/core/reference-list-test.cc Wed Nov 01 13:00:34 2006 +0100
+++ b/src/core/reference-list-test.cc Wed Nov 01 13:11:30 2006 +0100
@@ -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 @@
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;
}
--- a/src/core/reference-list.h Wed Nov 01 13:00:34 2006 +0100
+++ b/src/core/reference-list.h Wed Nov 01 13:11:30 2006 +0100
@@ -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 @@
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
--- a/src/core/system-file.h Wed Nov 01 13:00:34 2006 +0100
+++ b/src/core/system-file.h Wed Nov 01 13:11:30 2006 +0100
@@ -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 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
--- a/src/core/system-wall-clock-ms.h Wed Nov 01 13:00:34 2006 +0100
+++ b/src/core/system-wall-clock-ms.h Wed Nov 01 13:11:30 2006 +0100
@@ -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 @@
*/
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
--- a/src/core/test.cc Wed Nov 01 13:00:34 2006 +0100
+++ b/src/core/test.cc Wed Nov 01 13:11:30 2006 +0100
@@ -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 @@
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 @@
std::ostream &
Test::Failure (void)
{
- return TestManager::Failure ();
+ return TestManager::Failure ();
}
}; // namespace ns3
--- a/src/core/test.h Wed Nov 01 13:00:34 2006 +0100
+++ b/src/core/test.h Wed Nov 01 13:11:30 2006 +0100
@@ -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 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 @@
*/
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
--- a/src/core/unix-system-file.cc Wed Nov 01 13:00:34 2006 +0100
+++ b/src/core/unix-system-file.cc Wed Nov 01 13:11:30 2006 +0100
@@ -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 @@
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 @@
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
--- a/src/core/unix-system-wall-clock-ms.cc Wed Nov 01 13:00:34 2006 +0100
+++ b/src/core/unix-system-wall-clock-ms.cc Wed Nov 01 13:11:30 2006 +0100
@@ -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 @@
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
--- a/src/core/win32-system-file.cc Wed Nov 01 13:00:34 2006 +0100
+++ b/src/core/win32-system-file.cc Wed Nov 01 13:11:30 2006 +0100
@@ -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 @@
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 @@
}
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
--- a/src/core/win32-system-wall-clock-ms.cc Wed Nov 01 13:00:34 2006 +0100
+++ b/src/core/win32-system-wall-clock-ms.cc Wed Nov 01 13:11:30 2006 +0100
@@ -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 @@
class SystemWallClockMsPrivate {
public:
- void start (void);
- unsigned long long end (void);
+ void start (void);
+ unsigned long long end (void);
private:
};
@@ -38,28 +38,28 @@
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
--- a/src/simulator/event-id.cc Wed Nov 01 13:00:34 2006 +0100
+++ b/src/simulator/event-id.cc Wed Nov 01 13:11:30 2006 +0100
@@ -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;
}
--- a/src/simulator/event-id.h Wed Nov 01 13:00:34 2006 +0100
+++ b/src/simulator/event-id.h Wed Nov 01 13:11:30 2006 +0100
@@ -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 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
--- a/src/simulator/event-impl.cc Wed Nov 01 13:00:34 2006 +0100
+++ b/src/simulator/event-impl.cc Wed Nov 01 13:11:30 2006 +0100
@@ -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 ()
- : 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
--- a/src/simulator/event-impl.h Wed Nov 01 13:00:34 2006 +0100
+++ b/src/simulator/event-impl.h Wed Nov 01 13:11:30 2006 +0100
@@ -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 @@
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
--- a/src/simulator/nstime.h Wed Nov 01 13:00:34 2006 +0100
+++ b/src/simulator/nstime.h Wed Nov 01 13:11:30 2006 +0100
@@ -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 @@
*/
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 @@
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
--- a/src/simulator/scheduler-factory.cc Wed Nov 01 13:00:34 2006 +0100
+++ b/src/simulator/scheduler-factory.cc Wed Nov 01 13:11:30 2006 +0100
@@ -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 @@
Scheduler *
SchedulerFactory::Create (void) const
{
- return RealCreate ();
+ return RealCreate ();
}
}; // namespace ns3
--- a/src/simulator/scheduler-factory.h Wed Nov 01 13:00:34 2006 +0100
+++ b/src/simulator/scheduler-factory.h Wed Nov 01 13:11:30 2006 +0100
@@ -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 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
--- a/src/simulator/scheduler-heap.cc Wed Nov 01 13:00:34 2006 +0100
+++ b/src/simulator/scheduler-heap.cc Wed Nov 01 13:11:30 2006 +0100
@@ -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 @@
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 @@
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
--- a/src/simulator/scheduler-heap.h Wed Nov 01 13:00:34 2006 +0100
+++ b/src/simulator/scheduler-heap.h Wed Nov 01 13:11:30 2006 +0100
@@ -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 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
--- a/src/simulator/scheduler-list.cc Wed Nov 01 13:00:34 2006 +0100
+++ b/src/simulator/scheduler-list.cc Wed Nov 01 13:11:30 2006 +0100
@@ -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 @@
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
--- a/src/simulator/scheduler-list.h Wed Nov 01 13:00:34 2006 +0100
+++ b/src/simulator/scheduler-list.h Wed Nov 01 13:11:30 2006 +0100
@@ -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 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
--- a/src/simulator/scheduler-map.cc Wed Nov 01 13:00:34 2006 +0100
+++ b/src/simulator/scheduler-map.cc Wed Nov 01 13:11:30 2006 +0100
@@ -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 @@
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 ());
}
--- a/src/simulator/scheduler-map.h Wed Nov 01 13:00:34 2006 +0100
+++ b/src/simulator/scheduler-map.h Wed Nov 01 13:11:30 2006 +0100
@@ -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 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
--- a/src/simulator/scheduler.cc Wed Nov 01 13:00:34 2006 +0100
+++ b/src/simulator/scheduler.cc Wed Nov 01 13:11:30 2006 +0100
@@ -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 @@
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
--- a/src/simulator/scheduler.h Wed Nov 01 13:00:34 2006 +0100
+++ b/src/simulator/scheduler.h Wed Nov 01 13:11:30 2006 +0100
@@ -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 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
--- a/src/simulator/simulator.cc Wed Nov 01 13:00:34 2006 +0100
+++ b/src/simulator/simulator.cc Wed Nov 01 13:11:30 2006 +0100
@@ -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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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;
--- a/src/simulator/simulator.h Wed Nov 01 13:00:34 2006 +0100
+++ b/src/simulator/simulator.h Wed Nov 01 13:11:30 2006 +0100
@@ -1,4 +1,4 @@
-/* -*- Mode:NS3; -*- */
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005 INRIA
* All rights reserved.
@@ -49,530 +49,530 @@
*/
class Simulator {
public:
- /**
- * Enable ParallelSimulation.
- * This method must be invoked before every other method exported
- * by the Simulator class.
- */
- static void EnableParallelSimulation (void);
- /**
- * Force the use of an event scheduler based on a linked-list.
- * This method must be invoked before any other method exported
- * by the Simulator class.
- * - insert: O(n)
- * - remove: O(1)
- */
- static void SetLinkedList (void);
- /**
- * Force the use of an event scheduler based on a binary heap.
- * This method must be invoked before any other method exported
- * by the Simulator class.
- * - insert: O(log(n))
- * - remove: O(log(n))
- */
- static void SetBinaryHeap (void);
- /**
- * Force the use of an event scheduler based on a std::map.
- * This method must be invoked before any other method exported
- * by the Simulator class.
- * - insert: O(log(n))
- * - remove: O(log(n))
- */
- static void SetStdMap (void);
+ /**
+ * Enable ParallelSimulation.
+ * This method must be invoked before every other method exported
+ * by the Simulator class.
+ */
+ static void EnableParallelSimulation (void);
+ /**
+ * Force the use of an event scheduler based on a linked-list.
+ * This method must be invoked before any other method exported
+ * by the Simulator class.
+ * - insert: O(n)
+ * - remove: O(1)
+ */
+ static void SetLinkedList (void);
+ /**
+ * Force the use of an event scheduler based on a binary heap.
+ * This method must be invoked before any other method exported
+ * by the Simulator class.
+ * - insert: O(log(n))
+ * - remove: O(log(n))
+ */
+ static void SetBinaryHeap (void);
+ /**
+ * Force the use of an event scheduler based on a std::map.
+ * This method must be invoked before any other method exported
+ * by the Simulator class.
+ * - insert: O(log(n))
+ * - remove: O(log(n))
+ */
+ static void SetStdMap (void);
- /**
- * Force the use of a user-provided event scheduler.
- * This method must be invoked before any other method exported
- * by the Simulator class.
- */
- static void SetExternal (SchedulerFactory const*factory);
+ /**
+ * Force the use of a user-provided event scheduler.
+ * This method must be invoked before any other method exported
+ * by the Simulator class.
+ */
+ static void SetExternal (SchedulerFactory const*factory);
- /**
- * Enable logging to the file identified by filename. If the file
- * does not exist, it is created. If it exists, it is destroyed and
- * re-created. Every scheduling event is logged to this file in a
- * simple text format which can be read back by the event replay
- * utility. This allows you to record the scheduling behavior of
- * a simulation, and measure the exact overhead related to
- * event scheduling with the event replay utility. It is also possible
- * to compare the performance of every scheduling algorithms on this
- * specific scheduling load.
- * This method must be invoked before any call to Simulator::run
- * @param filename the name of the file to log to
- */
- static void EnableLogTo (char const *filename);
+ /**
+ * Enable logging to the file identified by filename. If the file
+ * does not exist, it is created. If it exists, it is destroyed and
+ * re-created. Every scheduling event is logged to this file in a
+ * simple text format which can be read back by the event replay
+ * utility. This allows you to record the scheduling behavior of
+ * a simulation, and measure the exact overhead related to
+ * event scheduling with the event replay utility. It is also possible
+ * to compare the performance of every scheduling algorithms on this
+ * specific scheduling load.
+ * This method must be invoked before any call to Simulator::run
+ * @param filename the name of the file to log to
+ */
+ static void EnableLogTo (char const *filename);
- /**
- * Every event scheduled by the Simulator::insertAtDestroy method is
- * invoked. Then, we ensure that any memory allocated by the
- * Simulator is freed.
- * This method is typically invoked at the end of a simulation
- * to avoid false-positive reports by a leak checker.
- * After this method has been invoked, it is actually possible
- * to restart a new simulation with a set of calls to Simulator::run
- * and Simulator::insert_*.
- */
- static void Destroy (void);
+ /**
+ * Every event scheduled by the Simulator::insertAtDestroy method is
+ * invoked. Then, we ensure that any memory allocated by the
+ * Simulator is freed.
+ * This method is typically invoked at the end of a simulation
+ * to avoid false-positive reports by a leak checker.
+ * After this method has been invoked, it is actually possible
+ * to restart a new simulation with a set of calls to Simulator::run
+ * and Simulator::insert_*.
+ */
+ static void Destroy (void);
- /**
- * If there any any events lefts to be scheduled, return
- * true. Return false otherwise.
- */
- static bool IsFinished (void);
- /**
- * If Simulator::isFinished returns true, the behavior of this
- * method is undefined. Otherwise, it returns the microsecond-based
- * time of the next event expected to be scheduled.
- */
- static Time Next (void);
+ /**
+ * If there any any events lefts to be scheduled, return
+ * true. Return false otherwise.
+ */
+ static bool IsFinished (void);
+ /**
+ * If Simulator::isFinished returns true, the behavior of this
+ * method is undefined. Otherwise, it returns the microsecond-based
+ * time of the next event expected to be scheduled.
+ */
+ static Time Next (void);
- /**
- * Run the simulation until one of:
- * - no events are present anymore
- * - the user called Simulator::stop
- * - the user called Simulator::stopAtUs and the
- * expiration time of the next event to be processed
- * is greater than or equal to the stop time.
- */
- static void Run (void);
- /**
- * If an event invokes this method, it will be the last
- * event scheduled by the Simulator::run method before
- * returning to the caller.
- */
- static void Stop (void);
- /**
- * Force the Simulator::run method to return to the caller
- * when the expiration time of the next event to be processed
- * is greater than or equal to the stop time.
- * @param time the stop time.
- */
- static void StopAt (Time const &time);
+ /**
+ * Run the simulation until one of:
+ * - no events are present anymore
+ * - the user called Simulator::stop
+ * - the user called Simulator::stopAtUs and the
+ * expiration time of the next event to be processed
+ * is greater than or equal to the stop time.
+ */
+ static void Run (void);
+ /**
+ * If an event invokes this method, it will be the last
+ * event scheduled by the Simulator::run method before
+ * returning to the caller.
+ */
+ static void Stop (void);
+ /**
+ * Force the Simulator::run method to return to the caller
+ * when the expiration time of the next event to be processed
+ * is greater than or equal to the stop time.
+ * @param time the stop time.
+ */
+ static void StopAt (Time const &time);
- /**
- * Schedule an event to expire when time is reached.
- * When the event expires, the input method will be invoked
- * on the input object.
- *
- * @param time the expiration time of the event.
- * @param mem_ptr member method pointer to invoke
- * @param obj the object on which to invoke the member method
- * @returns an id for the scheduled event.
- */
- template <typename T>
- static EventId Schedule (Time const &time, void (T::*mem_ptr) (void), T *obj);
- /**
- * @param time the expiration time of the event.
- * @param mem_ptr member method pointer to invoke
- * @param obj the object on which to invoke the member method
- * @param a1 the first argument to pass to the invoked method
- * @returns an id for the scheduled event.
- */
- template <typename T, typename T1>
- static EventId Schedule (Time const &time, void (T::*mem_ptr) (T1), T* obj, T1 a1);
- /**
- * @param time the expiration time of the event.
- * @param mem_ptr member method pointer to invoke
- * @param obj the object on which to invoke the member method
- * @param a1 the first argument to pass to the invoked method
- * @param a2 the second argument to pass to the invoked method
- * @returns an id for the scheduled event.
- */
- template <typename T, typename T1, typename T2>
- static EventId Schedule (Time const &time, void (T::*mem_ptr) (T1,T2), T* obj, T1 a1, T2 a2);
- /**
- * @param time the expiration time of the event.
- * @param mem_ptr member method pointer to invoke
- * @param obj the object on which to invoke the member method
- * @param a1 the first argument to pass to the invoked method
- * @param a2 the second argument to pass to the invoked method
- * @param a3 the third argument to pass to the invoked method
- * @returns an id for the scheduled event.
- */
- template <typename T, typename T1, typename T2, typename T3>
- static EventId Schedule (Time const &time, void (T::*mem_ptr) (T1,T2,T3), T* obj, T1 a1, T2 a2, T3 a3);
- /**
- * @param time the expiration time of the event.
- * @param mem_ptr member method pointer to invoke
- * @param obj the object on which to invoke the member method
- * @param a1 the first argument to pass to the invoked method
- * @param a2 the second argument to pass to the invoked method
- * @param a3 the third argument to pass to the invoked method
- * @param a4 the fourth argument to pass to the invoked method
- * @returns an id for the scheduled event.
- */
- template <typename T, typename T1, typename T2, typename T3, typename T4>
- static EventId Schedule (Time const &time, void (T::*mem_ptr) (T1,T2,T3,T4), T* obj, T1 a1, T2 a2, T3 a3, T4 a4);
- /**
- * @param time the expiration time of the event.
- * @param mem_ptr member method pointer to invoke
- * @param obj the object on which to invoke the member method
- * @param a1 the first argument to pass to the invoked method
- * @param a2 the second argument to pass to the invoked method
- * @param a3 the third argument to pass to the invoked method
- * @param a4 the fourth argument to pass to the invoked method
- * @param a5 the fifth argument to pass to the invoked method
- * @returns an id for the scheduled event.
- */
- template <typename T, typename T1, typename T2, typename T3, typename T4, typename T5>
- static EventId Schedule (Time const &time, void (T::*mem_ptr) (T1,T2,T3,T4,T5), T* obj,
- T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
- /**
- * @param time the expiration time of the event.
- * @param f the function to invoke
- * @returns an id for the scheduled event.
- */
- static EventId Schedule (Time const &time, void (*f) (void));
- /**
- * @param time the expiration time of the event.
- * @param f the function to invoke
- * @param a1 the first argument to pass to the function to invoke
- * @returns an id for the scheduled event.
- */
- template <typename T1>
- static EventId Schedule (Time const &time, void (*f) (T1), T1 a1);
- /**
- * @param time the expiration time of the event.
- * @param f the function to invoke
- * @param a1 the first argument to pass to the function to invoke
- * @param a2 the second argument to pass to the function to invoke
- * @returns an id for the scheduled event.
- */
- template <typename T1, typename T2>
- static EventId Schedule (Time const &time, void (*f) (T1,T2), T1 a1, T2 a2);
- /**
- * @param time the expiration time of the event.
- * @param f the function to invoke
- * @param a1 the first argument to pass to the function to invoke
- * @param a2 the second argument to pass to the function to invoke
- * @param a3 the third argument to pass to the function to invoke
- * @returns an id for the scheduled event.
- */
- template <typename T1, typename T2, typename T3>
- static EventId Schedule (Time const &time, void (*f) (T1,T2,T3), T1 a1, T2 a2, T3 a3);
- /**
- * @param time the expiration time of the event.
- * @param f the function to invoke
- * @param a1 the first argument to pass to the function to invoke
- * @param a2 the second argument to pass to the function to invoke
- * @param a3 the third argument to pass to the function to invoke
- * @param a4 the fourth argument to pass to the function to invoke
- * @returns an id for the scheduled event.
- */
- template <typename T1, typename T2, typename T3, typename T4>
- static EventId Schedule (Time const &time, void (*f) (T1,T2,T3,T4), T1 a1, T2 a2, T3 a3, T4 a4);
- /**
- * @param time the expiration time of the event.
- * @param f the function to invoke
- * @param a1 the first argument to pass to the function to invoke
- * @param a2 the second argument to pass to the function to invoke
- * @param a3 the third argument to pass to the function to invoke
- * @param a4 the fourth argument to pass to the function to invoke
- * @param a5 the fifth argument to pass to the function to invoke
- * @returns an id for the scheduled event.
- */
- template <typename T1, typename T2, typename T3, typename T4, typename T5>
- static EventId Schedule (Time const &time, void (*f) (T1,T2,T3,T4,T5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
+ /**
+ * Schedule an event to expire when time is reached.
+ * When the event expires, the input method will be invoked
+ * on the input object.
+ *
+ * @param time the expiration time of the event.
+ * @param mem_ptr member method pointer to invoke
+ * @param obj the object on which to invoke the member method
+ * @returns an id for the scheduled event.
+ */
+ template <typename T>
+ static EventId Schedule (Time const &time, void (T::*mem_ptr) (void), T *obj);
+ /**
+ * @param time the expiration time of the event.
+ * @param mem_ptr member method pointer to invoke
+ * @param obj the object on which to invoke the member method
+ * @param a1 the first argument to pass to the invoked method
+ * @returns an id for the scheduled event.
+ */
+ template <typename T, typename T1>
+ static EventId Schedule (Time const &time, void (T::*mem_ptr) (T1), T* obj, T1 a1);
+ /**
+ * @param time the expiration time of the event.
+ * @param mem_ptr member method pointer to invoke
+ * @param obj the object on which to invoke the member method
+ * @param a1 the first argument to pass to the invoked method
+ * @param a2 the second argument to pass to the invoked method
+ * @returns an id for the scheduled event.
+ */
+ template <typename T, typename T1, typename T2>
+ static EventId Schedule (Time const &time, void (T::*mem_ptr) (T1,T2), T* obj, T1 a1, T2 a2);
+ /**
+ * @param time the expiration time of the event.
+ * @param mem_ptr member method pointer to invoke
+ * @param obj the object on which to invoke the member method
+ * @param a1 the first argument to pass to the invoked method
+ * @param a2 the second argument to pass to the invoked method
+ * @param a3 the third argument to pass to the invoked method
+ * @returns an id for the scheduled event.
+ */
+ template <typename T, typename T1, typename T2, typename T3>
+ static EventId Schedule (Time const &time, void (T::*mem_ptr) (T1,T2,T3), T* obj, T1 a1, T2 a2, T3 a3);
+ /**
+ * @param time the expiration time of the event.
+ * @param mem_ptr member method pointer to invoke
+ * @param obj the object on which to invoke the member method
+ * @param a1 the first argument to pass to the invoked method
+ * @param a2 the second argument to pass to the invoked method
+ * @param a3 the third argument to pass to the invoked method
+ * @param a4 the fourth argument to pass to the invoked method
+ * @returns an id for the scheduled event.
+ */
+ template <typename T, typename T1, typename T2, typename T3, typename T4>
+ static EventId Schedule (Time const &time, void (T::*mem_ptr) (T1,T2,T3,T4), T* obj, T1 a1, T2 a2, T3 a3, T4 a4);
+ /**
+ * @param time the expiration time of the event.
+ * @param mem_ptr member method pointer to invoke
+ * @param obj the object on which to invoke the member method
+ * @param a1 the first argument to pass to the invoked method
+ * @param a2 the second argument to pass to the invoked method
+ * @param a3 the third argument to pass to the invoked method
+ * @param a4 the fourth argument to pass to the invoked method
+ * @param a5 the fifth argument to pass to the invoked method
+ * @returns an id for the scheduled event.
+ */
+ template <typename T, typename T1, typename T2, typename T3, typename T4, typename T5>
+ static EventId Schedule (Time const &time, void (T::*mem_ptr) (T1,T2,T3,T4,T5), T* obj,
+ T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
+ /**
+ * @param time the expiration time of the event.
+ * @param f the function to invoke
+ * @returns an id for the scheduled event.
+ */
+ static EventId Schedule (Time const &time, void (*f) (void));
+ /**
+ * @param time the expiration time of the event.
+ * @param f the function to invoke
+ * @param a1 the first argument to pass to the function to invoke
+ * @returns an id for the scheduled event.
+ */
+ template <typename T1>
+ static EventId Schedule (Time const &time, void (*f) (T1), T1 a1);
+ /**
+ * @param time the expiration time of the event.
+ * @param f the function to invoke
+ * @param a1 the first argument to pass to the function to invoke
+ * @param a2 the second argument to pass to the function to invoke
+ * @returns an id for the scheduled event.
+ */
+ template <typename T1, typename T2>
+ static EventId Schedule (Time const &time, void (*f) (T1,T2), T1 a1, T2 a2);
+ /**
+ * @param time the expiration time of the event.
+ * @param f the function to invoke
+ * @param a1 the first argument to pass to the function to invoke
+ * @param a2 the second argument to pass to the function to invoke
+ * @param a3 the third argument to pass to the function to invoke
+ * @returns an id for the scheduled event.
+ */
+ template <typename T1, typename T2, typename T3>
+ static EventId Schedule (Time const &time, void (*f) (T1,T2,T3), T1 a1, T2 a2, T3 a3);
+ /**
+ * @param time the expiration time of the event.
+ * @param f the function to invoke
+ * @param a1 the first argument to pass to the function to invoke
+ * @param a2 the second argument to pass to the function to invoke
+ * @param a3 the third argument to pass to the function to invoke
+ * @param a4 the fourth argument to pass to the function to invoke
+ * @returns an id for the scheduled event.
+ */
+ template <typename T1, typename T2, typename T3, typename T4>
+ static EventId Schedule (Time const &time, void (*f) (T1,T2,T3,T4), T1 a1, T2 a2, T3 a3, T4 a4);
+ /**
+ * @param time the expiration time of the event.
+ * @param f the function to invoke
+ * @param a1 the first argument to pass to the function to invoke
+ * @param a2 the second argument to pass to the function to invoke
+ * @param a3 the third argument to pass to the function to invoke
+ * @param a4 the fourth argument to pass to the function to invoke
+ * @param a5 the fifth argument to pass to the function to invoke
+ * @returns an id for the scheduled event.
+ */
+ template <typename T1, typename T2, typename T3, typename T4, typename T5>
+ static EventId Schedule (Time const &time, void (*f) (T1,T2,T3,T4,T5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
- /**
- * Schedule an event to expire Now. All events scheduled to
- * to expire "Now" are scheduled FIFO, after all normal events
- * have expired.
- *
- * @param mem_ptr member method pointer to invoke
- * @param obj the object on which to invoke the member method
- */
- template <typename T>
- static void ScheduleNow (void (T::*mem_ptr) (void), T *obj);
- /**
- * @param mem_ptr member method pointer to invoke
- * @param obj the object on which to invoke the member method
- * @param a1 the first argument to pass to the invoked method
- */
- template <typename T, typename T1>
- static void ScheduleNow (void (T::*mem_ptr) (T1), T* obj, T1 a1);
- /**
- * @param mem_ptr member method pointer to invoke
- * @param obj the object on which to invoke the member method
- * @param a1 the first argument to pass to the invoked method
- * @param a2 the second argument to pass to the invoked method
- */
- template <typename T, typename T1, typename T2>
- static void ScheduleNow (void (T::*mem_ptr) (T1,T2), T* obj, T1 a1, T2 a2);
- /**
- * @param time the expiration time of the event.
- * @param mem_ptr member method pointer to invoke
- * @param obj the object on which to invoke the member method
- * @param a1 the first argument to pass to the invoked method
- * @param a2 the second argument to pass to the invoked method
- * @param a3 the third argument to pass to the invoked method
- */
- template <typename T, typename T1, typename T2, typename T3>
- static void ScheduleNow (void (T::*mem_ptr) (T1,T2,T3), T* obj, T1 a1, T2 a2, T3 a3);
- /**
- * @param mem_ptr member method pointer to invoke
- * @param obj the object on which to invoke the member method
- * @param a1 the first argument to pass to the invoked method
- * @param a2 the second argument to pass to the invoked method
- * @param a3 the third argument to pass to the invoked method
- * @param a4 the fourth argument to pass to the invoked method
- */
- template <typename T, typename T1, typename T2, typename T3, typename T4>
- static void ScheduleNow (void (T::*mem_ptr) (T1,T2,T3,T4), T* obj,
- T1 a1, T2 a2, T3 a3, T4 a4);
- /**
- * @param mem_ptr member method pointer to invoke
- * @param obj the object on which to invoke the member method
- * @param a1 the first argument to pass to the invoked method
- * @param a2 the second argument to pass to the invoked method
- * @param a3 the third argument to pass to the invoked method
- * @param a4 the fourth argument to pass to the invoked method
- * @param a5 the fifth argument to pass to the invoked method
- */
- template <typename T, typename T1, typename T2, typename T3, typename T4, typename T5>
- static void ScheduleNow (void (T::*mem_ptr) (T1,T2,T3,T4,T5), T* obj,
- T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
- /**
- * @param f the function to invoke
- */
- static void ScheduleNow (void (*f) (void));
- /**
- * @param f the function to invoke
- * @param a1 the first argument to pass to the function to invoke
- */
- template <typename T1>
- static void ScheduleNow (void (*f) (T1), T1 a1);
- /**
- * @param f the function to invoke
- * @param a1 the first argument to pass to the function to invoke
- * @param a2 the second argument to pass to the function to invoke
- */
- template <typename T1, typename T2>
- static void ScheduleNow (void (*f) (T1,T2), T1 a1, T2 a2);
- /**
- * @param f the function to invoke
- * @param a1 the first argument to pass to the function to invoke
- * @param a2 the second argument to pass to the function to invoke
- * @param a3 the third argument to pass to the function to invoke
- */
- template <typename T1, typename T2, typename T3>
- static void ScheduleNow (void (*f) (T1,T2,T3), T1 a1, T2 a2, T3 a3);
- /**
- * @param f the function to invoke
- * @param a1 the first argument to pass to the function to invoke
- * @param a2 the second argument to pass to the function to invoke
- * @param a3 the third argument to pass to the function to invoke
- * @param a4 the fourth argument to pass to the function to invoke
- */
- template <typename T1, typename T2, typename T3, typename T4>
- static void ScheduleNow (void (*f) (T1,T2,T3,T4), T1 a1, T2 a2, T3 a3, T4 a4);
- /**
- * @param f the function to invoke
- * @param a1 the first argument to pass to the function to invoke
- * @param a2 the second argument to pass to the function to invoke
- * @param a3 the third argument to pass to the function to invoke
- * @param a4 the fourth argument to pass to the function to invoke
- * @param a5 the fifth argument to pass to the function to invoke
- */
- template <typename T1, typename T2, typename T3, typename T4, typename T5>
- static void ScheduleNow (void (*f) (T1,T2,T3,T4,T5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
+ /**
+ * Schedule an event to expire Now. All events scheduled to
+ * to expire "Now" are scheduled FIFO, after all normal events
+ * have expired.
+ *
+ * @param mem_ptr member method pointer to invoke
+ * @param obj the object on which to invoke the member method
+ */
+ template <typename T>
+ static void ScheduleNow (void (T::*mem_ptr) (void), T *obj);
+ /**
+ * @param mem_ptr member method pointer to invoke
+ * @param obj the object on which to invoke the member method
+ * @param a1 the first argument to pass to the invoked method
+ */
+ template <typename T, typename T1>
+ static void ScheduleNow (void (T::*mem_ptr) (T1), T* obj, T1 a1);
+ /**
+ * @param mem_ptr member method pointer to invoke
+ * @param obj the object on which to invoke the member method
+ * @param a1 the first argument to pass to the invoked method
+ * @param a2 the second argument to pass to the invoked method
+ */
+ template <typename T, typename T1, typename T2>
+ static void ScheduleNow (void (T::*mem_ptr) (T1,T2), T* obj, T1 a1, T2 a2);
+ /**
+ * @param time the expiration time of the event.
+ * @param mem_ptr member method pointer to invoke
+ * @param obj the object on which to invoke the member method
+ * @param a1 the first argument to pass to the invoked method
+ * @param a2 the second argument to pass to the invoked method
+ * @param a3 the third argument to pass to the invoked method
+ */
+ template <typename T, typename T1, typename T2, typename T3>
+ static void ScheduleNow (void (T::*mem_ptr) (T1,T2,T3), T* obj, T1 a1, T2 a2, T3 a3);
+ /**
+ * @param mem_ptr member method pointer to invoke
+ * @param obj the object on which to invoke the member method
+ * @param a1 the first argument to pass to the invoked method
+ * @param a2 the second argument to pass to the invoked method
+ * @param a3 the third argument to pass to the invoked method
+ * @param a4 the fourth argument to pass to the invoked method
+ */
+ template <typename T, typename T1, typename T2, typename T3, typename T4>
+ static void ScheduleNow (void (T::*mem_ptr) (T1,T2,T3,T4), T* obj,
+ T1 a1, T2 a2, T3 a3, T4 a4);
+ /**
+ * @param mem_ptr member method pointer to invoke
+ * @param obj the object on which to invoke the member method
+ * @param a1 the first argument to pass to the invoked method
+ * @param a2 the second argument to pass to the invoked method
+ * @param a3 the third argument to pass to the invoked method
+ * @param a4 the fourth argument to pass to the invoked method
+ * @param a5 the fifth argument to pass to the invoked method
+ */
+ template <typename T, typename T1, typename T2, typename T3, typename T4, typename T5>
+ static void ScheduleNow (void (T::*mem_ptr) (T1,T2,T3,T4,T5), T* obj,
+ T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
+ /**
+ * @param f the function to invoke
+ */
+ static void ScheduleNow (void (*f) (void));
+ /**
+ * @param f the function to invoke
+ * @param a1 the first argument to pass to the function to invoke
+ */
+ template <typename T1>
+ static void ScheduleNow (void (*f) (T1), T1 a1);
+ /**
+ * @param f the function to invoke
+ * @param a1 the first argument to pass to the function to invoke
+ * @param a2 the second argument to pass to the function to invoke
+ */
+ template <typename T1, typename T2>
+ static void ScheduleNow (void (*f) (T1,T2), T1 a1, T2 a2);
+ /**
+ * @param f the function to invoke
+ * @param a1 the first argument to pass to the function to invoke
+ * @param a2 the second argument to pass to the function to invoke
+ * @param a3 the third argument to pass to the function to invoke
+ */
+ template <typename T1, typename T2, typename T3>
+ static void ScheduleNow (void (*f) (T1,T2,T3), T1 a1, T2 a2, T3 a3);
+ /**
+ * @param f the function to invoke
+ * @param a1 the first argument to pass to the function to invoke
+ * @param a2 the second argument to pass to the function to invoke
+ * @param a3 the third argument to pass to the function to invoke
+ * @param a4 the fourth argument to pass to the function to invoke
+ */
+ template <typename T1, typename T2, typename T3, typename T4>
+ static void ScheduleNow (void (*f) (T1,T2,T3,T4), T1 a1, T2 a2, T3 a3, T4 a4);
+ /**
+ * @param f the function to invoke
+ * @param a1 the first argument to pass to the function to invoke
+ * @param a2 the second argument to pass to the function to invoke
+ * @param a3 the third argument to pass to the function to invoke
+ * @param a4 the fourth argument to pass to the function to invoke
+ * @param a5 the fifth argument to pass to the function to invoke
+ */
+ template <typename T1, typename T2, typename T3, typename T4, typename T5>
+ static void ScheduleNow (void (*f) (T1,T2,T3,T4,T5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
- /**
- * Schedule an event to expire at Destroy time. All events
- * scheduled to expire at "Destroy" time are scheduled FIFO,
- * after all normal events have expired and only when
- * Simulator::Destroy is invoked.
- *
- * @param mem_ptr member method pointer to invoke
- * @param obj the object on which to invoke the member method
- */
- template <typename T>
- static void ScheduleDestroy (void (T::*mem_ptr) (void), T *obj);
- /**
- * @param mem_ptr member method pointer to invoke
- * @param obj the object on which to invoke the member method
- * @param a1 the first argument to pass to the invoked method
- */
- template <typename T, typename T1>
- static void ScheduleDestroy (void (T::*mem_ptr) (T1), T* obj, T1 a1);
- /**
- * @param mem_ptr member method pointer to invoke
- * @param obj the object on which to invoke the member method
- * @param a1 the first argument to pass to the invoked method
- * @param a2 the second argument to pass to the invoked method
- */
- template <typename T, typename T1, typename T2>
- static void ScheduleDestroy (void (T::*mem_ptr) (T1,T2), T* obj, T1 a1, T2 a2);
- /**
- * @param time the expiration time of the event.
- * @param mem_ptr member method pointer to invoke
- * @param obj the object on which to invoke the member method
- * @param a1 the first argument to pass to the invoked method
- * @param a2 the second argument to pass to the invoked method
- * @param a3 the third argument to pass to the invoked method
- */
- template <typename T, typename T1, typename T2, typename T3>
- static void ScheduleDestroy (void (T::*mem_ptr) (T1,T2,T3), T* obj, T1 a1, T2 a2, T3 a3);
- /**
- * @param mem_ptr member method pointer to invoke
- * @param obj the object on which to invoke the member method
- * @param a1 the first argument to pass to the invoked method
- * @param a2 the second argument to pass to the invoked method
- * @param a3 the third argument to pass to the invoked method
- * @param a4 the fourth argument to pass to the invoked method
- */
- template <typename T, typename T1, typename T2, typename T3, typename T4>
- static void ScheduleDestroy (void (T::*mem_ptr) (T1,T2,T3,T4), T* obj,
- T1 a1, T2 a2, T3 a3, T4 a4);
- /**
- * @param mem_ptr member method pointer to invoke
- * @param obj the object on which to invoke the member method
- * @param a1 the first argument to pass to the invoked method
- * @param a2 the second argument to pass to the invoked method
- * @param a3 the third argument to pass to the invoked method
- * @param a4 the fourth argument to pass to the invoked method
- * @param a5 the fifth argument to pass to the invoked method
- */
- template <typename T, typename T1, typename T2, typename T3, typename T4, typename T5>
- static void ScheduleDestroy (void (T::*mem_ptr) (T1,T2,T3,T4,T5), T* obj,
- T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
- /**
- * @param f the function to invoke
- */
- static void ScheduleDestroy (void (*f) (void));
- /**
- * @param f the function to invoke
- * @param a1 the first argument to pass to the function to invoke
- */
- template <typename T1>
- static void ScheduleDestroy (void (*f) (T1), T1 a1);
- /**
- * @param f the function to invoke
- * @param a1 the first argument to pass to the function to invoke
- * @param a2 the second argument to pass to the function to invoke
- */
- template <typename T1, typename T2>
- static void ScheduleDestroy (void (*f) (T1,T2), T1 a1, T2 a2);
- /**
- * @param f the function to invoke
- * @param a1 the first argument to pass to the function to invoke
- * @param a2 the second argument to pass to the function to invoke
- * @param a3 the third argument to pass to the function to invoke
- */
- template <typename T1, typename T2, typename T3>
- static void ScheduleDestroy (void (*f) (T1,T2,T3), T1 a1, T2 a2, T3 a3);
- /**
- * @param f the function to invoke
- * @param a1 the first argument to pass to the function to invoke
- * @param a2 the second argument to pass to the function to invoke
- * @param a3 the third argument to pass to the function to invoke
- * @param a4 the fourth argument to pass to the function to invoke
- */
- template <typename T1, typename T2, typename T3, typename T4>
- static void ScheduleDestroy (void (*f) (T1,T2,T3,T4), T1 a1, T2 a2, T3 a3, T4 a4);
- /**
- * @param f the function to invoke
- * @param a1 the first argument to pass to the function to invoke
- * @param a2 the second argument to pass to the function to invoke
- * @param a3 the third argument to pass to the function to invoke
- * @param a4 the fourth argument to pass to the function to invoke
- * @param a5 the fifth argument to pass to the function to invoke
- */
- template <typename T1, typename T2, typename T3, typename T4, typename T5>
- static void ScheduleDestroy (void (*f) (T1,T2,T3,T4,T5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
+ /**
+ * Schedule an event to expire at Destroy time. All events
+ * scheduled to expire at "Destroy" time are scheduled FIFO,
+ * after all normal events have expired and only when
+ * Simulator::Destroy is invoked.
+ *
+ * @param mem_ptr member method pointer to invoke
+ * @param obj the object on which to invoke the member method
+ */
+ template <typename T>
+ static void ScheduleDestroy (void (T::*mem_ptr) (void), T *obj);
+ /**
+ * @param mem_ptr member method pointer to invoke
+ * @param obj the object on which to invoke the member method
+ * @param a1 the first argument to pass to the invoked method
+ */
+ template <typename T, typename T1>
+ static void ScheduleDestroy (void (T::*mem_ptr) (T1), T* obj, T1 a1);
+ /**
+ * @param mem_ptr member method pointer to invoke
+ * @param obj the object on which to invoke the member method
+ * @param a1 the first argument to pass to the invoked method
+ * @param a2 the second argument to pass to the invoked method
+ */
+ template <typename T, typename T1, typename T2>
+ static void ScheduleDestroy (void (T::*mem_ptr) (T1,T2), T* obj, T1 a1, T2 a2);
+ /**
+ * @param time the expiration time of the event.
+ * @param mem_ptr member method pointer to invoke
+ * @param obj the object on which to invoke the member method
+ * @param a1 the first argument to pass to the invoked method
+ * @param a2 the second argument to pass to the invoked method
+ * @param a3 the third argument to pass to the invoked method
+ */
+ template <typename T, typename T1, typename T2, typename T3>
+ static void ScheduleDestroy (void (T::*mem_ptr) (T1,T2,T3), T* obj, T1 a1, T2 a2, T3 a3);
+ /**
+ * @param mem_ptr member method pointer to invoke
+ * @param obj the object on which to invoke the member method
+ * @param a1 the first argument to pass to the invoked method
+ * @param a2 the second argument to pass to the invoked method
+ * @param a3 the third argument to pass to the invoked method
+ * @param a4 the fourth argument to pass to the invoked method
+ */
+ template <typename T, typename T1, typename T2, typename T3, typename T4>
+ static void ScheduleDestroy (void (T::*mem_ptr) (T1,T2,T3,T4), T* obj,
+ T1 a1, T2 a2, T3 a3, T4 a4);
+ /**
+ * @param mem_ptr member method pointer to invoke
+ * @param obj the object on which to invoke the member method
+ * @param a1 the first argument to pass to the invoked method
+ * @param a2 the second argument to pass to the invoked method
+ * @param a3 the third argument to pass to the invoked method
+ * @param a4 the fourth argument to pass to the invoked method
+ * @param a5 the fifth argument to pass to the invoked method
+ */
+ template <typename T, typename T1, typename T2, typename T3, typename T4, typename T5>
+ static void ScheduleDestroy (void (T::*mem_ptr) (T1,T2,T3,T4,T5), T* obj,
+ T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
+ /**
+ * @param f the function to invoke
+ */
+ static void ScheduleDestroy (void (*f) (void));
+ /**
+ * @param f the function to invoke
+ * @param a1 the first argument to pass to the function to invoke
+ */
+ template <typename T1>
+ static void ScheduleDestroy (void (*f) (T1), T1 a1);
+ /**
+ * @param f the function to invoke
+ * @param a1 the first argument to pass to the function to invoke
+ * @param a2 the second argument to pass to the function to invoke
+ */
+ template <typename T1, typename T2>
+ static void ScheduleDestroy (void (*f) (T1,T2), T1 a1, T2 a2);
+ /**
+ * @param f the function to invoke
+ * @param a1 the first argument to pass to the function to invoke
+ * @param a2 the second argument to pass to the function to invoke
+ * @param a3 the third argument to pass to the function to invoke
+ */
+ template <typename T1, typename T2, typename T3>
+ static void ScheduleDestroy (void (*f) (T1,T2,T3), T1 a1, T2 a2, T3 a3);
+ /**
+ * @param f the function to invoke
+ * @param a1 the first argument to pass to the function to invoke
+ * @param a2 the second argument to pass to the function to invoke
+ * @param a3 the third argument to pass to the function to invoke
+ * @param a4 the fourth argument to pass to the function to invoke
+ */
+ template <typename T1, typename T2, typename T3, typename T4>
+ static void ScheduleDestroy (void (*f) (T1,T2,T3,T4), T1 a1, T2 a2, T3 a3, T4 a4);
+ /**
+ * @param f the function to invoke
+ * @param a1 the first argument to pass to the function to invoke
+ * @param a2 the second argument to pass to the function to invoke
+ * @param a3 the third argument to pass to the function to invoke
+ * @param a4 the fourth argument to pass to the function to invoke
+ * @param a5 the fifth argument to pass to the function to invoke
+ */
+ template <typename T1, typename T2, typename T3, typename T4, typename T5>
+ static void ScheduleDestroy (void (*f) (T1,T2,T3,T4,T5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
- /**
- * Remove an event from the event list.
- * This method has the same visible effect as the
- * ns3::Simulator::cancel method or the ns3::EventId::cancel method
- * but its algorithmic complexity is much higher: it has often
- * O(log(n)) complexity, sometimes O(n), sometimes worse.
- * Note that it is not possible to remove events which were scheduled
- * for the "destroy" time. Doing so will result in a program error (crash).
- *
- * @param id the event to remove from the list of scheduled events.
- */
- static void Remove (EventId id);
- /**
- * Set the cancel bit on this event: the event's associated function
- * will not be invoked when it expires.
- * This method has the same visible effect as the
- * ns3::Simulator::remove method but its algorithmic complexity is
- * much lower: it has O(1) complexity.
- * This method has the exact same semantics as ns3::EventId::cancel.
- * Note that it is not possible to cancel events which were scheduled
- * for the "destroy" time. Doing so will result in a program error (crash).
- *
- * @param id the event to cancel
- */
- static void Cancel (EventId id);
- /**
- * This method has O(1) complexity.
- * Note that it is not possible to test for the expiration of
- * events which were scheduled for the "destroy" time. Doing so
- * will result in a program error (crash).
- * An event is said to "expire" when it starts being scheduled
- * which means that if the code executed by the event calls
- * this function, it will get true.
- *
- * @param id the event to test for expiration
- * @returns true if the event has expired, false otherwise.
- */
- static bool IsExpired (EventId id);
- /**
- * Return the "current simulation time".
- */
- static Time Now (void);
+ /**
+ * Remove an event from the event list.
+ * This method has the same visible effect as the
+ * ns3::Simulator::cancel method or the ns3::EventId::cancel method
+ * but its algorithmic complexity is much higher: it has often
+ * O(log(n)) complexity, sometimes O(n), sometimes worse.
+ * Note that it is not possible to remove events which were scheduled
+ * for the "destroy" time. Doing so will result in a program error (crash).
+ *
+ * @param id the event to remove from the list of scheduled events.
+ */
+ static void Remove (EventId id);
+ /**
+ * Set the cancel bit on this event: the event's associated function
+ * will not be invoked when it expires.
+ * This method has the same visible effect as the
+ * ns3::Simulator::remove method but its algorithmic complexity is
+ * much lower: it has O(1) complexity.
+ * This method has the exact same semantics as ns3::EventId::cancel.
+ * Note that it is not possible to cancel events which were scheduled
+ * for the "destroy" time. Doing so will result in a program error (crash).
+ *
+ * @param id the event to cancel
+ */
+ static void Cancel (EventId id);
+ /**
+ * This method has O(1) complexity.
+ * Note that it is not possible to test for the expiration of
+ * events which were scheduled for the "destroy" time. Doing so
+ * will result in a program error (crash).
+ * An event is said to "expire" when it starts being scheduled
+ * which means that if the code executed by the event calls
+ * this function, it will get true.
+ *
+ * @param id the event to test for expiration
+ * @returns true if the event has expired, false otherwise.
+ */
+ static bool IsExpired (EventId id);
+ /**
+ * Return the "current simulation time".
+ */
+ static Time Now (void);
private:
- Simulator ();
- ~Simulator ();
- template <typename T>
- static EventImpl *MakeEvent (void (T::*mem_ptr) (void), T *obj);
- template <typename T, typename T1>
- static EventImpl *MakeEvent (void (T::*mem_ptr) (T1), T* obj, T1 a1);
- template <typename T, typename T1, typename T2>
- static EventImpl *MakeEvent (void (T::*mem_ptr) (T1,T2), T* obj, T1 a1, T2 a2);
- template <typename T, typename T1, typename T2, typename T3>
- static EventImpl *MakeEvent (void (T::*mem_ptr) (T1,T2,T3), T* obj, T1 a1, T2 a2, T3 a3);
- template <typename T, typename T1, typename T2, typename T3, typename T4>
- static EventImpl *MakeEvent (void (T::*mem_ptr) (T1,T2,T3,T4), T* obj, T1 a1, T2 a2, T3 a3, T4 a4);
- template <typename T, typename T1, typename T2, typename T3, typename T4, typename T5>
- static EventImpl *MakeEvent (void (T::*mem_ptr) (T1,T2,T3,T4,T5), T* obj,
- T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
- static EventImpl *MakeEvent (void (*f) (void));
- template <typename T1>
- static EventImpl *MakeEvent (void (*f) (T1), T1 a1);
- template <typename T1, typename T2>
- static EventImpl *MakeEvent (void (*f) (T1,T2), T1 a1, T2 a2);
- template <typename T1, typename T2, typename T3>
- static EventImpl *MakeEvent (void (*f) (T1,T2,T3), T1 a1, T2 a2, T3 a3);
- template <typename T1, typename T2, typename T3, typename T4>
- static EventImpl *MakeEvent (void (*f) (T1,T2,T3,T4), T1 a1, T2 a2, T3 a3, T4 a4);
- template <typename T1, typename T2, typename T3, typename T4, typename T5>
- static EventImpl *MakeEvent (void (*f) (T1,T2,T3,T4,T5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
+ Simulator ();
+ ~Simulator ();
+ template <typename T>
+ static EventImpl *MakeEvent (void (T::*mem_ptr) (void), T *obj);
+ template <typename T, typename T1>
+ static EventImpl *MakeEvent (void (T::*mem_ptr) (T1), T* obj, T1 a1);
+ template <typename T, typename T1, typename T2>
+ static EventImpl *MakeEvent (void (T::*mem_ptr) (T1,T2), T* obj, T1 a1, T2 a2);
+ template <typename T, typename T1, typename T2, typename T3>
+ static EventImpl *MakeEvent (void (T::*mem_ptr) (T1,T2,T3), T* obj, T1 a1, T2 a2, T3 a3);
+ template <typename T, typename T1, typename T2, typename T3, typename T4>
+ static EventImpl *MakeEvent (void (T::*mem_ptr) (T1,T2,T3,T4), T* obj, T1 a1, T2 a2, T3 a3, T4 a4);
+ template <typename T, typename T1, typename T2, typename T3, typename T4, typename T5>
+ static EventImpl *MakeEvent (void (T::*mem_ptr) (T1,T2,T3,T4,T5), T* obj,
+ T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
+ static EventImpl *MakeEvent (void (*f) (void));
+ template <typename T1>
+ static EventImpl *MakeEvent (void (*f) (T1), T1 a1);
+ template <typename T1, typename T2>
+ static EventImpl *MakeEvent (void (*f) (T1,T2), T1 a1, T2 a2);
+ template <typename T1, typename T2, typename T3>
+ static EventImpl *MakeEvent (void (*f) (T1,T2,T3), T1 a1, T2 a2, T3 a3);
+ template <typename T1, typename T2, typename T3, typename T4>
+ static EventImpl *MakeEvent (void (*f) (T1,T2,T3,T4), T1 a1, T2 a2, T3 a3, T4 a4);
+ template <typename T1, typename T2, typename T3, typename T4, typename T5>
+ static EventImpl *MakeEvent (void (*f) (T1,T2,T3,T4,T5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
- static SimulatorPrivate *GetPriv (void);
- static EventId Schedule (Time const &time, EventImpl *event);
- static void ScheduleDestroy (EventImpl *event);
- static void ScheduleNow (EventImpl *event);
- static SimulatorPrivate *m_priv;
- static SchedulerFactory const*m_schedFactory;
- static enum ListType {
- LINKED_LIST,
- BINARY_HEAP,
- STD_MAP,
- EXTERNAL
- } m_listType;
+ static SimulatorPrivate *GetPriv (void);
+ static EventId Schedule (Time const &time, EventImpl *event);
+ static void ScheduleDestroy (EventImpl *event);
+ static void ScheduleNow (EventImpl *event);
+ static SimulatorPrivate *m_priv;
+ static SchedulerFactory const*m_schedFactory;
+ static enum ListType {
+ LINKED_LIST,
+ BINARY_HEAP,
+ STD_MAP,
+ EXTERNAL
+ } m_listType;
};
}; // namespace ns3
/********************************************************************
- Implementation of templates defined above
+ Implementation of templates defined above
********************************************************************/
namespace ns3 {
@@ -580,382 +580,382 @@
template <typename T>
EventImpl *Simulator::MakeEvent (void (T::*mem_ptr) (void), T *obj)
{
- // zero argument version
- class EventMemberImpl0 : public EventImpl {
- public:
- typedef void (T::*F)(void);
- EventMemberImpl0 (T *obj, F function)
- : m_obj (obj),
- m_function (function)
- {}
- virtual ~EventMemberImpl0 () {}
- private:
- virtual void Notify (void) {
- (m_obj->*m_function) ();
- }
- T* m_obj;
- F m_function;
- } *ev = new EventMemberImpl0 (obj, mem_ptr);
- return ev;
+ // zero argument version
+ class EventMemberImpl0 : public EventImpl {
+ public:
+ typedef void (T::*F)(void);
+ EventMemberImpl0 (T *obj, F function)
+ : m_obj (obj),
+ m_function (function)
+ {}
+ virtual ~EventMemberImpl0 () {}
+ private:
+ virtual void Notify (void) {
+ (m_obj->*m_function) ();
+ }
+ T* m_obj;
+ F m_function;
+ } *ev = new EventMemberImpl0 (obj, mem_ptr);
+ return ev;
}
template <typename T, typename T1>
EventImpl *Simulator::MakeEvent (void (T::*mem_ptr) (T1), T* obj, T1 a1)
{
- // one argument version
- class EventMemberImpl1 : public EventImpl {
- public:
- typedef void (T::*F)(T1);
- EventMemberImpl1 (T *obj, F function, T1 a1)
- : m_obj (obj),
- m_function (function),
- m_a1 (a1)
- {}
- protected:
- virtual ~EventMemberImpl1 () {}
- private:
- virtual void Notify (void) {
- (m_obj->*m_function) (m_a1);
- }
- T* m_obj;
- F m_function;
- T1 m_a1;
- } *ev = new EventMemberImpl1 (obj, mem_ptr, a1);
- return ev;
+ // one argument version
+ class EventMemberImpl1 : public EventImpl {
+ public:
+ typedef void (T::*F)(T1);
+ EventMemberImpl1 (T *obj, F function, T1 a1)
+ : m_obj (obj),
+ m_function (function),
+ m_a1 (a1)
+ {}
+ protected:
+ virtual ~EventMemberImpl1 () {}
+ private:
+ virtual void Notify (void) {
+ (m_obj->*m_function) (m_a1);
+ }
+ T* m_obj;
+ F m_function;
+ T1 m_a1;
+ } *ev = new EventMemberImpl1 (obj, mem_ptr, a1);
+ return ev;
}
template <typename T, typename T1, typename T2>
EventImpl *Simulator::MakeEvent (void (T::*mem_ptr) (T1,T2), T* obj, T1 a1, T2 a2)
{
- // two argument version
- class EventMemberImpl2 : public EventImpl {
- public:
- typedef void (T::*F)(T1, T2);
-
- EventMemberImpl2 (T *obj, F function, T1 a1, T2 a2)
- : m_obj (obj),
- m_function (function),
- m_a1 (a1),
- m_a2 (a2)
- { }
- protected:
- virtual ~EventMemberImpl2 () {}
- private:
- virtual void Notify (void) {
- (m_obj->*m_function) (m_a1, m_a2);
- }
- T* m_obj;
- F m_function;
- T1 m_a1;
- T2 m_a2;
- } *ev = new EventMemberImpl2 (obj, mem_ptr, a1, a2);
- return ev;
+ // two argument version
+ class EventMemberImpl2 : public EventImpl {
+ public:
+ typedef void (T::*F)(T1, T2);
+
+ EventMemberImpl2 (T *obj, F function, T1 a1, T2 a2)
+ : m_obj (obj),
+ m_function (function),
+ m_a1 (a1),
+ m_a2 (a2)
+ { }
+ protected:
+ virtual ~EventMemberImpl2 () {}
+ private:
+ virtual void Notify (void) {
+ (m_obj->*m_function) (m_a1, m_a2);
+ }
+ T* m_obj;
+ F m_function;
+ T1 m_a1;
+ T2 m_a2;
+ } *ev = new EventMemberImpl2 (obj, mem_ptr, a1, a2);
+ return ev;
}
template <typename T, typename T1, typename T2, typename T3>
EventImpl *Simulator::MakeEvent (void (T::*mem_ptr) (T1,T2,T3), T* obj, T1 a1, T2 a2, T3 a3)
{
- // three argument version
- class EventMemberImpl3 : public EventImpl {
- public:
- typedef void (T::*F)(T1, T2, T3);
-
- EventMemberImpl3 (T *obj, F function, T1 a1, T2 a2, T3 a3)
- : m_obj (obj),
- m_function (function),
- m_a1 (a1),
- m_a2 (a2),
- m_a3 (a3)
- { }
- protected:
- virtual ~EventMemberImpl3 () {}
- private:
- virtual void Notify (void) {
- (m_obj->*m_function) (m_a1, m_a2, m_a3);
- }
- T* m_obj;
- F m_function;
- T1 m_a1;
- T2 m_a2;
- T3 m_a3;
- } *ev = new EventMemberImpl3 (obj, mem_ptr, a1, a2, a3);
- return ev;
+ // three argument version
+ class EventMemberImpl3 : public EventImpl {
+ public:
+ typedef void (T::*F)(T1, T2, T3);
+
+ EventMemberImpl3 (T *obj, F function, T1 a1, T2 a2, T3 a3)
+ : m_obj (obj),
+ m_function (function),
+ m_a1 (a1),
+ m_a2 (a2),
+ m_a3 (a3)
+ { }
+ protected:
+ virtual ~EventMemberImpl3 () {}
+ private:
+ virtual void Notify (void) {
+ (m_obj->*m_function) (m_a1, m_a2, m_a3);
+ }
+ T* m_obj;
+ F m_function;
+ T1 m_a1;
+ T2 m_a2;
+ T3 m_a3;
+ } *ev = new EventMemberImpl3 (obj, mem_ptr, a1, a2, a3);
+ return ev;
}
template <typename T, typename T1, typename T2, typename T3, typename T4>
EventImpl *Simulator::MakeEvent (void (T::*mem_ptr) (T1,T2,T3,T4), T* obj, T1 a1, T2 a2, T3 a3, T4 a4)
{
- // four argument version
- class EventMemberImpl4 : public EventImpl {
- public:
- typedef void (T::*F)(T1, T2, T3, T4);
-
- EventMemberImpl4 (T *obj, F function, T1 a1, T2 a2, T3 a3, T4 a4)
- : m_obj (obj),
- m_function (function),
- m_a1 (a1),
- m_a2 (a2),
- m_a3 (a3),
- m_a4 (a4)
- { }
- protected:
- virtual ~EventMemberImpl4 () {}
- private:
- virtual void Notify (void) {
- (m_obj->*m_function) (m_a1, m_a2, m_a3, m_a4);
- }
- T* m_obj;
- F m_function;
- T1 m_a1;
- T2 m_a2;
- T3 m_a3;
- T4 m_a4;
- } *ev = new EventMemberImpl4 (obj, mem_ptr, a1, a2, a3, a4);
- return ev;
+ // four argument version
+ class EventMemberImpl4 : public EventImpl {
+ public:
+ typedef void (T::*F)(T1, T2, T3, T4);
+
+ EventMemberImpl4 (T *obj, F function, T1 a1, T2 a2, T3 a3, T4 a4)
+ : m_obj (obj),
+ m_function (function),
+ m_a1 (a1),
+ m_a2 (a2),
+ m_a3 (a3),
+ m_a4 (a4)
+ { }
+ protected:
+ virtual ~EventMemberImpl4 () {}
+ private:
+ virtual void Notify (void) {
+ (m_obj->*m_function) (m_a1, m_a2, m_a3, m_a4);
+ }
+ T* m_obj;
+ F m_function;
+ T1 m_a1;
+ T2 m_a2;
+ T3 m_a3;
+ T4 m_a4;
+ } *ev = new EventMemberImpl4 (obj, mem_ptr, a1, a2, a3, a4);
+ return ev;
}
template <typename T, typename T1, typename T2, typename T3, typename T4, typename T5>
EventImpl *Simulator::MakeEvent (void (T::*mem_ptr) (T1,T2,T3,T4,T5), T* obj,
- T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
+ T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
{
- // five argument version
- class EventMemberImpl5 : public EventImpl {
- public:
- typedef void (T::*F)(T1, T2, T3, T4, T5);
-
- EventMemberImpl5 (T *obj, F function, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
- : m_obj (obj),
- m_function (function),
- m_a1 (a1),
- m_a2 (a2),
- m_a3 (a3),
- m_a4 (a4),
- m_a5 (a5)
- { }
- protected:
- virtual ~EventMemberImpl5 () {}
- private:
- virtual void Notify (void) {
- (m_obj->*m_function) (m_a1, m_a2, m_a3, m_a4, m_a5);
- }
- T* m_obj;
- F m_function;
- T1 m_a1;
- T2 m_a2;
- T3 m_a3;
- T4 m_a4;
- T5 m_a5;
- } *ev = new EventMemberImpl5 (obj, mem_ptr, a1, a2, a3, a4, a5);
- return ev;
+ // five argument version
+ class EventMemberImpl5 : public EventImpl {
+ public:
+ typedef void (T::*F)(T1, T2, T3, T4, T5);
+
+ EventMemberImpl5 (T *obj, F function, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
+ : m_obj (obj),
+ m_function (function),
+ m_a1 (a1),
+ m_a2 (a2),
+ m_a3 (a3),
+ m_a4 (a4),
+ m_a5 (a5)
+ { }
+ protected:
+ virtual ~EventMemberImpl5 () {}
+ private:
+ virtual void Notify (void) {
+ (m_obj->*m_function) (m_a1, m_a2, m_a3, m_a4, m_a5);
+ }
+ T* m_obj;
+ F m_function;
+ T1 m_a1;
+ T2 m_a2;
+ T3 m_a3;
+ T4 m_a4;
+ T5 m_a5;
+ } *ev = new EventMemberImpl5 (obj, mem_ptr, a1, a2, a3, a4, a5);
+ return ev;
}
template <typename T1>
EventImpl *Simulator::MakeEvent (void (*f) (T1), T1 a1)
{
- // one arg version
- class EventFunctionImpl1 : public EventImpl {
- public:
- typedef void (*F)(T1);
-
- EventFunctionImpl1 (F function, T1 a1)
- : m_function (function),
- m_a1 (a1)
- { }
- protected:
- virtual ~EventFunctionImpl1 () {}
- private:
- virtual void Notify (void) {
- (*m_function) (m_a1);
- }
- F m_function;
- T1 m_a1;
- } *ev = new EventFunctionImpl1(f, a1);
- return ev;
+ // one arg version
+ class EventFunctionImpl1 : public EventImpl {
+ public:
+ typedef void (*F)(T1);
+
+ EventFunctionImpl1 (F function, T1 a1)
+ : m_function (function),
+ m_a1 (a1)
+ { }
+ protected:
+ virtual ~EventFunctionImpl1 () {}
+ private:
+ virtual void Notify (void) {
+ (*m_function) (m_a1);
+ }
+ F m_function;
+ T1 m_a1;
+ } *ev = new EventFunctionImpl1(f, a1);
+ return ev;
}
template <typename T1, typename T2>
EventImpl *Simulator::MakeEvent (void (*f) (T1,T2), T1 a1, T2 a2)
{
- // two arg version
- class EventFunctionImpl2 : public EventImpl {
- public:
- typedef void (*F)(T1, T2);
-
- EventFunctionImpl2 (F function, T1 a1, T2 a2)
- : m_function (function),
- m_a1 (a1),
- m_a2 (a2)
- { }
- protected:
- virtual ~EventFunctionImpl2 () {}
- private:
- virtual void Notify (void) {
- (*m_function) (m_a1, m_a2);
- }
- F m_function;
- T1 m_a1;
- T2 m_a2;
- } *ev = new EventFunctionImpl2 (f, a1, a2);
- return ev;
+ // two arg version
+ class EventFunctionImpl2 : public EventImpl {
+ public:
+ typedef void (*F)(T1, T2);
+
+ EventFunctionImpl2 (F function, T1 a1, T2 a2)
+ : m_function (function),
+ m_a1 (a1),
+ m_a2 (a2)
+ { }
+ protected:
+ virtual ~EventFunctionImpl2 () {}
+ private:
+ virtual void Notify (void) {
+ (*m_function) (m_a1, m_a2);
+ }
+ F m_function;
+ T1 m_a1;
+ T2 m_a2;
+ } *ev = new EventFunctionImpl2 (f, a1, a2);
+ return ev;
}
template <typename T1, typename T2, typename T3>
EventImpl *Simulator::MakeEvent (void (*f) (T1,T2,T3), T1 a1, T2 a2, T3 a3)
{
- // three arg version
- class EventFunctionImpl3 : public EventImpl {
- public:
- typedef void (*F)(T1, T2, T3);
-
- EventFunctionImpl3 (F function, T1 a1, T2 a2, T3 a3)
- : m_function (function),
- m_a1 (a1),
- m_a2 (a2),
- m_a3 (a3)
- { }
- protected:
- virtual ~EventFunctionImpl3 () {}
- private:
- virtual void Notify (void) {
- (*m_function) (m_a1, m_a2, m_a3);
- }
- F m_function;
- T1 m_a1;
- T2 m_a2;
- T3 m_a3;
- } *ev = new EventFunctionImpl3 (f, a1, a2, a3);
- return ev;
+ // three arg version
+ class EventFunctionImpl3 : public EventImpl {
+ public:
+ typedef void (*F)(T1, T2, T3);
+
+ EventFunctionImpl3 (F function, T1 a1, T2 a2, T3 a3)
+ : m_function (function),
+ m_a1 (a1),
+ m_a2 (a2),
+ m_a3 (a3)
+ { }
+ protected:
+ virtual ~EventFunctionImpl3 () {}
+ private:
+ virtual void Notify (void) {
+ (*m_function) (m_a1, m_a2, m_a3);
+ }
+ F m_function;
+ T1 m_a1;
+ T2 m_a2;
+ T3 m_a3;
+ } *ev = new EventFunctionImpl3 (f, a1, a2, a3);
+ return ev;
}
template <typename T1, typename T2, typename T3, typename T4>
EventImpl *Simulator::MakeEvent (void (*f) (T1,T2,T3,T4), T1 a1, T2 a2, T3 a3, T4 a4)
{
- // four arg version
- class EventFunctionImpl4 : public EventImpl {
- public:
- typedef void (*F)(T1, T2, T3, T4);
-
- EventFunctionImpl4 (F function, T1 a1, T2 a2, T3 a3, T4 a4)
- : m_function (function),
- m_a1 (a1),
- m_a2 (a2),
- m_a3 (a3),
- m_a4 (a4)
- { }
- protected:
- virtual ~EventFunctionImpl4 () {}
- private:
- virtual void Notify (void) {
- (*m_function) (m_a1, m_a2, m_a3, m_a4);
- }
- F m_function;
- T1 m_a1;
- T2 m_a2;
- T3 m_a3;
- T4 m_a4;
- } *ev = new EventFunctionImpl4 (f, a1, a2, a3, a4);
- return ev;
+ // four arg version
+ class EventFunctionImpl4 : public EventImpl {
+ public:
+ typedef void (*F)(T1, T2, T3, T4);
+
+ EventFunctionImpl4 (F function, T1 a1, T2 a2, T3 a3, T4 a4)
+ : m_function (function),
+ m_a1 (a1),
+ m_a2 (a2),
+ m_a3 (a3),
+ m_a4 (a4)
+ { }
+ protected:
+ virtual ~EventFunctionImpl4 () {}
+ private:
+ virtual void Notify (void) {
+ (*m_function) (m_a1, m_a2, m_a3, m_a4);
+ }
+ F m_function;
+ T1 m_a1;
+ T2 m_a2;
+ T3 m_a3;
+ T4 m_a4;
+ } *ev = new EventFunctionImpl4 (f, a1, a2, a3, a4);
+ return ev;
}
template <typename T1, typename T2, typename T3, typename T4, typename T5>
EventImpl *Simulator::MakeEvent (void (*f) (T1,T2,T3,T4,T5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
{
- // five arg version
- class EventFunctionImpl5 : public EventImpl {
- public:
- typedef void (*F)(T1, T2, T3, T4, T5);
-
- EventFunctionImpl5 (F function, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
- : m_function (function),
- m_a1 (a1),
- m_a2 (a2),
- m_a3 (a3),
- m_a4 (a4),
- m_a5 (a5)
- { }
- protected:
- virtual ~EventFunctionImpl5 () {}
- private:
- virtual void Notify (void) {
- (*m_function) (m_a1, m_a2, m_a3, m_a4, m_a5);
- }
- F m_function;
- T1 m_a1;
- T2 m_a2;
- T3 m_a3;
- T4 m_a4;
- T5 m_a5;
- } *ev = new EventFunctionImpl5 (f, a1, a2, a3, a4, a5);
- return ev;
+ // five arg version
+ class EventFunctionImpl5 : public EventImpl {
+ public:
+ typedef void (*F)(T1, T2, T3, T4, T5);
+
+ EventFunctionImpl5 (F function, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
+ : m_function (function),
+ m_a1 (a1),
+ m_a2 (a2),
+ m_a3 (a3),
+ m_a4 (a4),
+ m_a5 (a5)
+ { }
+ protected:
+ virtual ~EventFunctionImpl5 () {}
+ private:
+ virtual void Notify (void) {
+ (*m_function) (m_a1, m_a2, m_a3, m_a4, m_a5);
+ }
+ F m_function;
+ T1 m_a1;
+ T2 m_a2;
+ T3 m_a3;
+ T4 m_a4;
+ T5 m_a5;
+ } *ev = new EventFunctionImpl5 (f, a1, a2, a3, a4, a5);
+ return ev;
}
template <typename T>
EventId Simulator::Schedule (Time const &time, void (T::*mem_ptr) (void), T *obj)
{
- return Schedule (time, MakeEvent (mem_ptr, obj));
+ return Schedule (time, MakeEvent (mem_ptr, obj));
}
template <typename T, typename T1>
EventId Simulator::Schedule (Time const &time, void (T::*mem_ptr) (T1), T* obj, T1 a1)
{
- return Schedule (time, MakeEvent (mem_ptr, obj, a1));
+ return Schedule (time, MakeEvent (mem_ptr, obj, a1));
}
template <typename T, typename T1, typename T2>
EventId Simulator::Schedule (Time const &time, void (T::*mem_ptr) (T1,T2), T* obj, T1 a1, T2 a2)
{
- return Schedule (time, MakeEvent (mem_ptr, obj, a1, a2));
+ return Schedule (time, MakeEvent (mem_ptr, obj, a1, a2));
}
template <typename T, typename T1, typename T2, typename T3>
EventId Simulator::Schedule (Time const &time, void (T::*mem_ptr) (T1,T2,T3), T* obj, T1 a1, T2 a2, T3 a3)
{
- return Schedule (time, MakeEvent (mem_ptr, obj, a1, a2, a3));
+ return Schedule (time, MakeEvent (mem_ptr, obj, a1, a2, a3));
}
template <typename T, typename T1, typename T2, typename T3, typename T4>
EventId Simulator::Schedule (Time const &time, void (T::*mem_ptr) (T1,T2,T3,T4), T* obj, T1 a1, T2 a2, T3 a3, T4 a4)
{
- return Schedule (time, MakeEvent (mem_ptr, obj, a1, a2, a3, a4));
+ return Schedule (time, MakeEvent (mem_ptr, obj, a1, a2, a3, a4));
}
template <typename T, typename T1, typename T2, typename T3, typename T4, typename T5>
EventId Simulator::Schedule (Time const &time, void (T::*mem_ptr) (T1,T2,T3,T4,T5), T* obj,
- T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
+ T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
{
- return Schedule (time, MakeEvent (mem_ptr, obj, a1, a2, a3, a4, a5));
+ return Schedule (time, MakeEvent (mem_ptr, obj, a1, a2, a3, a4, a5));
}
template <typename T1>
EventId Simulator::Schedule (Time const &time, void (*f) (T1), T1 a1)
{
- return Schedule (time, MakeEvent (f, a1));
+ return Schedule (time, MakeEvent (f, a1));
}
template <typename T1, typename T2>
EventId Simulator::Schedule (Time const &time, void (*f) (T1,T2), T1 a1, T2 a2)
{
- return Schedule (time, MakeEvent (f, a1, a2));
+ return Schedule (time, MakeEvent (f, a1, a2));
}
template <typename T1, typename T2, typename T3>
EventId Simulator::Schedule (Time const &time, void (*f) (T1,T2,T3), T1 a1, T2 a2, T3 a3)
{
- return Schedule (time, MakeEvent (f, a1, a2, a3));
+ return Schedule (time, MakeEvent (f, a1, a2, a3));
}
template <typename T1, typename T2, typename T3, typename T4>
EventId Simulator::Schedule (Time const &time, void (*f) (T1,T2,T3,T4), T1 a1, T2 a2, T3 a3, T4 a4)
{
- return Schedule (time, MakeEvent (f, a1, a2, a3, a4));
+ return Schedule (time, MakeEvent (f, a1, a2, a3, a4));
}
template <typename T1, typename T2, typename T3, typename T4, typename T5>
EventId Simulator::Schedule (Time const &time, void (*f) (T1,T2,T3,T4,T5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
{
- return Schedule (time, MakeEvent (f, a1, a2, a3, a4, a5));
+ return Schedule (time, MakeEvent (f, a1, a2, a3, a4, a5));
}
@@ -965,7 +965,7 @@
void
Simulator::ScheduleNow (void (T::*mem_ptr) (void), T *obj)
{
- ScheduleNow (MakeEvent (mem_ptr, obj));
+ ScheduleNow (MakeEvent (mem_ptr, obj));
}
@@ -973,71 +973,71 @@
void
Simulator::ScheduleNow (void (T::*mem_ptr) (T1), T* obj, T1 a1)
{
- ScheduleNow (MakeEvent (mem_ptr, obj, a1));
+ ScheduleNow (MakeEvent (mem_ptr, obj, a1));
}
template <typename T, typename T1, typename T2>
void
Simulator::ScheduleNow (void (T::*mem_ptr) (T1,T2), T* obj, T1 a1, T2 a2)
{
- ScheduleNow (MakeEvent (mem_ptr, obj, a1, a2));
+ ScheduleNow (MakeEvent (mem_ptr, obj, a1, a2));
}
template <typename T, typename T1, typename T2, typename T3>
void
Simulator::ScheduleNow (void (T::*mem_ptr) (T1,T2,T3), T* obj, T1 a1, T2 a2, T3 a3)
{
- ScheduleNow (MakeEvent (mem_ptr, obj, a1, a2, a3));
+ ScheduleNow (MakeEvent (mem_ptr, obj, a1, a2, a3));
}
template <typename T, typename T1, typename T2, typename T3, typename T4>
void
Simulator::ScheduleNow (void (T::*mem_ptr) (T1,T2,T3,T4), T* obj, T1 a1, T2 a2, T3 a3, T4 a4)
{
- ScheduleNow (MakeEvent (mem_ptr, obj, a1, a2, a3, a4));
+ ScheduleNow (MakeEvent (mem_ptr, obj, a1, a2, a3, a4));
}
template <typename T, typename T1, typename T2, typename T3, typename T4, typename T5>
void
Simulator::ScheduleNow (void (T::*mem_ptr) (T1,T2,T3,T4,T5), T* obj,
- T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
+ T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
{
- ScheduleNow (MakeEvent (mem_ptr, obj, a1, a2, a3, a4, a5));
+ ScheduleNow (MakeEvent (mem_ptr, obj, a1, a2, a3, a4, a5));
}
template <typename T1>
void
Simulator::ScheduleNow (void (*f) (T1), T1 a1)
{
- ScheduleNow (MakeEvent (f, a1));
+ ScheduleNow (MakeEvent (f, a1));
}
template <typename T1, typename T2>
void
Simulator::ScheduleNow (void (*f) (T1,T2), T1 a1, T2 a2)
{
- ScheduleNow (MakeEvent (f, a1, a2));
+ ScheduleNow (MakeEvent (f, a1, a2));
}
template <typename T1, typename T2, typename T3>
void
Simulator::ScheduleNow (void (*f) (T1,T2,T3), T1 a1, T2 a2, T3 a3)
{
- ScheduleNow (MakeEvent (f, a1, a2, a3));
+ ScheduleNow (MakeEvent (f, a1, a2, a3));
}
template <typename T1, typename T2, typename T3, typename T4>
void
Simulator::ScheduleNow (void (*f) (T1,T2,T3,T4), T1 a1, T2 a2, T3 a3, T4 a4)
{
- ScheduleNow (MakeEvent (f, a1, a2, a3, a4));
+ ScheduleNow (MakeEvent (f, a1, a2, a3, a4));
}
template <typename T1, typename T2, typename T3, typename T4, typename T5>
void
Simulator::ScheduleNow (void (*f) (T1,T2,T3,T4,T5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
{
- ScheduleNow (MakeEvent (f, a1, a2, a3, a4, a5));
+ ScheduleNow (MakeEvent (f, a1, a2, a3, a4, a5));
}
@@ -1046,7 +1046,7 @@
void
Simulator::ScheduleDestroy (void (T::*mem_ptr) (void), T *obj)
{
- ScheduleDestroy (MakeEvent (mem_ptr, obj));
+ ScheduleDestroy (MakeEvent (mem_ptr, obj));
}
@@ -1054,71 +1054,71 @@
void
Simulator::ScheduleDestroy (void (T::*mem_ptr) (T1), T* obj, T1 a1)
{
- ScheduleDestroy (MakeEvent (mem_ptr, obj, a1));
+ ScheduleDestroy (MakeEvent (mem_ptr, obj, a1));
}
template <typename T, typename T1, typename T2>
void
Simulator::ScheduleDestroy (void (T::*mem_ptr) (T1,T2), T* obj, T1 a1, T2 a2)
{
- ScheduleDestroy (MakeEvent (mem_ptr, obj, a1, a2));
+ ScheduleDestroy (MakeEvent (mem_ptr, obj, a1, a2));
}
template <typename T, typename T1, typename T2, typename T3>
void
Simulator::ScheduleDestroy (void (T::*mem_ptr) (T1,T2,T3), T* obj, T1 a1, T2 a2, T3 a3)
{
- ScheduleDestroy (MakeEvent (mem_ptr, obj, a1, a2, a3));
+ ScheduleDestroy (MakeEvent (mem_ptr, obj, a1, a2, a3));
}
template <typename T, typename T1, typename T2, typename T3, typename T4>
void
Simulator::ScheduleDestroy (void (T::*mem_ptr) (T1,T2,T3,T4), T* obj, T1 a1, T2 a2, T3 a3, T4 a4)
{
- ScheduleDestroy (MakeEvent (mem_ptr, obj, a1, a2, a3, a4));
+ ScheduleDestroy (MakeEvent (mem_ptr, obj, a1, a2, a3, a4));
}
template <typename T, typename T1, typename T2, typename T3, typename T4, typename T5>
void
Simulator::ScheduleDestroy (void (T::*mem_ptr) (T1,T2,T3,T4,T5), T* obj,
- T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
+ T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
{
- ScheduleDestroy (MakeEvent (mem_ptr, obj, a1, a2, a3, a4, a5));
+ ScheduleDestroy (MakeEvent (mem_ptr, obj, a1, a2, a3, a4, a5));
}
template <typename T1>
void
Simulator::ScheduleDestroy (void (*f) (T1), T1 a1)
{
- ScheduleDestroy (MakeEvent (f, a1));
+ ScheduleDestroy (MakeEvent (f, a1));
}
template <typename T1, typename T2>
void
Simulator::ScheduleDestroy (void (*f) (T1,T2), T1 a1, T2 a2)
{
- ScheduleDestroy (MakeEvent (f, a1, a2));
+ ScheduleDestroy (MakeEvent (f, a1, a2));
}
template <typename T1, typename T2, typename T3>
void
Simulator::ScheduleDestroy (void (*f) (T1,T2,T3), T1 a1, T2 a2, T3 a3)
{
- ScheduleDestroy (MakeEvent (f, a1, a2, a3));
+ ScheduleDestroy (MakeEvent (f, a1, a2, a3));
}
template <typename T1, typename T2, typename T3, typename T4>
void
Simulator::ScheduleDestroy (void (*f) (T1,T2,T3,T4), T1 a1, T2 a2, T3 a3, T4 a4)
{
- ScheduleDestroy (MakeEvent (f, a1, a2, a3, a4));
+ ScheduleDestroy (MakeEvent (f, a1, a2, a3, a4));
}
template <typename T1, typename T2, typename T3, typename T4, typename T5>
void
Simulator::ScheduleDestroy (void (*f) (T1,T2,T3,T4,T5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
{
- ScheduleDestroy (MakeEvent (f, a1, a2, a3, a4, a5));
+ ScheduleDestroy (MakeEvent (f, a1, a2, a3, a4, a5));
}
}; // namespace ns3
--- a/src/simulator/time.cc Wed Nov 01 13:00:34 2006 +0100
+++ b/src/simulator/time.cc Wed Nov 01 13:11:30 2006 +0100
@@ -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 @@
return *this;
}
Time::Time (int64_t ns)
- : m_ns (ns)
+ : m_ns (ns)
{}
@@ -153,19 +153,19 @@
}
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)
{}
--- a/utils/bench-packets.cc Wed Nov 01 13:00:34 2006 +0100
+++ b/utils/bench-packets.cc Wed Nov 01 13:11:30 2006 +0100
@@ -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 @@
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;
}
--- a/utils/bench-simulator.cc Wed Nov 01 13:00:34 2006 +0100
+++ b/utils/bench-simulator.cc Wed Nov 01 13:11:30 2006 +0100
@@ -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 @@
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;
}
--- a/utils/replay-simulation.cc Wed Nov 01 13:00:34 2006 +0100
+++ b/utils/replay-simulation.cc Wed Nov 01 13:11:30 2006 +0100
@@ -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 @@
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 @@
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 ();
+ }
}
--- a/utils/run-tests.cc Wed Nov 01 13:00:34 2006 +0100
+++ b/utils/run-tests.cc Wed Nov 01 13:11:30 2006 +0100
@@ -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;
}