diff options
Diffstat (limited to 'src')
| -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 | 
5 files changed, 33 insertions, 19 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  | 
