DEEvent Class Reference

describes each single event in the simulation More...

#include <deevent.h>

Inherited by DECheckEvent.

Collaboration diagram for DEEvent:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 DEEvent ()
 Constructor.
virtual void Handler ()
 Handler of the event.
DETime getTime ()
 Returns the timestamp of the event.
void setTime (const DETime &T)
 Sets the absolute timestamp of the event.
void addTime (const DETime &T)
 Add T to the timestamp of the event.
bool IsInOverFlow () const
 Checks if the event is over timescale.
virtual const char * Type () const
 Returns a string identifying the event.
virtual bool EvCompareTarget (void *target)
 Compares an event against some test. It MUST be overridden.

Related Functions

(Note that these are not member functions.)

ostream & operator<< (ostream &os, const DEEvent &ev)
 Prints the event represented by ev.

Detailed Description

describes each single event in the simulation

Events are the way that NePSing have to count the time.

In a Discrete Event simulation, the time proceeds trough steps. Each step is not fixed, but associated with the execution of an event. Hence, the time will proceed by leapfrogging trough every event execution.

NePSing have an internal scheduler and will call every event according to its execution time. Syncronous events (i.e., events with the very same execution time) will be launched sequentially in a random order. Take a special care of concurrent events, as an event will have no way of telling if there is another even at the same time or not.

Events are scheduled by specifiying how much time they will be executed in. As is, a differential time from 'now'.

You can define also 'immediate' events, as is to be executed at the same time af the caller time. They are to be preferred to normal events with a zero delay time as they are faster.

WARNING: Events can be dangerous if not used wisely. An event is (more or less) a delayed function call. As a matter of fact, the event will call the target's event handler, but there is an important thing to remember. When an event is created, it goes to the NePSing scheduler, then it will be executed following the scheduler's rules. This means that even an immediate event will differ from a simple function call. Consider the following code:

 void fooFun(void) {
   cout << "before" << endl;
   newEvent( new EvFoo(this) );
   cout << "after" << endl;
 }
 
 void barFun(void) {
   cout << "before" << endl;
   HEvFoo();
   cout << "after" << endl;
 }
 
 // Handler for the EvFoo event
 void HEvFoo(void) {
   cout << "inside" << endl;
 }

of course barFun() will print: "before", then "inside", then "after". fooFun(), on the contrary, will print "before", then "after", then "inside". The important point is that a lot of function can be executed before an event is processed. This is especially important if you use pointers with events. You must ensure that the pointed object will be still valid (and meaningful) when the event handler will be called, otherwise... you know. One of the most common NePSing programming errors is to pass a pointer to an event and then destroy it. It is always better to use a data copy method instead of pointers with the events, unless for really huge data.

A special note about events and simulation speed.
Events have to be stored by NePSing in a time-ordered list, but this list have to be reordered every time a new event is generated. Since the reordering process is dependant on the event list length, the more active (i.e., unprocessed) events you have, the slower the simulation.

Moreover, since the time comparison involve is an unsigned long long int (64 bits on most machines), expect a huge improvement on simulation speed on 64-bits capable machines. probably, however, you will have to tweak the compiling options in order to optimize both the simulation and the NePSing libraries.


Constructor & Destructor Documentation

DEEvent::DEEvent  ) 
 

Constructor.

Construct a new event. The time of the event is set up by the Scheduler's functions.


Member Function Documentation

virtual bool DEEvent::EvCompareTarget void *  target  )  [virtual]
 

Compares an event against some test. It MUST be overridden.

Used by EventRemove. In order to use the DEDevice function RemoveEventsForMe(), you MUST override this on your own Events.

Returns:
TRUE if the events are similar, i.e., for the same target;

FALSE otherwise.

Usually this function will be more or less:
 bool MyEvent::EvCompareTarget(void *target) 
 { 
     if (eventTarget == target)
       return TRUE;
     else
       return FALSE;
 }

virtual void DEEvent::Handler  )  [inline, virtual]
 

Handler of the event.

This method must be overridden in each derived event and it is used only to call the actual event handler defined in the device.

Eg:

 void MyEvent::Handler() 
 { 
      dev.HandlerMyEvent(); 
 }

where:

  • MyEvent is an event derived from DEEvent.
  • dev is a member of MyEvent pointing to an instance of a class derived from DEDevice and it is the device where the event is delivered to.
  • HandlerMyEvent() is the method of dev which actually handles the event.


The documentation for this class was generated from the following file:
Generated on Wed Dec 22 23:23:49 2004 for NePSing by doxygen 1.3.9.1 ---- Hosted by SourceForge.net Logo