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 #include "MP_index.hpp"
14 
15 namespace flopc {
16 
17  class Boolean_bool : public Boolean_base {
18  friend class MP_boolean;
19  private:
20  Boolean_bool(bool b) : B(b) {}
21  bool evaluate() const {
22  return B;
23  }
24  bool B;
25  };
26 
27  class Boolean_Constant : public Boolean_base {
28  friend class MP_boolean;
29  private:
30  Boolean_Constant(const Constant& c) : C(c) {}
31  bool evaluate() const {
32  return C->evaluate();
33  }
35  };
36 
38  friend class MP_boolean;
39  private:
41  bool evaluate() const {
42  if (C->evaluate() == outOfBound) {
43  return false;
44  } else {
45  return true;
46  }
47  }
49  };
50 
51  class Boolean_negate : public Boolean_base {
52  friend MP_boolean operator!(const MP_boolean& b);
53  private:
54  Boolean_negate(const MP_boolean& b) : B(b) {}
55  bool evaluate() const {
56  return !(B->evaluate());
57  }
59  };
60 
61  class Boolean_and : public Boolean_base {
62  friend MP_boolean operator&&(const MP_boolean& e1, const MP_boolean& e2);
63  private:
64  Boolean_and(const MP_boolean& e1, const MP_boolean e2) : left(e1), right(e2) {}
65  bool evaluate() const {
66  return left->evaluate() && right->evaluate();
67  }
69  };
70 
71  class Boolean_or : public Boolean_base {
72  friend MP_boolean operator||(const MP_boolean& e1, const MP_boolean& e2);
73  private:
74  Boolean_or(const MP_boolean& e1, const MP_boolean& e2) : left(e1), right(e2) {}
75  bool evaluate() const {
76  return left->evaluate() || right->evaluate();
77  }
79  };
80 
81 // class Boolean_alltrue : public Boolean_base {
82 // friend MP_boolean alltrue(const MP_domain& d, const MP_boolean& b);
83 // private:
84 // Boolean_alltrue(const MP_domain& d, const MP_boolean& b) : D(d), B(b) {}
85 // bool evaluate() const {
86 // return true;
87 // }
88 // MP_domain D;
89 // MP_boolean B;
90 // };
91 
92  class Comparison : public Boolean_base {
93  protected:
94  Comparison(const Constant& e1, const Constant& e2) : left(e1), right(e2) {}
96  };
97 
98  class Boolean_lessEq : public Comparison {
99  friend MP_boolean operator<=(const MP_index_exp& e1,const MP_index_exp& e2);
100  friend MP_boolean operator<=(const Constant& e1, const Constant& e2);
101  private:
102  Boolean_lessEq(const Constant& e1, const Constant& e2):Comparison(e1,e2) {}
103  bool evaluate() const {
104  return (left->evaluate() <= right->evaluate());
105  }
106  };
107 
108  class Boolean_less : public Comparison {
109  friend MP_boolean operator<(const MP_index_exp& e1,
110  const MP_index_exp& e2);
111  friend MP_boolean operator<(const Constant& e1, const Constant& e2);
112  private:
113  Boolean_less(const Constant& e1, const Constant& e2) : Comparison(e1,e2) {}
114  bool evaluate() const {
115  return (left->evaluate() < right->evaluate());
116  }
117  };
118 
119  class Boolean_greaterEq : public Comparison {
120  friend MP_boolean operator>=(MP_index& e1, MP_index& e2);
121  friend MP_boolean operator>=(const MP_index_exp& e1,
122  const MP_index_exp& e2);
123  friend MP_boolean operator>=(const Constant& e1, const Constant& e2);
124  private:
125  Boolean_greaterEq(const Constant& e1, const Constant& e2) :
126  Comparison(e1,e2) {}
127  bool evaluate() const {
128  return (left->evaluate() >= right->evaluate());
129  }
130  };
131 
132  class Boolean_greater : public Comparison {
133  friend MP_boolean operator>(const MP_index_exp& e1, const MP_index_exp& e2);
134  friend MP_boolean operator>(const Constant& e1, const Constant& e2);
135  private:
136  Boolean_greater(const Constant& e1, const Constant& e2): Comparison(e1,e2) {}
137  bool evaluate() const {
138  return (left->evaluate() > right->evaluate());
139  }
140  };
141 
142  class Boolean_equal : public Comparison {
143  friend MP_boolean operator==(const MP_index_exp& e1, const MP_index_exp& e2);
144  friend MP_boolean operator==(const Constant& e1, const Constant& e2);
145  private:
146  Boolean_equal(const Constant& e1, const Constant& e2) : Comparison(e1,e2) {}
147  bool evaluate() const {
148  return (left->evaluate() == right->evaluate());
149  }
150  };
151 
152  class Boolean_not_equal : public Comparison {
153  friend MP_boolean operator!=(const MP_index_exp& e1, const MP_index_exp& e2);
154  friend MP_boolean operator!=(const Constant& e1, const Constant& e2);
155  private:
156  Boolean_not_equal(const Constant& e1, const Constant& e2) : Comparison(e1,e2) {}
157  bool evaluate() const {
158  return (left->evaluate() != right->evaluate());
159  }
160  };
161 
162 // MP_boolean alltrue(const MP_domain& d, const MP_boolean& b) {
163 // return new Boolean_alltrue(d,b);
164 // }
165 
167  return new Boolean_negate(b);
168  }
169  MP_boolean operator&&(const MP_boolean& e1, const MP_boolean& e2) {
170  return new Boolean_and(e1, e2);
171  }
172  MP_boolean operator||(const MP_boolean& e1, const MP_boolean& e2) {
173  return new Boolean_or(e1, e2);
174  }
176  return new Boolean_lessEq(e1, e2);
177  }
178  MP_boolean operator<=(const Constant& e1, const Constant& e2) {
179  return new Boolean_lessEq(e1, e2);
180  }
182  return new Boolean_less(e1, e2);
183  }
184  MP_boolean operator<(const Constant& e1, const Constant& e2) {
185  return new Boolean_less(e1, e2);
186  }
188  return new Boolean_greaterEq(e1, e2);
189  }
190  MP_boolean operator>=(const Constant& e1, const Constant& e2) {
191  return new Boolean_greaterEq(e1, e2);
192  }
194  return new Boolean_greater(e1, e2);
195  }
196  MP_boolean operator>(const Constant& e1, const Constant& e2) {
197  return new Boolean_greater(e1, e2);
198  }
200  return new Boolean_equal(e1, e2);
201  }
203  return new Boolean_not_equal(e1, e2);
204  }
205  MP_boolean operator==(const Constant& e1, const Constant& e2) {
206  return new Boolean_equal(e1, e2);
207  }
208  MP_boolean operator!=(const Constant& e1, const Constant& e2) {
209  return new Boolean_not_equal(e1, e2);
210  }
211 
212 } // End of namespace flopc
213 
214 using namespace flopc;
215 
217 
219 
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:169
bool evaluate() const
Definition: MP_boolean.cpp:75
Boolean_less(const Constant &e1, const Constant &e2)
Definition: MP_boolean.cpp:113
bool evaluate() const
Definition: MP_boolean.cpp:65
bool evaluate() const
Definition: MP_boolean.cpp:114
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:202
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:187
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:166
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:172
MP_boolean operator<=(const MP_index_exp &e1, const MP_index_exp &e2)
boolean which returns true if all in domain evaluate to true.This is used in the normal formation of ...
Definition: MP_boolean.cpp:175
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 "set".
Definition: MP_set.hpp:269
MP_boolean right
Definition: MP_boolean.cpp:68
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:193
Utility for doing reference counted pointers.
Boolean_not_equal(const Constant &e1, const Constant &e2)
Definition: MP_boolean.cpp:156
Comparison(const Constant &e1, const Constant &e2)
Definition: MP_boolean.cpp:94
bool evaluate() const
Definition: MP_boolean.cpp:147
bool evaluate() const
Definition: MP_boolean.cpp:55
Boolean_negate(const MP_boolean &b)
Definition: MP_boolean.cpp:54
Representation of an expression involving an index.This is one of the main public interface classes...
Definition: MP_index.hpp:141
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:181
Boolean_equal(const Constant &e1, const Constant &e2)
Definition: MP_boolean.cpp:146
Boolean_or(const MP_boolean &e1, const MP_boolean &e2)
Definition: MP_boolean.cpp:74
const int outOfBound
Distinct return value on conditions where an index goes out of bounds.
All flopc++ code is contained within the flopc namespace.
Definition: flopc.cpp:11
Boolean_greater(const Constant &e1, const Constant &e2)
Definition: MP_boolean.cpp:136
bool evaluate() const
Definition: MP_boolean.cpp:21
MP_boolean right
Definition: MP_boolean.cpp:78
Boolean_lessEq(const Constant &e1, const Constant &e2)
Definition: MP_boolean.cpp:102
Reference counted class for all "boolean" types of data.This contains counters to ConstantBase pointe...
Definition: MP_boolean.hpp:40
Reference counted class for all "constant" types of data.
Definition: MP_constant.hpp:49
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:199
bool evaluate() const
Definition: MP_boolean.cpp:103
Boolean_and(const MP_boolean &e1, const MP_boolean e2)
Definition: MP_boolean.cpp:64
Boolean_Constant(const Constant &c)
Definition: MP_boolean.cpp:30
Boolean_greaterEq(const Constant &e1, const Constant &e2)
Definition: MP_boolean.cpp:125
Boolean_SUBSETREF(SUBSETREF &c)
Definition: MP_boolean.cpp:40