diff options
author | Marius Kintel <marius@kintel.net> | 2010-11-07 22:12:34 (GMT) |
---|---|---|
committer | Marius Kintel <marius@kintel.net> | 2010-11-07 22:12:34 (GMT) |
commit | ab90b38780365943877d1f173d6ae0b692b6ce51 (patch) | |
tree | 91ed06b2b91991a2c00c4a3b4db4e03f5b9c3899 /src/value.cc | |
parent | e0a068a0e8678da426e1edd398feab5f4ea4d0f0 (diff) |
Value::QVector -> std::vector
Diffstat (limited to 'src/value.cc')
-rw-r--r-- | src/value.cc | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/src/value.cc b/src/value.cc index e934ff7..92aaff1 100644 --- a/src/value.cc +++ b/src/value.cc @@ -25,8 +25,8 @@ #include "value.h" #include <math.h> +#include <assert.h> #include <sstream> -#include <QString> Value::Value() { @@ -35,8 +35,7 @@ Value::Value() Value::~Value() { - for (int i = 0; i < this->vec.size(); i++) - delete this->vec[i]; + for (int i = 0; i < this->vec.size(); i++) delete this->vec[i]; this->vec.clear(); } @@ -72,8 +71,9 @@ Value& Value::operator = (const Value &v) this->type = v.type; this->b = v.b; this->num = v.num; - for (int i = 0; i < v.vec.size(); i++) - this->vec.append(new Value(*v.vec[i])); + for (int i = 0; i < v.vec.size(); i++) { + this->vec.push_back(new Value(*v.vec[i])); + } this->range_begin = v.range_begin; this->range_step = v.range_step; this->range_end = v.range_end; @@ -111,7 +111,7 @@ Value Value::operator + (const Value &v) const Value r; r.type = VECTOR; for (int i = 0; i < this->vec.size() && i < v.vec.size(); i++) - r.vec.append(new Value(*this->vec[i] + *v.vec[i])); + r.vec.push_back(new Value(*this->vec[i] + *v.vec[i])); return r; } if (this->type == NUMBER && v.type == NUMBER) { @@ -126,7 +126,7 @@ Value Value::operator - (const Value &v) const Value r; r.type = VECTOR; for (int i = 0; i < this->vec.size() && i < v.vec.size(); i++) - r.vec.append(new Value(*this->vec[i] - *v.vec[i])); + r.vec.push_back(new Value(*this->vec[i] - *v.vec[i])); return r; } if (this->type == NUMBER && v.type == NUMBER) { @@ -141,14 +141,14 @@ Value Value::operator * (const Value &v) const Value r; r.type = VECTOR; for (int i = 0; i < this->vec.size(); i++) - r.vec.append(new Value(*this->vec[i] * v)); + r.vec.push_back(new Value(*this->vec[i] * v)); return r; } if (this->type == NUMBER && v.type == VECTOR) { Value r; r.type = VECTOR; for (int i = 0; i < v.vec.size(); i++) - r.vec.append(new Value(*this * *v.vec[i])); + r.vec.push_back(new Value(*this * *v.vec[i])); return r; } if (this->type == NUMBER && v.type == NUMBER) { @@ -163,14 +163,14 @@ Value Value::operator / (const Value &v) const Value r; r.type = VECTOR; for (int i = 0; i < this->vec.size(); i++) - r.vec.append(new Value(*this->vec[i] / v)); + r.vec.push_back(new Value(*this->vec[i] / v)); return r; } if (this->type == NUMBER && v.type == VECTOR) { Value r; r.type = VECTOR; for (int i = 0; i < v.vec.size(); i++) - r.vec.append(new Value(v / *v.vec[i])); + r.vec.push_back(new Value(v / *v.vec[i])); return r; } if (this->type == NUMBER && v.type == NUMBER) { @@ -256,7 +256,7 @@ Value Value::inv() const Value r; r.type = VECTOR; for (int i = 0; i < this->vec.size(); i++) - r.vec.append(new Value(this->vec[i]->inv())); + r.vec.push_back(new Value(this->vec[i]->inv())); return r; } if (this->type == NUMBER) @@ -313,8 +313,7 @@ void Value::reset_undef() this->type = UNDEFINED; this->b = false; this->num = 0; - for (int i = 0; i < this->vec.size(); i++) - delete this->vec[i]; + for (int i = 0; i < this->vec.size(); i++) delete this->vec[i]; this->vec.clear(); this->range_begin = 0; this->range_step = 0; @@ -356,6 +355,16 @@ std::string Value::toString() const return stream.str(); } +/*! + Append a value to this vector. + This must be of type VECTOR. +*/ +void Value::append(Value *val) +{ + assert(this->type == VECTOR); + this->vec.push_back(val); +} + std::ostream &operator<<(std::ostream &stream, const Value &value) { stream << value.toString(); |