diff options
| -rw-r--r-- | src/dxfdim.cc | 4 | ||||
| -rw-r--r-- | src/expr.cc | 2 | ||||
| -rw-r--r-- | src/function.h | 1 | ||||
| -rw-r--r-- | src/value.cc | 37 | ||||
| -rw-r--r-- | src/value.h | 8 | ||||
| -rw-r--r-- | tests/cgaltest.cc | 6 | ||||
| -rw-r--r-- | tests/csgtermtest.cc | 6 | ||||
| -rw-r--r-- | tests/csgtexttest.cc | 6 | ||||
| -rw-r--r-- | tests/dumptest.cc | 6 | 
9 files changed, 45 insertions, 31 deletions
| diff --git a/src/dxfdim.cc b/src/dxfdim.cc index 160fb4a..e1444c7 100644 --- a/src/dxfdim.cc +++ b/src/dxfdim.cc @@ -180,8 +180,8 @@ Value builtin_dxf_cross(const Context *ctx, const QVector<QString> &argnames, co  			double y = y1 + ua*(y2 - y1);  			Value ret;  			ret.type = Value::VECTOR; -			ret.vec.append(new Value(x)); -			ret.vec.append(new Value(y)); +			ret.append(new Value(x)); +			ret.append(new Value(y));  			return dxf_cross_cache[key] = ret;  		}  	} diff --git a/src/expr.cc b/src/expr.cc index f8169c8..1cfe627 100644 --- a/src/expr.cc +++ b/src/expr.cc @@ -110,7 +110,7 @@ Value Expression::evaluate(const Context *context) const  		Value v;  		v.type = Value::VECTOR;  		for (int i = 0; i < children.size(); i++) -			v.vec.append(new Value(children[i]->evaluate(context))); +			v.append(new Value(children[i]->evaluate(context)));  		return v;  	}  	if (type == "L") diff --git a/src/function.h b/src/function.h index 3bb89c2..7b58e38 100644 --- a/src/function.h +++ b/src/function.h @@ -3,6 +3,7 @@  #include "value.h"  #include <QString> +#include <QVector>  class AbstractFunction  { 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(); diff --git a/src/value.h b/src/value.h index 3f9e9ba..9140912 100644 --- a/src/value.h +++ b/src/value.h @@ -1,7 +1,8 @@  #ifndef VALUE_H_  #define VALUE_H_ -#include <QVector> +#include <vector> +#include <string>  class Value  { @@ -19,7 +20,7 @@ public:  	bool b;  	double num; -	QVector<Value*> vec; +	std::vector<Value*> vec;  	double range_begin;  	double range_step;  	double range_end; @@ -60,6 +61,8 @@ public:  	std::string toString() const; +	void append(Value *val); +  private:  	void reset_undef();  }; @@ -67,6 +70,7 @@ private:  std::ostream &operator<<(std::ostream &stream, const Value &value);  // FIXME: Doesn't belong here.. +#include <QString>  std::ostream &operator<<(std::ostream &stream, const QString &str);  #endif diff --git a/tests/cgaltest.cc b/tests/cgaltest.cc index 9725bc3..ca3ddaf 100644 --- a/tests/cgaltest.cc +++ b/tests/cgaltest.cc @@ -125,9 +125,9 @@ int main(int argc, char **argv)  	Value zero3;  	zero3.type = Value::VECTOR; -	zero3.vec.append(new Value(0.0)); -	zero3.vec.append(new Value(0.0)); -	zero3.vec.append(new Value(0.0)); +	zero3.append(new Value(0.0)); +	zero3.append(new Value(0.0)); +	zero3.append(new Value(0.0));  	root_ctx.set_variable("$vpt", zero3);  	root_ctx.set_variable("$vpr", zero3); diff --git a/tests/csgtermtest.cc b/tests/csgtermtest.cc index 9eec025..85c3bfd 100644 --- a/tests/csgtermtest.cc +++ b/tests/csgtermtest.cc @@ -113,9 +113,9 @@ int main(int argc, char **argv)  	Value zero3;  	zero3.type = Value::VECTOR; -	zero3.vec.append(new Value(0.0)); -	zero3.vec.append(new Value(0.0)); -	zero3.vec.append(new Value(0.0)); +	zero3.append(new Value(0.0)); +	zero3.append(new Value(0.0)); +	zero3.append(new Value(0.0));  	root_ctx.set_variable("$vpt", zero3);  	root_ctx.set_variable("$vpr", zero3); diff --git a/tests/csgtexttest.cc b/tests/csgtexttest.cc index d097f7d..c259e2d 100644 --- a/tests/csgtexttest.cc +++ b/tests/csgtexttest.cc @@ -117,9 +117,9 @@ int main(int argc, char **argv)  	Value zero3;  	zero3.type = Value::VECTOR; -	zero3.vec.append(new Value(0.0)); -	zero3.vec.append(new Value(0.0)); -	zero3.vec.append(new Value(0.0)); +	zero3.append(new Value(0.0)); +	zero3.append(new Value(0.0)); +	zero3.append(new Value(0.0));  	root_ctx.set_variable("$vpt", zero3);  	root_ctx.set_variable("$vpr", zero3); diff --git a/tests/dumptest.cc b/tests/dumptest.cc index e26259c..097008f 100644 --- a/tests/dumptest.cc +++ b/tests/dumptest.cc @@ -111,9 +111,9 @@ int main(int argc, char **argv)  	Value zero3;  	zero3.type = Value::VECTOR; -	zero3.vec.append(new Value(0.0)); -	zero3.vec.append(new Value(0.0)); -	zero3.vec.append(new Value(0.0)); +	zero3.append(new Value(0.0)); +	zero3.append(new Value(0.0)); +	zero3.append(new Value(0.0));  	root_ctx.set_variable("$vpt", zero3);  	root_ctx.set_variable("$vpr", zero3); | 
