File: qtscript_QHostAddress.cpp

package info (click to toggle)
musescore 1.3%2Bdfsg1-0.1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 148,004 kB
  • ctags: 30,854
  • sloc: cpp: 372,716; xml: 148,276; ansic: 6,156; python: 2,202; perl: 710; sh: 505; makefile: 227
file content (432 lines) | stat: -rw-r--r-- 16,325 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
#include <QtScript/QScriptEngine>
#include <QtScript/QScriptContext>
#include <QtScript/QScriptValue>
#include <QtCore/QStringList>
#include <QtCore/QDebug>
#include <qmetaobject.h>

#include <qhostaddress.h>
#include <QVariant>
#include <qdatastream.h>
#include <qhostaddress.h>
#include <qpair.h>

static const char * const qtscript_QHostAddress_function_names[] = {
    "QHostAddress"
    // static
    , "parseSubnet"
    // prototype
    , "clear"
    , "isInSubnet"
    , "isNull"
    , "equals"
    , "protocol"
    , "readFrom"
    , "scopeId"
    , "setAddress"
    , "setScopeId"
    , "toIPv4Address"
    , "toIPv6Address"
    , "toString"
    , "writeTo"
};

static const char * const qtscript_QHostAddress_function_signatures[] = {
    "\nSpecialAddress address\nQHostAddress copy\nQIPv6Address ip6Addr\nString address\nunsigned int ip4Addr"
    // static
    , "String subnet"
    // prototype
    , ""
    , "QHostAddress subnet, int netmask\nQPair subnet"
    , ""
    , "SpecialAddress address\nQHostAddress address"
    , ""
    , "QDataStream arg__1"
    , ""
    , "QIPv6Address ip6Addr\nString address\nunsigned int ip4Addr"
    , "String id"
    , ""
    , ""
    , ""
    , "QDataStream arg__1"
};

static QScriptValue qtscript_QHostAddress_throw_ambiguity_error_helper(
    QScriptContext *context, const char *functionName, const char *signatures)
{
    QStringList lines = QString::fromLatin1(signatures).split(QLatin1Char('\n'));
    QStringList fullSignatures;
    for (int i = 0; i < lines.size(); ++i)
        fullSignatures.append(QString::fromLatin1("%0(%1)").arg(functionName).arg(lines.at(i)));
    return context->throwError(QString::fromLatin1("QHostAddress::%0(): could not find a function match; candidates are:\n%1")
        .arg(functionName).arg(fullSignatures.join(QLatin1String("\n"))));
}

Q_DECLARE_METATYPE(QHostAddress)
Q_DECLARE_METATYPE(QHostAddress*)
Q_DECLARE_METATYPE(QHostAddress::SpecialAddress)
template <> \
struct QMetaTypeId< QPair<QHostAddress,int> > \
{ \
    enum { Defined = 1 }; \
    static int qt_metatype_id() \
    { \
        static QBasicAtomicInt metatype_id = Q_BASIC_ATOMIC_INITIALIZER(0); \
        if (!metatype_id) \
            metatype_id = qRegisterMetaType< QPair<QHostAddress,int> >("QPair<QHostAddress,int>"); \
        return metatype_id; \
    } \
};
Q_DECLARE_METATYPE(QAbstractSocket::NetworkLayerProtocol)
Q_DECLARE_METATYPE(QDataStream*)
Q_DECLARE_METATYPE(QIPv6Address)

static QScriptValue qtscript_create_enum_class_helper(
    QScriptEngine *engine,
    QScriptEngine::FunctionSignature construct,
    QScriptEngine::FunctionSignature valueOf,
    QScriptEngine::FunctionSignature toString)
{
    QScriptValue proto = engine->newObject();
    proto.setProperty(QString::fromLatin1("valueOf"),
        engine->newFunction(valueOf), QScriptValue::SkipInEnumeration);
    proto.setProperty(QString::fromLatin1("toString"),
        engine->newFunction(toString), QScriptValue::SkipInEnumeration);
    return engine->newFunction(construct, proto, 1);
}

//
// QHostAddress::SpecialAddress
//

static const QHostAddress::SpecialAddress qtscript_QHostAddress_SpecialAddress_values[] = {
    QHostAddress::Null
    , QHostAddress::Broadcast
    , QHostAddress::LocalHost
    , QHostAddress::LocalHostIPv6
    , QHostAddress::Any
    , QHostAddress::AnyIPv6
};

static const char * const qtscript_QHostAddress_SpecialAddress_keys[] = {
    "Null"
    , "Broadcast"
    , "LocalHost"
    , "LocalHostIPv6"
    , "Any"
    , "AnyIPv6"
};

