/** * @description * Performs the first step of active object initialization by assigning * the virtual pointer and calling the superclass constructor. * * @param[in,out] me pointer (see @ref oop) * @param[in] initial pointer to the event to be dispatched to the MSM * * @note Must be called only ONCE before QMSM_INIT(). * * @sa QHsm_ctor() and QFsm_ctor() */ void QMActive_ctor(QMActive * const me, QStateHandler initial) { static QMActiveVtbl const vtbl = { /* QMActive virtual table */ { &QMsm_init_, &QMsm_dispatch_ }, &QActive_start_, &QActive_post_, &QActive_postLIFO_ }; /* clear the whole QActive object, so that the framework can start * correctly even if the startup code fails to clear the uninitialized * data (as is required by the C Standard). */ QF_bzero(me, (uint_fast16_t)sizeof(*me)); /** * @note QMActive inherits QActive, so by the @ref oop convention * it should call the constructor of the superclass, i.e., QActive_ctor(). * However, this would pull in the QActiveVtbl, which in turn will pull * in the code for QHsm_init_() and QHsm_dispatch_() implemetations, * which is expensive. To avoid this code size penalty, in case QHsm is * not used in a given project, the call to QMsm_ctor() avoids pulling * in the code for QHsm. */ QMsm_ctor(&me->super, initial); me->super.vptr = &vtbl.super; /* hook vptr to QMActive virtual table */ }
/* @(/2/12) ................................................................*/ QMsm * Mine2_ctor(uint8_t id) { Mine2 *me; Q_REQUIRE(id < GAME_MINES_MAX); me = &l_mine2[id]; /* superclass' ctor */ QMsm_ctor(&me->super, Q_STATE_CAST(&Mine2_initial)); return (QMsm *)me; }
void Calc_ctor(Calc * const me) { /* superclass' ctor */ QMsm_ctor(&me->super, Q_STATE_CAST(&Calc_initial)); me->operand1 = 0.0; me->operand2 = 0.0; me->len = 0U; me->opKey = 0U; }
/*..........................................................................*/ void QMActive_ctor(QMActive * const me, QStateHandler initial) { static QActiveVtbl const vtbl = { /* QMActive virtual table */ { &QMsm_init_, &QMsm_dispatch_ }, &QActive_start_, &QActive_post_, &QActive_postLIFO_ }; QMsm_ctor(&me->super, initial);/*call instead of QActive_ctor(), NOTE01 */ me->super.vptr = &vtbl.super;/* hook the vptr to QMActive virtual table */ }
/* @(/1/1) .................................................................*/ void QMsmTst_ctor(void) { QMsmTst *me = &l_msmtst; QMsm_ctor(&me->super, Q_STATE_CAST(&QMsmTst_initial)); }
/*${SMs::Calc_ctor} ........................................................*/ void Calc_ctor(void) { Calc *me = &l_calc; QMsm_ctor(&me->super, Q_STATE_CAST(&Calc_initial)); }