FLOPC++
MP_boolean.cpp
Go to the documentation of this file.
1 // ******************** FlopCpp **********************************************
2 // File: MP_boolean.cpp
3 // $Id$
4 // Author: Tim Helge Hultberg (thh@mat.ua.pt)
5 // Copyright (C) 2003 Tim Helge Hultberg
6 // All Rights Reserved.
7 //****************************************************************************
8 
9 #include "MP_boolean.hpp"
10 #include "MP_constant.hpp"
11 #include "MP_domain.hpp"
12 #include "MP_set.hpp"
13 
14 using namespace std;
15 
16 namespace flopc {
17 
18  class Boolean_bool : public Boolean_base {
19  friend class MP_boolean;
20  private:
21  Boolean_bool(bool b) : B(b) {}
22  bool evaluate() const {
23  return B;
24  }
25  bool B;
26  };
27 
28  class Boolean_Constant : public Boolean_base {
29  friend class MP_boolean;
30  private:
31  Boolean_Constant(const Constant& c) : C(c) {}
32  bool evaluate() const {
33  return C->evaluate();
34  }
36  };
37 
39  friend class MP_boolean;
40  private:
42  bool evaluate() const {
43  if (C->evaluate() == outOfBound) {
44  return false;
45  } else {
46  return true;
47  }
48  }
50  };
51 
52  class Boolean_negate : public Boolean_base {
53  friend MP_boolean operator!(const MP_boolean& b);
54  private:
55  Boolean_negate(const MP_boolean& b) : B(b) {}
56  bool evaluate() const {
57  return !(B->evaluate());
58  }
60  };
61 
62  class Boolean_and : public Boolean_base {
63  friend MP_boolean operator&&(const MP_boolean& e1, const MP_boolean& e2);
64  private:
65  Boolean_and(const MP_boolean& e1, const MP_boolean e2) : left(e1), right(e2) {}
66  bool evaluate() const {
67  return left->evaluate() && right->evaluate();
68  }
70  };
71 
72  class Boolean_or : public Boolean_base {
73  friend MP_boolean operator||(const MP_boolean& e1, const MP_boolean& e2);
74  private:
75  Boolean_or(const MP_boolean& e1, const MP_boolean& e2) : left(e1), right(e2) {}
76  bool evaluate() const {
77  return left->evaluate() || right->evaluate();
78  }
80  };
81 
82  class Boolean_alltrue : public Boolean_base {
83  friend MP_boolean alltrue(const MP_domain& d, const MP_boolean& b);
84  private:
85  Boolean_alltrue(const MP_domain& d, const MP_boolean& b) : D(d), B(b) {}
86  bool evaluate() const {
87  return true;
88  }
91  };
92 
93  class Comparison : public Boolean_base {
94  protected:
95  Comparison(const Constant& e1, const Constant& e2) : left(e1), right(e2) {}
97  };
98 
99  class Boolean_lessEq : public Comparison {
100  friend MP_boolean operator<=(const MP_index_exp& e1, const MP_index_exp& e2);
101  friend MP_boolean operator<=(const Constant& e1, const Constant& e2);
102  private:
103  Boolean_lessEq(const Constant& e1, const Constant& e2) : Comparison(e1,e2) {}
104  bool evaluate() const;
105  };
106 
107  class Boolean_less : public Comparison {
108  friend MP_boolean operator<(const MP_index_exp& e1,
109  const MP_index_exp& e2);
110  friend MP_boolean operator<(const Constant& e1, const Constant& e2);
111  private:
112  Boolean_less(const Constant& e1, const Constant& e2) : Comparison(e1,e2) {}
113  bool evaluate() const;
114  };
115 
116  class Boolean_greaterEq : public Comparison {
117  friend MP_boolean operator>=(MP_index& e1, MP_index& e2);
118  friend MP_boolean operator>=(const MP_index_exp& e1,
119  const MP_index_exp& e2);
120  friend MP_boolean operator>=(const Constant& e1, const Constant& e2);
121  private:
122  Boolean_greaterEq(const Constant& e1, const Constant& e2) :
123  Comparison(e1,e2) {}
124  bool evaluate() const;
125  };
126 
127  class Boolean_greater : public Comparison {
128  friend MP_boolean operator>(const MP_index_exp& e1, const MP_index_exp& e2);
129  friend MP_boolean operator>(const Constant& e1, const Constant& e2);
130  private:
131  Boolean_greater(const Constant& e1, const Constant& e2): Comparison(e1,e2) {}
132  bool evaluate() const;
133  };
134 
135  class Boolean_equal : public Comparison {
136  friend MP_boolean operator==(const MP_index_exp& e1, const MP_index_exp& e2);
137  friend MP_boolean operator==(const Constant& e1, const Constant& e2);
138  private:
139  Boolean_equal(const Constant& e1, const Constant& e2) : Comparison(e1,e2) {}
140  bool evaluate() const;
141  };
142 
143  class Boolean_not_equal : public Comparison {
144  friend MP_boolean operator!=(const MP_index_exp& e1, const MP_index_exp& e2);
145  friend MP_boolean operator!=(const Constant& e1, const Constant& e2);
146  private:
147  Boolean_not_equal(const Constant& e1, const Constant& e2) : Comparison(e1,e2) {}
148  bool evaluate() const;
149  };
150 
151 
152  MP_boolean alltrue(const MP_domain& d, const MP_boolean& b) {
153  return new Boolean_alltrue(d,b);
154  }
155 
157  return new Boolean_negate(b);
158  }
159  MP_boolean operator&&(const MP_boolean& e1, const MP_boolean& e2) {
160  return new Boolean_and(e1, e2);
161  }
162  MP_boolean operator||(const MP_boolean& e1, const MP_boolean& e2) {
163  return new Boolean_or(e1, e2);
164  }
166  return new Boolean_lessEq(e1, e2);
167  }
168  MP_boolean operator<=(const Constant& e1, const Constant& e2) {
169  return new Boolean_lessEq(e1, e2);
170  }
172  return new Boolean_less(e1, e2);
173  }
174  MP_boolean operator<(const Constant& e1, const Constant& e2) {
175  return new Boolean_less(e1, e2);
176  }
178  return new Boolean_greaterEq(e1, e2);
179  }
180  MP_boolean operator>=(const Constant& e1, const Constant& e2) {
181  return new Boolean_greaterEq(e1, e2);
182  }
184  return new Boolean_greater(e1, e2);
185  }
186  MP_boolean operator>(const Constant& e1, const Constant& e2) {
187  return new Boolean_greater(e1, e2);
188  }
190  return new Boolean_equal(e1, e2);
191  }
193  return new Boolean_not_equal(e1, e2);
194  }
195  MP_boolean operator==(const Constant& e1, const Constant& e2) {
196  return new Boolean_equal(e1, e2);
197  }
198  MP_boolean operator!=(const Constant& e1, const Constant& e2) {
199  return new Boolean_not_equal(e1, e2);
200  }
201 
202 } // End of namespace flopc
203 
204 using namespace flopc;
205 
206 MP_boolean::MP_boolean(bool b) : Handle<Boolean_base*>(new Boolean_bool(b)) {}
207 
210 
213 
215  return (left->evaluate() <= right->evaluate());
216 }
218  return (left->evaluate() < right->evaluate());
219 }
221  return (left->evaluate() >= right->evaluate());
222 }
224  return (left->evaluate() > right->evaluate());
225 }
227  return (left->evaluate() == right->evaluate());
228 }
230  return (left->evaluate() != right->evaluate());
231 }
232 
233 
Boolean_less(const Constant &e1, const Constant &e2)
Definition: MP_boolean.cpp:112
MP_boolean operator&&(const MP_boolean &e1, const MP_boolean &e2)
For computing the logical AND of two booleansThis is used in the normal formation of an expression...
Definition: MP_boolean.cpp:159
bool evaluate() const
Definition: MP_boolean.cpp:226
bool evaluate() const
Definition: MP_boolean.cpp:214
MP_boolean operator!=(const MP_index_exp &e1, const MP_index_exp &e2)
constructs a boolean evaluator using operator overloadingThis is used in the normal formation of an e...
Definition: MP_boolean.cpp:192
MP_boolean operator>=(const MP_index_exp &e1, const MP_index_exp &e2)
constructs a boolean evaluator using operator overloadingThis is used in the normal formation of an e...
Definition: MP_boolean.cpp:177
MP_boolean operator!(const MP_boolean &b)
For computing the logical negation of a booleanThis is used in the normal formation of an expression...
Definition: MP_boolean.cpp:156
bool evaluate() const
Definition: MP_boolean.cpp:22
Base class for all &quot;boolean&quot; types of data.
Definition: MP_boolean.hpp:23
bool evaluate() const
Definition: MP_boolean.cpp:56
MP_boolean operator||(const MP_boolean &e1, const MP_boolean &e2)
For computing the logical OR of two booleansThis is used in the normal formation of an expression...
Definition: MP_boolean.cpp:162
MP_boolean operator<=(const MP_index_exp &e1, const MP_index_exp &e2)
constructs a boolean evaluator using operator overloadingThis is used in the normal formation of an e...
Definition: MP_boolean.cpp:165
Representation of an index.This is one of the main public interface classes. It is used to iterate th...
Definition: MP_index.hpp:53
Internal representation of a &quot;set&quot;.
Definition: MP_set.hpp:273
MP_boolean right
Definition: MP_boolean.cpp:69
MP_boolean operator>(const MP_index_exp &e1, const MP_index_exp &e2)
constructs a boolean evaluator using operator overloadingThis is used in the normal formation of an e...
Definition: MP_boolean.cpp:183
Utility for doing reference counted pointers.
Boolean_alltrue(const MP_domain &d, const MP_boolean &b)
Definition: MP_boolean.cpp:85
Boolean_not_equal(const Constant &e1, const Constant &e2)
Definition: MP_boolean.cpp:147
Comparison(const Constant &e1, const Constant &e2)
Definition: MP_boolean.cpp:95
Boolean_negate(const MP_boolean &b)
Definition: MP_boolean.cpp:55
Representation of an expression involving an index.This is one of the main public interface classes...
Definition: MP_index.hpp:145
MP_boolean operator<(const MP_index_exp &e1, const MP_index_exp &e2)
constructs a boolean evaluator using operator overloadingThis is used in the normal formation of an e...
Definition: MP_boolean.cpp:171
Boolean_equal(const Constant &e1, const Constant &e2)
Definition: MP_boolean.cpp:139
Boolean_or(const MP_boolean &e1, const MP_boolean &e2)
Definition: MP_boolean.cpp:75
const int outOfBound
Distinct return value on conditions where an index goes out of bounds.
bool evaluate() const
Definition: MP_boolean.cpp:223
Boolean_greater(const Constant &e1, const Constant &e2)
Definition: MP_boolean.cpp:131
MP_boolean right
Definition: MP_boolean.cpp:79
Boolean_lessEq(const Constant &e1, const Constant &e2)
Definition: MP_boolean.cpp:103
Reference counted class for all &quot;boolean&quot; types of data.This contains counters to ConstantBase pointe...
Definition: MP_boolean.hpp:45
Range over which some other constuct is defined.This is one of the main public interface classes...
Definition: MP_domain.hpp:61
bool evaluate() const
Definition: MP_boolean.cpp:217
Reference counted class for all &quot;constant&quot; types of data.
Definition: MP_constant.hpp:48
MP_boolean alltrue(const MP_domain &d, const MP_boolean &b)
boolean which returns true if all in domain evaluate to true.This is used in the normal formation of ...
Definition: MP_boolean.cpp:152
bool evaluate() const
Definition: MP_boolean.cpp:86
MP_boolean operator==(const MP_index_exp &e1, const MP_index_exp &e2)
constructs a boolean evaluator using operator overloadingThis is used in the normal formation of an e...
Definition: MP_boolean.cpp:189
Boolean_and(const MP_boolean &e1, const MP_boolean e2)
Definition: MP_boolean.cpp:65
bool evaluate() const
Definition: MP_boolean.cpp:42
Boolean_Constant(const Constant &c)
Definition: MP_boolean.cpp:31
Boolean_greaterEq(const Constant &e1, const Constant &e2)
Definition: MP_boolean.cpp:122
Boolean_SUBSETREF(SUBSETREF &c)
Definition: MP_boolean.cpp:41
bool evaluate() const
Definition: MP_boolean.cpp:32
bool evaluate() const
Definition: MP_boolean.cpp:76
bool evaluate() const
Definition: MP_boolean.cpp:66