~ubuntu-branches/ubuntu/trusty/c++-annotations/trusty

« back to all changes in this revision

Viewing changes to yo/containers/destroying.yo

  • Committer: Package Import Robot
  • Author(s): tony mancill, Frank B. Brokken, tony mancill
  • Date: 2012-02-28 00:50:21 UTC
  • mfrom: (1.1.19)
  • Revision ID: package-import@ubuntu.com-20120228005021-sz7nnodntkvgh7qf
Tags: 9.2.1-1
[ Frank B. Brokken ]
* New upstream release (using flexc++, reauthored polymorphic semantic
  values and unrestricted unions). Upstream release 9.2.0 is implied by
  this release.

[ tony mancill ]
* Set Standards-Version to 3.9.3.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
tt(Data)'s destructor has a data member which is an unrestricted union. As the
 
2
union's destructor can't perform any actions, the union's proper destruction
 
3
is delegated to a member, tt(Union::destroy) destroying the fields for which
 
4
destructors are defined. As tt(d_tag) stores the currently used tt(Union)
 
5
field, tt(Data)'s destructor can pass tt(d_tag) to tt(Union::destroy) to
 
6
inform it about which field should be destroyed.
 
7
 
 
8
tt(Union::destroy) does not need to perform any action for tt(INT) tags, but
 
9
for tt(STRING) tags the memory allocated by tt(u_string) must be returned. For
 
10
this an explicit destructor call is used. tt(Union::destroy) and
 
11
tt(Data)'s destructor are therefore implemented like this:
 
12
        verb(
 
13
    void Data::Union::destroy(Tag myTag)
 
14
    {
 
15
        if (myTag == Tag::STRING)
 
16
            u_string.~string();
 
17
    }
 
18
 
 
19
    Data::~Data()
 
20
    {
 
21
        d_union.destroy(d_tag);
 
22
    }
 
23
        )