source: libcfa/src/bits/collection.hfa@ cde1bf9

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 cde1bf9 was 5e82d56, checked in by Peter A. Buhr <pabuhr@…>, 5 years ago

temporary collection types for testing

  • Property mode set to 100644
File size: 1.3 KB
Line 
1#pragma once
2
3struct Colable {
4 Colable * next; // next node in the list
5 // invariant: (next != 0) <=> listed()
6};
7
8inline {
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
27struct Collection {
28 void * root; // pointer to root element of list
29};
30
31inline {
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
49struct ColIter {
50 void * curr; // element to be returned by >>
51};
52
53inline {
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.