diff options
author | Marius Kintel <marius@kintel.net> | 2013-06-26 03:39:02 (GMT) |
---|---|---|
committer | Marius Kintel <marius@kintel.net> | 2013-06-26 03:39:02 (GMT) |
commit | 1b7cc41a7f454e005ca07815ba463a7fac5e1f8e (patch) | |
tree | 85f0d93ef9d547d17bd536d58e36be575d6ab0b9 | |
parent | d9b3f7b52b3c3d5c21dc11234325739d3e28ee02 (diff) |
Short circuit boolean logic - fixes #411
-rw-r--r-- | src/expr.cc | 3 | ||||
-rw-r--r-- | src/value.cc | 15 | ||||
-rw-r--r-- | src/value.h | 15 |
3 files changed, 3 insertions, 30 deletions
diff --git a/src/expr.cc b/src/expr.cc index 2e069f0..8500d13 100644 --- a/src/expr.cc +++ b/src/expr.cc @@ -105,8 +105,7 @@ Value Expression::evaluate(const Context *context) const if (this->type == ">") return this->children[0]->evaluate(context) > this->children[1]->evaluate(context); if (this->type == "?:") { - Value v = this->children[0]->evaluate(context); - return this->children[v.toBool() ? 1 : 2]->evaluate(context); + return this->children[this->children[0]->evaluate(context) ? 1 : 2]->evaluate(context); } if (this->type == "[]") { return this->children[0]->evaluate(context)[this->children[1]->evaluate(context)]; diff --git a/src/value.cc b/src/value.cc index ebb825d..8fbde44 100644 --- a/src/value.cc +++ b/src/value.cc @@ -297,11 +297,6 @@ Value &Value::operator=(const Value &v) return *this; } -Value Value::operator!() const -{ - return Value(!this->toBool()); -} - class equals_visitor : public boost::static_visitor<bool> { public: @@ -324,16 +319,6 @@ bool Value::operator!=(const Value &v) const return !(*this == v); } -bool Value::operator&&(const Value &v) const -{ - return this->toBool() && v.toBool(); -} - -bool Value::operator||(const Value &v) const -{ - return this->toBool() || v.toBool(); -} - class less_visitor : public boost::static_visitor<bool> { public: diff --git a/src/value.h b/src/value.h index 0445ff4..24e1b45 100644 --- a/src/value.h +++ b/src/value.h @@ -80,12 +80,11 @@ public: bool getVec3(double &x, double &y, double &z, double defaultval = 0.0) const; RangeType toRange() const; + operator bool() const { return this->toBool(); } + Value &operator=(const Value &v); - Value operator!() const; bool operator==(const Value &v) const; bool operator!=(const Value &v) const; - bool operator&&(const Value &v) const; - bool operator||(const Value &v) const; bool operator<(const Value &v) const; bool operator<=(const Value &v) const; bool operator>=(const Value &v) const; @@ -98,16 +97,6 @@ public: Value operator/(const Value &v) const; Value operator%(const Value &v) const; - /* - bool getnum(double &v) const; - bool getv2(double &x, double &y) const; - bool getv3(double &x, double &y, double &z, double defaultval = 0.0) const; - - bool toBool() const; - - void append(Value *val); - */ - friend std::ostream &operator<<(std::ostream &stream, const Value &value) { if (value.type() == Value::STRING) stream << QuotedString(value.toString()); else stream << value.toString(); |