SheafSystem  0.0.0.0
tern.cc
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 
18 // Implementation for class tern
19 
20 #include "SheafSystem/tern.h"
21 #include "SheafSystem/assert_contract.h"
22 #include "SheafSystem/error_message.h"
23 
27 
28 
29 
30 #ifdef TRUE
31 #undef TRUE
32 #endif
33 
34 #ifdef FALSE
35 #undef FALSE
36 #endif
37 
38 // =============================================================================
39 // TERN FACET
40 // =============================================================================
41 
45 {
46 
47  // Preconditions:
48 
49 
50  // Body:
51 
52  _state = NEITHER;
53 
54  // Postconditions:
55 
56  // Exit:
57 
58  return;
59 }
60 
61 
64 tern(const tern& xother)
65 {
66 
67  // Preconditions:
68 
69 
70  // Body:
71 
72  _state = xother._state;
73 
74  // Postconditions:
75 
76  // Exit:
77 
78  return;
79 }
80 
81 
82 // ///
83 // sheaf::tern::
84 // tern(const bool& xother)
85 // {
86 
87 // // Preconditions:
88 
89 
90 // // Body:
91 
92 // _state = xother ? TRUE : FALSE;
93 
94 // // Postconditions:
95 
96 // // Exit:
97 
98 // return;
99 // }
100 
101 
105 {
106  // Preconditions:
107 
108 
109  // Body:
110 
111  // Nothing to do.
112 
113  // Postconditions:
114 
115  // Exit:
116 
117  return;
118 }
119 
120 
124 operator=(const tern& xother)
125 {
126 
127  // Preconditions:
128 
129 
130  // Body:
131 
132  _state = xother._state;
133 
134  // Postconditions:
135 
136  // Exit
137 
138  return *this;
139 }
140 
141 // ///
142 // tern&
143 // sheaf::tern::
144 // operator=(const bool& xother)
145 // {
146 
147 // // Preconditions:
148 
149 
150 // // Body:
151 
152 // _state = xother ? TRUE : FALSE;
153 
154 // // Postconditions:
155 
156 // // Exit
157 
158 // return *this;
159 // }
160 
162 sheaf::tern::
163 operator bool() const
164 {
165  // Preconditions:
166 
167 
168  // Body:
169 
170  bool result = is_true();
171 
172 
173  // Postconditions:
174 
175  ensure(result == is_true());
176 
177  // Exit:
178 
179  return result;
180 }
181 
182 
184 bool
186 is_true() const
187 {
188  return _state == TRUE;
189 }
190 
192 bool
194 is_false() const
195 {
196  return _state == FALSE;
197 }
198 
200 bool
202 is_neither() const
203 {
204  return _state == NEITHER;
205 }
206 
210 {
211  // Preconditions:
212 
213 
214  // Body:
215 
216  _state = xstate;
217 
218  // Postconditions:
219 
220 
221  // Exit:
222 
223  return;
224 }
225 
226 
227 // =============================================================================
228 // NON-MEMBER FUNCTIONS
229 // =============================================================================
230 
tern & operator=(const tern &xother)
Assignment operator.
Definition: tern.cc:124
bool is_true() const
True if thi has value true.
Definition: tern.cc:186
A three state "bool". Does not provide the operations of ternary logic and is intended for use mostly...
Definition: tern.h:45
state_type
The three possible values.
Definition: tern.h:107
~tern()
/// Conversion from boolean.
Definition: tern.cc:104
bool is_neither() const
True if this is neither true nor false.
Definition: tern.cc:202
bool is_false() const
True if this has value false.
Definition: tern.cc:194
tern()
Default constructor.
Definition: tern.cc:44