SheafSystem  0.0.0.0
record_queue.cc
Go to the documentation of this file.
1 
2 //
3 // Copyright (c) 2014 Limit Point Systems, Inc.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 
20 
21 #include "SheafSystem/record_queue.h"
22 
23 #include "SheafSystem/assert_contract.h"
24 
25 // ===========================================================
26 // RECORD_QUEUE FACET
27 // ===========================================================
28 
29 // PUBLIC MEMBER FUNCTIONS
30 
33 {
34  // Preconditions:
35 
36  // Body:
37 
38  // Postconditions:
39 
40  ensure(invariant());
41  ensure(is_empty());
42 
43  // Exit:
44 
45  return;
46 }
47 
49 record_queue(const record_queue& xother)
50 {
51  // Preconditions:
52 
53  // Body:
54 
55  not_implemented();
56 
57  // Postconditions:
58 
59  ensure(invariant());
60 }
61 
64 {
65 
66  // Preconditions:
67 
68  // Body:
69 
70 
71  // Postconditions:
72 
73  // Exit:
74 
75  return;
76 }
77 
78 void
81 {
82  // Preconditions:
83 
84  // Body:
85 
86  // Insert xindex at the back of the read queue
87 
90 
91  _record_queue.push(xindex);
92 
93  // Postconditions:
94 
95  ensure(!is_empty());
96  ensure(unexecutable(ct() == old ct() + 1));
97 
98  // Exit
99 
100  return;
101 }
102 
106 {
107  // Preconditions:
108 
109  require(!is_empty());
110 
111  // Body:
112 
113  pod_index_type result = _record_queue.front();
114  _record_queue.pop();
115 
116  // Postconditions:
117 
118  ensure(unexecutable(ct() == old ct() - 1));
120 
121  // Exit
122 
123  return result;
124 }
125 
126 int
128 ct() const
129 {
130  return _record_queue.size();
131 }
132 
133 bool
135 is_empty() const
136 {
137  return _record_queue.empty();
138 }
139 
140 void
143 {
144  // Preconditions:
145 
146  // Body:
147 
148  while(!is_empty())
149  (void)dequeue();
150 
151  // Postconditions:
152 
153  ensure(is_empty());
154 
155  // Exit:
156 
157  return;
158 }
159 
160 // PROTECTED MEMBER FUNCTIONS
161 
162 // PRIVATE MEMBER FUNCTIONS
163 
164 
165 // ===========================================================
166 // RECORD_QUEUE FACET
167 // ===========================================================
168 
169 // PUBLIC MEMBER FUNCTIONS
170 
173 clone() const
174 {
175  record_queue* result;
176 
177  // Preconditions:
178 
179  // Body:
180 
181  result = new record_queue();
182 
183  // Postconditions:
184 
185  ensure(result != 0);
186  ensure(is_same_type(result));
187 
188  // Exit:
189 
190  return result;
191 }
192 
193 bool
195 invariant() const
196 {
197  bool result = true;
198 
199  // Preconditions:
200 
201  // Body:
202 
203  // Must satisfy base class invariant
204 
205  result = result && any::invariant();
206 
207  if(invariant_check())
208  {
209  // Prevent recursive calls to invariant
210 
212 
213  // Finished, turn invariant checking back on.
214 
216  }
217 
218  // Postconditions:
219 
220  // Exit
221 
222  return result;
223 }
224 
225 bool
227 is_ancestor_of(const any* other) const
228 {
229  // Preconditions:
230 
231  require(other != 0);
232 
233  // Body:
234 
235  // True if other conforms to this
236 
237  bool result = dynamic_cast<const record_queue*>(other) != 0;
238 
239  // Postconditions:
240 
241  // Exit:
242 
243  return result;
244 }
245 
246 // PROTECTED MEMBER FUNCTIONS
247 
248 // PRIVATE MEMBER FUNCTIONS
249 
250 
virtual bool invariant() const
Class invariant, intended to be redefined in each descendant. See below for template for invariant in...
Definition: any.cc:153
int ct() const
The number of requests in the record queue.
void clear()
Makes the record queue empty.
bool is_empty() const
True if the record queue is empty.
virtual ~record_queue()
Destructor.
Definition: record_queue.cc:63
Abstract base class with useful features for all objects.
Definition: any.h:39
pod_index_type dequeue()
Removes and returns the index at the front of the record queue.
record_queue()
Default constructor.
Definition: record_queue.cc:32
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
void disable_invariant_check() const
Disable invariant check. Intended for preventing recursive calls to invariant and for suppressing inv...
Definition: any.h:97
void enqueue(pod_index_type xindex)
Inserts xindex at the end of the record queue.
Definition: record_queue.cc:80
virtual record_queue * clone() const
Virtual constructor; makes a new instance of the same type as this.
bool invariant_check() const
True if invariant checking is enabled.
Definition: any.h:79
A queue for record read requests.
Definition: record_queue.h:50
virtual bool invariant() const
Class invariant.
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
bool is_same_type(const any *other) const
True if other is the same type as this.
Definition: any.cc:79
void enable_invariant_check() const
Enable invariant checking.
Definition: any.h:87