Пример #1
0
bool QDBusData::operator==(const QDBusData& other) const
{
    if (&other == this) return true;

    if (d == other.d) return true;

    if (d->type == other.d->type)
    {
        switch (d->type)
        {
            case QDBusData::Invalid:
                return true;

            case QDBusData::Bool:
                return d->value.boolValue == other.d->value.boolValue;

            case QDBusData::Byte:
                return d->value.byteValue == other.d->value.byteValue;

            case QDBusData::Int16:
                return d->value.int16Value == other.d->value.int16Value;

            case QDBusData::UInt16:
                return d->value.uint16Value == other.d->value.uint16Value;

            case QDBusData::Int32:
                return d->value.int32Value == other.d->value.int32Value;

            case QDBusData::UInt32:
                return d->value.uint32Value == other.d->value.uint32Value;

            case QDBusData::Int64:
                return d->value.int64Value == other.d->value.int64Value;

            case QDBusData::UInt64:
                return d->value.uint64Value == other.d->value.uint64Value;

            case QDBusData::Double:
                // FIXME: should not compare doubles for equality like this
                return d->value.doubleValue == other.d->value.doubleValue;

            case QDBusData::String:
                return toString() == other.toString();

            case QDBusData::ObjectPath:
                return toObjectPath() == other.toObjectPath();

            case QDBusData::List:
                return toList() == other.toList();

            case QDBusData::Struct:
                return toStruct() == other.toStruct();

            case QDBusData::Variant:
                return toVariant() == other.toVariant();

            case QDBusData::Map:
                if (d->keyType != other.d->keyType) return false;

                switch (d->keyType)
                {
                    case QDBusData::Byte:
                        toByteKeyMap() == other.toByteKeyMap();
                        break;

                    case QDBusData::Int16:
                        toInt16KeyMap() == other.toInt16KeyMap();
                        break;

                    case QDBusData::UInt16:
                        toUInt16KeyMap() == other.toUInt16KeyMap();
                        break;

                    case QDBusData::Int32:
                        toInt32KeyMap() == other.toInt32KeyMap();
                        break;

                    case QDBusData::UInt32:
                        toUInt32KeyMap() == other.toUInt32KeyMap();
                        break;
                    case QDBusData::Int64:
                        toInt64KeyMap() == other.toInt64KeyMap();
                        break;

                    case QDBusData::UInt64:
                        toUInt64KeyMap() == other.toUInt64KeyMap();
                        break;

                    case QDBusData::String:
                        toStringKeyMap() == other.toStringKeyMap();
                        break;

                    case QDBusData::ObjectPath:
                        toObjectPathKeyMap() == other.toObjectPathKeyMap();
                        break;

                    default:
                        qFatal("QDBusData operator== unhandled map key type %d(%s)",
                               d->keyType, QDBusData::typeName(d->keyType));
                        break;
                }

                break;
        }
    }

    return false;
}
Пример #2
0
DataInformation* toDataInformation(const QScriptValue& value, const ParserInfo& oldInfo)
{
    if (!value.isValid())
    {
        oldInfo.error() << "invalid value passed!";
        return 0;
    }
    ParserInfo info(oldInfo);
    QString nameOverride = value.property(PROPERTY_NAME).toString();
    if (!nameOverride.isEmpty())
        info.name = nameOverride;

    //check function array and date, since they are objects too
    if (value.isRegExp())
    {
        //apparently regexp is a function
        info.error() << "Cannot convert a RegExp object to DataInformation!";
        return 0;
    }
    if (value.isFunction())
    {
        info.error() << "Cannot convert a Function object to DataInformation!";
        return 0;
    }
    if (value.isArray())
    {
        info.error() << "Cannot convert a Array object to DataInformation!";
        return 0;
    }
    if (value.isDate())
    {
        info.error() << "Cannot convert a Date object to DataInformation!";
        return 0;
    }
    if (value.isError())
    {
        info.error() << "Cannot convert a Error object to DataInformation!";
        return 0;
    }
    //variant and qobject are also object types, however they cannot appear from user code, no need to check

    //if it is a string, we convert to primitive type, if not it has to be an object
    if (value.isString())
        return toPrimitive(value, info); //a type string is also okay

    if (!value.isObject())
    {
        if (value.isBool())
            info.error() << "Cannot convert Boolean to DataInformation!";
        else if (value.isNull())
            info.error() << "Cannot convert null to DataInformation!";
        else if (value.isUndefined())
            info.error() << "Cannot convert undefined to DataInformation!";
        else if (value.isNumber())
            info.error() << "Cannot convert Number to DataInformation!";
        else
            info.error() << "Cannot convert object of unknown type to DataInformation!";

        return 0; //no point trying to convert
    }

    QString type = value.property(PROPERTY_INTERNAL_TYPE).toString();
    if (type.isEmpty())
    {
        info.error() << "Cannot convert object since type of object could not be determined!";
        return 0;
    }
    DataInformation* returnVal = 0;

    if (type == TYPE_ARRAY)
        returnVal = toArray(value, info);

    else if (type == TYPE_STRUCT)
        returnVal = toStruct(value, info);

    else if (type == TYPE_UNION)
        returnVal = toUnion(value, info);

    else if (type == TYPE_BITFIELD)
        returnVal = toBitfield(value, info);

    else if (type == TYPE_ENUM)
        returnVal = toEnum(value, false, info);

    else if (type == TYPE_FLAGS)
        returnVal = toEnum(value, true, info);

    else if (type == TYPE_STRING)
        returnVal = toString(value, info);

    else if (type == TYPE_POINTER)
        returnVal = toPointer(value, info);

    else if (type == TYPE_TAGGED_UNION)
        returnVal = toTaggedUnion(value, info);

    else if (type == TYPE_PRIMITIVE)
        returnVal = toPrimitive(value, info);

    else
        info.error() << "Unknown type:" << type;

    if (returnVal)
    {
        CommonParsedData cpd(info);
        QString byteOrderStr = value.property(PROPERTY_BYTEORDER).toString();
        if (!byteOrderStr.isEmpty())
            cpd.endianess = ParserUtils::byteOrderFromString(byteOrderStr,
                    LoggerWithContext(info.logger, info.context()));
        cpd.updateFunc = value.property(PROPERTY_UPDATE_FUNC);
        cpd.validationFunc = value.property(PROPERTY_VALIDATION_FUNC);
        cpd.toStringFunc = value.property(PROPERTY_TO_STRING_FUNC);
        cpd.customTypeName = value.property(PROPERTY_CUSTOM_TYPE_NAME).toString();
        if (!DataInformationFactory::commonInitialization(returnVal, cpd))
        {
            delete returnVal; //error message has already been logged
            return 0;
        }
    }
    return returnVal;
}