summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/contract/example/meyer97/stack4.e
blob: 85d6e539d0f8099f7e1eac4f9e5864cb4e8b6784 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
-- Copyright (C) 2008-2018 Lorenzo Caminiti
-- Distributed under the Boost Software License, Version 1.0 (see accompanying
-- file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).
-- See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html

//[meyer97_stack4_e
-- Extra spaces, newlines, etc. for visual alignment with this library code.





indexing
    destription: "Dispenser with LIFO access policy and a fixed max capacity."
class interface STACK4[G] creation make -- Interface only (no implementation).







invariant
    count_non_negative: count >= 0
    count_bounded: count <= capacity
    empty_if_no_elements: empty = (count = 0)



feature -- Initialization

    -- Allocate stack for a maximum of n elements.
    make(n: INTEGER) is
        require
            non_negative_capacity: n >= 0
        ensure
            capacity_set: capacity = n
        end



















































feature -- Access

    -- Max number of stack elements.
    capacity: INTEGER

    
    
    
    
    -- Number of stack elements.
    count: INTEGER

    
    
    
    
    -- Top element.
    item: G is
        require
            not_empty: not empty -- i.e., count > 0
        end






feature -- Status report
    
    -- Is stack empty?
    empty: BOOLEAN is
        ensure
            empty_definition: result = (count = 0)
        end

    
    
    
    
    
    
    
    -- Is stack full?
    full: BOOLEAN is
        ensure
            full_definition: result = (count = capacity)
        end








feature -- Element change

    -- Add x on top.
    put(x: G) is
        require
            not_full: not full
        ensure
            not_empty: not empty
            added_to_top: item = x
            one_more_item: count = old count + 1
        end

    
    
    
    
    
    
    
    -- Remove top element.
    remove is
        require
            not_empty: not empty -- i.e., count > 0
        ensure
            not_full: not full
            one_fewer_item: count = old count - 1

        end























end -- class interface STACK4

-- End.
//]