diff options
author | Lars Knoll <lars.knoll@nokia.com> | 2012-01-16 22:40:25 +0100 |
---|---|---|
committer | Jamey Hicks <jamey.hicks@nokia.com> | 2012-01-16 22:46:37 +0100 |
commit | 9ec8bad9f415bdb924580e73c6cd6d7955d40c5a (patch) | |
tree | bba97ec256c7ce7f2827e236945f87732f03f6b5 /src | |
parent | 8edb205a9b15de62f5762770ccdb347121f96efe (diff) |
Rename QJsonValue::Number to Double
This leaves room for future integer optimisations.
It also is more consistent with Qt naming.
Remove the QJsonValue::toInt() method at the same time.
Change-Id: Iadac7cdfb94808597b7936596f64f45647bdec14
Sanity-Review: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Jamey Hicks <jamey.hicks@nokia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/qjson.cpp | 4 | ||||
-rw-r--r-- | src/qjson_p.h | 13 | ||||
-rw-r--r-- | src/qjsondocument.cpp | 2 | ||||
-rw-r--r-- | src/qjsonparser.cpp | 2 | ||||
-rw-r--r-- | src/qjsonvalue.cpp | 53 | ||||
-rw-r--r-- | src/qjsonvalue.h | 16 | ||||
-rw-r--r-- | src/qjsonwriter.cpp | 4 |
7 files changed, 34 insertions, 60 deletions
diff --git a/src/qjson.cpp b/src/qjson.cpp index d36f5e2..980b055 100644 --- a/src/qjson.cpp +++ b/src/qjson.cpp @@ -231,7 +231,7 @@ int Value::usedStorage(const Base *b) const { int s = 0; switch (type) { - case QJsonValue::Number: + case QJsonValue::Double: if (latinOrIntValue) break; s = sizeof(double); @@ -260,7 +260,7 @@ bool Value::isValid(const Base *b) const { int offset = 0; switch (type) { - case QJsonValue::Number: + case QJsonValue::Double: if (latinOrIntValue) break; // fall through diff --git a/src/qjson_p.h b/src/qjson_p.h index d96eb6a..36b0659 100644 --- a/src/qjson_p.h +++ b/src/qjson_p.h @@ -455,8 +455,7 @@ struct Value int usedStorage(const Base *b) const; bool toBoolean() const; - double toNumber(const Base *b) const; - int toInt() const; + double toDouble(const Base *b) const; QString toString(const Base *b) const; String asString(const Base *b) const; Latin1String asLatin1String(const Base *b) const; @@ -529,9 +528,9 @@ inline bool Value::toBoolean() const return val != 0; } -inline double Value::toNumber(const Base *b) const +inline double Value::toDouble(const Base *b) const { - Q_ASSERT(type == QJsonValue::Number); + Q_ASSERT(type == QJsonValue::Double); if (latinOrIntValue) return int_val; @@ -543,12 +542,6 @@ inline double Value::toNumber(const Base *b) const return d; } -inline int Value::toInt() const -{ - Q_ASSERT(type == QJsonValue::Number && latinOrIntValue); - return int_val; -} - inline QString Value::toString(const Base *b) const { char *d = data(b); diff --git a/src/qjsondocument.cpp b/src/qjsondocument.cpp index 5f9a709..2381441 100644 --- a/src/qjsondocument.cpp +++ b/src/qjsondocument.cpp @@ -240,7 +240,7 @@ QJsonDocument QJsonDocument::fromVariant(const QVariant &variant) \list \o Null an empty variant \o Bool QVariant::Bool - \o Number QVariant::Double + \o Double QVariant::Double \o String QVariant::String \o Array QVariant::List \o Object QVariant::Map diff --git a/src/qjsonparser.cpp b/src/qjsonparser.cpp index 2e70f86..50904b1 100644 --- a/src/qjsonparser.cpp +++ b/src/qjsonparser.cpp @@ -433,7 +433,7 @@ bool QJsonParser::parseValue(Private::Value *val, int baseOffset) bool QJsonParser::parseNumber(Private::Value *val, int baseOffset) { BEGIN << "parseNumber" << json; - val->type = QJsonValue::Number; + val->type = QJsonValue::Double; const char *start = json; bool isInt = true; diff --git a/src/qjsonvalue.cpp b/src/qjsonvalue.cpp index 803f4fa..f20221e 100644 --- a/src/qjsonvalue.cpp +++ b/src/qjsonvalue.cpp @@ -68,7 +68,7 @@ static const Private::Base emptyObject = { { qToLittleEndian(sizeof(Private::Bas \list \o bool QJsonValue::Bool - \o double QJsonValue::Number + \o double QJsonValue::Double \o string QJsonValue::String \o array QJsonValue::Array \o object QJsonValue::Object @@ -111,8 +111,8 @@ QJsonValue::QJsonValue(Private::Data *data, Private::Base *base, const Private:: case Bool: b = v.toBoolean(); break; - case Number: - dbl = v.toNumber(base); + case Double: + dbl = v.toDouble(base); break; case String: { QString s = v.toString(base); @@ -140,20 +140,20 @@ QJsonValue::QJsonValue(bool b) } /*! - Creates a value of type Number, with value \a n. + Creates a value of type Double, with value \a n. */ QJsonValue::QJsonValue(double n) - : t(Number), d(0) + : t(Double), d(0) { this->dbl = n; } /*! \overload - Creates a value of type Number, with value \a n. + Creates a value of type Double, with value \a n. */ QJsonValue::QJsonValue(int n) - : t(Number), d(0) + : t(Double), d(0) { this->dbl = n; } @@ -270,7 +270,7 @@ QJsonValue &QJsonValue::operator =(const QJsonValue &other) \o QVariant::Double \o QVariant::LongLong \o QVariant::ULongLong - \o QVariant::UInt to Number + \o QVariant::UInt to Double \o QVariant::String to String \o QVariant::StringList \o QVariant::VariantList to Array @@ -288,7 +288,6 @@ QJsonValue QJsonValue::fromVariant(const QVariant &variant) case QVariant::Bool: return QJsonValue(variant.toBool()); case QVariant::Int: - return QJsonValue(variant.toInt()); case QVariant::Double: case QVariant::LongLong: case QVariant::ULongLong: @@ -318,7 +317,7 @@ QJsonValue QJsonValue::fromVariant(const QVariant &variant) \value Null QVariant() \value Bool QVariant::Bool - \value Number QVariant::Double + \value Double QVariant::Double \value String QVariant::String \value Array QVariantList \value Object QVariantMap @@ -331,7 +330,7 @@ QVariant QJsonValue::toVariant() const switch (t) { case Bool: return b; - case Number: + case Double: return dbl; case String: return toString(); @@ -353,7 +352,7 @@ QVariant QJsonValue::toVariant() const \value Null A Null value \value Bool A boolean value. Use toBool() to convert to a bool. - \value Number A number. Use toNumber() to convert to a double. + \value Double A double. Use toDouble() to convert to a double. \value String A string. Use toString() to convert to a QString. \value Array An array. Use toArray() to convert to a QJsonArray. \value Object An object. Use toObject() to convert to a QJsonObject. @@ -387,28 +386,16 @@ bool QJsonValue::toBool() const /*! Converts the value to a double and returns it. - If type() is not Number, 0. will be returned. + If type() is not Double, 0. will be returned. */ -double QJsonValue::toNumber() const +double QJsonValue::toDouble() const { - if (t != Number) + if (t != Double) return 0; return dbl; } /*! - Converts the value to an int and returns it. - - If type() is not Number, 0. will be returned. - */ -int QJsonValue::toInt() const -{ - if (t != Number) - return 0; - return (int)dbl; -} - -/*! Converts the value to a QString and returns it. If type() is not String, a QString() will be returned. @@ -461,7 +448,7 @@ bool QJsonValue::operator==(const QJsonValue &other) const break; case Bool: return b == other.b; - case Number: + case Double: return dbl == other.dbl; case String: return toString() == other.toString(); @@ -504,7 +491,7 @@ int QJsonValue::requiredStorage(bool *compressed) const { *compressed = false; switch (t) { - case Number: + case Double: if (Private::compressedNumber(dbl) != INT_MAX) { *compressed = true; return 0; @@ -537,7 +524,7 @@ uint QJsonValue::valueToStore(uint offset) const break; case Bool: return b; - case Number: { + case Double: { int c = Private::compressedNumber(dbl); if (c != INT_MAX) return c; @@ -556,7 +543,7 @@ uint QJsonValue::valueToStore(uint offset) const void QJsonValue::copyData(char *dest, bool compressed) const { switch (t) { - case Number: + case Double: if (!compressed) { *((quint64 *)dest) = qToLittleEndian(ui); } @@ -646,8 +633,8 @@ QDebug operator<<(QDebug dbg, const QtJson::QJsonValue &o) case QtJson::QJsonValue::Bool: dbg.nospace() << "QJsonValue(bool, " << o.toBool() << ")"; break; - case QtJson::QJsonValue::Number: - dbg.nospace() << "QJsonValue(number, " << o.toNumber() << ")"; + case QtJson::QJsonValue::Double: + dbg.nospace() << "QJsonValue(double, " << o.toDouble() << ")"; break; case QtJson::QJsonValue::String: dbg.nospace() << "QJsonValue(string, " << o.toString() << ")"; diff --git a/src/qjsonvalue.h b/src/qjsonvalue.h index 4f5b7da..eba93f5 100644 --- a/src/qjsonvalue.h +++ b/src/qjsonvalue.h @@ -56,7 +56,7 @@ public: enum Type { Null = 0x0, Bool = 0x1, - Number = 0x2, + Double = 0x2, String = 0x3, Array = 0x4, Object = 0x5, @@ -83,15 +83,14 @@ public: Type type() const; inline bool isNull() const { return type() == Null; } inline bool isBool() const { return type() == Bool; } - inline bool isNumber() const { return type() == Number; } + inline bool isDouble() const { return type() == Double; } inline bool isString() const { return type() == String; } inline bool isArray() const { return type() == Array; } inline bool isObject() const { return type() == Object; } inline bool isUndefined() const { return type() == Undefined; } bool toBool() const; - double toNumber() const; - int toInt() const; + double toDouble() const; QString toString() const; QJsonArray toArray() const; QJsonObject toObject() const; @@ -117,10 +116,6 @@ private: uint valueToStore(uint offset) const; void copyData(char *dest, bool compressed) const; - // ### This should be: - // Private::Data *d; - // Private::Base *b; - // Private::Value *v; Type t; Private::Data *d; // needed for Objects and Arrays union { @@ -149,15 +144,14 @@ public: inline QJsonValue::Type type() const { return toValue().type(); } inline bool isNull() const { return type() == QJsonValue::Null; } inline bool isBool() const { return type() == QJsonValue::Bool; } - inline bool isNumber() const { return type() == QJsonValue::Number; } + inline bool isDouble() const { return type() == QJsonValue::Double; } inline bool isString() const { return type() == QJsonValue::String; } inline bool isArray() const { return type() == QJsonValue::Array; } inline bool isObject() const { return type() == QJsonValue::Object; } inline bool isUndefined() const { return type() == QJsonValue::Undefined; } inline bool toBool() const { return toValue().toBool(); } - inline double toNumber() const { return toValue().toNumber(); } - inline int toInt() const { return toValue().toInt(); } + inline double toDouble() const { return toValue().toDouble(); } inline QString toString() const { return toValue().toString(); } inline QJsonArray toArray() const; inline QJsonObject toObject() const; diff --git a/src/qjsonwriter.cpp b/src/qjsonwriter.cpp index 7f98886..d709cbc 100644 --- a/src/qjsonwriter.cpp +++ b/src/qjsonwriter.cpp @@ -182,8 +182,8 @@ static void valueToJson(const Private::Base *b, const Private::Value &v, QByteAr case QJsonValue::Bool: json += v.toBoolean() ? "true" : "false"; break; - case QJsonValue::Number: - json += QByteArray::number(v.toNumber(b)); + case QJsonValue::Double: + json += QByteArray::number(v.toDouble(b)); break; case QJsonValue::String: json += '"'; |