ADT
arm-eh
ast-experimental
enum
forall-pointer-decay
jacob/cs343-translation
new-ast-unique-expr
pthread-emulation
qualifiedEnum
Last change
on this file since adf34b3 was 58870e6b, checked in by Peter A. Buhr <pabuhr@…>, 5 years ago |
switch from reference back to pointer
|
-
Property mode
set to
100644
|
File size:
1.6 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 {
|
---|
[7c1144b] | 9 | // PUBLIC
|
---|
| 10 |
|
---|
[5e82d56] | 11 | void ?{}( Colable & co ) with( co ) {
|
---|
| 12 | next = 0p;
|
---|
| 13 | } // post: ! listed()
|
---|
| 14 |
|
---|
| 15 | // return true iff *this is an element of a collection
|
---|
| 16 | bool listed( Colable & co ) with( co ) { // pre: this != 0
|
---|
[636d3715] | 17 | return next != 0p;
|
---|
[5e82d56] | 18 | }
|
---|
| 19 |
|
---|
[7c1144b] | 20 | Colable & getNext( Colable & co ) with( co ) {
|
---|
| 21 | return *next;
|
---|
[5e82d56] | 22 | }
|
---|
| 23 |
|
---|
[7c1144b] | 24 | // PRIVATE
|
---|
| 25 |
|
---|
[5e82d56] | 26 | Colable *& Next( Colable * cp ) {
|
---|
| 27 | return cp->next;
|
---|
| 28 | }
|
---|
[636d3715] | 29 |
|
---|
[7c1144b] | 30 | // wrappers to make Collection have T
|
---|
[636d3715] | 31 | forall( dtype T ) {
|
---|
[58870e6b] | 32 | T *& Next( T * n ) {
|
---|
| 33 | return (T *)Next( (Colable *)n );
|
---|
[636d3715] | 34 | }
|
---|
| 35 |
|
---|
| 36 | bool listed( T * n ) {
|
---|
| 37 | return Next( (Colable *)n ) != 0p;
|
---|
| 38 | }
|
---|
| 39 | } // distribution
|
---|
[5e82d56] | 40 | } // distribution
|
---|
| 41 |
|
---|
[636d3715] | 42 |
|
---|
[5e82d56] | 43 | struct Collection {
|
---|
| 44 | void * root; // pointer to root element of list
|
---|
| 45 | };
|
---|
| 46 |
|
---|
| 47 | inline {
|
---|
| 48 | // class invariant: root == 0 & empty() | *root in *this
|
---|
| 49 | void ?{}( Collection &, const Collection & ) = void; // no copy
|
---|
| 50 | Collection & ?=?( const Collection & ) = void; // no assignment
|
---|
| 51 |
|
---|
| 52 | void ?{}( Collection & collection ) with( collection ) {
|
---|
| 53 | root = 0p;
|
---|
| 54 | } // post: empty()
|
---|
| 55 |
|
---|
| 56 | bool empty( Collection & collection ) with( collection ) { // 0 <=> *this contains no elements
|
---|
| 57 | return root == 0p;
|
---|
| 58 | }
|
---|
[636d3715] | 59 |
|
---|
[5e82d56] | 60 | void * head( Collection & collection ) with( collection ) {
|
---|
| 61 | return root;
|
---|
| 62 | } // post: empty() & head() == 0 | !empty() & head() in *this
|
---|
| 63 | } // distribution
|
---|
| 64 |
|
---|
| 65 |
|
---|
| 66 | struct ColIter {
|
---|
| 67 | void * curr; // element to be returned by >>
|
---|
| 68 | };
|
---|
| 69 |
|
---|
| 70 | inline {
|
---|
| 71 | void ?{}( ColIter & colIter ) with( colIter ) {
|
---|
| 72 | curr = 0p;
|
---|
| 73 | } // post: elts = null
|
---|
[636d3715] | 74 |
|
---|
| 75 | forall( dtype T ) {
|
---|
| 76 | T * Curr( ColIter & ci ) with( ci ) {
|
---|
| 77 | return (T *)curr;
|
---|
| 78 | }
|
---|
| 79 | } // distribution
|
---|
[5e82d56] | 80 | } // distribution
|
---|
Note:
See
TracBrowser
for help on using the repository browser.