cppannotations/annotations/yo/containers/destroying.yo
Frank B. Brokken 777b182edd Moved all files but 'excluded', 'sf', and 'sourcetar' to ./annotations
This allowed me to standardize the sourcetar and sf/* scripts: the base
    directory (containing ./git) is now empty, except for maintenance scripts,
    while the source files and build scripts of the annotations are stored in
    a subdirectory of their own.
2013-05-29 20:44:08 +02:00

23 lines
916 B
Text

tt(Data)'s destructor has a data member which is an unrestricted union. As the
union's destructor can't perform any actions, the union's proper destruction
is delegated to a member, tt(Union::destroy) destroying the fields for which
destructors are defined. As tt(d_tag) stores the currently used tt(Union)
field, tt(Data)'s destructor can pass tt(d_tag) to tt(Union::destroy) to
inform it about which field should be destroyed.
tt(Union::destroy) does not need to perform any action for tt(INT) tags, but
for tt(STRING) tags the memory allocated by tt(u_string) must be returned. For
this an explicit destructor call is used. tt(Union::destroy) and
tt(Data)'s destructor are therefore implemented like this:
verb(
void Data::Union::destroy(Tag myTag)
{
if (myTag == Tag::STRING)
u_string.~string();
}
Data::~Data()
{
d_union.destroy(d_tag);
}
)