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 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
|
// This file is part of ff3d - http://www.freefem.org/ff3d
// Copyright (C) 2001, 2002, 2003 Stphane Del Pino
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2, or (at your option)
// any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// $Id: BooleanExpression.hpp,v 1.2 2003/05/04 18:09:01 delpinux Exp $
#ifndef _BOOLEAN_EXPRESSION_HPP_
#define _BOOLEAN_EXPRESSION_HPP_
#include <Expression.hpp>
#include <RealExpression.hpp>
class BooleanExpression
: public Expression
{
protected:
bool __boolValue;
private:
std::ostream& put(std::ostream& os) const
{
os << __boolValue;
return os;
}
public:
/*!
Returns the value of the expression.
\todo Return type should use traits.
*/
const bool boolValue() const
{
return __boolValue;
}
BooleanExpression(const BooleanExpression& e)
: Expression(e),
__boolValue(e.__boolValue)
{
;
}
BooleanExpression()
: Expression(Expression::boolean)
{
;
}
virtual ~BooleanExpression()
{
;
}
};
class BooleanExpressionValue
: public BooleanExpression
{
public:
void execute()
{
;
}
BooleanExpressionValue(bool b)
{
__boolValue = b;
}
BooleanExpressionValue(const BooleanExpressionValue& re)
: BooleanExpression(re)
{
;
}
~BooleanExpressionValue()
{
;
}
};
template <bool (*F)(const bool x)>
class BooleanExpressionUnaryOperator
: public BooleanExpression
{
private:
ReferenceCounting<BooleanExpression> __r;
public:
void execute()
{
(*__r).execute();
__boolValue = (*F)((*__r).boolValue());
}
BooleanExpressionUnaryOperator(ReferenceCounting<BooleanExpression> r)
: __r(r)
{
;
}
BooleanExpressionUnaryOperator(const BooleanExpressionUnaryOperator<F>& e)
: __r(e.__r)
{
;
}
~BooleanExpressionUnaryOperator()
{
;
}
};
template <bool(*B)(const real_t x, const real_t y)>
class BooleanExpressionCompareOperator
: public BooleanExpression
{
private:
ReferenceCounting<RealExpression> __r1;
ReferenceCounting<RealExpression> __r2;
real_t __r1Value;
real_t __r2Value;
public:
void execute()
{
(*__r1).execute();
__r1Value = (*__r1).realValue();
(*__r2).execute();
__r2Value = (*__r2).realValue();
__boolValue = B(__r1Value, __r2Value);
}
BooleanExpressionCompareOperator(ReferenceCounting<RealExpression> r1,
ReferenceCounting<RealExpression> r2)
: __r1(r1),
__r2(r2),
__r1Value(0),
__r2Value(0)
{
;
}
BooleanExpressionCompareOperator(const BooleanExpressionCompareOperator<B>& e)
: __r1(e.__r1),
__r2(e.__r2),
__r1Value(e.__r1Value),
__r2Value(e.__r2Value)
{
;
}
~BooleanExpressionCompareOperator()
{
;
}
};
template <bool(*B)(const bool a, const bool b)>
class BooleanExpressionBinaryOperator
: public BooleanExpression
{
private:
ReferenceCounting<BooleanExpression> __r1;
ReferenceCounting<BooleanExpression> __r2;
public:
void execute()
{
(*__r1).execute();
(*__r2).execute();
__boolValue = B((*__r1).boolValue(), (*__r2).boolValue());
}
BooleanExpressionBinaryOperator(ReferenceCounting<BooleanExpression> r1,
ReferenceCounting<BooleanExpression> r2)
: __r1(r1),
__r2(r2)
{
;
}
BooleanExpressionBinaryOperator(const BooleanExpressionBinaryOperator<B>& e)
: __r1(e.__r1),
__r2(e.__r2)
{
;
}
~BooleanExpressionBinaryOperator()
{
;
}
};
/*
class BooleanVariable;
class BooleanExpressionVariable
: public BooleanExpression
{
private:
ReferenceCounting<BooleanVariable> __booleanVariable;
ReferenceCounting<BooleanExpression> __expression;
public:
const real_t value() const;
void execute();
BooleanExpressionVariable(ReferenceCounting<BooleanVariable> r);
BooleanExpressionVariable(const BooleanExpressionVariable& e);
~BooleanExpressionVariable();
};
*/
#endif // _BOOLEAN_EXPRESSION_HPP_
|