ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change
on this file since 63ec5fa was
5e82d56,
checked in by Peter A. Buhr <pabuhr@…>, 4 years ago
|
temporary collection types for testing
|
-
Property mode set to
100644
|
File size:
1.3 KB
|
Rev | Line | |
---|
[5e82d56] | 1 | #pragma once |
---|
| 2 | |
---|
| 3 | struct Colable { |
---|
| 4 | Colable * next; // next node in the list |
---|
| 5 | // invariant: (next != 0) <=> listed() |
---|
| 6 | }; |
---|
| 7 | |
---|
| 8 | inline { |
---|
| 9 | void ?{}( Colable & co ) with( co ) { |
---|
| 10 | next = 0p; |
---|
| 11 | } // post: ! listed() |
---|
| 12 | |
---|
| 13 | // return true iff *this is an element of a collection |
---|
| 14 | bool listed( Colable & co ) with( co ) { // pre: this != 0 |
---|
| 15 | return next != 0; |
---|
| 16 | } |
---|
| 17 | |
---|
| 18 | Colable * getNext( Colable & co ) with( co ) { |
---|
| 19 | return next; |
---|
| 20 | } |
---|
| 21 | |
---|
| 22 | Colable *& Next( Colable * cp ) { |
---|
| 23 | return cp->next; |
---|
| 24 | } |
---|
| 25 | } // distribution |
---|
| 26 | |
---|
| 27 | struct Collection { |
---|
| 28 | void * root; // pointer to root element of list |
---|
| 29 | }; |
---|
| 30 | |
---|
| 31 | inline { |
---|
| 32 | // class invariant: root == 0 & empty() | *root in *this |
---|
| 33 | void ?{}( Collection &, const Collection & ) = void; // no copy |
---|
| 34 | Collection & ?=?( const Collection & ) = void; // no assignment |
---|
| 35 | |
---|
| 36 | void ?{}( Collection & collection ) with( collection ) { |
---|
| 37 | root = 0p; |
---|
| 38 | } // post: empty() |
---|
| 39 | |
---|
| 40 | bool empty( Collection & collection ) with( collection ) { // 0 <=> *this contains no elements |
---|
| 41 | return root == 0p; |
---|
| 42 | } |
---|
| 43 | void * head( Collection & collection ) with( collection ) { |
---|
| 44 | return root; |
---|
| 45 | } // post: empty() & head() == 0 | !empty() & head() in *this |
---|
| 46 | } // distribution |
---|
| 47 | |
---|
| 48 | |
---|
| 49 | struct ColIter { |
---|
| 50 | void * curr; // element to be returned by >> |
---|
| 51 | }; |
---|
| 52 | |
---|
| 53 | inline { |
---|
| 54 | void ?{}( ColIter & colIter ) with( colIter ) { |
---|
| 55 | curr = 0p; |
---|
| 56 | } // post: elts = null |
---|
| 57 | } // distribution |
---|
Note: See
TracBrowser
for help on using the repository browser.