diff options
author | Marius Kintel <marius@kintel.net> | 2010-11-07 21:29:34 (GMT) |
---|---|---|
committer | Marius Kintel <marius@kintel.net> | 2010-11-07 21:29:34 (GMT) |
commit | e0a068a0e8678da426e1edd398feab5f4ea4d0f0 (patch) | |
tree | 5eaa05991d1652fd10692eb7410143d973db6643 /src/value.cc | |
parent | d310e364d14444a1a27ae2337cfb4bd0ab061113 (diff) |
Refactored some QString usage in the backend to std::string
Diffstat (limited to 'src/value.cc')
-rw-r--r-- | src/value.cc | 83 |
1 files changed, 51 insertions, 32 deletions
diff --git a/src/value.cc b/src/value.cc index a237c5a..e934ff7 100644 --- a/src/value.cc +++ b/src/value.cc @@ -25,6 +25,8 @@ #include "value.h" #include <math.h> +#include <sstream> +#include <QString> Value::Value() { @@ -52,7 +54,7 @@ Value::Value(double v) this->num = v; } -Value::Value(const QString &t) +Value::Value(const std::string &t) { reset_undef(); this->type = STRING; @@ -306,36 +308,6 @@ bool Value::getv3(double &x, double &y, double &z) const return true; } -QString Value::dump() const -{ - if (this->type == STRING) { - return QString("\"") + this->text + QString("\""); - } - if (this->type == VECTOR) { - QString text = "["; - for (int i = 0; i < this->vec.size(); i++) { - if (i > 0) - text += ", "; - text += this->vec[i]->dump(); - } - return text + "]"; - } - if (this->type == RANGE) { - QString text; - text.sprintf("[ %g : %g : %g ]", this->range_begin, this->range_step, this->range_end); - return text; - } - if (this->type == NUMBER) { - QString text; - text.sprintf("%g", this->num); - return text; - } - if (this->type == BOOL) { - return QString(this->b ? "true" : "false"); - } - return QString("undef"); -} - void Value::reset_undef() { this->type = UNDEFINED; @@ -347,5 +319,52 @@ void Value::reset_undef() this->range_begin = 0; this->range_step = 0; this->range_end = 0; - this->text = QString(); + this->text = ""; } + +std::string Value::toString() const +{ + std::stringstream stream; + + switch (this->type) { + case STRING: + stream << '"' << this->text << '"'; + break; + case VECTOR: + stream << '['; + for (int i = 0; i < this->vec.size(); i++) { + if (i > 0) stream << ", "; + stream << *(this->vec[i]); + } + stream << ']'; + break; + case RANGE: + stream << "[ " + << this->range_begin << " : " << this->range_step << " : " << this->range_end + << " ]"; + break; + case NUMBER: + stream << this->num; + break; + case BOOL: + stream << this->b; + break; + default: + stream << "undef"; + } + + return stream.str(); +} + +std::ostream &operator<<(std::ostream &stream, const Value &value) +{ + stream << value.toString(); + return stream; +} + +std::ostream &operator<<(std::ostream &stream, const QString &str) +{ + stream << str.toStdString(); + return stream; +} + |