static QString qtscript_QHostAddress_SpecialAddress_toStringHelper(QHostAddress::SpecialAddress value)
{
    if ((value >= QHostAddress::Null) && (value <= QHostAddress::AnyIPv6))
        return qtscript_QHostAddress_SpecialAddress_keys[static_cast<int>(value)-static_cast<int>(QHostAddress::Null)];
    return QString();
}

static QScriptValue qtscript_QHostAddress_SpecialAddress_toScriptValue(QScriptEngine *engine, const QHostAddress::SpecialAddress &value)
{
    QScriptValue clazz = engine->globalObject().property(QString::fromLatin1("QHostAddress"));
    return clazz.property(qtscript_QHostAddress_SpecialAddress_toStringHelper(value));
}

static void qtscript_QHostAddress_SpecialAddress_fromScriptValue(const QScriptValue &value, QHostAddress::SpecialAddress &out)
{
    out = qvariant_cast<QHostAddress::SpecialAddress>(value.toVariant());
}

static QScriptValue qtscript_construct_QHostAddress_SpecialAddress(QScriptContext *context, QScriptEngine *engine)
{
    int arg = context->argument(0).toInt32();
    if ((arg >= QHostAddress::Null) && (arg <= QHostAddress::AnyIPv6))
        return qScriptValueFromValue(engine,  static_cast<QHostAddress::SpecialAddress>(arg));
    return context->throwError(QString::fromLatin1("SpecialAddress(): invalid enum value (%0)").arg(arg));
}

static QScriptValue qtscript_QHostAddress_SpecialAddress_valueOf(QScriptContext *context, QScriptEngine *engine)
{
    QHostAddress::SpecialAddress value = qscriptvalue_cast<QHostAddress::SpecialAddress>(context->thisObject());
    return QScriptValue(engine, static_cast<int>(value));
}

static QScriptValue qtscript_QHostAddress_SpecialAddress_toString(QScriptContext *context, QScriptEngine *engine)
{
    QHostAddress::SpecialAddress value = qscriptvalue_cast<QHostAddress::SpecialAddress>(context->thisObject());
    return QScriptValue(engine, qtscript_QHostAddress_SpecialAddress_toStringHelper(value));
}

static QScriptValue qtscript_create_QHostAddress_SpecialAddress_class(QScriptEngine *engine, QScriptValue &clazz)
{
    QScriptValue ctor = qtscript_create_enum_class_helper(
        engine, qtscript_construct_QHostAddress_SpecialAddress,
        qtscript_QHostAddress_SpecialAddress_valueOf, qtscript_QHostAddress_SpecialAddress_toString);
    qScriptRegisterMetaType<QHostAddress::SpecialAddress>(engine, qtscript_QHostAddress_SpecialAddress_toScriptValue,
        qtscript_QHostAddress_SpecialAddress_fromScriptValue, ctor.property(QString::fromLatin1("prototype")));
    for (int i = 0; i < 6; ++i) {
        clazz.setProperty(QString::fromLatin1(qtscript_QHostAddress_SpecialAddress_keys[i]),
            engine->newVariant(qVariantFromValue(qtscript_QHostAddress_SpecialAddress_values[i])),
            QScriptValue::ReadOnly | QScriptValue::Undeletable);
    }
    return ctor;
}

//
// QHostAddress
//

