$declare$define1
The $define ${<model-item>}
directive requests generating a definition of the <model-item>. QM can generate definitions for the following item types:
Class Definition
Class Calc
with a State Machine used in the following examples of code generationThe directive $define ${<Class>}
generates the class definition, which consists of all operations (member functions) defined in the class as well as all static attributes (class variables). Additionally, if the class has a State Machine, the State Machine code will also be generated.
- Note
- QM generates code only for operations with non-empty operation code filed in the Class Operation Property Sheet. This allows the developer to provide external definitions of such operations (member functions) in other modules.
Class Definition in C
The following listing shows fragments of the generated code for the class Calc
in C. The code shows class operations, such as `Calc_eval().
Calc Calc_inst;
static bool Calc_eval(Calc * const me,
double op,
uint8_t oper)
{
double result;
. . .
if ((result < -99999999.0) || (99999999.0 < result)) {
BSP_display_error(" Error 1 ");
return false;
}
if ((-0.0000001 < result) && (result < 0.0000001)) {
result = 0.0;
}
BSP_display(result);
return true;
}
. . .
. . .
- Note
- Please refer to Section Basic Modeling | Working with Class Operations | Class Operations in C for more information about special class operations, such as constructors and destructors.
Class Definition in C++
The following listing shows fragments of the generated code for the class Calc
in C++. The code shows class operations, such as Calc::Calc()
constructor and the Calc::eval() operation.
Calc Calc::inst;
Calc::Calc()
: QHsm(Q_STATE_CAST(&Calc::initial))
{}
bool Calc::eval(
double op,
uint8_t oper) noexcept
{
double result;
. . .
if ((result < -99999999.0) || (99999999.0 < result)) {
BSP_display_error(" Error 1 ");
return false;
}
if ((-0.0000001 < result) && (result < 0.0000001)) {
result = 0.0;
}
BSP_display(result);
return true;
}
- Note
- Please refer to Section Basic Modeling | Working with Class Operations for more information about special class operations, such as constructors and destructors.
Free Attribute Definition
Free attribute AO_Ship
with an "initializer" used in the code generation examples
Free Attribute Definition in C
The following listing shows fragments of the generated code for the free attribute AO_Ship
in C.
QActive * const AO_Ship = &Ship_inst.super;
- Note
- Note the attribute initialization with the provided initializer, which is necessary at the point of definition because the attribute is
const
and cannot be initialized later.
Free Attribute Definition in C++
The following listing shows fragments of the generated code for the free attribute AO_Ship
in C++.
namespace GAME {
QP::QActive * const AO_Ship = &Ship::inst;
}
- Note
- Note the attribute initialization with the provided initializer, which is necessary at the point of definition because the attribute is
const
and cannot be initialized later.
Free Operation Definition
Free operation gc()
in a package with namespace QF_
resulting in QF_gc()
Free Operation Definition in C
The following listing shows fragments of the generated code for the free operation gc()
in C.
. . .
void QF_gc(QEvt const * const e) {
. . .
QF_CRIT_STAT
QF_CRIT_ENTRY();
QF_MEM_SYS();
if (e->refCtr_ > 1U) {
. . .
}
}
- Note
- The free operation
gc()
in a package QF-dyn
with namespace QF_
resulting in QF_gc()
Free Operation Definition in C++
The following listing shows fragments of the generated code for the free operation gc()
in C.
namespace QP {
namespace QF {
. . .
void gc(QEvt const * const e) noexcept {
std::uint_fast8_t const poolNum = QEvt_getPoolId_(e);
if (poolNum != 0U) {
QF_CRIT_STAT
. . .
}
}
. . .
- Note
- The free operation
gc()
in a package QF-dyn
with namespace QF::
resulting in QF::gc()
Package Definition
The $define ${<package>}
directive requests generating a recursive definition of all classes, free attributes, and free operations in the <package>
, as described in the sections above. If a package contains other packages, these packages are recursively defined, as described in the first sentence.
- Note
- The QM™ generates code in the same order as they appear in the Model Explorer.
$declare$define1