Attributes and generation properties
Attributes are variables that an object encapsulates to maintain its state. Objects encapsulate attributes as a set of data items. A data item designates a variable with a name and a type, where the type is a data type. A data item for an object is mapped to a member of the object's structure. The member's name and type are the same as those of the object data.
For
example, the isClosed
attribute
of the Valve
object type is embedded by value as
a data member inside the Valve
structure:
struct Valve {
/*** User explicit entries ***/
RiCBoolean isClosed; /*## attribute isClosed ##*/
};
The RiCBoolean
type is the C equivalent of
OMBoolean
, a Boolean data type defined in the Rhapsody®
Developer for C++ framework.
An accessor operation enables you to access the
data, whereas a mutator operation enables you to modify the data.
The accessor is generated if the C_CG::Attribute::AccessorGenerate
property
is set to Checked
. Similarly, the mutator is generated
if the C_CG::Attribute::MutatorGenerate
property
is set to Always
. The default AccessorGenerate
is Cleared
.
The default for MutatorGenerate
is Never
.
Accessor and mutator operations are generated in
the user implicit entries area of the specification file for the object
type. For example, prototypes for the _getIsClosed()
accessor
operation and the _setIsClosed()
mutator operation
are generated for the isClosed
attribute in the Valve.h
file:
/*** User implicit entries ***/
RiCBoolean Valve _getIsClosed(const Valve* const me);
void Valve _setIsClosed(Valve* const me, RiCBoolean
p_isClosed);
The bodies of the accessor and mutator
operations
are generated in the implementation file for the object type. For
example, the following implementations are generated for the _getIsClosed()
and _setIsClosed()
operations
in the Valve.c
file:
/*** Methods implementation ***/
RiCBoolean Valve_getIsClosed(const Valve* const me) {
return me->isClosed;
}
void Valve _setIsClosed(Valve* const me, RiCBoolean
p_isClosed) {
me->isClosed = p_isClosed;
}
Rhapsody generates attributes in the following order:
- Attributes are grouped into user‑defined and implicit attributes (such as relation containers).
- The attributes in each subgroup are generated in alphabetical order.