From 0fade9d7aff2b9ae6b3d2aca15cbf37fe0d7c8d7 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Wed, 1 Nov 2006 13:11:30 +0100 Subject: [PATCH] fix coding style --- samples/main-callback.cc | 72 +- samples/main-packet.cc | 70 +- samples/main-simulator.cc | 30 +- samples/main-test.cc | 24 +- samples/main-trace.cc | 50 +- src/common/buffer.cc | 1016 +++++++-------- src/common/buffer.h | 950 +++++++------- src/common/callback-tracer.h | 90 +- src/common/data-writer.cc | 66 +- src/common/data-writer.h | 12 +- src/common/f-variable-tracer.h | 36 +- src/common/header.cc | 20 +- src/common/header.h | 62 +- src/common/packet.cc | 110 +- src/common/packet.h | 364 +++--- src/common/pcap-writer.cc | 54 +- src/common/pcap-writer.h | 52 +- src/common/si-variable-tracer.h | 206 +-- src/common/stream-tracer-test.cc | 46 +- src/common/stream-tracer.h | 66 +- src/common/tags.cc | 372 +++--- src/common/tags.h | 256 ++-- src/common/trace-container.cc | 208 +-- src/common/trace-container.h | 346 ++--- src/common/trailer.cc | 20 +- src/common/trailer.h | 62 +- src/common/ui-variable-tracer.h | 214 ++-- src/common/variable-tracer-test.cc | 382 +++--- src/core/callback-test.cc | 198 +-- src/core/callback.h | 312 ++--- src/core/reference-list-test.cc | 98 +- src/core/reference-list.h | 148 +-- src/core/system-file.h | 68 +- src/core/system-wall-clock-ms.h | 32 +- src/core/test.cc | 82 +- src/core/test.h | 76 +- src/core/unix-system-file.cc | 66 +- src/core/unix-system-wall-clock-ms.cc | 34 +- src/core/win32-system-file.cc | 20 +- src/core/win32-system-wall-clock-ms.cc | 18 +- src/simulator/event-id.cc | 26 +- src/simulator/event-id.h | 48 +- src/simulator/event-impl.cc | 20 +- src/simulator/event-impl.h | 22 +- src/simulator/nstime.h | 44 +- src/simulator/scheduler-factory.cc | 4 +- src/simulator/scheduler-factory.h | 16 +- src/simulator/scheduler-heap.cc | 172 +-- src/simulator/scheduler-heap.h | 54 +- src/simulator/scheduler-list.cc | 80 +- src/simulator/scheduler-list.h | 30 +- src/simulator/scheduler-map.cc | 56 +- src/simulator/scheduler-map.h | 34 +- src/simulator/scheduler.cc | 50 +- src/simulator/scheduler.h | 124 +- src/simulator/simulator.cc | 592 ++++----- src/simulator/simulator.h | 1596 ++++++++++++------------ src/simulator/time.cc | 18 +- utils/bench-packets.cc | 134 +- utils/bench-simulator.cc | 166 +-- utils/replay-simulation.cc | 400 +++--- utils/run-tests.cc | 8 +- 62 files changed, 5051 insertions(+), 5051 deletions(-) diff --git a/samples/main-callback.cc b/samples/main-callback.cc index 87f27d922..202f47151 100644 --- a/samples/main-callback.cc +++ b/samples/main-callback.cc @@ -1,4 +1,4 @@ -/* -*- Mode:NS3; -*- */ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ #include "ns3/callback.h" #include #include @@ -8,51 +8,51 @@ using namespace ns3; static double CbOne (double a, double b) { - std::cout << "invoke cbOne a=" << a << ", b=" << b << std::endl; - return a; + std::cout << "invoke cbOne a=" << a << ", b=" << b << std::endl; + return a; } class MyCb { public: - int CbTwo (double a) { - std::cout << "invoke cbTwo a=" << a << std::endl; - return -5; - } + int CbTwo (double a) { + std::cout << "invoke cbTwo a=" << a << std::endl; + return -5; + } }; int main (int argc, char *argv[]) { - // return type: double - // first arg type: double - // second arg type: double - Callback 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 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 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 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 (); - // 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 (); + // 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; } diff --git a/samples/main-packet.cc b/samples/main-packet.cc index 23a11888c..1dd4411f6 100644 --- a/samples/main-packet.cc +++ b/samples/main-packet.cc @@ -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 @@ -9,18 +9,18 @@ using namespace ns3; */ class MyHeader : public Header { public: - MyHeader (); - virtual ~MyHeader (); + MyHeader (); + virtual ~MyHeader (); - void SetData (uint16_t data); - uint16_t GetData (void) const; + void SetData (uint16_t data); + uint16_t GetData (void) const; private: - virtual void PrintTo (std::ostream &os) const; - virtual void SerializeTo (Buffer::Iterator start) const; - virtual void DeserializeFrom (Buffer::Iterator start); - virtual uint32_t GetSerializedSize (void) const; + virtual void PrintTo (std::ostream &os) const; + virtual void SerializeTo (Buffer::Iterator start) const; + virtual void DeserializeFrom (Buffer::Iterator start); + virtual uint32_t GetSerializedSize (void) const; - uint16_t m_data; + uint16_t m_data; }; MyHeader::MyHeader () @@ -30,41 +30,41 @@ MyHeader::~MyHeader () void MyHeader::PrintTo (std::ostream &os) const { - os << "MyHeader data=" << m_data << std::endl; + os << "MyHeader data=" << m_data << std::endl; } uint32_t MyHeader::GetSerializedSize (void) const { - return 2; + return 2; } void MyHeader::SerializeTo (Buffer::Iterator start) const { - // serialize in head of buffer - start.WriteHtonU16 (m_data); + // serialize in head of buffer + start.WriteHtonU16 (m_data); } void MyHeader::DeserializeFrom (Buffer::Iterator start) { - // deserialize from head of buffer - m_data = start.ReadNtohU16 (); + // deserialize from head of buffer + m_data = start.ReadNtohU16 (); } void MyHeader::SetData (uint16_t data) { - m_data = data; + m_data = data; } uint16_t MyHeader::GetData (void) const { - return m_data; + return m_data; } /* A sample Tag implementation */ struct MyTag { - uint16_t m_streamId; + uint16_t m_streamId; }; static TagRegistration g_MyTagRegistration ("ns3::MyTag", 0); @@ -73,25 +73,25 @@ static TagRegistration g_MyTagRegistration ("ns3::MyTag", 0); static void Receive (Packet p) { - MyHeader my; - p.Peek (my); - p.Remove (my); - std::cout << "received data=" << my.GetData () << std::endl; - struct MyTag myTag; - p.PeekTag (myTag); + MyHeader my; + p.Peek (my); + p.Remove (my); + std::cout << "received data=" << my.GetData () << std::endl; + struct MyTag myTag; + p.PeekTag (myTag); } int main (int argc, char *argv[]) { - Packet p; - MyHeader my; - my.SetData (2); - std::cout << "send data=2" << std::endl; - p.Add (my); - struct MyTag myTag; - myTag.m_streamId = 5; - p.AddTag (myTag); - Receive (p); - return 0; + Packet p; + MyHeader my; + my.SetData (2); + std::cout << "send data=2" << std::endl; + p.Add (my); + struct MyTag myTag; + myTag.m_streamId = 5; + p.AddTag (myTag); + Receive (p); + return 0; } diff --git a/samples/main-simulator.cc b/samples/main-simulator.cc index c1e43c332..fa63f8e70 100644 --- a/samples/main-simulator.cc +++ b/samples/main-simulator.cc @@ -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 @@ -7,41 +7,41 @@ using namespace ns3; class MyModel { public: - void Start (void); + void Start (void); private: - void DealWithEvent (double eventValue); + void DealWithEvent (double eventValue); }; void MyModel::Start (void) { - Simulator::Schedule (Now () + Seconds (10.0), - &MyModel::DealWithEvent, - this, Simulator::Now ().ApproximateToSeconds ()); + Simulator::Schedule (Now () + Seconds (10.0), + &MyModel::DealWithEvent, + this, Simulator::Now ().ApproximateToSeconds ()); } void MyModel::DealWithEvent (double value) { - std::cout << "Member method received event at " << Simulator::Now ().ApproximateToSeconds () - << "s started at " << value << "s" << std::endl; + std::cout << "Member method received event at " << Simulator::Now ().ApproximateToSeconds () + << "s started at " << value << "s" << std::endl; } static void random_function (MyModel *model) { - std::cout << "random function received event at " << - Simulator::Now ().ApproximateToSeconds () << "s" << std::endl; - model->Start (); + std::cout << "random function received event at " << + Simulator::Now ().ApproximateToSeconds () << "s" << std::endl; + model->Start (); } int main (int argc, char *argv[]) { - MyModel model; + MyModel model; - Simulator::Schedule (Now () + Seconds (10.0), &random_function, &model); + Simulator::Schedule (Now () + Seconds (10.0), &random_function, &model); - Simulator::Run (); + Simulator::Run (); - Simulator::Destroy (); + Simulator::Destroy (); } diff --git a/samples/main-test.cc b/samples/main-test.cc index b28970d99..b765ffa42 100644 --- a/samples/main-test.cc +++ b/samples/main-test.cc @@ -1,4 +1,4 @@ -/* -*- Mode:NS3; -*- */ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ #include "ns3/test.h" @@ -9,24 +9,24 @@ using namespace ns3; // declare subclass of base class Test class MyTest : public Test { public: - MyTest (bool ok); - virtual ~MyTest (); - virtual bool RunTests (void); + MyTest (bool ok); + virtual ~MyTest (); + virtual bool RunTests (void); private: - bool m_ok; + bool m_ok; }; // implement MyTest MyTest::MyTest (bool ok) - : Test ("My"), - m_ok (ok) + : Test ("My"), + m_ok (ok) {} MyTest::~MyTest () {} bool MyTest::RunTests (void) { - return m_ok; + return m_ok; } // instantiate MyTest once @@ -36,8 +36,8 @@ static MyTest g_my_test = MyTest (true); int main (int argc, char *argv[]) { - // run tests - TestManager::EnableVerbose (); - TestManager::RunTests (); - return 0; + // run tests + TestManager::EnableVerbose (); + TestManager::RunTests (); + return 0; } diff --git a/samples/main-trace.cc b/samples/main-trace.cc index d792b517d..8a888e38c 100644 --- a/samples/main-trace.cc +++ b/samples/main-trace.cc @@ -1,4 +1,4 @@ -/* -*- Mode:NS3; -*- */ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ #include "ns3/trace-container.h" #include "ns3/ui-variable-tracer.h" #include "ns3/callback-tracer.h" @@ -17,22 +17,22 @@ CallbackTracer d; void RegisterAllTraceSources (TraceContainer *container) { - container->RegisterCallback ("source-a", &a); - container->RegisterUiVariable ("source-b", &b); - container->RegisterStream ("source-c", &c); - container->RegisterCallback ("source-d", &d); + container->RegisterCallback ("source-a", &a); + container->RegisterUiVariable ("source-b", &b); + container->RegisterStream ("source-c", &c); + container->RegisterCallback ("source-d", &d); } void GenerateTraceEvents (void) { - // log en empty packet - a (Packet ()); - b = 10; - b += 100; - b += 50; - b = (unsigned short) -20; - c << "this is a simple test b=" << b << std::endl; - d (3.1415, 3); + // log en empty packet + a (Packet ()); + b = 10; + b += 100; + b += 50; + b = (unsigned short) -20; + c << "this is a simple test b=" << b << std::endl; + d (3.1415, 3); } void @@ -46,16 +46,16 @@ CallbackEvent (double a, int b) int main (int argc, char *argv[]) { - TraceContainer traces; - RegisterAllTraceSources (&traces); - PcapWriter pcap; - pcap.Open ("trace-test.log"); - pcap.WriteHeaderEthernet (); - traces.SetCallback ("source-a", - MakeCallback (&PcapWriter::WritePacket, &pcap)); - traces.SetUiVariableCallback ("source-b", MakeCallback (&VariableEvent)); - traces.SetStream ("source-c", &std::cout); - traces.SetCallback ("source-d", MakeCallback (&CallbackEvent)); - GenerateTraceEvents (); - return 0; + TraceContainer traces; + RegisterAllTraceSources (&traces); + PcapWriter pcap; + pcap.Open ("trace-test.log"); + pcap.WriteHeaderEthernet (); + traces.SetCallback ("source-a", + MakeCallback (&PcapWriter::WritePacket, &pcap)); + traces.SetUiVariableCallback ("source-b", MakeCallback (&VariableEvent)); + traces.SetStream ("source-c", &std::cout); + traces.SetCallback ("source-d", MakeCallback (&CallbackEvent)); + GenerateTraceEvents (); + return 0; } diff --git a/src/common/buffer.cc b/src/common/buffer.cc index ed13fa8eb..2305e150d 100644 --- a/src/common/buffer.cc +++ b/src/common/buffer.cc @@ -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 @@ uint32_t Buffer::m_maxTotalAddEnd = 0; 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(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(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 (data); - delete [] buf; + uint8_t *buf = reinterpret_cast (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 @@ namespace ns3 { 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="< 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 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 @@ private: 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(m_data + GetIndex (2)); - m_current += 2; - return *buffer; + uint16_t *buffer = reinterpret_cast(m_data + GetIndex (2)); + m_current += 2; + return *buffer; } uint32_t Buffer::Iterator::ReadU32 (void) { - uint32_t *buffer = reinterpret_cast(m_data + GetIndex (4)); - m_current += 4; - return *buffer; + uint32_t *buffer = reinterpret_cast(m_data + GetIndex (4)); + m_current += 4; + return *buffer; } uint64_t Buffer::Iterator::ReadU64 (void) { - uint64_t *buffer = reinterpret_cast(m_data + GetIndex (8)); - m_current += 8; - return *buffer; + uint64_t *buffer = reinterpret_cast(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 (current[0]) << 8; - retval |= static_cast (current[1]) << 0; - m_current += 2; - return retval; + uint8_t *current = m_data + GetIndex (2); + uint16_t retval = 0; + retval |= static_cast (current[0]) << 8; + retval |= static_cast (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 (current[0]) << 24; - retval |= static_cast (current[1]) << 16; - retval |= static_cast (current[2]) << 8; - retval |= static_cast (current[3]) << 0; - m_current += 4; - return retval; + uint8_t *current = m_data + GetIndex (4); + uint32_t retval = 0; + retval |= static_cast (current[0]) << 24; + retval |= static_cast (current[1]) << 16; + retval |= static_cast (current[2]) << 8; + retval |= static_cast (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 (current[0]) << 56; - retval |= static_cast (current[1]) << 48; - retval |= static_cast (current[2]) << 40; - retval |= static_cast (current[3]) << 32; - retval |= static_cast (current[4]) << 24; - retval |= static_cast (current[5]) << 16; - retval |= static_cast (current[6]) << 8; - retval |= static_cast (current[7]) << 0; - m_current += 8; - return retval; + uint8_t *current = m_data + GetIndex (8); + uint64_t retval = 0; + retval |= static_cast (current[0]) << 56; + retval |= static_cast (current[1]) << 48; + retval |= static_cast (current[2]) << 40; + retval |= static_cast (current[3]) << 32; + retval |= static_cast (current[4]) << 24; + retval |= static_cast (current[5]) << 16; + retval |= static_cast (current[6]) << 8; + retval |= static_cast (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 diff --git a/src/common/callback-tracer.h b/src/common/callback-tracer.h index b08d3c3ed..76167a834 100644 --- a/src/common/callback-tracer.h +++ b/src/common/callback-tracer.h @@ -1,4 +1,4 @@ -/* -*- Mode:NS3; -*- */ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * Copyright (c) 2005,2006 INRIA * All rights reserved. @@ -35,54 +35,54 @@ class CallbackTracerBase {}; * are forwarded to the internal matching ns3::Callback. */ template + typename T3 = empty, typename T4 = empty, + typename T5 = empty> class CallbackTracer : public CallbackTracerBase{ public: - CallbackTracer () - : m_callback () {} - void SetCallback (Callback 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 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 m_callback; + Callback m_callback; }; }; // namespace ns3 diff --git a/src/common/data-writer.cc b/src/common/data-writer.cc index b35467d6c..53fc2d3cd 100644 --- a/src/common/data-writer.cc +++ b/src/common/data-writer.cc @@ -1,4 +1,4 @@ -/* -*- Mode:NS3; -*- */ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * Copyright (c) 2005 INRIA * All rights reserved. @@ -46,32 +46,32 @@ namespace ns3 { class DataWriterPrivate { public: - DataWriterPrivate (); - ~DataWriterPrivate (); + DataWriterPrivate (); + ~DataWriterPrivate (); - void open (char const *filename); - void write (uint8_t *buffer, uint32_t size); + void open (char const *filename); + void write (uint8_t *buffer, uint32_t size); private: - uint8_t m_data[BUFFER_SIZE]; - uint32_t m_current; - int m_fd; + uint8_t m_data[BUFFER_SIZE]; + uint32_t m_current; + int m_fd; }; DataWriterPrivate::DataWriterPrivate () - : m_current (0) + : m_current (0) {} DataWriterPrivate::~DataWriterPrivate () { - ::Write (m_fd, m_data, m_current); - ::Close (m_fd); + ::Write (m_fd, m_data, m_current); + ::Close (m_fd); } void DataWriterPrivate::Open (char const *filename) { - m_fd = ::Open (filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); - assert (m_fd != -1); + m_fd = ::Open (filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); + assert (m_fd != -1); } #ifndef min @@ -81,41 +81,41 @@ DataWriterPrivate::Open (char const *filename) void DataWriterPrivate::Write (uint8_t *buffer, uint32_t size) { - while (size > 0) - { - uint32_t toCopy = min (BUFFER_SIZE - m_current, size); - memcpy (m_data + m_current, buffer, toCopy); - size -= toCopy; - m_current += toCopy; - buffer += toCopy; - if (m_current == BUFFER_SIZE) - { - ssize_t written = 0; - written = ::Write (m_fd, m_data, BUFFER_SIZE); - assert (written == BUFFER_SIZE); - m_current = 0; - } - } + while (size > 0) + { + uint32_t toCopy = min (BUFFER_SIZE - m_current, size); + memcpy (m_data + m_current, buffer, toCopy); + size -= toCopy; + m_current += toCopy; + buffer += toCopy; + if (m_current == BUFFER_SIZE) + { + ssize_t written = 0; + written = ::Write (m_fd, m_data, BUFFER_SIZE); + assert (written == BUFFER_SIZE); + m_current = 0; + } + } } DataWriter::DataWriter () - : m_priv (new DataWriterPrivate ()) + : m_priv (new DataWriterPrivate ()) {} DataWriter::~DataWriter () { - delete m_priv; - m_priv = 0; + delete m_priv; + m_priv = 0; } void DataWriter::Open (char const *filename) { - m_priv->Open (filename); + m_priv->Open (filename); } void DataWriter::Write (uint8_t *buffer, uint32_t size) { - m_priv->Write (buffer, size); + m_priv->Write (buffer, size); } }; // namespace diff --git a/src/common/data-writer.h b/src/common/data-writer.h index e82f81bae..ee9b1f8b3 100644 --- a/src/common/data-writer.h +++ b/src/common/data-writer.h @@ -1,4 +1,4 @@ -/* -*- Mode:NS3; -*- */ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * Copyright (c) 2005 INRIA * All rights reserved. @@ -30,13 +30,13 @@ class DataWriterPrivate; class DataWriter { public: - DataWriter (); - ~DataWriter (); + DataWriter (); + ~DataWriter (); - void open (char const *filename); - void write (uint8_t *buffer, uint32_t size); + void open (char const *filename); + void write (uint8_t *buffer, uint32_t size); private: - DataWriterPrivate *m_priv; + DataWriterPrivate *m_priv; }; }; //namespace ns3 diff --git a/src/common/f-variable-tracer.h b/src/common/f-variable-tracer.h index 8d1b56c78..4e2353e3c 100644 --- a/src/common/f-variable-tracer.h +++ b/src/common/f-variable-tracer.h @@ -1,4 +1,4 @@ -/* -*- Mode:NS3; -*- */ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * Copyright (c) 2006 INRIA * All rights reserved. @@ -29,28 +29,28 @@ namespace ns3 { class FVariableTracerBase { public: - typedef Callback ChangeNotifyCallback; + typedef Callback 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; }; diff --git a/src/common/header.cc b/src/common/header.cc index 28d17b9fc..9a88cc617 100644 --- a/src/common/header.cc +++ b/src/common/header.cc @@ -1,4 +1,4 @@ -/* -*- Mode:NS3; -*- */ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * Copyright (c) 2005 INRIA * All rights reserved. @@ -25,33 +25,33 @@ namespace ns3 { Header::Header () - : m_isDeserialized (false) {} + : m_isDeserialized (false) {} void Header::Print (std::ostream &os) const { - PrintTo (os); + PrintTo (os); } uint32_t Header::GetSize (void) const { - return GetSerializedSize (); + return GetSerializedSize (); } void Header::Serialize (Buffer::Iterator start) const { - SerializeTo (start); + SerializeTo (start); } void Header::Deserialize (Buffer::Iterator start) { - DeserializeFrom (start); - m_isDeserialized = true; + DeserializeFrom (start); + m_isDeserialized = true; } bool Header::IsDeserialized (void) const { - return m_isDeserialized; + return m_isDeserialized; } @@ -61,8 +61,8 @@ Header::~Header () std::ostream& operator<< (std::ostream& os, Header const& header) { - header.Print (os); - return os; + header.Print (os); + return os; } }; // namespace ns3 diff --git a/src/common/header.h b/src/common/header.h index d21e8dd2e..899747499 100644 --- a/src/common/header.h +++ b/src/common/header.h @@ -1,4 +1,4 @@ -/* -*- Mode:NS3; -*- */ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * Copyright (c) 2005 INRIA * All rights reserved. @@ -41,40 +41,40 @@ namespace ns3 { */ class Header { public: - Header (); - /** - * Derived classes must provide an explicit virtual destructor - */ - virtual ~Header () = 0; + Header (); + /** + * Derived classes must provide an explicit virtual destructor + */ + virtual ~Header () = 0; - void Print (std::ostream &os) const; - uint32_t GetSize (void) const; - void Serialize (Buffer::Iterator start) const; - void Deserialize (Buffer::Iterator start); - bool IsDeserialized (void) const; + void Print (std::ostream &os) const; + uint32_t GetSize (void) const; + void Serialize (Buffer::Iterator start) const; + void Deserialize (Buffer::Iterator start); + bool IsDeserialized (void) const; private: - bool m_isDeserialized; - /** - * \param os the std output stream in which this - * protocol header must print itself. - */ - virtual void PrintTo (std::ostream &os) const = 0; + bool m_isDeserialized; + /** + * \param os the std output stream in which this + * protocol header must print itself. + */ + virtual void PrintTo (std::ostream &os) const = 0; - /** - * \returns the size of the serialized Header. - */ - virtual uint32_t GetSerializedSize (void) const = 0; + /** + * \returns the size of the serialized Header. + */ + virtual uint32_t GetSerializedSize (void) const = 0; - /** - * \param start the buffer iterator in which the protocol header - * must serialize itself. - */ - virtual void SerializeTo (Buffer::Iterator start) const = 0; - /** - * \param start the buffer iterator from which the protocol header must - * deserialize itself. - */ - virtual void DeserializeFrom (Buffer::Iterator start) = 0; + /** + * \param start the buffer iterator in which the protocol header + * must serialize itself. + */ + virtual void SerializeTo (Buffer::Iterator start) const = 0; + /** + * \param start the buffer iterator from which the protocol header must + * deserialize itself. + */ + virtual void DeserializeFrom (Buffer::Iterator start) = 0; }; std::ostream& operator<< (std::ostream& os, Header const& header); diff --git a/src/common/packet.cc b/src/common/packet.cc index a3d5712a7..d24c97f32 100644 --- a/src/common/packet.cc +++ b/src/common/packet.cc @@ -1,4 +1,4 @@ -/* -*- Mode:NS3; -*- */ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * Copyright (c) 2005,2006 INRIA * All rights reserved. @@ -26,135 +26,135 @@ namespace ns3 { uint32_t Packet::m_global_uid = 0; Packet::Packet () - : m_buffer (), - m_uid (m_global_uid) + : m_buffer (), + m_uid (m_global_uid) { - m_global_uid++; + m_global_uid++; } Packet::Packet (uint32_t size) - : m_buffer (size), - m_uid (m_global_uid) + : m_buffer (size), + m_uid (m_global_uid) { - m_global_uid++; + m_global_uid++; } Packet::Packet (Buffer buffer, Tags tags, uint32_t uid) - : m_buffer (buffer), - m_tags (tags), - m_uid (uid) + : m_buffer (buffer), + m_tags (tags), + m_uid (uid) {} Packet Packet::CreateFragment (uint32_t start, uint32_t length) const { - Buffer tmp = m_buffer.CreateFragment (start, length); - return Packet (tmp, m_tags, m_uid); + Buffer tmp = m_buffer.CreateFragment (start, length); + return Packet (tmp, m_tags, m_uid); } uint32_t Packet::GetSize (void) const { - return m_buffer.GetSize (); + return m_buffer.GetSize (); } void Packet::Add (Header const &header) { - m_buffer.AddAtStart (header.GetSize ()); - header.Serialize (m_buffer.Begin ()); + m_buffer.AddAtStart (header.GetSize ()); + header.Serialize (m_buffer.Begin ()); } void Packet::Peek (Header &header) { - header.Deserialize (m_buffer.Begin ()); + header.Deserialize (m_buffer.Begin ()); } void Packet::Remove (Header const &header) { - assert (header.IsDeserialized ()); - m_buffer.RemoveAtStart (header.GetSize ()); + assert (header.IsDeserialized ()); + m_buffer.RemoveAtStart (header.GetSize ()); } void Packet::Add (Trailer const &trailer) { - m_buffer.AddAtEnd (trailer.GetSize ()); - Buffer::Iterator start = m_buffer.End (); - start.Prev (trailer.GetSize ()); - trailer.Serialize (start); + m_buffer.AddAtEnd (trailer.GetSize ()); + Buffer::Iterator start = m_buffer.End (); + start.Prev (trailer.GetSize ()); + trailer.Serialize (start); } void Packet::Peek (Trailer &trailer) { - Buffer::Iterator start = m_buffer.End (); - start.Prev (trailer.GetSize ()); - trailer.Deserialize (start); + Buffer::Iterator start = m_buffer.End (); + start.Prev (trailer.GetSize ()); + trailer.Deserialize (start); } void Packet::Remove (Trailer const &trailer) { - assert (trailer.IsDeserialized ()); - m_buffer.RemoveAtEnd (trailer.GetSize ()); + assert (trailer.IsDeserialized ()); + m_buffer.RemoveAtEnd (trailer.GetSize ()); } void Packet::AddAtEnd (Packet packet) { - Buffer src = packet.m_buffer; - m_buffer.AddAtEnd (src.GetSize ()); - Buffer::Iterator destStart = m_buffer.End (); - destStart.Prev (src.GetSize ()); - destStart.Write (src.Begin (), src.End ()); - /** - * XXX: we might need to merge the tag list of the - * other packet into the current packet. - */ + Buffer src = packet.m_buffer; + m_buffer.AddAtEnd (src.GetSize ()); + Buffer::Iterator destStart = m_buffer.End (); + destStart.Prev (src.GetSize ()); + destStart.Write (src.Begin (), src.End ()); + /** + * XXX: we might need to merge the tag list of the + * other packet into the current packet. + */ } void Packet::AddAtEnd (Packet packet, uint32_t start, uint32_t size) { - assert (packet.GetSize () <= start + size); - Buffer src = packet.m_buffer; - m_buffer.AddAtEnd (src.GetSize ()); - Buffer::Iterator destStart = m_buffer.End (); - destStart.Prev (size); - Buffer::Iterator srcStart = src.Begin (); - srcStart.Next (start); - Buffer::Iterator srcEnd = srcStart; - srcEnd.Next (size); - destStart.Write (srcStart, srcEnd); - /** - * XXX: we might need to merge the tag list of the - * other packet into the current packet. - */ + assert (packet.GetSize () <= start + size); + Buffer src = packet.m_buffer; + m_buffer.AddAtEnd (src.GetSize ()); + Buffer::Iterator destStart = m_buffer.End (); + destStart.Prev (size); + Buffer::Iterator srcStart = src.Begin (); + srcStart.Next (start); + Buffer::Iterator srcEnd = srcStart; + srcEnd.Next (size); + destStart.Write (srcStart, srcEnd); + /** + * XXX: we might need to merge the tag list of the + * other packet into the current packet. + */ } void Packet::RemoveAtEnd (uint32_t size) { - m_buffer.RemoveAtEnd (size); + m_buffer.RemoveAtEnd (size); } void Packet::RemoveAtStart (uint32_t size) { - m_buffer.RemoveAtStart (size); + m_buffer.RemoveAtStart (size); } void Packet::RemoveAllTags (void) { - m_tags.RemoveAll (); + m_tags.RemoveAll (); } uint8_t const * Packet::PeekData (void) const { - return m_buffer.PeekData (); + return m_buffer.PeekData (); } uint32_t Packet::GetUid (void) const { - return m_uid; + return m_uid; } }; // namespace ns3 diff --git a/src/common/packet.h b/src/common/packet.h index f69ba501d..e3f21f902 100644 --- a/src/common/packet.h +++ b/src/common/packet.h @@ -1,4 +1,4 @@ -/* -*- Mode:NS3; -*- */ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * Copyright (c) 2005,2006 INRIA * All rights reserved. @@ -87,192 +87,192 @@ namespace ns3 { */ class Packet { public: - /** - * Create an empty packet with a new uid (as returned - * by getUid). - */ - Packet (); - /** - * Create a packet with a zero-filled payload. - * The memory necessary for the payload is not allocated: - * it will be allocated at any later point if you attempt - * to fragment this packet or to access the zero-filled - * bytes. The packet is allocated with a new uid (as - * returned by getUid). - * - * \param size the size of the zero-filled payload - */ - Packet (uint32_t size); - /** - * Create a new packet which contains a fragment of the original - * packet. The returned packet shares the same uid as this packet. - * - * \param start offset from start of packet to start of fragment to create - * \param length length of fragment to create - * \returns a fragment of the original packet - */ - Packet CreateFragment (uint32_t start, uint32_t length) const; - /** - * \returns the size in bytes of the packet (including the zero-filled - * initial payload) - */ - uint32_t GetSize (void) const; - /** - * Add header to this packet. This method invokes the - * ns3::Header::serializeTo method to request the header to serialize - * itself in the packet buffer. - * - * \param header a reference to the header to add to this packet. - */ - void Add (Header const &header); - /** - * Deserialize header from this packet. This method invokes the - * ns3::Header::deserializeFrom method to request the header to deserialize - * itself from the packet buffer. This method does not remove - * the data from the buffer. It merely reads it. - * - * \param header a reference to the header to deserialize from the buffer - */ - void Peek (Header &header); - /** - * Remove a deserialized header from the internal buffer. - * This method removes the bytes read by Packet::peek from - * the packet buffer. - * - * \param header a reference to the header to remove from the internal buffer. - */ - void Remove (Header const &header); - /** - * Add trailer to this packet. This method invokes the - * ns3::Trailer::serializeTo method to request the trailer to serialize - * itself in the packet buffer. - * - * \param trailer a reference to the trailer to add to this packet. - */ - void Add (Trailer const &trailer); - /** - * Deserialize trailer from this packet. This method invokes the - * ns3::Trailer::deserializeFrom method to request the trailer to deserialize - * itself from the packet buffer. This method does not remove - * the data from the buffer. It merely reads it. - * - * \param trailer a reference to the trailer to deserialize from the buffer - */ - void Peek (Trailer &trailer); - /** - * Remove a deserialized trailer from the internal buffer. - * This method removes the bytes read by Packet::peek from - * the packet buffer. - * - * \param trailer a reference to the trailer to remove from the internal buffer. - */ - void Remove (Trailer const &trailer); - /** - * Attach a tag to this packet. The tag is fully copied - * in a packet-specific internal buffer. This operation - * is expected to be really fast. - * - * \param tag a pointer to the tag to attach to this packet. - */ - template - 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 - 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 - 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 + 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 + 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 + bool PeekTag (T &tag) const; + /** + * Remove all the tags stored in this packet. This operation is + * much much faster than invoking removeTag n times. + */ + void RemoveAllTags (void); + /** + * Concatenate the input packet at the end of the current + * packet. This does not alter the uid of either packet. + * + * \param packet packet to concatenate + */ + void AddAtEnd (Packet packet); + /** + * Concatenate the fragment of the input packet identified + * by the offset and size parameters at the end of the current + * packet. This does not alter the uid of either packet. + * + * \param packet to concatenate + * \param offset offset of fragment to copy from the start of the input packet + * \param size size of fragment of input packet to copy. + */ + void AddAtEnd (Packet packet, uint32_t offset, uint32_t size); + /** + * Remove size bytes from the end of the current packet + * It is safe to remove more bytes that what is present in + * the packet. + * + * \param size number of bytes from remove + */ + void RemoveAtEnd (uint32_t size); + /** + * Remove size bytes from the start of the current packet. + * It is safe to remove more bytes that what is present in + * the packet. + * + * \param size number of bytes from remove + */ + void RemoveAtStart (uint32_t size); + + /** + * If you try to change the content of the buffer + * returned by this method, you will die. + * + * \returns a pointer to the internal buffer of the packet. + */ + uint8_t const *PeekData (void) const; - /** - * A packet is allocated a new uid when it is created - * empty or with zero-filled payload. - * - * \returns an integer identifier which uniquely - * identifies this packet. - */ - uint32_t GetUid (void) const; + /** + * A packet is allocated a new uid when it is created + * empty or with zero-filled payload. + * + * \returns an integer identifier which uniquely + * identifies this packet. + */ + uint32_t GetUid (void) const; private: - Packet (Buffer buffer, Tags tags, uint32_t uid); - Buffer m_buffer; - Tags m_tags; - uint32_t m_uid; - static uint32_t m_global_uid; + Packet (Buffer buffer, Tags tags, uint32_t uid); + Buffer m_buffer; + Tags m_tags; + uint32_t m_uid; + static uint32_t m_global_uid; }; }; // namespace ns3 /************************************************** - Start of implementation of templates defined - above + Start of implementation of templates defined + above *************************************************/ namespace ns3 { @@ -280,17 +280,17 @@ namespace ns3 { template void Packet::AddTag (T const& tag) { - m_tags.Add (tag); + m_tags.Add (tag); } template bool Packet::RemoveTag (T & tag) { - return m_tags.Remove (tag); + return m_tags.Remove (tag); } template bool Packet::PeekTag (T & tag) const { - return m_tags.Peek (tag); + return m_tags.Peek (tag); } }; // namespace ns3 diff --git a/src/common/pcap-writer.cc b/src/common/pcap-writer.cc index a835adc55..37d2b80ba 100644 --- a/src/common/pcap-writer.cc +++ b/src/common/pcap-writer.cc @@ -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 diff --git a/src/common/pcap-writer.h b/src/common/pcap-writer.h index e312738dd..c50981b44 100644 --- a/src/common/pcap-writer.h +++ b/src/common/pcap-writer.h @@ -1,4 +1,4 @@ -/* -*- Mode:NS3; -*- */ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * Copyright (c) 2005,2006 INRIA * All rights reserved. @@ -38,36 +38,36 @@ class SystemFile; */ class PcapWriter { public: - PcapWriter (); - ~PcapWriter (); + PcapWriter (); + ~PcapWriter (); - /** - * \param name the name of the file to store packet log into. - * This method creates the file if it does not exist. If it - * exists, the file is emptied. - */ - void Open (char const *name); + /** + * \param name the name of the file to store packet log into. + * This method creates the file if it does not exist. If it + * exists, the file is emptied. + */ + void Open (char const *name); - /** - * Write a pcap header in the output file which specifies - * that the content of the file will Packets with - * Ethernet/LLC/SNAP encapsulation. This method should - * be invoked before ns3::PcapWriter::writePacket and after - * ns3::PcapWriter::open. - */ - void WriteHeaderEthernet (void); + /** + * Write a pcap header in the output file which specifies + * that the content of the file will Packets with + * Ethernet/LLC/SNAP encapsulation. This method should + * be invoked before ns3::PcapWriter::writePacket and after + * ns3::PcapWriter::open. + */ + void WriteHeaderEthernet (void); - /** - * \param packet packet to write to output file - */ - void WritePacket (Packet const packet); + /** + * \param packet packet to write to output file + */ + void WritePacket (Packet const packet); private: - void WriteData (uint8_t *buffer, uint32_t size); - void Write32 (uint32_t data); - void Write16 (uint16_t data); - SystemFile *m_writer; - Callback m_writeCallback; + void WriteData (uint8_t *buffer, uint32_t size); + void Write32 (uint32_t data); + void Write16 (uint16_t data); + SystemFile *m_writer; + Callback m_writeCallback; }; }; // namespace ns3 diff --git a/src/common/si-variable-tracer.h b/src/common/si-variable-tracer.h index a3e600057..512a69189 100644 --- a/src/common/si-variable-tracer.h +++ b/src/common/si-variable-tracer.h @@ -1,4 +1,4 @@ -/* -*- Mode:NS3; -*- */ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * Copyright (c) 2006 INRIA * All rights reserved. @@ -29,28 +29,28 @@ namespace ns3 { class SiVariableTracerBase { public: - typedef Callback ChangeNotifyCallback; + typedef Callback 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 @@ -84,153 +84,153 @@ class UiVariableTracer; template 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 - SiVariableTracer &operator = (SiVariableTracer const &o) { - Assign (o.Get ()); - return *this; - } - template - SiVariableTracer &operator = (UiVariableTracer 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 + SiVariableTracer &operator = (SiVariableTracer const &o) { + Assign (o.Get ()); + return *this; + } + template + SiVariableTracer &operator = (UiVariableTracer 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 SiVariableTracer &operator += (SiVariableTracer &lhs, SiVariableTracer const &rhs) { - lhs.Assign (lhs.Get () + rhs.Get ()); - return lhs; + lhs.Assign (lhs.Get () + rhs.Get ()); + return lhs; } template SiVariableTracer &operator -= (SiVariableTracer &lhs, SiVariableTracer const &rhs) { - lhs.Assign (lhs.Get () - rhs.Get ()); - return lhs; + lhs.Assign (lhs.Get () - rhs.Get ()); + return lhs; } template SiVariableTracer &operator *= (SiVariableTracer &lhs, SiVariableTracer const &rhs) { - lhs.Assign (lhs.Get () * rhs.Get ()); - return lhs; + lhs.Assign (lhs.Get () * rhs.Get ()); + return lhs; } template SiVariableTracer &operator /= (SiVariableTracer &lhs, SiVariableTracer const &rhs) { - lhs.Assign (lhs.Get () / rhs.Get ()); - return lhs; + lhs.Assign (lhs.Get () / rhs.Get ()); + return lhs; } template SiVariableTracer &operator <<= (SiVariableTracer &lhs, SiVariableTracer const &rhs) { - lhs.Assign (lhs.Get () << rhs.Get ()); - return lhs; + lhs.Assign (lhs.Get () << rhs.Get ()); + return lhs; } template SiVariableTracer &operator >>= (SiVariableTracer &lhs, SiVariableTracer const &rhs) { - lhs.Assign (lhs.Get () >> rhs.Get ()); - return lhs; + lhs.Assign (lhs.Get () >> rhs.Get ()); + return lhs; } template SiVariableTracer &operator &= (SiVariableTracer &lhs, SiVariableTracer const &rhs) { - lhs.Assign (lhs.Get () & rhs.Get ()); - return lhs; + lhs.Assign (lhs.Get () & rhs.Get ()); + return lhs; } template SiVariableTracer &operator |= (SiVariableTracer &lhs, SiVariableTracer const &rhs) { - lhs.Assign (lhs.Get () | rhs.Get ()); - return lhs; + lhs.Assign (lhs.Get () | rhs.Get ()); + return lhs; } template SiVariableTracer &operator ^= (SiVariableTracer &lhs, SiVariableTracer const &rhs) { - lhs.Assign (lhs.Get () ^ rhs.Get ()); - return lhs; + lhs.Assign (lhs.Get () ^ rhs.Get ()); + return lhs; } template SiVariableTracer &operator += (SiVariableTracer &lhs, U const &rhs) { - lhs.Assign (lhs.Get () + rhs); - return lhs; + lhs.Assign (lhs.Get () + rhs); + return lhs; } template SiVariableTracer &operator -= (SiVariableTracer &lhs, U const &rhs) { - lhs.Assign (lhs.Get () - rhs); - return lhs; + lhs.Assign (lhs.Get () - rhs); + return lhs; } template SiVariableTracer &operator *= (SiVariableTracer &lhs, U const &rhs) { - lhs.Assign (lhs.Get () * rhs); - return lhs; + lhs.Assign (lhs.Get () * rhs); + return lhs; } template SiVariableTracer &operator /= (SiVariableTracer &lhs, U const &rhs) { - lhs.Assign (lhs.Get () / rhs); - return lhs; + lhs.Assign (lhs.Get () / rhs); + return lhs; } template SiVariableTracer &operator <<= (SiVariableTracer &lhs, U const &rhs) { - lhs.Assign (lhs.Get () << rhs); - return lhs; + lhs.Assign (lhs.Get () << rhs); + return lhs; } template SiVariableTracer &operator >>= (SiVariableTracer &lhs, U const &rhs) { - lhs.Assign (lhs.Get () >> rhs); - return lhs; + lhs.Assign (lhs.Get () >> rhs); + return lhs; } template SiVariableTracer &operator &= (SiVariableTracer &lhs, U const &rhs) { - lhs.Assign (lhs.Get () & rhs); - return lhs; + lhs.Assign (lhs.Get () & rhs); + return lhs; } template SiVariableTracer &operator |= (SiVariableTracer &lhs, U const &rhs) { - lhs.Assign (lhs.Get () | rhs); - return lhs; + lhs.Assign (lhs.Get () | rhs); + return lhs; } template SiVariableTracer &operator ^= (SiVariableTracer &lhs, U const &rhs) { - lhs.Assign (lhs.Get () ^ rhs); - return lhs; + lhs.Assign (lhs.Get () ^ rhs); + return lhs; } }; // namespace ns3 diff --git a/src/common/stream-tracer-test.cc b/src/common/stream-tracer-test.cc index 9777cb7f7..f38e80dc4 100644 --- a/src/common/stream-tracer-test.cc +++ b/src/common/stream-tracer-test.cc @@ -1,4 +1,4 @@ -/* -*- Mode:NS3; -*- */ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * Copyright (c) 2006 INRIA * All rights reserved. @@ -28,38 +28,38 @@ namespace { class TestStreamTracer : public ns3::Test { public: - TestStreamTracer (); - virtual bool RunTests (void); + TestStreamTracer (); + virtual bool RunTests (void); }; static TestStreamTracer gTestStream; TestStreamTracer::TestStreamTracer () - : Test ("StreamTracer") + : Test ("StreamTracer") {} bool TestStreamTracer::RunTests (void) { - bool ok = true; - ns3::StreamTracer trace; - //trace.setStream (&std::cout); - trace << 1; - trace << " X "; - trace << 1.0; - trace << std::endl; - trace << "test "; - trace << 1 << " test"; - trace << "test " - << 1.0 << " " - << 0xdeadbead - << std::endl; - trace << "0x" << std::hex - << 0xdeadbeaf - << std::dec << " " - << 0xdeadbeaf - << std::endl; - return ok; + bool ok = true; + ns3::StreamTracer trace; + //trace.setStream (&std::cout); + trace << 1; + trace << " X "; + trace << 1.0; + trace << std::endl; + trace << "test "; + trace << 1 << " test"; + trace << "test " + << 1.0 << " " + << 0xdeadbead + << std::endl; + trace << "0x" << std::hex + << 0xdeadbeaf + << std::dec << " " + << 0xdeadbeaf + << std::endl; + return ok; } diff --git a/src/common/stream-tracer.h b/src/common/stream-tracer.h index fd3e2150c..c2f287321 100644 --- a/src/common/stream-tracer.h +++ b/src/common/stream-tracer.h @@ -1,4 +1,4 @@ -/* -*- Mode:NS3; -*- */ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * Copyright (c) 2006 INRIA * All rights reserved. @@ -34,40 +34,40 @@ namespace ns3 { */ class StreamTracer { public: - StreamTracer () - : m_os (0) {} - template - StreamTracer &operator << (T const&v) { - if (m_os != 0) - { - (*m_os) << v; - } - return *this; - } - template - 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 + StreamTracer &operator << (T const&v) { + if (m_os != 0) + { + (*m_os) << v; + } + return *this; + } + template + 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 diff --git a/src/common/tags.cc b/src/common/tags.cc index e33bbfad5..9fe451266 100644 --- a/src/common/tags.cc +++ b/src/common/tags.cc @@ -1,4 +1,4 @@ -/* -*- Mode:NS3; -*- */ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * Copyright (c) 2006 INRIA * All rights reserved. @@ -30,42 +30,42 @@ TagRegistry::TagsData TagRegistry::m_registry; void TagRegistry::Record (std::string uuid, PrettyPrinter prettyPrinter) { - assert (!m_sorted); - m_registry.push_back (make_pair (uuid, prettyPrinter)); + assert (!m_sorted); + m_registry.push_back (make_pair (uuid, prettyPrinter)); } uint32_t TagRegistry::LookupUid (std::string uuid) { - if (!m_sorted) - { - std::sort (m_registry.begin (), m_registry.end ()); - m_sorted = true; - } - assert (m_sorted); - uint32_t uid = 0; - for (TagsDataCI i = m_registry.begin (); i != m_registry.end (); i++) - { - if (i->first == uuid) - { - return uid; - } - uid++; - } - // someone asked for a uid for an unregistered uuid. - assert ("You tried to use unregistered tag: make sure you create an " - "instance of type TagRegistration."); - // 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."); + // quiet compiler + return 0; } void TagRegistry::PrettyPrint (uint32_t uid, uint8_t buf[Tags::SIZE], std::ostream &os) { - assert (m_registry.size () > uid); - PrettyPrinter prettyPrinter = m_registry[uid].second; - if (prettyPrinter != 0) - { - prettyPrinter (buf, os); - } + assert (m_registry.size () > uid); + PrettyPrinter prettyPrinter = m_registry[uid].second; + if (prettyPrinter != 0) + { + prettyPrinter (buf, os); + } } @@ -77,98 +77,98 @@ uint32_t Tags::gN_free = 0; struct Tags::TagData * Tags::AllocData (void) { - struct Tags::TagData *retval; - if (gFree != 0) - { - retval = gFree; - gFree = gFree->m_next; - gN_free--; - } - else - { - retval = new struct Tags::TagData (); - } - return retval; + struct Tags::TagData *retval; + if (gFree != 0) + { + retval = gFree; + gFree = gFree->m_next; + gN_free--; + } + else + { + retval = new struct Tags::TagData (); + } + return retval; } void Tags::FreeData (struct TagData *data) { - if (gN_free > 1000) - { - delete data; - return; - } - gN_free++; - data->m_next = gFree; - gFree = data; + if (gN_free > 1000) + { + delete data; + return; + } + gN_free++; + data->m_next = gFree; + gFree = data; } #else struct Tags::TagData * Tags::AllocData (void) { - struct Tags::TagData *retval; - retval = new struct Tags::TagData (); - return retval; + struct Tags::TagData *retval; + retval = new struct Tags::TagData (); + return retval; } void Tags::FreeData (struct TagData *data) { - delete data; + delete data; } #endif bool Tags::Remove (uint32_t id) { - bool found = false; - for (struct TagData *cur = m_next; cur != 0; cur = cur->m_next) - { - if (cur->m_id == id) - { - found = true; - } - } - if (!found) - { - return false; - } - struct TagData *start = 0; - struct TagData **prevNext = &start; - for (struct TagData *cur = m_next; cur != 0; cur = cur->m_next) - { - if (cur->m_id == id) - { - /** - * XXX - * Note: I believe that we could optimize this to - * avoid copying each TagData located after the target id - * and just link the already-copied list to the next tag. - */ - continue; - } - struct TagData *copy = AllocData (); - copy->m_id = cur->m_id; - copy->m_count = 1; - copy->m_next = 0; - memcpy (copy->m_data, cur->m_data, Tags::SIZE); - *prevNext = copy; - prevNext = ©->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 @@ namespace ns3 { class TagsTest : Test { public: - TagsTest (); - virtual ~TagsTest (); - virtual bool RunTests (void); + TagsTest (); + virtual ~TagsTest (); + virtual bool RunTests (void); }; struct myTagA { - uint8_t a; + uint8_t a; }; struct myTagB { - uint32_t b; + uint32_t b; }; struct myTagC { - uint8_t c [Tags::SIZE]; + uint8_t c [Tags::SIZE]; }; struct myInvalidTag { - uint8_t invalid [Tags::SIZE+1]; + uint8_t invalid [Tags::SIZE+1]; }; static void myTagAPrettyPrinterCb (struct myTagA *a, std::ostream &os) { - os << "struct myTagA, a="<<(uint32_t)a->a< - void Add (T const&tag); + template + void Add (T const&tag); - template - bool Remove (T &tag); + template + bool Remove (T &tag); - template - bool Peek (T &tag) const; + template + bool Peek (T &tag) const; - void PrettyPrint (std::ostream &os); + void PrettyPrint (std::ostream &os); - inline void RemoveAll (void); + inline void RemoveAll (void); - enum { - SIZE = TAGS_MAX_SIZE - }; + enum { + SIZE = TAGS_MAX_SIZE + }; private: - struct TagData { - struct TagData *m_next; - uint32_t m_id; - uint32_t m_count; - uint8_t m_data[Tags::SIZE]; - }; + struct TagData { + struct TagData *m_next; + uint32_t m_id; + uint32_t m_count; + uint8_t m_data[Tags::SIZE]; + }; - bool Remove (uint32_t id); - struct Tags::TagData *AllocData (void); - void FreeData (struct TagData *data); + bool Remove (uint32_t id); + struct Tags::TagData *AllocData (void); + void FreeData (struct TagData *data); - static struct Tags::TagData *gFree; - static uint32_t gN_free; + static struct Tags::TagData *gFree; + static uint32_t gN_free; - struct TagData *m_next; + struct TagData *m_next; }; /** @@ -91,15 +91,15 @@ private: template 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 (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 (std::string uuid, void(*fn) (T *, std::ostream &)); private: - static void PrettyPrinterCb (uint8_t *buf, std::ostream &os); - static void(*m_prettyPrinter) (T *, std::ostream &); + static void PrettyPrinterCb (uint8_t *buf, std::ostream &os); + static void(*m_prettyPrinter) (T *, std::ostream &); }; }; // namespace ns3 @@ -107,7 +107,7 @@ private: /************************************************************** - An implementation of the templates defined above + An implementation of the templates defined above *************************************************************/ #include #include @@ -116,15 +116,15 @@ namespace ns3 { class TagRegistry { public: - typedef void (*PrettyPrinter) (uint8_t [Tags::SIZE], std::ostream &); - static void Record (std::string uuid, PrettyPrinter prettyPrinter); - static uint32_t LookupUid (std::string uuid); - static void PrettyPrint (uint32_t uid, uint8_t buf[Tags::SIZE], std::ostream &os); + typedef void (*PrettyPrinter) (uint8_t [Tags::SIZE], std::ostream &); + static void Record (std::string uuid, PrettyPrinter prettyPrinter); + static uint32_t LookupUid (std::string uuid); + static void PrettyPrint (uint32_t uid, uint8_t buf[Tags::SIZE], std::ostream &os); private: - typedef std::vector > TagsData; - typedef std::vector >::const_iterator TagsDataCI; - static bool m_sorted; - static TagsData m_registry; + typedef std::vector > TagsData; + typedef std::vector >::const_iterator TagsDataCI; + static bool m_sorted; + static TagsData m_registry; }; /** * The TypeUid class is used to create a mapping Type --> uid @@ -137,31 +137,31 @@ private: template 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 void TypeUid::Record (std::string uuid) { - *(GetUuid ()) = uuid; + *(GetUuid ()) = uuid; } template const uint32_t TypeUid::GetUid (void) { - static const uint32_t uid = TagRegistry::LookupUid (*(GetUuid ())); - return uid; + static const uint32_t uid = TagRegistry::LookupUid (*(GetUuid ())); + return uid; } template std::string *TypeUid::GetUuid (void) { - static std::string uuid; - return &uuid; + static std::string uuid; + return &uuid; } @@ -175,18 +175,18 @@ std::string *TypeUid::GetUuid (void) template TagRegistration::TagRegistration (std::string uuid, void (*prettyPrinter) (T *, std::ostream &)) { - assert (sizeof (T) <= Tags::SIZE); - m_prettyPrinter = prettyPrinter; - TagRegistry::Record (uuid, &TagRegistration::PrettyPrinterCb); - TypeUid::Record (uuid); + assert (sizeof (T) <= Tags::SIZE); + m_prettyPrinter = prettyPrinter; + TagRegistry::Record (uuid, &TagRegistration::PrettyPrinterCb); + TypeUid::Record (uuid); } template void TagRegistration::PrettyPrinterCb (uint8_t *buf, std::ostream &os) { - assert (sizeof (T) <= Tags::SIZE); - T *tag = reinterpret_cast (buf); - (*m_prettyPrinter) (tag, os); + assert (sizeof (T) <= Tags::SIZE); + T *tag = reinterpret_cast (buf); + (*m_prettyPrinter) (tag, os); } template @@ -199,106 +199,106 @@ template void Tags::Add (T const&tag) { - assert (sizeof (T) <= Tags::SIZE); - uint8_t const*buf = reinterpret_cast (&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::GetUid ()); - } - struct TagData *newStart = AllocData (); - newStart->m_count = 1; - newStart->m_next = 0; - newStart->m_id = TypeUid::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 (&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::GetUid ()); + } + struct TagData *newStart = AllocData (); + newStart->m_count = 1; + newStart->m_next = 0; + newStart->m_id = TypeUid::GetUid (); + memcpy (newStart->m_data, buf, sizeof (T)); + newStart->m_next = m_next; + m_next = newStart; } template bool Tags::Remove (T &tag) { - assert (sizeof (T) <= Tags::SIZE); - return Remove (TypeUid::GetUid ()); + assert (sizeof (T) <= Tags::SIZE); + return Remove (TypeUid::GetUid ()); } template bool Tags::Peek (T &tag) const { - assert (sizeof (T) <= Tags::SIZE); - uint8_t *buf = reinterpret_cast (&tag); - for (struct TagData *cur = m_next; cur != 0; cur = cur->m_next) - { - if (cur->m_id == TypeUid::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 (&tag); + for (struct TagData *cur = m_next; cur != 0; cur = cur->m_next) + { + if (cur->m_id == TypeUid::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; } diff --git a/src/common/trace-container.cc b/src/common/trace-container.cc index 0ae5a290b..13070a207 100644 --- a/src/common/trace-container.cc +++ b/src/common/trace-container.cc @@ -1,4 +1,4 @@ -/* -*- Mode:NS3; -*- */ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * Copyright (c) 2006 INRIA * All rights reserved. @@ -30,118 +30,118 @@ TraceContainer::TraceContainer () {} TraceContainer::~TraceContainer () { - m_uiList.erase (m_uiList.begin (), m_uiList.end ()); - m_siList.erase (m_siList.begin (), m_siList.end ()); - m_fList.erase (m_fList.begin (), m_fList.end ()); + m_uiList.erase (m_uiList.begin (), m_uiList.end ()); + m_siList.erase (m_siList.begin (), m_siList.end ()); + m_fList.erase (m_fList.begin (), m_fList.end ()); } void TraceContainer::SetUiVariableCallback (char const *name, Callback 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 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 callback) { - assert (false); + assert (false); } void TraceContainer::SetStream (char const *name, std::ostream *os) { - for (StreamTracerListI i = m_traceStreamList.begin (); i != m_traceStreamList.end (); i++) - { - if ((*i).second == name) - { - (*i).first->SetStream (os); - return; - } - } - assert (false); + for (StreamTracerListI i = m_traceStreamList.begin (); i != m_traceStreamList.end (); i++) + { + if ((*i).second == name) + { + (*i).first->SetStream (os); + return; + } + } + assert (false); } void TraceContainer::RegisterUiVariable (char const *name, UiVariableTracerBase *var) { - // ensure unicity - for (UiListI i = m_uiList.begin (); i != m_uiList.end (); i++) - { - if (i->second == name) - { - m_uiList.erase (i); - break; - } - } - m_uiList.push_back (std::make_pair (var, name)); + // ensure unicity + for (UiListI i = m_uiList.begin (); i != m_uiList.end (); i++) + { + if (i->second == name) + { + m_uiList.erase (i); + break; + } + } + m_uiList.push_back (std::make_pair (var, name)); } void TraceContainer::RegisterSiVariable (char const *name, SiVariableTracerBase *var) { - // ensure unicity - for (SiListI i = m_siList.begin (); i != m_siList.end (); i++) - { - if (i->second == name) - { - m_siList.erase (i); - break; - } - } - m_siList.push_back (std::make_pair (var, name)); + // ensure unicity + for (SiListI i = m_siList.begin (); i != m_siList.end (); i++) + { + if (i->second == name) + { + m_siList.erase (i); + break; + } + } + m_siList.push_back (std::make_pair (var, name)); } void TraceContainer::RegisterFVariable (char const *name, FVariableTracerBase *var) { - assert (false); + assert (false); } void TraceContainer::RegisterStream (char const *name, StreamTracer *stream) { - // ensure unicity - for (StreamTracerListI i = m_traceStreamList.begin (); i != m_traceStreamList.end (); i++) - { - if (i->second == name) - { - m_traceStreamList.erase (i); - break; - } - } - m_traceStreamList.push_back (std::make_pair (stream,name)); + // ensure unicity + for (StreamTracerListI i = m_traceStreamList.begin (); i != m_traceStreamList.end (); i++) + { + if (i->second == name) + { + m_traceStreamList.erase (i); + break; + } + } + m_traceStreamList.push_back (std::make_pair (stream,name)); } void TraceContainer::RegisterCallback (char const *name, CallbackTracerBase *tracer) { - for (CallbackListI i = m_callbackList.begin (); i != m_callbackList.end (); i++) - { - if (i->second == name) - { - m_callbackList.erase (i); - break; - } - } - m_callbackList.push_back (std::make_pair (tracer, name)); + for (CallbackListI i = m_callbackList.begin (); i != m_callbackList.end (); i++) + { + if (i->second == name) + { + m_callbackList.erase (i); + break; + } + } + m_callbackList.push_back (std::make_pair (tracer, name)); } @@ -153,36 +153,36 @@ TraceContainer::RegisterCallback (char const *name, CallbackTracerBase *tracer) void ns3::TraceContainer::PrintDebug (void) { - if (!m_uiList.empty ()) - { - std::cout << "ui var: " << std::endl; - for (UiListI i = m_uiList.begin (); i != m_uiList.end (); i++) - { - std::cout << " \"" << (*i).second << "\""<second << "\""<second << "\""< 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 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 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 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 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 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 - */ - template - void SetCallback (char const *name, Callback 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 - */ - template - void SetCallback (char const *name, Callback 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 - */ - template - void SetCallback (char const *name, Callback 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 - */ - template - void SetCallback (char const *name, Callback 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 - */ - template - void SetCallback (char const *name, Callback 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 + */ + template + void SetCallback (char const *name, Callback 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 + */ + template + void SetCallback (char const *name, Callback 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 + */ + template + void SetCallback (char const *name, Callback 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 + */ + template + void SetCallback (char const *name, Callback 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 + */ + template + void SetCallback (char const *name, Callback 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 > UiList; - typedef std::list >::iterator UiListI; - typedef std::list > SiList; - typedef std::list >::iterator SiListI; - typedef std::list > FList; - typedef std::list >::iterator FListI; - typedef std::list > StreamTracerList; - typedef std::list >::iterator StreamTracerListI; - typedef std::list > CallbackList; - typedef std::list >::iterator CallbackListI; + typedef std::list > UiList; + typedef std::list >::iterator UiListI; + typedef std::list > SiList; + typedef std::list >::iterator SiListI; + typedef std::list > FList; + typedef std::list >::iterator FListI; + typedef std::list > StreamTracerList; + typedef std::list >::iterator StreamTracerListI; + typedef std::list > CallbackList; + typedef std::list >::iterator CallbackListI; - UiList m_uiList; - SiList m_siList; - FList m_fList; - StreamTracerList m_traceStreamList; - CallbackList m_callbackList; + UiList m_uiList; + SiList m_siList; + FList m_fList; + StreamTracerList m_traceStreamList; + CallbackList m_callbackList; }; }; // namespace ns3 @@ -206,80 +206,80 @@ template void TraceContainer::SetCallback (char const *name, Callback callback) { - for (CallbackListI i = m_callbackList.begin (); i != m_callbackList.end (); i++) - { - if (i->second == name) - { - static_cast *> (i->first)->SetCallback (callback); - return; - } - } + for (CallbackListI i = m_callbackList.begin (); i != m_callbackList.end (); i++) + { + if (i->second == name) + { + static_cast *> (i->first)->SetCallback (callback); + return; + } + } #ifndef NDEBUG - assert (false); + assert (false); #endif } template void TraceContainer::SetCallback (char const *name, Callback callback) { - for (CallbackListI i = m_callbackList.begin (); i != m_callbackList.end (); i++) - { - if (i->second == name) - { - static_cast *> (i->first)->SetCallback (callback); - return; - } - } + for (CallbackListI i = m_callbackList.begin (); i != m_callbackList.end (); i++) + { + if (i->second == name) + { + static_cast *> (i->first)->SetCallback (callback); + return; + } + } #ifndef NDEBUG - assert (false); + assert (false); #endif } template void TraceContainer::SetCallback (char const *name, Callback callback) { - for (CallbackListI i = m_callbackList.begin (); i != m_callbackList.end (); i++) - { - if (i->second == name) - { - static_cast *> (i->first)->SetCallback (callback); - return; - } - } + for (CallbackListI i = m_callbackList.begin (); i != m_callbackList.end (); i++) + { + if (i->second == name) + { + static_cast *> (i->first)->SetCallback (callback); + return; + } + } #ifndef NDEBUG - assert (false); + assert (false); #endif } template void TraceContainer::SetCallback (char const *name, Callback callback) { - for (CallbackListI i = m_callbackList.begin (); i != m_callbackList.end (); i++) - { - if (i->second == name) - { - static_cast *> (i->first)->SetCallback (callback); - return; - } - } + for (CallbackListI i = m_callbackList.begin (); i != m_callbackList.end (); i++) + { + if (i->second == name) + { + static_cast *> (i->first)->SetCallback (callback); + return; + } + } #ifndef NDEBUG - assert (false); + assert (false); #endif } template void TraceContainer::SetCallback (char const *name, Callback callback) { - for (CallbackListI i = m_callbackList.begin (); i != m_callbackList.end (); i++) - { - if (i->second == name) - { - static_cast *> (i->first)->SetCallback (callback); - return; - } - } + for (CallbackListI i = m_callbackList.begin (); i != m_callbackList.end (); i++) + { + if (i->second == name) + { + static_cast *> (i->first)->SetCallback (callback); + return; + } + } #ifndef NDEBUG - assert (false); + assert (false); #endif } diff --git a/src/common/trailer.cc b/src/common/trailer.cc index 467421aee..3531e89f4 100644 --- a/src/common/trailer.cc +++ b/src/common/trailer.cc @@ -1,4 +1,4 @@ -/* -*- Mode:NS3; -*- */ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * Copyright (c) 2005 INRIA * All rights reserved. @@ -25,33 +25,33 @@ namespace ns3 { Trailer::Trailer () - : m_isDeserialized (false) {} + : m_isDeserialized (false) {} void Trailer::Print (std::ostream &os) const { - PrintTo (os); + PrintTo (os); } uint32_t Trailer::GetSize (void) const { - return GetSerializedSize (); + return GetSerializedSize (); } void Trailer::Serialize (Buffer::Iterator start) const { - SerializeTo (start); + SerializeTo (start); } void Trailer::Deserialize (Buffer::Iterator start) { - DeserializeFrom (start); - m_isDeserialized = true; + DeserializeFrom (start); + m_isDeserialized = true; } bool Trailer::IsDeserialized (void) const { - return m_isDeserialized; + return m_isDeserialized; } @@ -61,8 +61,8 @@ Trailer::~Trailer () std::ostream& operator<< (std::ostream& os, Trailer const& trailer) { - trailer.Print (os); - return os; + trailer.Print (os); + return os; } }; // namespace ns3 diff --git a/src/common/trailer.h b/src/common/trailer.h index b6f00ef3a..5daac0ca2 100644 --- a/src/common/trailer.h +++ b/src/common/trailer.h @@ -1,4 +1,4 @@ -/* -*- Mode:NS3; -*- */ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * Copyright (c) 2005 INRIA * All rights reserved. @@ -41,40 +41,40 @@ namespace ns3 { */ class Trailer { public: - Trailer (); - /** - * Derived classes must provide an explicit virtual destructor - */ - virtual ~Trailer () = 0; + Trailer (); + /** + * Derived classes must provide an explicit virtual destructor + */ + virtual ~Trailer () = 0; - void Print (std::ostream &os) const; - uint32_t GetSize (void) const; - void Serialize (Buffer::Iterator start) const; - void Deserialize (Buffer::Iterator start); - bool IsDeserialized (void) const; + void Print (std::ostream &os) const; + uint32_t GetSize (void) const; + void Serialize (Buffer::Iterator start) const; + void Deserialize (Buffer::Iterator start); + bool IsDeserialized (void) const; private: - bool m_isDeserialized; - /** - * \param os the std output stream in which this - * protocol trailer must print itself. - */ - virtual void PrintTo (std::ostream &os) const = 0; + bool m_isDeserialized; + /** + * \param os the std output stream in which this + * protocol trailer must print itself. + */ + virtual void PrintTo (std::ostream &os) const = 0; - /** - * \returns the size of the serialized Trailer. - */ - virtual uint32_t GetSerializedSize (void) const = 0; + /** + * \returns the size of the serialized Trailer. + */ + virtual uint32_t GetSerializedSize (void) const = 0; - /** - * \param start the buffer iterator in which the protocol trailer - * must serialize itself. - */ - virtual void SerializeTo (Buffer::Iterator start) const = 0; - /** - * \param start the buffer iterator from which the protocol trailer must - * deserialize itself. - */ - virtual void DeserializeFrom (Buffer::Iterator start) = 0; + /** + * \param start the buffer iterator in which the protocol trailer + * must serialize itself. + */ + virtual void SerializeTo (Buffer::Iterator start) const = 0; + /** + * \param start the buffer iterator from which the protocol trailer must + * deserialize itself. + */ + virtual void DeserializeFrom (Buffer::Iterator start) = 0; }; std::ostream& operator<< (std::ostream& os, Trailer const& trailer); diff --git a/src/common/ui-variable-tracer.h b/src/common/ui-variable-tracer.h index 44c60e407..dd0cdb083 100644 --- a/src/common/ui-variable-tracer.h +++ b/src/common/ui-variable-tracer.h @@ -1,4 +1,4 @@ -/* -*- Mode:NS3; -*- */ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * Copyright (c) 2006 INRIA * All rights reserved. @@ -29,31 +29,31 @@ namespace ns3 { class UiVariableTracerBase { public: - typedef Callback ChangeNotifyCallback; + typedef Callback 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 @@ -86,153 +86,153 @@ class SiVariableTracer; template 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 - UiVariableTracer &operator = (UiVariableTracer const &o) { - Assign (o.Get ()); - return *this; - } - template - UiVariableTracer &operator = (SiVariableTracer 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 + UiVariableTracer &operator = (UiVariableTracer const &o) { + Assign (o.Get ()); + return *this; + } + template + UiVariableTracer &operator = (SiVariableTracer 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 UiVariableTracer &operator += (UiVariableTracer &lhs, UiVariableTracer const &rhs) { - lhs.Assign (lhs.Get () + rhs.Get ()); - return lhs; + lhs.Assign (lhs.Get () + rhs.Get ()); + return lhs; } template UiVariableTracer &operator -= (UiVariableTracer &lhs, UiVariableTracer const &rhs) { - lhs.Assign (lhs.Get () - rhs.Get ()); - return lhs; + lhs.Assign (lhs.Get () - rhs.Get ()); + return lhs; } template UiVariableTracer &operator *= (UiVariableTracer &lhs, UiVariableTracer const &rhs) { - lhs.Assign (lhs.Get () * rhs.Get ()); - return lhs; + lhs.Assign (lhs.Get () * rhs.Get ()); + return lhs; } template UiVariableTracer &operator /= (UiVariableTracer &lhs, UiVariableTracer const &rhs) { - lhs.Assign (lhs.Get () / rhs.Get ()); - return lhs; + lhs.Assign (lhs.Get () / rhs.Get ()); + return lhs; } template UiVariableTracer &operator <<= (UiVariableTracer &lhs, UiVariableTracer const &rhs) { - lhs.Assign (lhs.Get () << rhs.Get ()); - return lhs; + lhs.Assign (lhs.Get () << rhs.Get ()); + return lhs; } template UiVariableTracer &operator >>= (UiVariableTracer &lhs, UiVariableTracer const &rhs) { - lhs.Assign (lhs.Get () >> rhs.Get ()); - return lhs; + lhs.Assign (lhs.Get () >> rhs.Get ()); + return lhs; } template UiVariableTracer &operator &= (UiVariableTracer &lhs, UiVariableTracer const &rhs) { - lhs.Assign (lhs.Get () & rhs.Get ()); - return lhs; + lhs.Assign (lhs.Get () & rhs.Get ()); + return lhs; } template UiVariableTracer &operator |= (UiVariableTracer &lhs, UiVariableTracer const &rhs) { - lhs.Assign (lhs.Get () | rhs.Get ()); - return lhs; + lhs.Assign (lhs.Get () | rhs.Get ()); + return lhs; } template UiVariableTracer &operator ^= (UiVariableTracer &lhs, UiVariableTracer const &rhs) { - lhs.Assign (lhs.Get () ^ rhs.Get ()); - return lhs; + lhs.Assign (lhs.Get () ^ rhs.Get ()); + return lhs; } template UiVariableTracer &operator += (UiVariableTracer &lhs, U const &rhs) { - lhs.Assign (lhs.Get () + rhs); - return lhs; + lhs.Assign (lhs.Get () + rhs); + return lhs; } template UiVariableTracer &operator -= (UiVariableTracer &lhs, U const &rhs) { - lhs.Assign (lhs.Get () - rhs); - return lhs; + lhs.Assign (lhs.Get () - rhs); + return lhs; } template UiVariableTracer &operator *= (UiVariableTracer &lhs, U const &rhs) { - lhs.Assign (lhs.Get () * rhs); - return lhs; + lhs.Assign (lhs.Get () * rhs); + return lhs; } template UiVariableTracer &operator /= (UiVariableTracer &lhs, U const &rhs) { - lhs.Assign (lhs.Get () / rhs); - return lhs; + lhs.Assign (lhs.Get () / rhs); + return lhs; } template UiVariableTracer &operator <<= (UiVariableTracer &lhs, U const &rhs) { - lhs.Assign (lhs.Get () << rhs); - return lhs; + lhs.Assign (lhs.Get () << rhs); + return lhs; } template UiVariableTracer &operator >>= (UiVariableTracer &lhs, U const &rhs) { - lhs.Assign (lhs.Get () >> rhs); - return lhs; + lhs.Assign (lhs.Get () >> rhs); + return lhs; } template UiVariableTracer &operator &= (UiVariableTracer &lhs, U const &rhs) { - lhs.Assign (lhs.Get () & rhs); - return lhs; + lhs.Assign (lhs.Get () & rhs); + return lhs; } template UiVariableTracer &operator |= (UiVariableTracer &lhs, U const &rhs) { - lhs.Assign (lhs.Get () | rhs); - return lhs; + lhs.Assign (lhs.Get () | rhs); + return lhs; } template UiVariableTracer &operator ^= (UiVariableTracer &lhs, U const &rhs) { - lhs.Assign (lhs.Get () ^ rhs); - return lhs; + lhs.Assign (lhs.Get () ^ rhs); + return lhs; } }; // namespace ns3 diff --git a/src/common/variable-tracer-test.cc b/src/common/variable-tracer-test.cc index e0959f91a..342906793 100644 --- a/src/common/variable-tracer-test.cc +++ b/src/common/variable-tracer-test.cc @@ -1,4 +1,4 @@ -/* -*- Mode:NS3; -*- */ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * Copyright (c) 2006 INRIA * All rights reserved. @@ -29,238 +29,238 @@ namespace ns3 { class Foo { public: - void Notify (uint64_t oldVal, uint64_t newVal) {} + void Notify (uint64_t oldVal, uint64_t newVal) {} }; class VariableTracerTest: public Test { public: - VariableTracerTest (); - void RunUnsignedTests (void); - void RunSignedUnsignedTests (void); - virtual bool RunTests (void); + VariableTracerTest (); + void RunUnsignedTests (void); + void RunSignedUnsignedTests (void); + virtual bool RunTests (void); }; void VariableTracerTest::RunUnsignedTests (void) { - UiVariableTracer var, ovar, tmp; - uint32_t utmp; - Foo *foo = new Foo (); - - var.SetCallback (MakeCallback (&Foo::Notify, foo)); + UiVariableTracer 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 uvar = 10; - UiVariableTracer uivar = 5; - SiVariableTracer svar = 5; - SiVariableTracer sivar = 5; - uvar = svar; - svar = uvar; - uvar += svar; - svar += uvar; + UiVariableTracer uvar = 10; + UiVariableTracer uivar = 5; + SiVariableTracer svar = 5; + SiVariableTracer 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; diff --git a/src/core/callback-test.cc b/src/core/callback-test.cc index 382ba92f5..54ee88b5b 100644 --- a/src/core/callback-test.cc +++ b/src/core/callback-test.cc @@ -1,4 +1,4 @@ -/* -*- Mode:NS3; -*- */ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * Copyright (c) 2005,2006 INRIA * All rights reserved. @@ -33,164 +33,164 @@ static bool gTest7 = false; void Test5 (void) { - gTest5 = true; + gTest5 = true; } void Test6 (int) { - gTest6 = true; + gTest6 = true; } int Test7 (int a) { - gTest7 = true; - return a; + gTest7 = true; + return a; } class CallbackTest : public ns3::Test { private: - bool m_test1; - bool m_test2; - bool m_test3; - bool m_test4; + bool m_test1; + bool m_test2; + bool m_test3; + bool m_test4; public: - CallbackTest (); - virtual bool RunTests (void); - void Reset (void); - bool IsWrong (void); - void Test1 (void); - int Test2 (void); - void Test3 (double a); - int Test4 (double a, int b); - void Test8 (Callback 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 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 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 A; - typedef ns3::Callback B; - typedef ns3::Callback C; - typedef ns3::Callback D; - typedef ns3::Callback E; - typedef ns3::Callback F; - typedef ns3::Callback 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 A; + typedef ns3::Callback B; + typedef ns3::Callback C; + typedef ns3::Callback D; + typedef ns3::Callback E; + typedef ns3::Callback F; + typedef ns3::Callback 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 a2; + Callback a2; - if (IsWrong ()) - { - ok = false; - } - return ok; + if (IsWrong ()) + { + ok = false; + } + return ok; } static CallbackTest gCallbackTest; diff --git a/src/core/callback.h b/src/core/callback.h index b912417e3..1610e6e65 100644 --- a/src/core/callback.h +++ b/src/core/callback.h @@ -1,4 +1,4 @@ -/* -*- Mode:NS3; -*- */ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * Copyright (c) 2005,2006 INRIA * All rights reserved. @@ -64,43 +64,43 @@ class CallbackImpl; template class CallbackImpl { public: - virtual ~CallbackImpl () {} - virtual R operator() (void) = 0; + virtual ~CallbackImpl () {} + virtual R operator() (void) = 0; }; // define CallbackImpl for 1 params template class CallbackImpl { public: - virtual ~CallbackImpl () {} - virtual R operator() (T1) = 0; + virtual ~CallbackImpl () {} + virtual R operator() (T1) = 0; }; // define CallbackImpl for 2 params template class CallbackImpl { public: - virtual ~CallbackImpl () {} - virtual R operator() (T1, T2) = 0; + virtual ~CallbackImpl () {} + virtual R operator() (T1, T2) = 0; }; // define CallbackImpl for 3 params template class CallbackImpl { 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 class CallbackImpl { 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 class CallbackImpl { public: - virtual ~CallbackImpl () {} - virtual R operator() (T1, T2, T3, T4, T5) = 0; + virtual ~CallbackImpl () {} + virtual R operator() (T1, T2, T3, T4, T5) = 0; }; @@ -108,59 +108,59 @@ public: template class FunctorCallbackImpl : public CallbackImpl { 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 class MemPtrCallbackImpl : public CallbackImpl { public: - MemPtrCallbackImpl (OBJ_PTR const&objPtr, MEM_PTR mem_ptr) - : m_objPtr (objPtr), m_memPtr (mem_ptr) {} - virtual ~MemPtrCallbackImpl () {} - R operator() (void) { - return ((*m_objPtr).*m_memPtr) (); - } - R operator() (T1 a1) { - return ((*m_objPtr).*m_memPtr) (a1); - } - R operator() (T1 a1,T2 a2) { - return ((*m_objPtr).*m_memPtr) (a1,a2); - } - R operator() (T1 a1,T2 a2,T3 a3) { - return ((*m_objPtr).*m_memPtr) (a1,a2,a3); - } - R operator() (T1 a1,T2 a2,T3 a3,T4 a4) { - return ((*m_objPtr).*m_memPtr) (a1,a2,a3,a4); - } - R operator() (T1 a1,T2 a2,T3 a3,T4 a4,T5 a5) { - return ((*m_objPtr).*m_memPtr) (a1,a2,a3,a4,a5); - } + MemPtrCallbackImpl (OBJ_PTR const&objPtr, MEM_PTR mem_ptr) + : m_objPtr (objPtr), m_memPtr (mem_ptr) {} + virtual ~MemPtrCallbackImpl () {} + R operator() (void) { + return ((*m_objPtr).*m_memPtr) (); + } + R operator() (T1 a1) { + return ((*m_objPtr).*m_memPtr) (a1); + } + R operator() (T1 a1,T2 a2) { + return ((*m_objPtr).*m_memPtr) (a1,a2); + } + R operator() (T1 a1,T2 a2,T3 a3) { + return ((*m_objPtr).*m_memPtr) (a1,a2,a3); + } + R operator() (T1 a1,T2 a2,T3 a3,T4 a4) { + return ((*m_objPtr).*m_memPtr) (a1,a2,a3,a4); + } + R operator() (T1 a1,T2 a2,T3 a3,T4 a4,T5 a5) { + return ((*m_objPtr).*m_memPtr) (a1,a2,a3,a4,a5); + } private: - OBJ_PTR const m_objPtr; - MEM_PTR m_memPtr; + OBJ_PTR const m_objPtr; + MEM_PTR m_memPtr; }; /** @@ -192,50 +192,50 @@ private: * \include samples/main-callback.cc */ template + typename T1 = empty, typename T2 = empty, + typename T3 = empty, typename T4 = empty, + typename T5 = empty> class Callback { public: - template - Callback (FUNCTOR const &functor) - : m_impl (new FunctorCallbackImpl (functor)) - {} + template + Callback (FUNCTOR const &functor) + : m_impl (new FunctorCallbackImpl (functor)) + {} - template - Callback (OBJ_PTR const &objPtr, MEM_PTR mem_ptr) - : m_impl (new MemPtrCallbackImpl (objPtr, mem_ptr)) - {} + template + Callback (OBJ_PTR const &objPtr, MEM_PTR mem_ptr) + : m_impl (new MemPtrCallbackImpl (objPtr, mem_ptr)) + {} - Callback (ReferenceList *> const &impl) - : m_impl (impl) - {} + Callback (ReferenceList *> 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*> m_impl; + ReferenceList*> m_impl; }; /** @@ -253,7 +253,7 @@ private: */ template Callback MakeCallback (R (OBJ::*mem_ptr) (), OBJ *const objPtr) { - return Callback (objPtr, mem_ptr); + return Callback (objPtr, mem_ptr); } /** * \ingroup MakeCallback @@ -265,7 +265,7 @@ Callback MakeCallback (R (OBJ::*mem_ptr) (), OBJ *const objPtr) { */ template Callback MakeCallback (R (OBJ::*mem_ptr) (T1), OBJ *const objPtr) { - return Callback (objPtr, mem_ptr); + return Callback (objPtr, mem_ptr); } /** * \ingroup MakeCallback @@ -277,7 +277,7 @@ Callback MakeCallback (R (OBJ::*mem_ptr) (T1), OBJ *const objPtr) { */ template Callback MakeCallback (R (OBJ::*mem_ptr) (T1,T2), OBJ *const objPtr) { - return Callback (objPtr, mem_ptr); + return Callback (objPtr, mem_ptr); } /** * \ingroup MakeCallback @@ -289,7 +289,7 @@ Callback MakeCallback (R (OBJ::*mem_ptr) (T1,T2), OBJ *const objPtr) { */ template Callback MakeCallback (R (OBJ::*mem_ptr) (T1,T2,T3), OBJ *const objPtr) { - return Callback (objPtr, mem_ptr); + return Callback (objPtr, mem_ptr); } /** * \ingroup MakeCallback @@ -301,7 +301,7 @@ Callback MakeCallback (R (OBJ::*mem_ptr) (T1,T2,T3), OBJ *const objP */ template Callback MakeCallback (R (OBJ::*mem_ptr) (T1,T2,T3,T4), OBJ *const objPtr) { - return Callback (objPtr, mem_ptr); + return Callback (objPtr, mem_ptr); } /** * \ingroup MakeCallback @@ -313,7 +313,7 @@ Callback MakeCallback (R (OBJ::*mem_ptr) (T1,T2,T3,T4), OBJ *cons */ template Callback MakeCallback (R (OBJ::*mem_ptr) (T1,T2,T3,T4,T5), OBJ *const objPtr) { - return Callback (objPtr, mem_ptr); + return Callback (objPtr, mem_ptr); } /** @@ -325,7 +325,7 @@ Callback MakeCallback (R (OBJ::*mem_ptr) (T1,T2,T3,T4,T5), OBJ */ template Callback MakeCallback (R (*fnPtr) ()) { - return Callback (fnPtr); + return Callback (fnPtr); } /** * \ingroup MakeCallback @@ -336,7 +336,7 @@ Callback MakeCallback (R (*fnPtr) ()) { */ template Callback MakeCallback (R (*fnPtr) (T1)) { - return Callback (fnPtr); + return Callback (fnPtr); } /** * \ingroup MakeCallback @@ -347,7 +347,7 @@ Callback MakeCallback (R (*fnPtr) (T1)) { */ template Callback MakeCallback (R (*fnPtr) (T1,T2)) { - return Callback (fnPtr); + return Callback (fnPtr); } /** * \ingroup MakeCallback @@ -358,7 +358,7 @@ Callback MakeCallback (R (*fnPtr) (T1,T2)) { */ template Callback MakeCallback (R (*fnPtr) (T1,T2,T3)) { - return Callback (fnPtr); + return Callback (fnPtr); } /** * \ingroup MakeCallback @@ -369,7 +369,7 @@ Callback MakeCallback (R (*fnPtr) (T1,T2,T3)) { */ template Callback MakeCallback (R (*fnPtr) (T1,T2,T3,T4)) { - return Callback (fnPtr); + return Callback (fnPtr); } /** * \ingroup MakeCallback @@ -380,7 +380,7 @@ Callback MakeCallback (R (*fnPtr) (T1,T2,T3,T4)) { */ template Callback MakeCallback (R (*fnPtr) (T1,T2,T3,T4,T5)) { - return Callback (fnPtr); + return Callback (fnPtr); } @@ -393,7 +393,7 @@ Callback MakeCallback (R (*fnPtr) (T1,T2,T3,T4,T5)) { */ template Callback MakeNullCallback (void) { - return Callback (); + return Callback (); } /** * \ingroup MakeCallback @@ -403,7 +403,7 @@ Callback MakeNullCallback (void) { */ template Callback MakeNullCallback (void) { - return Callback (); + return Callback (); } /** * \ingroup MakeCallback @@ -413,7 +413,7 @@ Callback MakeNullCallback (void) { */ template Callback MakeNullCallback (void) { - return Callback (); + return Callback (); } /** * \ingroup MakeCallback @@ -423,7 +423,7 @@ Callback MakeNullCallback (void) { */ template Callback MakeNullCallback (void) { - return Callback (); + return Callback (); } /** * \ingroup MakeCallback @@ -433,7 +433,7 @@ Callback MakeNullCallback (void) { */ template Callback MakeNullCallback (void) { - return Callback (); + return Callback (); } /** * \ingroup MakeCallback @@ -443,7 +443,7 @@ Callback MakeNullCallback (void) { */ template Callback MakeNullCallback (void) { - return Callback (); + return Callback (); } @@ -456,64 +456,64 @@ Callback MakeNullCallback (void) { template class BoundFunctorCallbackImpl : public CallbackImpl { 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 Callback MakeBoundCallback (R (*fnPtr) (TX,T1), TX a) { - ReferenceList*> impl = - ReferenceList*> ( - new BoundFunctorCallbackImpl (fnPtr, a) - ); - return Callback (impl); + ReferenceList*> impl = + ReferenceList*> ( + new BoundFunctorCallbackImpl (fnPtr, a) + ); + return Callback (impl); } template Callback MakeBoundCallback (R (*fnPtr) (TX,T1,T2), TX a) { - ReferenceList*> impl = - ReferenceList*> ( - new BoundFunctorCallbackImpl (fnPtr, a) - ); - return Callback (impl); + ReferenceList*> impl = + ReferenceList*> ( + new BoundFunctorCallbackImpl (fnPtr, a) + ); + return Callback (impl); } template Callback MakeBoundCallback (R (*fnPtr) (TX,T1,T2,T3,T4), TX a) { - ReferenceList*> impl = - ReferenceList*> ( - new BoundFunctorCallbackImpl (fnPtr, a) - ); - return Callback (impl); + ReferenceList*> impl = + ReferenceList*> ( + new BoundFunctorCallbackImpl (fnPtr, a) + ); + return Callback (impl); } template Callback MakeBoundCallback (R (*fnPtr) (TX,T1,T2,T3,T4,T5), TX a) { - ReferenceList*> impl = - ReferenceList*> ( - new BoundFunctorCallbackImpl (fnPtr, a) - ); - return Callback (impl); + ReferenceList*> impl = + ReferenceList*> ( + new BoundFunctorCallbackImpl (fnPtr, a) + ); + return Callback (impl); } diff --git a/src/core/reference-list-test.cc b/src/core/reference-list-test.cc index 3a7b6d13f..fdbad33ac 100644 --- a/src/core/reference-list-test.cc +++ b/src/core/reference-list-test.cc @@ -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 #define TRACE(x) \ - std::cout << x << std::endl; + std::cout << x << std::endl; #else #define TRACE(x) #endif @@ -37,79 +37,79 @@ namespace { class A { public: - A () { - TRACE ("constructor"); - } - ~A () { - TRACE ("destructor"); - } - void Trace (void) { - TRACE ("trace"); - } + A () { + TRACE ("constructor"); + } + ~A () { + TRACE ("destructor"); + } + void Trace (void) { + TRACE ("trace"); + } }; class RefTest : public ns3::Test { public: - RefTest (); - virtual bool RunTests (void); + RefTest (); + virtual bool RunTests (void); private: - void OneTest (ns3::ReferenceList); + void OneTest (ns3::ReferenceList); }; RefTest::RefTest () - : ns3::Test ("ReferenceList") + : ns3::Test ("ReferenceList") {} void RefTest::OneTest (ns3::ReferenceList a) { - a->Trace (); + a->Trace (); } bool RefTest::RunTests (void) { - bool ok = true; + bool ok = true; - { - ns3::ReferenceList tmp; - { - ns3::ReferenceList 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 tmp; + { + ns3::ReferenceList 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 tmp; - } + { + ns3::ReferenceList tmp; + } - { - ns3::ReferenceList tmp (new A ()); - } + { + ns3::ReferenceList tmp (new A ()); + } - { - ns3::ReferenceList tmp; - tmp.Set (new A ()); - } + { + ns3::ReferenceList tmp; + tmp.Set (new A ()); + } - { - TRACE ("test assignement"); - ns3::ReferenceList a0 (new A ()); - ns3::ReferenceList a1 (new A ()); - a0 = a1; - } + { + TRACE ("test assignement"); + ns3::ReferenceList a0 (new A ()); + ns3::ReferenceList a1 (new A ()); + a0 = a1; + } - return ok; + return ok; } diff --git a/src/core/reference-list.h b/src/core/reference-list.h index f67a0e9e1..1f21a39a6 100644 --- a/src/core/reference-list.h +++ b/src/core/reference-list.h @@ -1,4 +1,4 @@ -/* -*- Mode:NS3; -*- */ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * Copyright (c) 2006 INRIA * All rights reserved. @@ -37,80 +37,80 @@ class ReferenceList; template 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 diff --git a/src/core/system-file.h b/src/core/system-file.h index 5596271b8..a1dba2b13 100644 --- a/src/core/system-file.h +++ b/src/core/system-file.h @@ -1,4 +1,4 @@ -/* -*- Mode:NS3; -*- */ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * Copyright (c) 2005 INRIA * All rights reserved. @@ -35,41 +35,41 @@ class SystemFilePrivate; */ class SystemFile { public: - /** - * This method does not create or open any - * file on disk. - */ - SystemFile (); - /** - * If a file has been opened, it is closed by - * this destructor. - */ - ~SystemFile (); + /** + * This method does not create or open any + * file on disk. + */ + SystemFile (); + /** + * If a file has been opened, it is closed by + * this destructor. + */ + ~SystemFile (); - /** - * \param filename name of file to open - * - * Open a file for writing. If the file does not - * exist, it is created. If it exists, it is - * emptied first. - */ - void Open (char const *filename); - /** - * \param buffer data to write - * \param size size of data to write - * - * Write data in file on disk. This method cannot fail: - * it will write _all_ the data to disk. This method does not - * perform any data caching and forwards the data - * to the OS through a direct syscall. However, - * it is not possible to rely on the data being - * effectively written to disk after this method returns. - * To make sure the data is written to disk, destroy - * this object. - */ - void Write (uint8_t const*buffer, uint32_t size); + /** + * \param filename name of file to open + * + * Open a file for writing. If the file does not + * exist, it is created. If it exists, it is + * emptied first. + */ + void Open (char const *filename); + /** + * \param buffer data to write + * \param size size of data to write + * + * Write data in file on disk. This method cannot fail: + * it will write _all_ the data to disk. This method does not + * perform any data caching and forwards the data + * to the OS through a direct syscall. However, + * it is not possible to rely on the data being + * effectively written to disk after this method returns. + * To make sure the data is written to disk, destroy + * this object. + */ + void Write (uint8_t const*buffer, uint32_t size); private: - SystemFilePrivate *m_priv; + SystemFilePrivate *m_priv; }; }; //namespace ns3 diff --git a/src/core/system-wall-clock-ms.h b/src/core/system-wall-clock-ms.h index 1ba16cd2a..47564c10f 100644 --- a/src/core/system-wall-clock-ms.h +++ b/src/core/system-wall-clock-ms.h @@ -1,4 +1,4 @@ -/* -*- Mode:NS3; -*- */ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * Copyright (c) 2005 INRIA * All rights reserved. @@ -29,23 +29,23 @@ namespace ns3 { */ class SystemWallClockMs { public: - SystemWallClockMs (); - ~SystemWallClockMs (); + SystemWallClockMs (); + ~SystemWallClockMs (); - /** - * Start a measure. - */ - void Start (void); - /** - * \returns the measured elapsed wall clock time since - * ns3::SystemWallClockMs::start was invoked. - * - * It is possible to start a new measurement with ns3::SystemWallClockMs::start - * after this method returns. - */ - unsigned long long End (void); + /** + * Start a measure. + */ + void Start (void); + /** + * \returns the measured elapsed wall clock time since + * ns3::SystemWallClockMs::start was invoked. + * + * It is possible to start a new measurement with ns3::SystemWallClockMs::start + * after this method returns. + */ + unsigned long long End (void); private: - class SystemWallClockMsPrivate *m_priv; + class SystemWallClockMsPrivate *m_priv; }; }; // namespace ns3 diff --git a/src/core/test.cc b/src/core/test.cc index 4947e54ba..8c8e2b120 100644 --- a/src/core/test.cc +++ b/src/core/test.cc @@ -1,4 +1,4 @@ -/* -*- Mode:NS3; -*- */ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * Copyright (c) 2005 INRIA * All rights reserved. @@ -29,76 +29,76 @@ namespace ns3 { TestManager * TestManager::Get (void) { - static TestManager manager; - return &manager; + static TestManager manager; + return &manager; } TestManager::TestManager () - : m_verbose (false) + : m_verbose (false) {} TestManager::~TestManager () { - TestsI i = m_tests.begin (); - while (i != m_tests.end ()) - { - delete (*i).second; - i = m_tests.erase (i); - } + TestsI i = m_tests.begin (); + while (i != m_tests.end ()) + { + delete (*i).second; + i = m_tests.erase (i); + } } void TestManager::Add (Test *test, char const *name) { - Get ()->m_tests.push_back (std::make_pair (test, new std::string (name))); + Get ()->m_tests.push_back (std::make_pair (test, new std::string (name))); } void TestManager::EnableVerbose (void) { - Get ()->m_verbose = true; + Get ()->m_verbose = true; } std::ostream & TestManager::Failure (void) { - return std::cerr; + return std::cerr; } bool TestManager::RunTests (void) { - return Get ()->RealRunTests (); + return Get ()->RealRunTests (); } bool TestManager::RealRunTests (void) { - bool isSuccess = true; - for (TestsCI i = m_tests.begin (); i != m_tests.end (); i++) - { - std::string *testName = (*i).second; - if (!(*i).first->RunTests ()) - { - isSuccess = false; - if (m_verbose) - { - std::cerr << "FAIL " << *testName << std::endl; - } - } - else - { - if (m_verbose) - { - std::cerr << "PASS "<<*testName << std::endl; - } - } - } - if (!isSuccess) - { - std::cerr << "FAIL" << std::endl; - } - return isSuccess; + bool isSuccess = true; + for (TestsCI i = m_tests.begin (); i != m_tests.end (); i++) + { + std::string *testName = (*i).second; + if (!(*i).first->RunTests ()) + { + isSuccess = false; + if (m_verbose) + { + std::cerr << "FAIL " << *testName << std::endl; + } + } + else + { + if (m_verbose) + { + std::cerr << "PASS "<<*testName << std::endl; + } + } + } + if (!isSuccess) + { + std::cerr << "FAIL" << std::endl; + } + return isSuccess; } Test::Test (char const *name) { - TestManager::Add (this, name); + TestManager::Add (this, name); } Test::~Test () @@ -107,7 +107,7 @@ Test::~Test () std::ostream & Test::Failure (void) { - return TestManager::Failure (); + return TestManager::Failure (); } }; // namespace ns3 diff --git a/src/core/test.h b/src/core/test.h index 057e915dd..aa7766f42 100644 --- a/src/core/test.h +++ b/src/core/test.h @@ -1,4 +1,4 @@ -/* -*- Mode:NS3; -*- */ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * Copyright (c) 2005 INRIA * All rights reserved. @@ -46,23 +46,23 @@ class TestManager; */ class Test { public: - /** - * \param name the name of the test - */ - Test (char const *name); - virtual ~Test (); + /** + * \param name the name of the test + */ + Test (char const *name); + virtual ~Test (); - /** - * \returns true if the test was successful, false otherwise. - */ - virtual bool RunTests (void) = 0; + /** + * \returns true if the test was successful, false otherwise. + */ + virtual bool RunTests (void) = 0; protected: - /** - * \returns an output stream which base classes can write to - * to return extra information on test errors. - */ - std::ostream &Failure (void); + /** + * \returns an output stream which base classes can write to + * to return extra information on test errors. + */ + std::ostream &Failure (void); }; /** @@ -70,34 +70,34 @@ protected: */ class TestManager { public: - /** - * Enable verbose output. If you do not enable verbose output, - * nothing is printed on screen during the test runs. - */ - static void EnableVerbose (void); - /** - * \returns true if all tests passed, false otherwise. - * - * run all registered regression tests - */ - static bool RunTests (void); + /** + * Enable verbose output. If you do not enable verbose output, + * nothing is printed on screen during the test runs. + */ + static void EnableVerbose (void); + /** + * \returns true if all tests passed, false otherwise. + * + * run all registered regression tests + */ + static bool RunTests (void); private: - friend class Test; - static void Add (Test *test, char const *name); - static std::ostream &Failure (void); - static TestManager *Get (void); - bool RealRunTests (void); + friend class Test; + static void Add (Test *test, char const *name); + static std::ostream &Failure (void); + static TestManager *Get (void); + bool RealRunTests (void); - TestManager (); - ~TestManager (); + TestManager (); + ~TestManager (); - typedef std::list > Tests; - typedef std::list >::iterator TestsI; - typedef std::list >::const_iterator TestsCI; + typedef std::list > Tests; + typedef std::list >::iterator TestsI; + typedef std::list >::const_iterator TestsCI; - Tests m_tests; - bool m_verbose; + Tests m_tests; + bool m_verbose; }; }; // namespace ns3 diff --git a/src/core/unix-system-file.cc b/src/core/unix-system-file.cc index f56c59794..909f6d89f 100644 --- a/src/core/unix-system-file.cc +++ b/src/core/unix-system-file.cc @@ -1,4 +1,4 @@ -/* -*- Mode:NS3; -*- */ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * Copyright (c) 2005 INRIA * All rights reserved. @@ -46,32 +46,32 @@ namespace ns3 { class SystemFilePrivate { public: - SystemFilePrivate (); - ~SystemFilePrivate (); + SystemFilePrivate (); + ~SystemFilePrivate (); - void Open (char const *filename); - void Write (uint8_t const*buffer, uint32_t size); + void Open (char const *filename); + void Write (uint8_t const*buffer, uint32_t size); private: - uint8_t m_data[BUFFER_SIZE]; - uint32_t m_current; - int m_fd; + uint8_t m_data[BUFFER_SIZE]; + uint32_t m_current; + int m_fd; }; SystemFilePrivate::SystemFilePrivate () - : m_current (0) + : m_current (0) {} SystemFilePrivate::~SystemFilePrivate () { - ::write (m_fd, m_data, m_current); - ::close (m_fd); + ::write (m_fd, m_data, m_current); + ::close (m_fd); } void SystemFilePrivate::Open (char const *filename) { - m_fd = ::open (filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); - assert (m_fd != -1); + m_fd = ::open (filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); + assert (m_fd != -1); } #ifndef min @@ -81,41 +81,41 @@ SystemFilePrivate::Open (char const *filename) void SystemFilePrivate::Write (uint8_t const*buffer, uint32_t size) { - while (size > 0) - { - uint32_t toCopy = min (BUFFER_SIZE - m_current, size); - memcpy (m_data + m_current, buffer, toCopy); - size -= toCopy; - m_current += toCopy; - buffer += toCopy; - if (m_current == BUFFER_SIZE) - { - ssize_t written = 0; - written = ::write (m_fd, m_data, BUFFER_SIZE); - assert (written == BUFFER_SIZE); - m_current = 0; - } - } + while (size > 0) + { + uint32_t toCopy = min (BUFFER_SIZE - m_current, size); + memcpy (m_data + m_current, buffer, toCopy); + size -= toCopy; + m_current += toCopy; + buffer += toCopy; + if (m_current == BUFFER_SIZE) + { + ssize_t written = 0; + written = ::write (m_fd, m_data, BUFFER_SIZE); + assert (written == BUFFER_SIZE); + m_current = 0; + } + } } SystemFile::SystemFile () - : m_priv (new SystemFilePrivate ()) + : m_priv (new SystemFilePrivate ()) {} SystemFile::~SystemFile () { - delete m_priv; - m_priv = 0; + delete m_priv; + m_priv = 0; } void SystemFile::Open (char const *filename) { - m_priv->Open (filename); + m_priv->Open (filename); } void SystemFile::Write (uint8_t const*buffer, uint32_t size) { - m_priv->Write (buffer, size); + m_priv->Write (buffer, size); } }; // namespace diff --git a/src/core/unix-system-wall-clock-ms.cc b/src/core/unix-system-wall-clock-ms.cc index af3b81050..09f342074 100644 --- a/src/core/unix-system-wall-clock-ms.cc +++ b/src/core/unix-system-wall-clock-ms.cc @@ -1,4 +1,4 @@ -/* -*- Mode:NS3; -*- */ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * Copyright (c) 2005 INRIA * All rights reserved. @@ -26,49 +26,49 @@ namespace ns3 { class SystemWallClockMsPrivate { public: - void Start (void); - unsigned long long End (void); + void Start (void); + unsigned long long End (void); private: - struct timeval m_startTv; - struct timeval m_endTv; + struct timeval m_startTv; + struct timeval m_endTv; }; void SystemWallClockMsPrivate::Start (void) { - struct timezone tz; - gettimeofday (&m_startTv, &tz); + struct timezone tz; + gettimeofday (&m_startTv, &tz); } unsigned long long SystemWallClockMsPrivate::End (void) { - struct timezone tz; - gettimeofday (&m_endTv, &tz); - unsigned long long end = m_endTv.tv_sec *1000 + m_endTv.tv_usec / 1000; - unsigned long long start = m_startTv.tv_sec *1000 + m_startTv.tv_usec / 1000; - return end - start; + struct timezone tz; + gettimeofday (&m_endTv, &tz); + unsigned long long end = m_endTv.tv_sec *1000 + m_endTv.tv_usec / 1000; + unsigned long long start = m_startTv.tv_sec *1000 + m_startTv.tv_usec / 1000; + return end - start; } SystemWallClockMs::SystemWallClockMs () - : m_priv (new SystemWallClockMsPrivate ()) + : m_priv (new SystemWallClockMsPrivate ()) {} SystemWallClockMs::~SystemWallClockMs () { - delete m_priv; - m_priv = 0; + delete m_priv; + m_priv = 0; } void SystemWallClockMs::Start (void) { - m_priv->Start (); + m_priv->Start (); } unsigned long long SystemWallClockMs::End (void) { - return m_priv->End (); + return m_priv->End (); } }; // namespace ns3 diff --git a/src/core/win32-system-file.cc b/src/core/win32-system-file.cc index f26ac1801..4812633d7 100644 --- a/src/core/win32-system-file.cc +++ b/src/core/win32-system-file.cc @@ -1,4 +1,4 @@ -/* -*- Mode:NS3; -*- */ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * Copyright (c) 2005 INRIA * All rights reserved. @@ -38,11 +38,11 @@ namespace ns3 { class SystemFilePrivate { public: - SystemFilePrivate (); - ~SystemFilePrivate (); + SystemFilePrivate (); + ~SystemFilePrivate (); - void open (char const *filename); - void write (uint8_t const*buffer, uint32_t size); + void open (char const *filename); + void write (uint8_t const*buffer, uint32_t size); private: }; @@ -64,23 +64,23 @@ SystemFilePrivate::Write (uint8_t const*buffer, uint32_t size) } SystemFile::SystemFile () - : m_priv (new SystemFilePrivate ()) + : m_priv (new SystemFilePrivate ()) {} SystemFile::~SystemFile () { - delete m_priv; - m_priv = 0; + delete m_priv; + m_priv = 0; } void SystemFile::Open (char const *filename) { - m_priv->Open (filename); + m_priv->Open (filename); } void SystemFile::Write (uint8_t const*buffer, uint32_t size) { - m_priv->Write (buffer, size); + m_priv->Write (buffer, size); } }; // namespace diff --git a/src/core/win32-system-wall-clock-ms.cc b/src/core/win32-system-wall-clock-ms.cc index 39a400f7a..db81d580c 100644 --- a/src/core/win32-system-wall-clock-ms.cc +++ b/src/core/win32-system-wall-clock-ms.cc @@ -1,4 +1,4 @@ -/* -*- Mode:NS3; -*- */ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * Copyright (c) 2005 INRIA * All rights reserved. @@ -25,8 +25,8 @@ namespace ns3 { class SystemWallClockMsPrivate { public: - void start (void); - unsigned long long end (void); + void start (void); + unsigned long long end (void); private: }; @@ -38,28 +38,28 @@ SystemWallClockMsPrivate::Start (void) unsigned long long SystemWallClockMsPrivate::End (void) { - return 0; + return 0; } SystemWallClockMs::SystemWallClockMs () - : m_priv (new SystemWallClockMsPrivate ()) + : m_priv (new SystemWallClockMsPrivate ()) {} SystemWallClockMs::~SystemWallClockMs () { - delete m_priv; - m_priv = 0; + delete m_priv; + m_priv = 0; } void SystemWallClockMs::Start (void) { - m_priv->Start (); + m_priv->Start (); } unsigned long long SystemWallClockMs::End (void) { - return m_priv->End (); + return m_priv->End (); } }; // namespace ns3 diff --git a/src/simulator/event-id.cc b/src/simulator/event-id.cc index 399fc2181..41d9e308e 100644 --- a/src/simulator/event-id.cc +++ b/src/simulator/event-id.cc @@ -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; } diff --git a/src/simulator/event-id.h b/src/simulator/event-id.h index f0c64592c..988ab3e39 100644 --- a/src/simulator/event-id.h +++ b/src/simulator/event-id.h @@ -1,4 +1,4 @@ -/* -*- Mode:NS3; -*- */ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * Copyright (c) 2005 INRIA * All rights reserved. @@ -32,31 +32,31 @@ class EventImpl; */ class EventId { public: - EventId (); - EventId (EventImpl *impl, uint64_t ns, uint32_t uid); - /** - * This method is syntactic sugar for the ns3::Simulator::cancel - * method. - */ - void Cancel (void); - /** - * This method is syntactic sugar for the ns3::Simulator::isExpired - * method. - * \returns true if the event has expired, false otherwise. - */ - bool IsExpired (void); + EventId (); + EventId (EventImpl *impl, uint64_t ns, uint32_t uid); + /** + * This method is syntactic sugar for the ns3::Simulator::cancel + * method. + */ + void Cancel (void); + /** + * This method is syntactic sugar for the ns3::Simulator::isExpired + * method. + * \returns true if the event has expired, false otherwise. + */ + bool IsExpired (void); public: - /* The following methods are semi-private - * they are supposed to be invoked only by - * subclasses of the Scheduler base class. - */ - EventImpl *GetEventImpl (void) const; - uint64_t GetNs (void) const; - uint32_t GetUid (void) const; + /* The following methods are semi-private + * they are supposed to be invoked only by + * subclasses of the Scheduler base class. + */ + EventImpl *GetEventImpl (void) const; + uint64_t GetNs (void) const; + uint32_t GetUid (void) const; private: - EventImpl *m_eventImpl; - uint64_t m_ns; - uint32_t m_uid; + EventImpl *m_eventImpl; + uint64_t m_ns; + uint32_t m_uid; }; }; // namespace ns3 diff --git a/src/simulator/event-impl.cc b/src/simulator/event-impl.cc index dd174fbf3..ac1489cd0 100644 --- a/src/simulator/event-impl.cc +++ b/src/simulator/event-impl.cc @@ -1,4 +1,4 @@ -/* -*- Mode:NS3; -*- */ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * Copyright (c) 2005 INRIA * All rights reserved. @@ -29,31 +29,31 @@ EventImpl::~EventImpl () {} EventImpl::EventImpl () - : m_internalIterator (0), - m_cancel (false) + : m_internalIterator (0), + m_cancel (false) {} void EventImpl::Invoke (void) { - if (!m_cancel) - { - Notify (); - } + if (!m_cancel) + { + Notify (); + } } void EventImpl::SetInternalIterator (void *tag) { - m_internalIterator = tag; + m_internalIterator = tag; } void * EventImpl::GetInternalIterator (void) const { - return m_internalIterator; + return m_internalIterator; } void EventImpl::Cancel (void) { - m_cancel = true; + m_cancel = true; } }; // namespace ns3 diff --git a/src/simulator/event-impl.h b/src/simulator/event-impl.h index 25b9a7c4d..1944384b9 100644 --- a/src/simulator/event-impl.h +++ b/src/simulator/event-impl.h @@ -1,4 +1,4 @@ -/* -*- Mode:NS3; -*- */ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * Copyright (c) 2005,2006 INRIA * All rights reserved. @@ -27,18 +27,18 @@ namespace ns3 { class EventImpl { public: - EventImpl (); - virtual ~EventImpl () = 0; - void Invoke (void); - void Cancel (void); - void SetInternalIterator (void *iterator); - void *GetInternalIterator (void) const; + EventImpl (); + virtual ~EventImpl () = 0; + void Invoke (void); + void Cancel (void); + void SetInternalIterator (void *iterator); + void *GetInternalIterator (void) const; protected: - virtual void Notify (void) = 0; + virtual void Notify (void) = 0; private: - friend class Event; - void *m_internalIterator; - bool m_cancel; + friend class Event; + void *m_internalIterator; + bool m_cancel; }; }; // namespace ns3 diff --git a/src/simulator/nstime.h b/src/simulator/nstime.h index 4fc43fe12..89f41be44 100644 --- a/src/simulator/nstime.h +++ b/src/simulator/nstime.h @@ -1,4 +1,4 @@ -/* -*- Mode:NS3; -*- */ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * Copyright (c) 2005,2006 INRIA * All rights reserved. @@ -33,28 +33,28 @@ namespace ns3 { */ class Time { public: - Time (Time const &o); - Time &operator = (Time const &o); + Time (Time const &o); + Time &operator = (Time const &o); - bool IsNegative (void) const; - bool IsPositive (void) const; - bool IsStrictlyNegative (void) const; - bool IsStrictlyPositive (void) const; - bool IsZero (void) const; + bool IsNegative (void) const; + bool IsPositive (void) const; + bool IsStrictlyNegative (void) const; + bool IsStrictlyPositive (void) const; + bool IsZero (void) const; - Time operator += (Time const &o); - Time operator -= (Time const &o); + Time operator += (Time const &o); + Time operator -= (Time const &o); - double ApproximateToSeconds (void) const; - int64_t ApproximateToMilliSeconds (void) const; - int64_t ApproximateToMicroSeconds (void) const; - int64_t ApproximateToNanoSeconds (void) const; + double ApproximateToSeconds (void) const; + int64_t ApproximateToMilliSeconds (void) const; + int64_t ApproximateToMicroSeconds (void) const; + int64_t ApproximateToNanoSeconds (void) const; protected: - Time (int64_t ns); + Time (int64_t ns); private: - Time (); - int64_t m_ns; + Time (); + int64_t m_ns; }; Time operator + (Time const &lhs, Time const &rhs); @@ -69,28 +69,28 @@ bool operator >= (Time const &lhs, Time const &rhs); class Now : public Time { public: - Now (); + Now (); }; class Seconds : public Time { public: - Seconds (double s); + Seconds (double s); }; class MilliSeconds : public Time { public: - MilliSeconds (int32_t ms); + MilliSeconds (int32_t ms); }; class MicroSeconds : public Time { public: - MicroSeconds (int32_t us); + MicroSeconds (int32_t us); }; class NanoSeconds : public Time { public: - NanoSeconds (int64_t ns); + NanoSeconds (int64_t ns); }; }; // namespace ns3 diff --git a/src/simulator/scheduler-factory.cc b/src/simulator/scheduler-factory.cc index 2c7bdde26..ebc8042cb 100644 --- a/src/simulator/scheduler-factory.cc +++ b/src/simulator/scheduler-factory.cc @@ -1,4 +1,4 @@ -/* -*- Mode:NS3; -*- */ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * Copyright (c) 2006 INRIA * All rights reserved. @@ -28,7 +28,7 @@ SchedulerFactory::~SchedulerFactory () Scheduler * SchedulerFactory::Create (void) const { - return RealCreate (); + return RealCreate (); } }; // namespace ns3 diff --git a/src/simulator/scheduler-factory.h b/src/simulator/scheduler-factory.h index c96c527bf..ce5a5706d 100644 --- a/src/simulator/scheduler-factory.h +++ b/src/simulator/scheduler-factory.h @@ -1,4 +1,4 @@ -/* -*- Mode:NS3; -*- */ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * Copyright (c) 2006 INRIA * All rights reserved. @@ -35,14 +35,14 @@ class Scheduler; */ class SchedulerFactory { public: - virtual ~SchedulerFactory (); - Scheduler *Create (void) const; + virtual ~SchedulerFactory (); + Scheduler *Create (void) const; private: - /** - * \returns a newly-created scheduler. The caller takes - * ownership of the returned pointer. - */ - virtual Scheduler *RealCreate (void) const = 0; + /** + * \returns a newly-created scheduler. The caller takes + * ownership of the returned pointer. + */ + virtual Scheduler *RealCreate (void) const = 0; }; }; // namespace ns3 diff --git a/src/simulator/scheduler-heap.cc b/src/simulator/scheduler-heap.cc index 746155079..c01c3b090 100644 --- a/src/simulator/scheduler-heap.cc +++ b/src/simulator/scheduler-heap.cc @@ -1,4 +1,4 @@ -/* -*- Mode:NS3; -*- */ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * Copyright (c) 2006 INRIA * Copyright (c) 2005 Mathieu Lacage @@ -53,11 +53,11 @@ namespace ns3 { SchedulerHeap::SchedulerHeap () { - // we purposedly waste an item at the start of - // the array to make sure the indexes in the - // array start at one. - Scheduler::EventKey emptyKey = {0,0}; - m_heap.push_back (std::make_pair (static_cast(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(0), emptyKey)); } SchedulerHeap::~SchedulerHeap () @@ -66,186 +66,186 @@ SchedulerHeap::~SchedulerHeap () void SchedulerHeap::StoreInEvent (EventImpl *ev, uint32_t index) const { - long tmp = index; - ev->SetInternalIterator ((void *)tmp); + long tmp = index; + ev->SetInternalIterator ((void *)tmp); } uint32_t SchedulerHeap::GetFromEvent (EventImpl *ev) const { - long tmp = (long)ev->GetInternalIterator (); - return (uint32_t)tmp; + long tmp = (long)ev->GetInternalIterator (); + return (uint32_t)tmp; } uint32_t SchedulerHeap::Parent (uint32_t id) const { - return id / 2; + return id / 2; } uint32_t SchedulerHeap::Sibling (uint32_t id) const { - return id + 1; + return id + 1; } uint32_t SchedulerHeap::LeftChild (uint32_t id) const { - return id * 2; + return id * 2; } uint32_t SchedulerHeap::RightChild (uint32_t id) const { - return id * 2 + 1; + return id * 2 + 1; } uint32_t SchedulerHeap::Root (void) const { - return 1; + return 1; } bool SchedulerHeap::IsRoot (uint32_t id) const { - return (id == Root ())?true:false; + return (id == Root ())?true:false; } uint32_t SchedulerHeap::Last (void) const { - return m_heap.size () - 1; + return m_heap.size () - 1; } bool SchedulerHeap::IsBottom (uint32_t id) const { - return (id >= m_heap.size ())?true:false; + return (id >= m_heap.size ())?true:false; } void SchedulerHeap::Exch (uint32_t a, uint32_t b) { - assert (b < m_heap.size () && a < m_heap.size ()); - TRACE ("Exch " << a << ", " << b); - std::pair 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 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 diff --git a/src/simulator/scheduler-heap.h b/src/simulator/scheduler-heap.h index 4fa8c57f4..c4d29f90f 100644 --- a/src/simulator/scheduler-heap.h +++ b/src/simulator/scheduler-heap.h @@ -1,4 +1,4 @@ -/* -*- Mode:NS3; -*- */ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * Copyright (c) 2005 INRIA * All rights reserved. @@ -32,38 +32,38 @@ class EventHolder; class SchedulerHeap : public Scheduler { public: - SchedulerHeap (); - virtual ~SchedulerHeap (); + SchedulerHeap (); + virtual ~SchedulerHeap (); private: - virtual EventId RealInsert (EventImpl *event, Scheduler::EventKey key); - virtual bool RealIsEmpty (void) const; - virtual EventImpl *RealPeekNext (void) const; - virtual Scheduler::EventKey RealPeekNextKey (void) const; - virtual void RealRemoveNext (void); - virtual EventImpl *RealRemove (EventId ev, Scheduler::EventKey *key); - virtual bool RealIsValid (EventId id); + virtual EventId RealInsert (EventImpl *event, Scheduler::EventKey key); + virtual bool RealIsEmpty (void) const; + virtual EventImpl *RealPeekNext (void) const; + virtual Scheduler::EventKey RealPeekNextKey (void) const; + virtual void RealRemoveNext (void); + virtual EventImpl *RealRemove (EventId ev, Scheduler::EventKey *key); + virtual bool RealIsValid (EventId id); - typedef std::vector > BinaryHeap; - inline void StoreInEvent (EventImpl *ev, uint32_t index) const; - uint32_t GetFromEvent (EventImpl *ev) const; + typedef std::vector > 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 diff --git a/src/simulator/scheduler-list.cc b/src/simulator/scheduler-list.cc index 4aedccc37..4e238dd56 100644 --- a/src/simulator/scheduler-list.cc +++ b/src/simulator/scheduler-list.cc @@ -1,4 +1,4 @@ -/* -*- Mode:NS3; -*- */ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * Copyright (c) 2005 INRIA * All rights reserved. @@ -40,82 +40,82 @@ SchedulerList::~SchedulerList () EventId SchedulerList::GetEventId (Scheduler::EventKey key, EventsI i) { - assert (sizeof (i) <= sizeof (void *)); - void *internalIterator; - memcpy ((char *)&(internalIterator), (char *)&i, sizeof (void *)); - EventImpl *ev = i->first; - ev->SetInternalIterator (internalIterator); - return EventId (ev, key.m_ns, key.m_uid); + assert (sizeof (i) <= sizeof (void *)); + void *internalIterator; + memcpy ((char *)&(internalIterator), (char *)&i, sizeof (void *)); + EventImpl *ev = i->first; + ev->SetInternalIterator (internalIterator); + return EventId (ev, key.m_ns, key.m_uid); } SchedulerList::EventsI SchedulerList::GetIterator (EventId id) { - SchedulerList::EventsI i; - assert (sizeof (i) <= sizeof (void *)); - EventImpl *ev = id.GetEventImpl (); - void *internalIterator = ev->GetInternalIterator (); - memcpy ((char *)&i, (char *)&(internalIterator), sizeof (void *)); - return i; + SchedulerList::EventsI i; + assert (sizeof (i) <= sizeof (void *)); + EventImpl *ev = id.GetEventImpl (); + void *internalIterator = ev->GetInternalIterator (); + memcpy ((char *)&i, (char *)&(internalIterator), sizeof (void *)); + return i; } EventId SchedulerList::RealInsert (EventImpl *event, Scheduler::EventKey key) { - Scheduler::EventKeyCompare compare; - for (EventsI i = m_events.begin (); i != m_events.end (); i++) - { - if (compare (key, i->second)) - { - m_events.insert (i, std::make_pair (event, key)); - return GetEventId (key, i); - } - } - m_events.push_back (std::make_pair (event, key)); - return GetEventId (key, --(m_events.end ())); + Scheduler::EventKeyCompare compare; + for (EventsI i = m_events.begin (); i != m_events.end (); i++) + { + if (compare (key, i->second)) + { + m_events.insert (i, std::make_pair (event, key)); + return GetEventId (key, i); + } + } + m_events.push_back (std::make_pair (event, key)); + return GetEventId (key, --(m_events.end ())); } bool SchedulerList::RealIsEmpty (void) const { - return m_events.empty (); + return m_events.empty (); } EventImpl * SchedulerList::RealPeekNext (void) const { - return m_events.front ().first; + return m_events.front ().first; } Scheduler::EventKey SchedulerList::RealPeekNextKey (void) const { - return m_events.front ().second; + return m_events.front ().second; } void SchedulerList::RealRemoveNext (void) { - m_events.pop_front (); + m_events.pop_front (); } EventImpl * SchedulerList::RealRemove (EventId id, Scheduler::EventKey *key) { - EventsI i = GetIterator (id); - *key = i->second; - assert (key->m_ns == id.GetNs () && - key->m_uid == id.GetUid ()); - EventImpl *ev = i->first; - m_events.erase (i); - return ev; + EventsI i = GetIterator (id); + *key = i->second; + assert (key->m_ns == id.GetNs () && + key->m_uid == id.GetUid ()); + EventImpl *ev = i->first; + m_events.erase (i); + return ev; } bool SchedulerList::RealIsValid (EventId id) { - EventsI i = GetIterator (id); - Scheduler::EventKey key = i->second; - return (key.m_ns == id.GetNs () && - key.m_uid == id.GetUid ()); - + EventsI i = GetIterator (id); + Scheduler::EventKey key = i->second; + return (key.m_ns == id.GetNs () && + key.m_uid == id.GetUid ()); + } }; // namespace ns3 diff --git a/src/simulator/scheduler-list.h b/src/simulator/scheduler-list.h index 3a40ddb64..f85d2eb09 100644 --- a/src/simulator/scheduler-list.h +++ b/src/simulator/scheduler-list.h @@ -1,4 +1,4 @@ -/* -*- Mode:NS3; -*- */ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * Copyright (c) 2005 INRIA * All rights reserved. @@ -34,23 +34,23 @@ class EventImpl; class SchedulerList : public Scheduler { public: - SchedulerList (); - virtual ~SchedulerList (); + SchedulerList (); + virtual ~SchedulerList (); private: - virtual EventId RealInsert (EventImpl *event, EventKey key); - virtual bool RealIsEmpty (void) const; - virtual EventImpl *RealPeekNext (void) const; - virtual Scheduler::EventKey RealPeekNextKey (void) const; - virtual void RealRemoveNext (void); - virtual EventImpl *RealRemove (EventId ev, Scheduler::EventKey *key); - virtual bool RealIsValid (EventId id); + virtual EventId RealInsert (EventImpl *event, EventKey key); + virtual bool RealIsEmpty (void) const; + virtual EventImpl *RealPeekNext (void) const; + virtual Scheduler::EventKey RealPeekNextKey (void) const; + virtual void RealRemoveNext (void); + virtual EventImpl *RealRemove (EventId ev, Scheduler::EventKey *key); + virtual bool RealIsValid (EventId id); - typedef std::list > Events; - typedef std::list >::iterator EventsI; - EventId GetEventId (Scheduler::EventKey key, EventsI i); - EventsI GetIterator (EventId id); - Events m_events; + typedef std::list > Events; + typedef std::list >::iterator EventsI; + EventId GetEventId (Scheduler::EventKey key, EventsI i); + EventsI GetIterator (EventId id); + Events m_events; }; }; // namespace ns3 diff --git a/src/simulator/scheduler-map.cc b/src/simulator/scheduler-map.cc index 4739ccc3e..76b08f293 100644 --- a/src/simulator/scheduler-map.cc +++ b/src/simulator/scheduler-map.cc @@ -1,4 +1,4 @@ -/* -*- Mode:NS3; -*- */ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * Copyright (c) 2006 INRIA * All rights reserved. @@ -47,70 +47,70 @@ SchedulerMap::~SchedulerMap () void SchedulerMap::StoreInEvent (EventImpl *ev, EventMapI i) const { - void *tag; - memcpy (&(tag), &i, sizeof (tag)); - ev->SetInternalIterator (tag); + void *tag; + memcpy (&(tag), &i, sizeof (tag)); + ev->SetInternalIterator (tag); } SchedulerMap::EventMapI SchedulerMap::GetFromEvent (EventImpl *ev) const { - EventMapI i; - void *tag = ev->GetInternalIterator (); - memcpy (&i, &(tag), sizeof (i)); - return i; + EventMapI i; + void *tag = ev->GetInternalIterator (); + memcpy (&i, &(tag), sizeof (i)); + return i; } EventId SchedulerMap::RealInsert (EventImpl *event, Scheduler::EventKey key) { - std::pair 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 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 ()); } diff --git a/src/simulator/scheduler-map.h b/src/simulator/scheduler-map.h index ea7373a93..8b277b990 100644 --- a/src/simulator/scheduler-map.h +++ b/src/simulator/scheduler-map.h @@ -1,4 +1,4 @@ -/* -*- Mode:NS3; -*- */ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * Copyright (c) 2006 INRIA * All rights reserved. @@ -33,27 +33,27 @@ class EventImpl; class SchedulerMap : public Scheduler { public: - SchedulerMap (); - virtual ~SchedulerMap (); + SchedulerMap (); + virtual ~SchedulerMap (); private: - virtual EventId RealInsert (EventImpl *event, Scheduler::EventKey key); - virtual bool RealIsEmpty (void) const; - virtual EventImpl *RealPeekNext (void) const; - virtual Scheduler::EventKey RealPeekNextKey (void) const; - virtual void RealRemoveNext (void); - virtual EventImpl *RealRemove (EventId ev, Scheduler::EventKey *key); - virtual bool RealIsValid (EventId id); + virtual EventId RealInsert (EventImpl *event, Scheduler::EventKey key); + virtual bool RealIsEmpty (void) const; + virtual EventImpl *RealPeekNext (void) const; + virtual Scheduler::EventKey RealPeekNextKey (void) const; + virtual void RealRemoveNext (void); + virtual EventImpl *RealRemove (EventId ev, Scheduler::EventKey *key); + virtual bool RealIsValid (EventId id); - typedef std::map EventMap; - typedef std::map::iterator EventMapI; - typedef std::map::const_iterator EventMapCI; + typedef std::map EventMap; + typedef std::map::iterator EventMapI; + typedef std::map::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 diff --git a/src/simulator/scheduler.cc b/src/simulator/scheduler.cc index 9fb532150..0dfaba891 100644 --- a/src/simulator/scheduler.cc +++ b/src/simulator/scheduler.cc @@ -1,4 +1,4 @@ -/* -*- Mode:NS3; -*- */ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * Copyright (c) 2006 INRIA * All rights reserved. @@ -35,60 +35,60 @@ Scheduler::~Scheduler () bool Scheduler::EventKeyCompare::operator () (struct EventKey a, struct EventKey b) { - assert (a.m_uid != b.m_uid); - if (a.m_ns < b.m_ns) - { - return true; - } - else if (a.m_ns == b.m_ns && a.m_uid < b.m_uid) - { - return true; - } - else - { - return false; - } + assert (a.m_uid != b.m_uid); + if (a.m_ns < b.m_ns) + { + return true; + } + else if (a.m_ns == b.m_ns && a.m_uid < b.m_uid) + { + return true; + } + else + { + return false; + } } EventId Scheduler::Insert (EventImpl *event, struct EventKey key) { - return RealInsert (event, key); + return RealInsert (event, key); } bool Scheduler::IsEmpty (void) const { - return RealIsEmpty (); + return RealIsEmpty (); } EventImpl * Scheduler::PeekNext (void) const { - assert (!RealIsEmpty ()); - return RealPeekNext (); + assert (!RealIsEmpty ()); + return RealPeekNext (); } Scheduler::EventKey Scheduler::PeekNextKey (void) const { - assert (!RealIsEmpty ()); - return RealPeekNextKey (); + assert (!RealIsEmpty ()); + return RealPeekNextKey (); } void Scheduler::RemoveNext (void) { - assert (!RealIsEmpty ()); - return RealRemoveNext (); + assert (!RealIsEmpty ()); + return RealRemoveNext (); } EventImpl * Scheduler::Remove (EventId id, EventKey *key) { - assert (!RealIsEmpty ()); - return RealRemove (id, key); + assert (!RealIsEmpty ()); + return RealRemove (id, key); } bool Scheduler::IsValid (EventId id) { - return RealIsValid (id); + return RealIsValid (id); } }; // namespace ns3 diff --git a/src/simulator/scheduler.h b/src/simulator/scheduler.h index 653441ea2..5177a74f2 100644 --- a/src/simulator/scheduler.h +++ b/src/simulator/scheduler.h @@ -1,4 +1,4 @@ -/* -*- Mode:NS3; -*- */ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * Copyright (c) 2005 INRIA * All rights reserved. @@ -54,71 +54,71 @@ class EventImpl; */ class Scheduler { public: - struct EventKey { - uint64_t m_ns; - uint32_t m_uid; - }; - class EventKeyCompare { - public: - bool operator () (struct EventKey a, struct EventKey b); - }; + struct EventKey { + uint64_t m_ns; + uint32_t m_uid; + }; + class EventKeyCompare { + public: + bool operator () (struct EventKey a, struct EventKey b); + }; - virtual ~Scheduler () = 0; + virtual ~Scheduler () = 0; - EventId Insert (EventImpl *event, EventKey key); - bool IsEmpty (void) const; - EventImpl *PeekNext (void) const; - Scheduler::EventKey PeekNextKey (void) const ; - void RemoveNext (void); - EventImpl *Remove (EventId id, EventKey *key); - bool IsValid (EventId id); + EventId Insert (EventImpl *event, EventKey key); + bool IsEmpty (void) const; + EventImpl *PeekNext (void) const; + Scheduler::EventKey PeekNextKey (void) const ; + void RemoveNext (void); + EventImpl *Remove (EventId id, EventKey *key); + bool IsValid (EventId id); private: - /** - * \param event event to store in the event list - * \param key timecode associated to this new event - * \returns an event id which identifies the event inserted - * - * This method takes ownership of the event pointer. - */ - virtual EventId RealInsert (EventImpl *event, EventKey key) = 0; - /** - * \returns true if the event list is empty and false otherwise. - */ - virtual bool RealIsEmpty (void) const = 0; - /** - * \returns a pointer to the next earliest event. The caller - * takes ownership of the returned pointer. - * - * This method cannot be invoked if the list is empty. - */ - virtual EventImpl *RealPeekNext (void) const = 0; - /** - * \returns the timecode associated with the next earliest event. - * - * This method cannot be invoked if the list is empty. - */ - virtual Scheduler::EventKey RealPeekNextKey (void) const = 0; - /** - * This method cannot be invoked if the list is empty. - * Remove the next earliest event from the event list. - */ - virtual void RealRemoveNext (void) = 0; - /** - * \param id the id of the event to remove - * \param key the timecode of the event removed - * \returns a pointer to the event removed. The caller - * takes ownership of the returned pointer. - * - * This methods cannot be invoked if the list is empty. - */ - virtual EventImpl *RealRemove (EventId id, EventKey *key) = 0; - /** - * \param id event id to validate - * \returns true if the event id identifies an existing valid - * event stored in the event list and false otherwise. - */ - virtual bool RealIsValid (EventId id) = 0; + /** + * \param event event to store in the event list + * \param key timecode associated to this new event + * \returns an event id which identifies the event inserted + * + * This method takes ownership of the event pointer. + */ + virtual EventId RealInsert (EventImpl *event, EventKey key) = 0; + /** + * \returns true if the event list is empty and false otherwise. + */ + virtual bool RealIsEmpty (void) const = 0; + /** + * \returns a pointer to the next earliest event. The caller + * takes ownership of the returned pointer. + * + * This method cannot be invoked if the list is empty. + */ + virtual EventImpl *RealPeekNext (void) const = 0; + /** + * \returns the timecode associated with the next earliest event. + * + * This method cannot be invoked if the list is empty. + */ + virtual Scheduler::EventKey RealPeekNextKey (void) const = 0; + /** + * This method cannot be invoked if the list is empty. + * Remove the next earliest event from the event list. + */ + virtual void RealRemoveNext (void) = 0; + /** + * \param id the id of the event to remove + * \param key the timecode of the event removed + * \returns a pointer to the event removed. The caller + * takes ownership of the returned pointer. + * + * This methods cannot be invoked if the list is empty. + */ + virtual EventImpl *RealRemove (EventId id, EventKey *key) = 0; + /** + * \param id event id to validate + * \returns true if the event id identifies an existing valid + * event stored in the event list and false otherwise. + */ + virtual bool RealIsValid (EventId id) = 0; }; }; // namespace ns3 diff --git a/src/simulator/simulator.cc b/src/simulator/simulator.cc index 185bde08e..9493d5e75 100644 --- a/src/simulator/simulator.cc +++ b/src/simulator/simulator.cc @@ -1,4 +1,4 @@ -/* -*- Mode:NS3; -*- */ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * Copyright (c) 2005,2006 INRIA * All rights reserved. @@ -49,39 +49,39 @@ namespace ns3 { class SimulatorPrivate { public: - SimulatorPrivate (Scheduler *events); - ~SimulatorPrivate (); + SimulatorPrivate (Scheduler *events); + ~SimulatorPrivate (); - void EnableLogTo (char const *filename); + void EnableLogTo (char const *filename); - bool IsFinished (void) const; - Time Next (void) const; - void Stop (void); - void StopAt (Time const &time); - EventId Schedule (Time const &time, EventImpl *event); - void ScheduleNow (EventImpl *event); - void ScheduleDestroy (EventImpl *event); - void Remove (EventId ev); - void Cancel (EventId ev); - bool IsExpired (EventId ev); - void Run (void); - Time Now (void) const; + bool IsFinished (void) const; + Time Next (void) const; + void Stop (void); + void StopAt (Time const &time); + EventId Schedule (Time const &time, EventImpl *event); + void ScheduleNow (EventImpl *event); + void ScheduleDestroy (EventImpl *event); + void Remove (EventId ev); + void Cancel (EventId ev); + bool IsExpired (EventId ev); + void Run (void); + Time Now (void) const; private: - void ProcessOneEvent (void); - uint64_t NextNs (void) const; + void ProcessOneEvent (void); + uint64_t NextNs (void) const; - typedef std::list > 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 > Events; + Events m_destroy; + uint64_t m_stopAt; + bool m_stop; + Scheduler *m_events; + uint32_t m_uid; + uint32_t m_currentUid; + uint64_t m_currentNs; + std::ofstream m_log; + std::ifstream m_inputLog; + bool m_logEnable; }; @@ -89,69 +89,69 @@ private: SimulatorPrivate::SimulatorPrivate (Scheduler *events) { - m_stop = false; - m_stopAt = 0; - m_events = events; - m_uid = 0; - m_logEnable = false; - m_currentNs = 0; + m_stop = false; + m_stopAt = 0; + m_events = events; + m_uid = 0; + m_logEnable = false; + m_currentNs = 0; } SimulatorPrivate::~SimulatorPrivate () { - while (!m_destroy.empty ()) - { - EventImpl *ev = m_destroy.front ().first; - m_destroy.pop_front (); - TRACE ("handle destroy " << ev); - ev->Invoke (); - delete ev; - } - delete m_events; - m_events = (Scheduler *)0xdeadbeaf; + while (!m_destroy.empty ()) + { + EventImpl *ev = m_destroy.front ().first; + m_destroy.pop_front (); + TRACE ("handle destroy " << ev); + ev->Invoke (); + delete ev; + } + delete m_events; + m_events = (Scheduler *)0xdeadbeaf; } void SimulatorPrivate::EnableLogTo (char const *filename) { - m_log.open (filename); - m_logEnable = true; + m_log.open (filename); + m_logEnable = true; } void SimulatorPrivate::ProcessOneEvent (void) { - EventImpl *nextEv = m_events->PeekNext (); - Scheduler::EventKey nextKey = m_events->PeekNextKey (); - m_events->RemoveNext (); - TRACE ("handle " << nextEv); - m_currentNs = nextKey.m_ns; - m_currentUid = nextKey.m_uid; - if (m_logEnable) - { - m_log << "e "<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 "<Invoke (); + delete nextEv; } bool SimulatorPrivate::IsFinished (void) const { - return m_events->IsEmpty (); + return m_events->IsEmpty (); } uint64_t SimulatorPrivate::NextNs (void) const { - assert (!m_events->IsEmpty ()); - Scheduler::EventKey nextKey = m_events->PeekNextKey (); - return nextKey.m_ns; + assert (!m_events->IsEmpty ()); + Scheduler::EventKey nextKey = m_events->PeekNextKey (); + return nextKey.m_ns; } Time SimulatorPrivate::Next (void) const { - return NanoSeconds (NextNs ()); + return NanoSeconds (NextNs ()); } @@ -159,103 +159,103 @@ void SimulatorPrivate::Run (void) { - while (!m_events->IsEmpty () && !m_stop && - (m_stopAt == 0 || m_stopAt > NextNs ())) - { - ProcessOneEvent (); - } - m_log.close (); + while (!m_events->IsEmpty () && !m_stop && + (m_stopAt == 0 || m_stopAt > NextNs ())) + { + ProcessOneEvent (); + } + m_log.close (); } void SimulatorPrivate::Stop (void) { - m_stop = true; + m_stop = true; } void SimulatorPrivate::StopAt (Time const &at) { - assert (at.IsPositive ()); - m_stopAt = at.ApproximateToNanoSeconds (); + assert (at.IsPositive ()); + m_stopAt = at.ApproximateToNanoSeconds (); } EventId SimulatorPrivate::Schedule (Time const &time, EventImpl *event) { - assert (time.IsPositive ()); - assert (time >= NanoSeconds (m_currentNs)); - uint64_t ns = (uint64_t) time.ApproximateToNanoSeconds (); - Scheduler::EventKey key = {ns, m_uid}; - if (m_logEnable) - { - m_log << "i "<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 "<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 "<Insert (event, key); + uint64_t ns = m_currentNs; + Scheduler::EventKey key = {ns, m_uid}; + if (m_logEnable) + { + m_log << "i "<Insert (event, key); } void SimulatorPrivate::ScheduleDestroy (EventImpl *event) { m_destroy.push_back (std::make_pair (event, m_uid)); if (m_logEnable) - { - m_log << "id " << m_currentUid << " " << Now ().ApproximateToNanoSeconds () << " " - << m_uid << std::endl; - } + { + m_log << "id " << m_currentUid << " " << Now ().ApproximateToNanoSeconds () << " " + << m_uid << std::endl; + } m_uid++; } Time SimulatorPrivate::Now (void) const { - return NanoSeconds (m_currentNs); + return NanoSeconds (m_currentNs); } void SimulatorPrivate::Remove (EventId ev) { - Scheduler::EventKey key; - EventImpl *impl = m_events->Remove (ev, &key); - delete impl; - if (m_logEnable) - { - m_log << "r " << m_currentUid << " " << m_currentNs << " " - << key.m_uid << " " << key.m_ns << std::endl; - } + Scheduler::EventKey key; + EventImpl *impl = m_events->Remove (ev, &key); + delete impl; + if (m_logEnable) + { + m_log << "r " << m_currentUid << " " << m_currentNs << " " + << key.m_uid << " " << key.m_ns << std::endl; + } } void SimulatorPrivate::Cancel (EventId id) { - assert (m_events->IsValid (id)); - EventImpl *ev = id.GetEventImpl (); - ev->Cancel (); + assert (m_events->IsValid (id)); + EventImpl *ev = id.GetEventImpl (); + ev->Cancel (); } bool SimulatorPrivate::IsExpired (EventId ev) { - if (ev.GetEventImpl () != 0 && - ev.GetNs () <= m_currentNs && - ev.GetUid () < m_currentUid) - { - return false; - } - return true; + if (ev.GetEventImpl () != 0 && + ev.GetNs () <= m_currentNs && + ev.GetUid () < m_currentUid) + { + return false; + } + return true; } @@ -276,168 +276,168 @@ SchedulerFactory const*Simulator::m_schedFactory = 0; void Simulator::SetLinkedList (void) { - m_listType = LINKED_LIST; + m_listType = LINKED_LIST; } void Simulator::SetBinaryHeap (void) { - m_listType = BINARY_HEAP; + m_listType = BINARY_HEAP; } void Simulator::SetStdMap (void) { - m_listType = STD_MAP; + m_listType = STD_MAP; } void Simulator::SetExternal (SchedulerFactory const*factory) { - assert (factory != 0); - m_schedFactory = factory; - m_listType = EXTERNAL; + assert (factory != 0); + m_schedFactory = factory; + m_listType = EXTERNAL; } void Simulator::EnableLogTo (char const *filename) { - GetPriv ()->EnableLogTo (filename); + GetPriv ()->EnableLogTo (filename); } SimulatorPrivate * Simulator::GetPriv (void) { - if (m_priv == 0) - { - Scheduler *events; - switch (m_listType) { - case LINKED_LIST: - events = new SchedulerList (); - break; - case BINARY_HEAP: - events = new SchedulerHeap (); - break; - case STD_MAP: - events = new SchedulerMap (); - break; - case EXTERNAL: - events = m_schedFactory->Create (); - default: // not reached - events = 0; - assert (false); - break; - } - m_priv = new SimulatorPrivate (events); + if (m_priv == 0) + { + Scheduler *events; + switch (m_listType) { + case LINKED_LIST: + events = new SchedulerList (); + break; + case BINARY_HEAP: + events = new SchedulerHeap (); + break; + case STD_MAP: + events = new SchedulerMap (); + break; + case EXTERNAL: + events = m_schedFactory->Create (); + default: // not reached + events = 0; + assert (false); + break; } - TRACE_S ("priv " << m_priv); - return m_priv; + m_priv = new SimulatorPrivate (events); + } + TRACE_S ("priv " << m_priv); + return m_priv; } void Simulator::Destroy (void) { - delete m_priv; - m_priv = 0; + delete m_priv; + m_priv = 0; } bool Simulator::IsFinished (void) { - return GetPriv ()->IsFinished (); + return GetPriv ()->IsFinished (); } Time Simulator::Next (void) { - return GetPriv ()->Next (); + return GetPriv ()->Next (); } void Simulator::Run (void) { - GetPriv ()->Run (); + GetPriv ()->Run (); } void Simulator::Stop (void) { - TRACE ("stop"); - GetPriv ()->Stop (); + TRACE ("stop"); + GetPriv ()->Stop (); } void Simulator::StopAt (Time const &at) { - GetPriv ()->StopAt (at); + GetPriv ()->StopAt (at); } Time Simulator::Now (void) { - return GetPriv ()->Now (); + return GetPriv ()->Now (); } EventImpl * Simulator::MakeEvent (void (*f) (void)) { - // zero arg version - class EventFunctionImpl0 : public EventImpl { - public: - typedef void (*F)(void); - - EventFunctionImpl0 (F function) - : m_function (function) - {} - virtual ~EventFunctionImpl0 () {} - protected: - virtual void Notify (void) { - (*m_function) (); - } - private: - F m_function; - } *ev = new EventFunctionImpl0 (f); - return ev; + // zero arg version + class EventFunctionImpl0 : public EventImpl { + public: + typedef void (*F)(void); + + EventFunctionImpl0 (F function) + : m_function (function) + {} + virtual ~EventFunctionImpl0 () {} + protected: + virtual void Notify (void) { + (*m_function) (); + } + private: + F m_function; + } *ev = new EventFunctionImpl0 (f); + return ev; } EventId Simulator::Schedule (Time const &time, EventImpl *ev) { - return GetPriv ()->Schedule (time, ev); + return GetPriv ()->Schedule (time, ev); } void Simulator::ScheduleNow (EventImpl *ev) { - GetPriv ()->ScheduleNow (ev); + GetPriv ()->ScheduleNow (ev); } void Simulator::ScheduleDestroy (EventImpl *ev) { - GetPriv ()->ScheduleDestroy (ev); + GetPriv ()->ScheduleDestroy (ev); } EventId Simulator::Schedule (Time const &time, void (*f) (void)) { - return Schedule (time, MakeEvent (f)); + return Schedule (time, MakeEvent (f)); } void Simulator::ScheduleNow (void (*f) (void)) { - return ScheduleNow (MakeEvent (f)); + return ScheduleNow (MakeEvent (f)); } void Simulator::ScheduleDestroy (void (*f) (void)) { - return ScheduleDestroy (MakeEvent (f)); + return ScheduleDestroy (MakeEvent (f)); } void Simulator::Remove (EventId ev) { - return GetPriv ()->Remove (ev); + return GetPriv ()->Remove (ev); } void Simulator::Cancel (EventId ev) { - return GetPriv ()->Cancel (ev); + return GetPriv ()->Cancel (ev); } bool Simulator::IsExpired (EventId id) { - return GetPriv ()->IsExpired (id); + return GetPriv ()->IsExpired (id); } }; // namespace ns3 @@ -465,76 +465,76 @@ static void foo5 (int, int, int, int, int) class SimulatorTests : public Test { public: - SimulatorTests (); - virtual ~SimulatorTests (); - virtual bool RunTests (void); + SimulatorTests (); + virtual ~SimulatorTests (); + virtual bool RunTests (void); private: - uint64_t NowUs (); - bool RunOneTest (void); - void A (int a); - void B (int b); - void C (int c); - void D (int d); - void bar0 (void); - void bar1 (int); - void bar2 (int, int); - void bar3 (int, int, int); - void bar4 (int, int, int, int); - void bar5 (int, int, int, int, int); + uint64_t NowUs (); + bool RunOneTest (void); + void A (int a); + void B (int b); + void C (int c); + void D (int d); + void bar0 (void); + void bar1 (int); + void bar2 (int, int); + void bar3 (int, int, int); + void bar4 (int, int, int, int); + void bar5 (int, int, int, int, int); - bool m_b; - bool m_a; - bool m_c; - bool m_d; - EventId m_idC; + bool m_b; + bool m_a; + bool m_c; + bool m_d; + EventId m_idC; }; SimulatorTests::SimulatorTests () - : Test ("Simulator") + : Test ("Simulator") {} SimulatorTests::~SimulatorTests () {} uint64_t SimulatorTests::NowUs (void) { - uint64_t ns = Now ().ApproximateToNanoSeconds (); - return ns / 1000; + uint64_t ns = Now ().ApproximateToNanoSeconds (); + return ns / 1000; } void SimulatorTests::A (int a) { - m_a = false; + m_a = false; } void SimulatorTests::B (int b) { - if (b != 2 || NowUs () != 11) - { - m_b = false; - } - else - { - m_b = true; - } - Simulator::Remove (m_idC); - Simulator::Schedule (Now () + MicroSeconds (10), &SimulatorTests::D, this, 4); + if (b != 2 || NowUs () != 11) + { + m_b = false; + } + else + { + m_b = true; + } + Simulator::Remove (m_idC); + Simulator::Schedule (Now () + MicroSeconds (10), &SimulatorTests::D, this, 4); } void SimulatorTests::C (int c) { - m_c = false; + m_c = false; } void SimulatorTests::D (int d) { - if (d != 4 || NowUs () != (11+10)) - { - m_d = false; - } - else - { - m_d = true; - } + if (d != 4 || NowUs () != (11+10)) + { + m_d = false; + } + else + { + m_d = true; + } } void SimulatorTests::bar0 (void) @@ -558,89 +558,89 @@ SimulatorTests::bar5 (int, int, int, int, int) bool SimulatorTests::RunOneTest (void) { - bool ok = true; - m_a = true; - m_b = false; - m_c = true; - m_d = false; + bool ok = true; + m_a = true; + m_b = false; + m_c = true; + m_d = false; - EventId a = Simulator::Schedule (Now () + MicroSeconds (10), &SimulatorTests::A, this, 1); - Simulator::Schedule (Now () + MicroSeconds (11), &SimulatorTests::B, this, 2); - m_idC = Simulator::Schedule (Now () + MicroSeconds (12), &SimulatorTests::C, this, 3); + EventId a = Simulator::Schedule (Now () + MicroSeconds (10), &SimulatorTests::A, this, 1); + Simulator::Schedule (Now () + MicroSeconds (11), &SimulatorTests::B, this, 2); + m_idC = Simulator::Schedule (Now () + MicroSeconds (12), &SimulatorTests::C, this, 3); - Simulator::Cancel (a); - Simulator::Run (); + Simulator::Cancel (a); + Simulator::Run (); - if (!m_a || !m_b || !m_c || !m_d) - { - ok = false; - } - return ok; + if (!m_a || !m_b || !m_c || !m_d) + { + ok = false; + } + return ok; } bool SimulatorTests::RunTests (void) { - bool ok = true; + bool ok = true; - Simulator::SetLinkedList (); - if (!RunOneTest ()) - { - ok = false; - } - Simulator::Destroy (); - Simulator::SetBinaryHeap (); - if (!RunOneTest ()) - { - ok = false; - } - Simulator::Destroy (); - Simulator::SetStdMap (); - if (!RunOneTest ()) - { - ok = false; - } - Simulator::Destroy (); + Simulator::SetLinkedList (); + if (!RunOneTest ()) + { + ok = false; + } + Simulator::Destroy (); + Simulator::SetBinaryHeap (); + if (!RunOneTest ()) + { + ok = false; + } + Simulator::Destroy (); + Simulator::SetStdMap (); + if (!RunOneTest ()) + { + ok = false; + } + Simulator::Destroy (); - Simulator::Schedule (Seconds (0.0), &foo0); - Simulator::Schedule (Seconds (0.0), &foo1, 0); - Simulator::Schedule (Seconds (0.0), &foo2, 0, 0); - Simulator::Schedule (Seconds (0.0), &foo3, 0, 0, 0); - Simulator::Schedule (Seconds (0.0), &foo4, 0, 0, 0, 0); - Simulator::Schedule (Seconds (0.0), &foo5, 0, 0, 0, 0, 0); - Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar0, this); - Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar1, this, 0); - Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar2, this, 0, 0); - Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar3, this, 0, 0, 0); - Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar4, this, 0, 0, 0, 0); - Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar5, this, 0, 0, 0, 0, 0); - Simulator::ScheduleNow (&foo0); - Simulator::ScheduleNow (&foo1, 0); - Simulator::ScheduleNow (&foo2, 0, 0); - Simulator::ScheduleNow (&foo3, 0, 0, 0); - Simulator::ScheduleNow (&foo4, 0, 0, 0, 0); - Simulator::ScheduleNow (&foo5, 0, 0, 0, 0, 0); - Simulator::ScheduleNow (&SimulatorTests::bar0, this); - Simulator::ScheduleNow (&SimulatorTests::bar1, this, 0); - Simulator::ScheduleNow (&SimulatorTests::bar2, this, 0, 0); - Simulator::ScheduleNow (&SimulatorTests::bar3, this, 0, 0, 0); - Simulator::ScheduleNow (&SimulatorTests::bar4, this, 0, 0, 0, 0); - Simulator::ScheduleNow (&SimulatorTests::bar5, this, 0, 0, 0, 0, 0); - Simulator::ScheduleDestroy (&foo0); - Simulator::ScheduleDestroy (&foo1, 0); - Simulator::ScheduleDestroy (&foo2, 0, 0); - Simulator::ScheduleDestroy (&foo3, 0, 0, 0); - Simulator::ScheduleDestroy (&foo4, 0, 0, 0, 0); - Simulator::ScheduleDestroy (&foo5, 0, 0, 0, 0, 0); - Simulator::ScheduleDestroy (&SimulatorTests::bar0, this); - Simulator::ScheduleDestroy (&SimulatorTests::bar1, this, 0); - Simulator::ScheduleDestroy (&SimulatorTests::bar2, this, 0, 0); - Simulator::ScheduleDestroy (&SimulatorTests::bar3, this, 0, 0, 0); - Simulator::ScheduleDestroy (&SimulatorTests::bar4, this, 0, 0, 0, 0); - Simulator::ScheduleDestroy (&SimulatorTests::bar5, this, 0, 0, 0, 0, 0); - + Simulator::Schedule (Seconds (0.0), &foo0); + Simulator::Schedule (Seconds (0.0), &foo1, 0); + Simulator::Schedule (Seconds (0.0), &foo2, 0, 0); + Simulator::Schedule (Seconds (0.0), &foo3, 0, 0, 0); + Simulator::Schedule (Seconds (0.0), &foo4, 0, 0, 0, 0); + Simulator::Schedule (Seconds (0.0), &foo5, 0, 0, 0, 0, 0); + Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar0, this); + Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar1, this, 0); + Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar2, this, 0, 0); + Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar3, this, 0, 0, 0); + Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar4, this, 0, 0, 0, 0); + Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar5, this, 0, 0, 0, 0, 0); + Simulator::ScheduleNow (&foo0); + Simulator::ScheduleNow (&foo1, 0); + Simulator::ScheduleNow (&foo2, 0, 0); + Simulator::ScheduleNow (&foo3, 0, 0, 0); + Simulator::ScheduleNow (&foo4, 0, 0, 0, 0); + Simulator::ScheduleNow (&foo5, 0, 0, 0, 0, 0); + Simulator::ScheduleNow (&SimulatorTests::bar0, this); + Simulator::ScheduleNow (&SimulatorTests::bar1, this, 0); + Simulator::ScheduleNow (&SimulatorTests::bar2, this, 0, 0); + Simulator::ScheduleNow (&SimulatorTests::bar3, this, 0, 0, 0); + Simulator::ScheduleNow (&SimulatorTests::bar4, this, 0, 0, 0, 0); + Simulator::ScheduleNow (&SimulatorTests::bar5, this, 0, 0, 0, 0, 0); + Simulator::ScheduleDestroy (&foo0); + Simulator::ScheduleDestroy (&foo1, 0); + Simulator::ScheduleDestroy (&foo2, 0, 0); + Simulator::ScheduleDestroy (&foo3, 0, 0, 0); + Simulator::ScheduleDestroy (&foo4, 0, 0, 0, 0); + Simulator::ScheduleDestroy (&foo5, 0, 0, 0, 0, 0); + Simulator::ScheduleDestroy (&SimulatorTests::bar0, this); + Simulator::ScheduleDestroy (&SimulatorTests::bar1, this, 0); + Simulator::ScheduleDestroy (&SimulatorTests::bar2, this, 0, 0); + Simulator::ScheduleDestroy (&SimulatorTests::bar3, this, 0, 0, 0); + Simulator::ScheduleDestroy (&SimulatorTests::bar4, this, 0, 0, 0, 0); + Simulator::ScheduleDestroy (&SimulatorTests::bar5, this, 0, 0, 0, 0, 0); + - return ok; + return ok; } SimulatorTests gSimulatorTests; diff --git a/src/simulator/simulator.h b/src/simulator/simulator.h index 981fb2464..ef39e26d5 100644 --- a/src/simulator/simulator.h +++ b/src/simulator/simulator.h @@ -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 SchedulerFactory; */ 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 - 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 - 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 - 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 - 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 - 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 - 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 - 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 - 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 - 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 - 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 - 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 + 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 + 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 + 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 + 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 + 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 + 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 + 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 + 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 + 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 + 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 + 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 - 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 - 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 - 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 - 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 - 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 - 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 - 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 - 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 - 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 - 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 - 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 + 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 + 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 + 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 + 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 + 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 + 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 + 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 + 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 + 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 + 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 + 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 - 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 - 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 - 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 - 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 - 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 - 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 - 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 - 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 - 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 - 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 - 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 + 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 + 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 + 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 + 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 + 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 + 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 + 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 + 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 + 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 + 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 + 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 - static EventImpl *MakeEvent (void (T::*mem_ptr) (void), T *obj); - template - static EventImpl *MakeEvent (void (T::*mem_ptr) (T1), T* obj, T1 a1); - template - static EventImpl *MakeEvent (void (T::*mem_ptr) (T1,T2), T* obj, T1 a1, T2 a2); - template - static EventImpl *MakeEvent (void (T::*mem_ptr) (T1,T2,T3), T* obj, T1 a1, T2 a2, T3 a3); - template - static EventImpl *MakeEvent (void (T::*mem_ptr) (T1,T2,T3,T4), T* obj, T1 a1, T2 a2, T3 a3, T4 a4); - template - 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 - static EventImpl *MakeEvent (void (*f) (T1), T1 a1); - template - static EventImpl *MakeEvent (void (*f) (T1,T2), T1 a1, T2 a2); - template - static EventImpl *MakeEvent (void (*f) (T1,T2,T3), T1 a1, T2 a2, T3 a3); - template - static EventImpl *MakeEvent (void (*f) (T1,T2,T3,T4), T1 a1, T2 a2, T3 a3, T4 a4); - template - static EventImpl *MakeEvent (void (*f) (T1,T2,T3,T4,T5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5); + Simulator (); + ~Simulator (); + template + static EventImpl *MakeEvent (void (T::*mem_ptr) (void), T *obj); + template + static EventImpl *MakeEvent (void (T::*mem_ptr) (T1), T* obj, T1 a1); + template + static EventImpl *MakeEvent (void (T::*mem_ptr) (T1,T2), T* obj, T1 a1, T2 a2); + template + static EventImpl *MakeEvent (void (T::*mem_ptr) (T1,T2,T3), T* obj, T1 a1, T2 a2, T3 a3); + template + static EventImpl *MakeEvent (void (T::*mem_ptr) (T1,T2,T3,T4), T* obj, T1 a1, T2 a2, T3 a3, T4 a4); + template + 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 + static EventImpl *MakeEvent (void (*f) (T1), T1 a1); + template + static EventImpl *MakeEvent (void (*f) (T1,T2), T1 a1, T2 a2); + template + static EventImpl *MakeEvent (void (*f) (T1,T2,T3), T1 a1, T2 a2, T3 a3); + template + static EventImpl *MakeEvent (void (*f) (T1,T2,T3,T4), T1 a1, T2 a2, T3 a3, T4 a4); + template + static EventImpl *MakeEvent (void (*f) (T1,T2,T3,T4,T5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5); - 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 @@ namespace ns3 { template 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 EventId Simulator::Schedule (Time const &time, void (*f) (T1), T1 a1) { - return Schedule (time, MakeEvent (f, a1)); + return Schedule (time, MakeEvent (f, a1)); } template 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 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 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 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 @@ template void Simulator::ScheduleNow (void (T::*mem_ptr) (void), T *obj) { - ScheduleNow (MakeEvent (mem_ptr, obj)); + ScheduleNow (MakeEvent (mem_ptr, obj)); } @@ -973,71 +973,71 @@ template 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 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 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 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 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 void Simulator::ScheduleNow (void (*f) (T1), T1 a1) { - ScheduleNow (MakeEvent (f, a1)); + ScheduleNow (MakeEvent (f, a1)); } template void Simulator::ScheduleNow (void (*f) (T1,T2), T1 a1, T2 a2) { - ScheduleNow (MakeEvent (f, a1, a2)); + ScheduleNow (MakeEvent (f, a1, a2)); } template 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 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 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 @@ template void Simulator::ScheduleDestroy (void (T::*mem_ptr) (void), T *obj) { - ScheduleDestroy (MakeEvent (mem_ptr, obj)); + ScheduleDestroy (MakeEvent (mem_ptr, obj)); } @@ -1054,71 +1054,71 @@ template 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 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 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 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 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 void Simulator::ScheduleDestroy (void (*f) (T1), T1 a1) { - ScheduleDestroy (MakeEvent (f, a1)); + ScheduleDestroy (MakeEvent (f, a1)); } template void Simulator::ScheduleDestroy (void (*f) (T1,T2), T1 a1, T2 a2) { - ScheduleDestroy (MakeEvent (f, a1, a2)); + ScheduleDestroy (MakeEvent (f, a1, a2)); } template 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 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 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 diff --git a/src/simulator/time.cc b/src/simulator/time.cc index c7b21d662..358144e9f 100644 --- a/src/simulator/time.cc +++ b/src/simulator/time.cc @@ -1,4 +1,4 @@ -/* -*- Mode:NS3; -*- */ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * Copyright (c) 2005,2006 INRIA * All rights reserved. @@ -24,10 +24,10 @@ namespace ns3 { Time::Time () - : m_ns (0) + : m_ns (0) {} Time::Time (Time const &o) - : m_ns (o.m_ns) + : m_ns (o.m_ns) {} Time & Time::operator = (Time const &o) @@ -36,7 +36,7 @@ Time::operator = (Time const &o) return *this; } Time::Time (int64_t ns) - : m_ns (ns) + : m_ns (ns) {} @@ -153,19 +153,19 @@ bool operator >= (Time const &lhs, Time const &rhs) } Now::Now () - : Time (Simulator::Now ()) + : Time (Simulator::Now ()) {} Seconds::Seconds (double s) - : Time ((int64_t)(s * 1000000000)) + : Time ((int64_t)(s * 1000000000)) {} MilliSeconds::MilliSeconds (int32_t ms) - : Time ((int64_t)(ms * 1000000)) + : Time ((int64_t)(ms * 1000000)) {} MicroSeconds::MicroSeconds (int32_t us) - : Time ((int64_t)(us * 1000)) + : Time ((int64_t)(us * 1000)) {} NanoSeconds::NanoSeconds (int64_t ns) - : Time (ns) + : Time (ns) {} diff --git a/utils/bench-packets.cc b/utils/bench-packets.cc index ef4ccd3aa..b99274b94 100644 --- a/utils/bench-packets.cc +++ b/utils/bench-packets.cc @@ -1,4 +1,4 @@ -/* -*- Mode:NS3; -*- */ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * Copyright (c) 2006 INRIA * All rights reserved. @@ -30,106 +30,106 @@ using namespace ns3; static void benchPtrA (uint32_t n) { - ChunkConstantData data = ChunkConstantData (2000, 1); - ChunkUdp udp; - ChunkIpv4 ipv4; + ChunkConstantData data = ChunkConstantData (2000, 1); + ChunkUdp udp; + ChunkIpv4 ipv4; - for (uint32_t i = 0; i < n; i++) { - Packet p; - p.add (&data); - p.add (&udp); - p.add (&ipv4); - Packet o = p; - o.peek (&ipv4); - o.remove (&ipv4); - o.peek (&udp); - o.remove (&udp); - o.peek (&data); - o.remove (&data); - } + for (uint32_t i = 0; i < n; i++) { + Packet p; + p.add (&data); + p.add (&udp); + p.add (&ipv4); + Packet o = p; + o.peek (&ipv4); + o.remove (&ipv4); + o.peek (&udp); + o.remove (&udp); + o.peek (&data); + o.remove (&data); + } } static void benchPtrB (uint32_t n) { - ChunkConstantData data = ChunkConstantData (2000, 1); - ChunkUdp udp; - ChunkIpv4 ipv4; + ChunkConstantData data = ChunkConstantData (2000, 1); + ChunkUdp udp; + ChunkIpv4 ipv4; - for (uint32_t i = 0; i < n; i++) { - Packet p; - p.add (&data); - p.add (&udp); - p.add (&ipv4); - } + for (uint32_t i = 0; i < n; i++) { + Packet p; + p.add (&data); + p.add (&udp); + p.add (&ipv4); + } } static void ptrC2 (Packet p) { - ChunkConstantData data = ChunkConstantData (2000, 1); - ChunkUdp udp; + ChunkConstantData data = ChunkConstantData (2000, 1); + ChunkUdp udp; - p.peek (&udp); - p.remove (&udp); - p.peek (&data); - p.remove (&data); + p.peek (&udp); + p.remove (&udp); + p.peek (&data); + p.remove (&data); } static void ptrC1 (Packet p) { - ChunkIpv4 ipv4; - p.peek (&ipv4); - p.remove (&ipv4); - ptrC2 (p); + ChunkIpv4 ipv4; + p.peek (&ipv4); + p.remove (&ipv4); + ptrC2 (p); } static void benchPtrC (uint32_t n) { - ChunkConstantData data = ChunkConstantData (2000, 1); - ChunkUdp udp; - ChunkIpv4 ipv4; + ChunkConstantData data = ChunkConstantData (2000, 1); + ChunkUdp udp; + ChunkIpv4 ipv4; - for (uint32_t i = 0; i < n; i++) { - Packet p; - p.add (&data); - p.add (&udp); - p.add (&ipv4); - ptrC1 (p); - } + for (uint32_t i = 0; i < n; i++) { + Packet p; + p.add (&data); + p.add (&udp); + p.add (&ipv4); + ptrC1 (p); + } } static void runBench (void (*bench) (uint32_t), uint32_t n, char const *name) { - WallClockMs time; - time.start (); - (*bench) (n); - unsigned long long deltaMs = time.end (); - double ps = n; - ps *= 1000; - ps /= deltaMs; - std::cout << name<<"=" << ps << " packets/s" << std::endl; + WallClockMs time; + time.start (); + (*bench) (n); + unsigned long long deltaMs = time.end (); + double ps = n; + ps *= 1000; + ps /= deltaMs; + std::cout << name<<"=" << ps << " packets/s" << std::endl; } int main (int argc, char *argv[]) { - uint32_t n = 0; - while (argc > 0) { - if (strncmp ("--n=", argv[0],strlen ("--n=")) == 0) { - char const *nAscii = argv[0] + strlen ("--n="); - n = atoi (nAscii); - } - argc--; - argv++; - } + uint32_t n = 0; + while (argc > 0) { + if (strncmp ("--n=", argv[0],strlen ("--n=")) == 0) { + char const *nAscii = argv[0] + strlen ("--n="); + n = atoi (nAscii); + } + argc--; + argv++; + } - runBench (&benchPtrA, n, "a"); - runBench (&benchPtrB, n, "b"); - runBench (&benchPtrC, n, "c"); + runBench (&benchPtrA, n, "a"); + runBench (&benchPtrB, n, "b"); + runBench (&benchPtrC, n, "c"); - return 0; + return 0; } diff --git a/utils/bench-simulator.cc b/utils/bench-simulator.cc index de0dfec31..567ca4c8b 100644 --- a/utils/bench-simulator.cc +++ b/utils/bench-simulator.cc @@ -1,4 +1,4 @@ -/* -*- Mode:NS3; -*- */ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * Copyright (c) 2006 INRIA * All rights reserved. @@ -32,115 +32,115 @@ bool gDebug = false; class Bench { public: - void ReadDistribution (std::istream &istream); - void SetTotal (uint32_t total); - void RunBench (void); + void ReadDistribution (std::istream &istream); + void SetTotal (uint32_t total); + void RunBench (void); private: - void Cb (void); - std::vector m_distribution; - std::vector::const_iterator m_current; - uint32_t m_n; - uint32_t m_total; + void Cb (void); + std::vector m_distribution; + std::vector::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::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::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=" < 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; } diff --git a/utils/replay-simulation.cc b/utils/replay-simulation.cc index f9670b0cf..25c597efc 100644 --- a/utils/replay-simulation.cc +++ b/utils/replay-simulation.cc @@ -1,4 +1,4 @@ -/* -*- Mode:NS3; -*- */ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * Copyright (c) 2006 INRIA * All rights reserved. @@ -32,45 +32,45 @@ using namespace ns3; class LogReader { public: - void readFrom_filename (char const *filename); - void run (void); - void printStats (void); + void readFrom_filename (char const *filename); + void run (void); + void printStats (void); private: - struct Command { - enum { - REMOVE, - INSERT, - INSERT_LATER, - INSERT_REMOVE - } m_type; - // uid at which this command is supposed to be executed. - uint32_t m_uid; - union { - struct { - // time at which the event is supposed to expire - uint64_t m_evUs; - } insert; - struct { - // location in the array of events to remove where - // to insert this event once it is inserted in - // the scheduler. - uint32_t m_evLoc; - // time at which the event is supposed to expire - uint64_t m_evUs; - } insertRemove; - }; - }; - void executeLogCommands (uint32_t uid); + struct Command { + enum { + REMOVE, + INSERT, + INSERT_LATER, + INSERT_REMOVE + } m_type; + // uid at which this command is supposed to be executed. + uint32_t m_uid; + union { + struct { + // time at which the event is supposed to expire + uint64_t m_evUs; + } insert; + struct { + // location in the array of events to remove where + // to insert this event once it is inserted in + // the scheduler. + uint32_t m_evLoc; + // time at which the event is supposed to expire + uint64_t m_evUs; + } insertRemove; + }; + }; + void executeLogCommands (uint32_t uid); - typedef std::deque Commands; - typedef std::deque::iterator CommandsI; - typedef std::deque RemoveEvents; - + typedef std::deque Commands; + typedef std::deque::iterator CommandsI; + typedef std::deque 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 > Removes; @@ -79,187 +79,187 @@ typedef std::vector >::iterator RemovesI; void LogReader::ReadFrom_filename (char const *filename) { - std::ifstream log; - std::cout << "read log..." << std::endl; - Removes removes; - log.open (filename); - while (!log.eof ()) { - std::string type; - log >> type; - if (type == "i") { - uint32_t nowUid, evUid; - uint64_t nowUs, evUs; - log >> nowUid >> nowUs >> evUid >> evUs; - struct Command cmd; - cmd.m_type = Command::INSERT; - cmd.m_uid = nowUid; - cmd.insert.m_evUs = evUs; - m_commands.push_back (cmd); - } else if (type == "r") { - uint32_t nowUid, evUid; - uint64_t nowUs, evUs; - log >> nowUid >> nowUs >> evUid >> evUs; - struct Command cmd; - cmd.m_type = Command::REMOVE; - cmd.m_uid = nowUid; - m_commands.push_back (cmd); - removes.push_back (std::Make_pair (nowUid, evUid)); - } else if (type == "il") { - uint32_t nowUid, evUid; - uint64_t nowUs, evUs; - log >> nowUid >> nowUs >> evUid >> evUs; - struct Command cmd; - cmd.m_type = Command::INSERT_LATER; - cmd.m_uid = nowUid; - m_commands.push_back (cmd); - } - } - log.close (); + std::ifstream log; + std::cout << "read log..." << std::endl; + Removes removes; + log.open (filename); + while (!log.eof ()) { + std::string type; + log >> type; + if (type == "i") { + uint32_t nowUid, evUid; + uint64_t nowUs, evUs; + log >> nowUid >> nowUs >> evUid >> evUs; + struct Command cmd; + cmd.m_type = Command::INSERT; + cmd.m_uid = nowUid; + cmd.insert.m_evUs = evUs; + m_commands.push_back (cmd); + } else if (type == "r") { + uint32_t nowUid, evUid; + uint64_t nowUs, evUs; + log >> nowUid >> nowUs >> evUid >> evUs; + struct Command cmd; + cmd.m_type = Command::REMOVE; + cmd.m_uid = nowUid; + m_commands.push_back (cmd); + removes.push_back (std::Make_pair (nowUid, evUid)); + } else if (type == "il") { + uint32_t nowUid, evUid; + uint64_t nowUs, evUs; + log >> nowUid >> nowUs >> evUid >> evUs; + struct Command cmd; + cmd.m_type = Command::INSERT_LATER; + cmd.m_uid = nowUid; + m_commands.push_back (cmd); + } + } + log.close (); - std::cout << "gather insert removes..." << std::endl; - for (CommandsI i = m_commands.begin (); i != m_commands.end (); i++) { - if (i->m_type == Command::INSERT) { - for (RemovesI j = removes.begin (); j != removes.end (); j++) { - if (j->second == i->m_uid) { - // this insert will be removed later. - uint64_t us = i->insert.m_evUs; - uint32_t uid = i->m_uid; - i->m_type = Command::INSERT_REMOVE; - i->m_uid = uid; - i->insertRemove.m_evUs = us; - i->insertRemove.m_evLoc = j->first; - break; - } - } - } - } - std::cout << "calculate remove locations..." << std::endl; - // calculate the final insert/remove location. - for (CommandsI i = m_commands.begin (); i != m_commands.end (); i++) { - if (i->m_type == Command::INSERT_REMOVE) { - uint32_t loc = 0; - for (CommandsI tmp = i; tmp != m_commands.end (); tmp++) { - if (tmp->m_type == Command::REMOVE && - tmp->m_uid == i->insertRemove.m_evLoc) { - i->insertRemove.m_evLoc = loc; - break; - } - loc++; - } - } - } + std::cout << "gather insert removes..." << std::endl; + for (CommandsI i = m_commands.begin (); i != m_commands.end (); i++) { + if (i->m_type == Command::INSERT) { + for (RemovesI j = removes.begin (); j != removes.end (); j++) { + if (j->second == i->m_uid) { + // this insert will be removed later. + uint64_t us = i->insert.m_evUs; + uint32_t uid = i->m_uid; + i->m_type = Command::INSERT_REMOVE; + i->m_uid = uid; + i->insertRemove.m_evUs = us; + i->insertRemove.m_evLoc = j->first; + break; + } + } + } + } + std::cout << "calculate remove locations..." << std::endl; + // calculate the final insert/remove location. + for (CommandsI i = m_commands.begin (); i != m_commands.end (); i++) { + if (i->m_type == Command::INSERT_REMOVE) { + uint32_t loc = 0; + for (CommandsI tmp = i; tmp != m_commands.end (); tmp++) { + if (tmp->m_type == Command::REMOVE && + tmp->m_uid == i->insertRemove.m_evLoc) { + i->insertRemove.m_evLoc = loc; + break; + } + loc++; + } + } + } } void LogReader::ExecuteLogCommands (uint32_t uid) { - if (m_command == m_commands.end ()) { - return; - } - //std::cout << "one event, uid=" <m_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="<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="< 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 (); + } } diff --git a/utils/run-tests.cc b/utils/run-tests.cc index 6ef6a75c1..5e7552654 100644 --- a/utils/run-tests.cc +++ b/utils/run-tests.cc @@ -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; }