FACT++  1.0
EventImp Class Reference

A general base-class describing events issues in a state machine. More...

#include <EventImp.h>

+ Inheritance diagram for EventImp:
+ Collaboration diagram for EventImp:

Public Member Functions

 EventImp ()
 Constructor. Stores the target state given. More...
 EventImp (const EventImp &cmd)
 Copy constructor. More...
virtual ~EventImp ()
virtual void SetDescription (const std::string &)
virtual std::string GetDescription () const
EventImpAssignFunction (const std::function< int(const EventImp &)> &func=std::function< int(const EventImp &)>())
bool HasFunc () const
int ExecFunc () const
EventImpoperator() (const std::function< int(const EventImp &)> &func)
EventImpoperator() (const std::string str)
EventImpoperator() (const char *str)
EventImpoperator() (int state)
virtual void Print (std::ostream &out, bool strip=false) const
virtual void Print (bool strip=false) const
void AddAllowedState (int state)
void AddAllowedStates (const std::string &states)
bool IsStateAllowed (int state) const
virtual std::string GetName () const
virtual std::string GetFormat () const
virtual const void * GetData () const
virtual size_t GetSize () const
virtual Time GetTime () const
virtual int GetQoS () const
virtual bool IsEmpty () const
std::string GetTimeAsStr (const char *fmt) const
uint64_t GetJavaDate () const
template<typename T >
Get (size_t offset=0) const
template<typename T >
const T * Ptr (size_t offset=0) const
template<typename T >
const T & Ref (size_t offset=0) const
const char * GetText () const
bool GetBool () const
int16_t GetShort () const
uint16_t GetUShort () const
int32_t GetInt () const
uint32_t GetUInt () const
int64_t GetXtra () const
uint64_t GetUXtra () const
float GetFloat () const
double GetDouble () const
std::vector< char > GetVector () const
std::string GetString () const

Private Attributes

std::vector< int > fAllowedStates
std::function< int(const EventImp &)> fFunction
 List of states in which this event is allowed. More...

Detailed Description

A general base-class describing events issues in a state machine.


The general purpose of this class is to describe an event which can occur in one of our StateMachines. It provides pointers to data associated with the event, a target state and stores the states in which issuing this event is allowed. The target state might be negative to describe that no transition of the state is requested.

Such an event canjust be a description of an event, but can also be an issued event which already contain data.

The format can, but need not, contain the format of the data area. As a rule, it should follow the format also used in the DIM network.

functions to an event

To any event a function call can be assigned. Thanks to boost::bind there are various and different very powerful ways to do that.

The function assigned with AssignFunction must return int. When it is executed it is given a const reference of the current event as an argument, i.e. if you want to get such a reference in your function, you can reference it using the placeholder _1. (Remark: it is allowe to omit the _1 placeholder if no reference to the EventImp object is needed)

A few examples:

int function(const EventImp &evt, int i, const char *txt) { return i; }
evt.AssignFunction(boost::bind(function, _1, 7, "hallo"));
cout << evt.Exec() << endl;
// 7

When the function is executed later via ExecFunc() in will get a reference to the executing EventImp as its first argument (indicated by '_1'), it will get 7 and "hallo" as second and third argument.

int function(int i, const char *txt, const EventImp &evt) { return i; }
evt.AssignFunction(boost::bind(function, 7, "hallo", _1));
cout << evt.Exec() << endl;
// 7

Is the same example than the one above, but the arguments are in a different order.

class A
int function(const EventImp &evt, int i, const char *txt)
cout << this << endl; return i;
A a;
evt.AssignFunction(boost::bind(&A::function, &a, _1, 7, "hallo"));
cout << evt.Exec() << endl;
// &a
// 7

The advanatge of boost::bind is that it also works for member functions of classes. In this case the first argument after the function-pointer must be a pointer to a valid class-object. This can also be this if called from within a class object.

Also note that everything (as usual) which is not a reference is copied when the bind function is invoked. If you want to distribute a reference instead use ref(something), like

int function(int &i) { return i; }
int j = 5;
evt.AssignFunction(bind(function, ref(j));
j = 7;
cout << evt.Exec() << endl;
// 7

Note, that you are responsible for the validity, that means: Do not destroy your object (eg. reference to j) while bind might still be called later, or a pointer to this.


Add link to DIM format

Definition at line 11 of file EventImp.h.

The documentation for this class was generated from the following files: