FACT++
1.0
|
A general base-class describing events issues in a state machine. More...
#include <EventImp.h>
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 |
EventImp & | AssignFunction (const std::function< int(const EventImp &)> &func=std::function< int(const EventImp &)>()) |
bool | HasFunc () const |
int | ExecFunc () const |
EventImp & | operator() (const std::function< int(const EventImp &)> &func) |
EventImp & | operator() (const std::string str) |
EventImp & | operator() (const char *str) |
EventImp & | operator() (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 > | |
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... | |
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.
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:
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.
Is the same example than the one above, but the arguments are in a different order.
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
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.
Definition at line 11 of file EventImp.h.