static QScriptValue qtscript_QHostAddress_prototype_call(QScriptContext *context, QScriptEngine *)
{
#if QT_VERSION > 0x040400
    Q_ASSERT(context->callee().isFunction());
    uint _id = context->callee().data().toUInt32();
#else
    uint _id;
    if (context->callee().isFunction())
        _id = context->callee().data().toUInt32();
    else
        _id = 0xBABE0000 + 13;
#endif
    Q_ASSERT((_id & 0xFFFF0000) == 0xBABE0000);
    _id &= 0x0000FFFF;
    QHostAddress* _q_self = qscriptvalue_cast<QHostAddress*>(context->thisObject());
    if (!_q_self) {
        return context->throwError(QScriptContext::TypeError,
            QString::fromLatin1("QHostAddress.%0(): this object is not a QHostAddress")
            .arg(qtscript_QHostAddress_function_names[_id+2]));
    }

    switch (_id) {
    case 0:
    if (context->argumentCount() == 0) {
        _q_self->clear();
        return context->engine()->undefinedValue();
    }
    break;

    case 1:
    if (context->argumentCount() == 1) {
        QPair<QHostAddress,int> _q_arg0 = qscriptvalue_cast<QPair<QHostAddress,int> >(context->argument(0));
        bool _q_result = _q_self->isInSubnet(_q_arg0);
        return QScriptValue(context->engine(), _q_result);
    }
    if (context->argumentCount() == 2) {
        QHostAddress _q_arg0 = qscriptvalue_cast<QHostAddress>(context->argument(0));
        int _q_arg1 = context->argument(1).toInt32();
        bool _q_result = _q_self->isInSubnet(_q_arg0, _q_arg1);
        return QScriptValue(context->engine(), _q_result);
    }
    break;

    case 2:
    if (context->argumentCount() == 0) {
        bool _q_result = _q_self->isNull();
        return QScriptValue(context->engine(), _q_result);
    }
    break;

    case 3:
    if (context->argumentCount() == 1) {
        if ((qMetaTypeId<QHostAddress::SpecialAddress>() == context->argument(0).toVariant().userType())) {
            QHostAddress::SpecialAddress _q_arg0 = qscriptvalue_cast<QHostAddress::SpecialAddress>(context->argument(0));
            bool _q_result = _q_self->operator==(_q_arg0);
            return QScriptValue(context->engine(), _q_result);
        } else if ((qMetaTypeId<QHostAddress>() == context->argument(0).toVariant().userType())) {
            QHostAddress _q_arg0 = qscriptvalue_cast<QHostAddress>(context->argument(0));
            bool _q_result = _q_self->operator==(_q_arg0);
            return QScriptValue(context->engine(), _q_result);
        }
    }
    break;

    case 4:
    if (context->argumentCount() == 0) {
        QAbstractSocket::NetworkLayerProtocol _q_result = _q_self->protocol();
        return qScriptValueFromValue(context->engine(), _q_result);
    }
    break;

    case 5:
    if (context->argumentCount() == 1) {
        QDataStream* _q_arg0 = qscriptvalue_cast<QDataStream*>(context->argument(0));
        operator>>(*_q_arg0, *_q_self);
        return context->engine()->undefinedValue();
    }
    break;

    case 6:
    if (context->argumentCount() == 0) {
        QString _q_result = _q_self->scopeId();
        return QScriptValue(context->engine(), _q_result);
    }
    break;

    case 7:
    if (context->argumentCount() == 1) {
        if ((qMetaTypeId<QIPv6Address>() == context->argument(0).toVariant().userType())) {
            QIPv6Address _q_arg0 = qscriptvalue_cast<QIPv6Address>(context->argument(0));
            _q_self->setAddress(_q_arg0);
            return context->engine()->undefinedValue();
        } else if (context->argument(0).isString()) {
            QString _q_arg0 = context->argument(0).toString();
            bool _q_result = _q_self->setAddress(_q_arg0);
            return QScriptValue(context->engine(), _q_result);
        } else if (context->argument(0).isNumber()) {
            uint _q_arg0 = context->argument(0).toUInt32();
            _q_self->setAddress(_q_arg0);
            return context->engine()->undefinedValue();
        }
    }
    break;

    case 8:
    if (context->argumentCount() == 1) {
        QString _q_arg0 = context->argument(0).toString();
        _q_self->setScopeId(_q_arg0);
        return context->engine()->undefinedValue();
    }
    break;

    case 9:
    if (context->argumentCount() == 0) {
        uint _q_result = _q_self->toIPv4Address();
        return QScriptValue(context->engine(), _q_result);
    }
    break;

    case 10:
    if (context->argumentCount() == 0) {
        QIPv6Address _q_result = _q_self->toIPv6Address();
        return qScriptValueFromValue(context->engine(), _q_result);
    }
    break;

    case 11:
    if (context->argumentCount() == 0) {
        QString _q_result = _q_self->toString();
        return QScriptValue(context->engine(), _q_result);
    }
    break;

    case 12:
    if (context->argumentCount() == 1) {
        QDataStream* _q_arg0 = qscriptvalue_cast<QDataStream*>(context->argument(0));
        operator<<(*_q_arg0, *_q_self);
        return context->engine()->undefinedValue();
    }
    break;

    default:
    Q_ASSERT(false);
    }
    return qtscript_QHostAddress_throw_ambiguity_error_helper(context,
        qtscript_QHostAddress_function_names[_id+2],
        qtscript_QHostAddress_function_signatures[_id+2]);
}

