summaryrefslogtreecommitdiff
path: root/src/value.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/value.cc')
-rw-r--r--src/value.cc54
1 files changed, 36 insertions, 18 deletions
diff --git a/src/value.cc b/src/value.cc
index 139bd1c..53fd6dc 100644
--- a/src/value.cc
+++ b/src/value.cc
@@ -36,7 +36,7 @@ Value::Value()
Value::~Value()
{
- for (int i = 0; i < this->vec.size(); i++) delete this->vec[i];
+ for (size_t i = 0; i < this->vec.size(); i++) delete this->vec[i];
this->vec.clear();
}
@@ -72,7 +72,7 @@ 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++) {
+ for (size_t i = 0; i < v.vec.size(); i++) {
this->vec.push_back(new Value(*v.vec[i]));
}
this->range_begin = v.range_begin;
@@ -111,7 +111,7 @@ Value Value::operator + (const Value &v) const
if (this->type == VECTOR && v.type == VECTOR) {
Value r;
r.type = VECTOR;
- for (int i = 0; i < this->vec.size() && i < v.vec.size(); i++)
+ for (size_t i = 0; i < this->vec.size() && i < v.vec.size(); i++)
r.vec.push_back(new Value(*this->vec[i] + *v.vec[i]));
return r;
}
@@ -126,7 +126,7 @@ Value Value::operator - (const Value &v) const
if (this->type == VECTOR && v.type == VECTOR) {
Value r;
r.type = VECTOR;
- for (int i = 0; i < this->vec.size() && i < v.vec.size(); i++)
+ for (size_t i = 0; i < this->vec.size() && i < v.vec.size(); i++)
r.vec.push_back(new Value(*this->vec[i] - *v.vec[i]));
return r;
}
@@ -141,14 +141,14 @@ Value Value::operator * (const Value &v) const
if (this->type == VECTOR && v.type == NUMBER) {
Value r;
r.type = VECTOR;
- for (int i = 0; i < this->vec.size(); i++)
+ for (size_t i = 0; i < this->vec.size(); i++)
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++)
+ for (size_t i = 0; i < v.vec.size(); i++)
r.vec.push_back(new Value(*this * *v.vec[i]));
return r;
}
@@ -163,14 +163,14 @@ Value Value::operator / (const Value &v) const
if (this->type == VECTOR && v.type == NUMBER) {
Value r;
r.type = VECTOR;
- for (int i = 0; i < this->vec.size(); i++)
+ for (size_t i = 0; i < this->vec.size(); i++)
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++)
+ for (size_t i = 0; i < v.vec.size(); i++)
r.vec.push_back(new Value(v / *v.vec[i]));
return r;
}
@@ -218,7 +218,7 @@ Value Value::operator == (const Value &v) const
if (this->type == VECTOR && v.type == VECTOR) {
if (this->vec.size() != v.vec.size())
return Value(false);
- for (int i=0; i<this->vec.size(); i++)
+ for (size_t i=0; i<this->vec.size(); i++)
if (!(*this->vec[i] == *v.vec[i]).b)
return Value(false);
return Value(true);
@@ -256,7 +256,7 @@ Value Value::inv() const
if (this->type == VECTOR) {
Value r;
r.type = VECTOR;
- for (int i = 0; i < this->vec.size(); i++)
+ for (size_t i = 0; i < this->vec.size(); i++)
r.vec.push_back(new Value(this->vec[i]->inv()));
return r;
}
@@ -314,7 +314,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 (size_t i = 0; i < this->vec.size(); i++) delete this->vec[i];
this->vec.clear();
this->range_begin = 0;
this->range_step = 0;
@@ -333,7 +333,7 @@ std::string Value::toString() const
break;
case VECTOR:
stream << '[';
- for (int i = 0; i < this->vec.size(); i++) {
+ for (size_t i = 0; i < this->vec.size(); i++) {
if (i > 0) stream << ", ";
stream << *(this->vec[i]);
}
@@ -361,6 +361,30 @@ std::string Value::toString() const
return stream.str();
}
+bool Value::toBool() const
+{
+ switch (this->type) {
+ case STRING:
+ return this->text.size() > 0;
+ break;
+ case VECTOR:
+ return this->vec.size() > 0;
+ break;
+ case RANGE:
+ return true;
+ break;
+ case NUMBER:
+ return this->num != 0;
+ break;
+ case BOOL:
+ return this->b;
+ break;
+ default:
+ return false;
+ break;
+ }
+}
+
/*!
Append a value to this vector.
This must be of type VECTOR.
@@ -377,9 +401,3 @@ std::ostream &operator<<(std::ostream &stream, const Value &value)
return stream;
}
-std::ostream &operator<<(std::ostream &stream, const QString &str)
-{
- stream << str.toStdString();
- return stream;
-}
-
contact: Jan Huwald // Impressum