YansCoreNS::EventQueue Class Reference

The structure holding scheduled events. More...

List of all members.

Public Member Functions

void AddEvent (Time time, boost::shared_ptr< Event > event)
 Schedules an event to the queue.
 EventQueue (RandomNumberGenerator &rng)
 Constructor.
TimedEvent GetNextEvent (void)
 Returns the event scheduled to happen next.
bool RemoveEvent (boost::shared_ptr< Event const > event)
 Removes an event from the queue.
bool RemoveEvent (Time time, boost::shared_ptr< Event const > event)
 Removes an event from the queue.
 ~EventQueue (void)
 Destructor.


Detailed Description

The structure holding scheduled events.

Warning:
Do not inherit from this class! Doing so will lead to a memory leak.

Constructor & Destructor Documentation

YansCoreNS::EventQueue::EventQueue ( RandomNumberGenerator rng  )  [explicit]

Constructor.

Parameters:
[in,out] rng A random number generator instance.
Note:
rng is used to shuffle events scheduled at the same time.

YansCoreNS::EventQueue::~EventQueue ( void   ) 

Destructor.


Member Function Documentation

void YansCoreNS::EventQueue::AddEvent ( Time  time,
boost::shared_ptr< Event event 
)

Schedules an event to the queue.

Parameters:
[in] time The time the event is scheduled to happen.
[in,out] event The event to be scheduled.
Note:
The coomplexity of this method is O(log(n)) in the number of events currently in the queue.

TimedEvent YansCoreNS::EventQueue::GetNextEvent ( void   ) 

Returns the event scheduled to happen next.

Returns:
The event (with its scheduled time) scheduled to happen next.
Exceptions:
runtime_error If the queue is empty. NOTE that this should not happen: the simulation should end at the occurrance of a simulationEndEvent. The exception thrown indicates that no such event was scheduled, therefore the simulation would run until infinity.
Note:
The method removes the returned event from the queue, so repeated calls to the method will return different events.

The complexity of this method is O(log(n)) in the number of events currently in the queue.

bool YansCoreNS::EventQueue::RemoveEvent ( boost::shared_ptr< Event const >  event  ) 

Removes an event from the queue.

Parameters:
[in] event The event to be removed.
Returns:
true if the event was successfully removed from the queue; false otherwise.
Note:
The method removes the first occurrance of event from the queue. If no instances of event were found, the function returns false.

If the time the event was scheduled is known, it is more efficient to call the two-parameter version of this function.

The complexity of the method is O(n) in the number of events currently in the queue.

bool YansCoreNS::EventQueue::RemoveEvent ( Time  time,
boost::shared_ptr< Event const >  event 
)

Removes an event from the queue.

Parameters:
[in] time The time the event is scheduled to happen.
[in] event The event to be removed.
Returns:
true if the event was successfully removed from the queue; false otherwise.
Note:
The method removes the first occurrance of event scheduled at time. If no instances of event were found at time, the function returns false.

The complexity of this method is O(n) in the number of events scheduled at time.


Generated on Sat May 2 19:18:06 2009 for Yans - Yet another network simulator by  doxygen 1.5.8