static QScriptValue qtscript_QHostAddress_static_call(QScriptContext *context, QScriptEngine *)
{
    uint _id = context->callee().data().toUInt32();
    Q_ASSERT((_id & 0xFFFF0000) == 0xBABE0000);
    _id &= 0x0000FFFF;
    switch (_id) {
    case 0:
    if (context->thisObject().strictlyEquals(context->engine()->globalObject())) {
        return context->throwError(QString::fromLatin1("QHostAddress(): Did you forget to construct with 'new'?"));
    }
    if (context->argumentCount() == 0) {
        QHostAddress _q_cpp_result;
        QScriptValue _q_result = context->engine()->newVariant(context->thisObject(), qVariantFromValue(_q_cpp_result));
        return _q_result;
    } else if (context->argumentCount() == 1) {
        if ((qMetaTypeId<QHostAddress::SpecialAddress>() == context->argument(0).toVariant().userType())) {
            QHostAddress::SpecialAddress _q_arg0 = qscriptvalue_cast<QHostAddress::SpecialAddress>(context->argument(0));
            QHostAddress _q_cpp_result(_q_arg0);
            QScriptValue _q_result = context->engine()->newVariant(context->thisObject(), qVariantFromValue(_q_cpp_result));
            return _q_result;
        } else if ((qMetaTypeId<QHostAddress>() == context->argument(0).toVariant().userType())) {
            QHostAddress _q_arg0 = qscriptvalue_cast<QHostAddress>(context->argument(0));
            QHostAddress _q_cpp_result(_q_arg0);
            QScriptValue _q_result = context->engine()->newVariant(context->thisObject(), qVariantFromValue(_q_cpp_result));
            return _q_result;
        } else if ((qMetaTypeId<QIPv6Address>() == context->argument(0).toVariant().userType())) {
            QIPv6Address _q_arg0 = qscriptvalue_cast<QIPv6Address>(context->argument(0));
            QHostAddress _q_cpp_result(_q_arg0);
            QScriptValue _q_result = context->engine()->newVariant(context->thisObject(), qVariantFromValue(_q_cpp_result));
            return _q_result;
        } else if (context->argument(0).isString()) {
            QString _q_arg0 = context->argument(0).toString();
            QHostAddress _q_cpp_result(_q_arg0);
            QScriptValue _q_result = context->engine()->newVariant(context->thisObject(), qVariantFromValue(_q_cpp_result));
            return _q_result;
        } else if (context->argument(0).isNumber()) {
            uint _q_arg0 = context->argument(0).toUInt32();
            QHostAddress _q_cpp_result(_q_arg0);
            QScriptValue _q_result = context->engine()->newVariant(context->thisObject(), qVariantFromValue(_q_cpp_result));
            return _q_result;
        }
    }
    break;

    case 1:
    if (context->argumentCount() == 1) {
        QString _q_arg0 = context->argument(0).toString();
        QPair<QHostAddress,int> _q_result = QHostAddress::parseSubnet(_q_arg0);
        return qScriptValueFromValue(context->engine(), _q_result);
    }
    break;

    default:
    Q_ASSERT(false);
    }
    return qtscript_QHostAddress_throw_ambiguity_error_helper(context,
        qtscript_QHostAddress_function_names[_id],
        qtscript_QHostAddress_function_signatures[_id]);
}

QScriptValue qtscript_create_QHostAddress_class(QScriptEngine *engine)
{
    static const int function_lengths[] = {
        1
        // static
        , 1
        // prototype
        , 0
        , 2
        , 0
        , 1
        , 0
        , 1
        , 0
        , 1
        , 1
        , 0
        , 0
        , 0
        , 1
    };
    engine->setDefaultPrototype(qMetaTypeId<QHostAddress*>(), QScriptValue());
    QScriptValue proto = engine->newVariant(qVariantFromValue((QHostAddress*)0));
    for (int i = 0; i < 13; ++i) {
        QScriptValue fun = engine->newFunction(qtscript_QHostAddress_prototype_call, function_lengths[i+2]);
        fun.setData(QScriptValue(engine, uint(0xBABE0000 + i)));
        proto.setProperty(QString::fromLatin1(qtscript_QHostAddress_function_names[i+2]),
            fun, QScriptValue::SkipInEnumeration);
    }

    engine->setDefaultPrototype(qMetaTypeId<QHostAddress>(), proto);
    engine->setDefaultPrototype(qMetaTypeId<QHostAddress*>(), proto);

    QScriptValue ctor = engine->newFunction(qtscript_QHostAddress_static_call, proto, function_lengths[0]);
    ctor.setData(QScriptValue(engine, uint(0xBABE0000 + 0)));
    for (int i = 0; i < 1; ++i) {
        QScriptValue fun = engine->newFunction(qtscript_QHostAddress_static_call,
            function_lengths[i+1]);
        fun.setData(QScriptValue(engine, uint(0xBABE0000 + i+1)));
        ctor.setProperty(QString::fromLatin1(qtscript_QHostAddress_function_names[i+1]),
            fun, QScriptValue::SkipInEnumeration);
    }

    ctor.setProperty(QString::fromLatin1("SpecialAddress"),
        qtscript_create_QHostAddress_SpecialAddress_class(engine, ctor));
    return ctor;
}