Esempio n. 1
0
bool Database::removeBase(QString filename)
{
    emit toDebug(objectName(),
            QString("Удаляем старую базу '%1'.").arg(filename));

    removeConnection();
    QFile f(filename);
    if(f.exists())
    {
        if(f.remove())
        {
            emit toDebug(objectName(),
                         QString("База '%1' успешно удалена.").arg(filename));
            return true;
        }
        else
        {
            emit toDebug(objectName(),
                         QString("Невозможно удалить файл '%1'. Ошибка: %2")
                         .arg(filename)
                         .arg(f.errorString()));
            return false;
        }
    }
    else
    {
        emit toDebug(objectName(),
                QString("Невозможно удалить файл '%1'. Файл не существует.")
                     .arg(filename));
        return true;
    }
}
Esempio n. 2
0
void Database::createConnection()
{
    if(_connected)
        return;

    emit toDebug(objectName(),
                 QString("Cоздаем соединение к базе '%1'.").arg(baseName()));

    QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName(baseName());
    db.setUserName("user");
    db.setHostName("rt");
    db.setPassword("user");
    if (!db.open())
    {
        _connected=false;
        emit toDebug(objectName(),
                     QString("База данных '%1' не может быть открыта. Ошибка: %2")
                     .arg(baseName())
                     .arg(db.lastError().text()));
    }
    else
    {
        _connected=true;
        emit toDebug(objectName(),
                     QString("База данных '%1' открыта.").arg(baseName()));
    }
}
DatabaseWidget::DatabaseWidget(QWidget *parent) :
    QWidget(parent),
    _ui(new Ui::DatabaseWidget),
    _csvFileName(DefaultBaseName),
    _thread(nullptr)
{
    _ui->setupUi(this);
    _db = new Database;
    _thread = new QThread;
    _db->moveToThread(_thread);
    _thread->start();

    connect(_db, SIGNAL(baseOpening()),
            this, SLOT(onBaseOpening()));
    connect(_db, SIGNAL(baseOpened()),
            this, SLOT(onBaseOpened()));

    connect(_db, SIGNAL(toDebug(QString,QString)),
             this, SIGNAL(toDebug(QString,QString)));

    connect(&_futureWatcher, SIGNAL(finished()),
            this, SLOT(onProcessOfOpenFinished()));
    connect(&_futureWatcherParser, SIGNAL(finished()),
            this, SLOT(onProcessOfParsingFinished()));

    _parser = new XlsParser;

    connect(_ui->comboBoxTypeFSubj, SIGNAL(activated(int)), this, SLOT(onFindButtonClicked()));
    connect(_ui->lineEditFSubj, SIGNAL(returnPressed()), this, SLOT(onFindButtonClicked()));
    connect(_ui->lineEditDistrict, SIGNAL(returnPressed()), this, SLOT(onFindButtonClicked()));
    connect(_ui->lineEditTypeOfCity, SIGNAL(returnPressed()), this, SLOT(onFindButtonClicked()));
    connect(_ui->lineEditTypeOfCity2, SIGNAL(returnPressed()), this, SLOT(onFindButtonClicked()));
    connect(_ui->lineEditCity, SIGNAL(returnPressed()), this, SLOT(onFindButtonClicked()));
    connect(_ui->lineEditCity2, SIGNAL(returnPressed()), this, SLOT(onFindButtonClicked()));
    connect(_ui->lineEditTypeOfStreet, SIGNAL(returnPressed()), this, SLOT(onFindButtonClicked()));
    connect(_ui->lineEditStreet, SIGNAL(returnPressed()), this, SLOT(onFindButtonClicked()));
    connect(_ui->lineEditBuild, SIGNAL(returnPressed()), this, SLOT(onFindButtonClicked()));
    connect(_ui->lineEditKorp, SIGNAL(returnPressed()), this, SLOT(onFindButtonClicked()));
    connect(_ui->lineEditLiter, SIGNAL(returnPressed()), this, SLOT(onFindButtonClicked()));
    connect(_ui->lineEditAdditional, SIGNAL(returnPressed()), this, SLOT(onFindButtonClicked()));

    connect(_ui->_lineEditAddress, SIGNAL(returnPressed()), this, SLOT(onParseButtonClicked()));

    connect(this, SIGNAL(selectAddress(Address)),
            _db, SLOT(selectAddress(Address)));
    connect(_db, SIGNAL(selectedRows(int)),
            this, SLOT(onSelectedRows(int)));

    connect(this, SIGNAL(updateModel()),
            _db, SLOT(updateTableModel()));
    _ui->_pushButtonDelete->hide();
}
void DatabaseWidget::readCsvBase(QString openFilename)
{
//    QString currTime=QDateTime::currentDateTime().toString("dd.MM.yyyy hh:mm:ss.zzz");
//    qDebug().noquote() << "readCsvBase BEGIN"
//             << currTime
//             << this->thread()->currentThreadId();

    emit toDebug(objectName(),
                 QString("Открывается файл '%1'.").arg(openFilename));

    QString name = QFileInfo(openFilename).fileName();
    if(!QFileInfo(openFilename).exists())
    {
        emit toDebug(objectName(),
                     QString("Файл '%1' не найден").arg(openFilename));
        return;
    }


    QProgressDialog *dialog = new QProgressDialog;
    dialog->setWindowTitle(trUtf8("Обработка базы (1/3)"));
    dialog->setLabelText(trUtf8("Открывается файл \"%1\". \nОжидайте ...")
                         .arg(name));
    dialog->setCancelButtonText(trUtf8("Отмена"));
    QObject::connect(dialog, SIGNAL(canceled()),
                     &_futureWatcher, SLOT(cancel()));
    QObject::connect(&_futureWatcher, SIGNAL(progressRangeChanged(int,int)),
                     dialog, SLOT(setRange(int,int)));
    QObject::connect(&_futureWatcher, SIGNAL(progressValueChanged(int)),
                     dialog, SLOT(setValue(int)));
    QObject::connect(&_futureWatcher, SIGNAL(finished()),
                     dialog, SLOT(deleteLater()));
    QObject::connect(&_futureWatcher, SIGNAL(finished()),
                     dialog, SLOT(hide()));

    QFuture<ListAddress> f1 = QtConcurrent::run(
                                         readFile,
                                         openFilename,
                                         MAX_OPEN_ROWS);
    // Start the computation.
    _futureWatcher.setFuture(f1);
    dialog->exec();

//    currTime=QDateTime::currentDateTime().toString("dd.MM.yyyy hh:mm:ss.zzz");
//    qDebug().noquote() << "readCsvBase END"
//             << currTime
//             << this->thread()->currentThreadId();
}
Esempio n. 5
0
void TypedefDeclaration::toObjFile(int multiobj)
{
    //printf("TypedefDeclaration::toObjFile('%s')\n", toChars());

    if (type->ty == Terror)
    {   error("had semantic errors when compiling");
        return;
    }

    if (global.params.symdebug)
        toDebug(this);

    type->genTypeInfo(NULL);

    TypeTypedef *tc = (TypeTypedef *)type;
    if (type->isZeroInit() || !tc->sym->init)
        ;
    else
    {
        enum_SC scclass = SCglobal;
        if (isInstantiated())
            scclass = SCcomdat;

        // Generate static initializer
        toInitializer();
        sinit->Sclass = scclass;
        sinit->Sfl = FLdata;
        sinit->Sdt = Initializer_toDt(tc->sym->init);
        out_readonly(sinit);
        outdata(sinit);
    }
}
Esempio n. 6
0
        void visit(StructDeclaration *sd)
        {
            //printf("StructDeclaration::toObjFile('%s')\n", sd->toChars());

            if (sd->type->ty == Terror)
            {
                sd->error("had semantic errors when compiling");
                return;
            }

            if (multiobj && !sd->hasStaticCtorOrDtor())
            {
                obj_append(sd);
                return;
            }

            // Anonymous structs/unions only exist as part of others,
            // do not output forward referenced structs's
            if (!sd->isAnonymous() && sd->members)
            {
                if (global.params.symdebug)
                    toDebug(sd);

                genTypeInfo(sd->type, NULL);

                // Generate static initializer
                toInitializer(sd);
                if (sd->isInstantiated())
                {
                    sd->sinit->Sclass = SCcomdat;
                }
                else
                {
                    sd->sinit->Sclass = SCglobal;
                }

                sd->sinit->Sfl = FLdata;
                StructDeclaration_toDt(sd, &sd->sinit->Sdt);
                dt_optimize(sd->sinit->Sdt);
                out_readonly(sd->sinit);    // put in read-only segment
                outdata(sd->sinit);

                // Put out the members
                for (size_t i = 0; i < sd->members->dim; i++)
                {
                    Dsymbol *member = (*sd->members)[i];
                    /* There might be static ctors in the members, and they cannot
                     * be put in separate obj files.
                     */
                    member->accept(this);
                }

                if (sd->xeq && sd->xeq != StructDeclaration::xerreq)
                    sd->xeq->accept(this);
                if (sd->xcmp && sd->xcmp != StructDeclaration::xerrcmp)
                    sd->xcmp->accept(this);
                if (sd->xhash)
                    sd->xhash->accept(this);
            }
        }
Esempio n. 7
0
File: toobj.c Progetto: sjh2014/dmd
void StructDeclaration::toObjFile(int multiobj)
{
    //printf("StructDeclaration::toObjFile('%s')\n", toChars());

    if (type->ty == Terror)
    {   error("had semantic errors when compiling");
        return;
    }

    if (multiobj && !hasStaticCtorOrDtor())
    {   obj_append(this);
        return;
    }

    // Anonymous structs/unions only exist as part of others,
    // do not output forward referenced structs's
    if (!isAnonymous() && members)
    {
        if (global.params.symdebug)
            toDebug();

        type->getTypeInfo(NULL);        // generate TypeInfo

        if (1)
        {
            // Generate static initializer
            toInitializer();
            if (isInstantiated())
            {
                sinit->Sclass = SCcomdat;
            }
            else
            {
                sinit->Sclass = SCglobal;
            }

            sinit->Sfl = FLdata;
            toDt(&sinit->Sdt);
            dt_optimize(sinit->Sdt);
            out_readonly(sinit);    // put in read-only segment
            outdata(sinit);
        }

        // Put out the members
        for (size_t i = 0; i < members->dim; i++)
        {
            Dsymbol *member = (*members)[i];
            /* There might be static ctors in the members, and they cannot
             * be put in separate obj files.
             */
            member->toObjFile(multiobj);
        }

        if (xeq && xeq != xerreq)
            xeq->toObjFile(multiobj);
        if (xcmp && xcmp != xerrcmp)
            xcmp->toObjFile(multiobj);
    }
}
void DatabaseWidget::onProcessOfOpenFinished()
{
    if(_futureWatcher.isFinished()
            && !_futureWatcher.isCanceled())
    {
        _paddr.reset(new ListAddress(_futureWatcher.future().result()));
        emit toDebug(objectName(),
                     QString("Открытие файла успешно завершено. Прочитано строк = %1")
                     .arg(_paddr.data()->size()));
        if(!_paddr.data()->isEmpty())
        {
//                QString currTime=QDateTime::currentDateTime().toString("dd.MM.yyyy hh:mm:ss.zzz");
//                qDebug().noquote() << "onProcessOfOpenFinished BEGIN"
//                         << currTime
//                         << this->thread()->currentThreadId();

            emit toDebug(objectName(),
                         QString("Начало обработки прочитанной базы."));

            QProgressDialog *dialog = new QProgressDialog;
            dialog->setWindowTitle(trUtf8("Обработка базы (2/3)"));
            dialog->setLabelText(trUtf8("Обрабатывается файл. Строк: \"%1\". \nОжидайте ...")
                                 .arg(_paddr.data()->size()));
            dialog->setCancelButtonText(trUtf8("Отмена"));
            QObject::connect(dialog, SIGNAL(canceled()),
                             &_futureWatcherParser, SLOT(cancel()));
            QObject::connect(&_futureWatcherParser, SIGNAL(progressRangeChanged(int,int)),
                             dialog, SLOT(setRange(int,int)));
            QObject::connect(&_futureWatcherParser, SIGNAL(progressValueChanged(int)),
                             dialog, SLOT(setValue(int)));
            QObject::connect(&_futureWatcherParser, SIGNAL(finished()),
                             dialog, SLOT(deleteLater()));

            QFuture<void> f1 = QtConcurrent::map(*_paddr,
                                                 parsingAddress
                                                 );
            // Start the computation.
            _futureWatcherParser.setFuture(f1);
            dialog->exec();

//            currTime=QDateTime::currentDateTime().toString("dd.MM.yyyy hh:mm:ss.zzz");
//            qDebug().noquote() << "onProcessOfOpenFinished END"
//                               << currTime
//                               << this->thread()->currentThreadId();
        }
Esempio n. 9
0
void Database::createModel()
{
    clear();
    _model = new QSqlTableModel;
    _model->setTable(TableName);
    _model->setEditStrategy(QSqlTableModel::OnManualSubmit);
    _model->select();

    if(_model->lastError().isValid())
    {
        emit toDebug(objectName(),
                     "При создании модели возникла ошибка: "+_model->lastError().text());
    }
    else
    {
        emit toDebug(objectName(),
                     QString("Модель успешно создана и открыта."));
//        emit selectedRows(_model->rowCount());
    }
}
Esempio n. 10
0
void Database::updateTableModel()
{
    emit toDebug(objectName(),
                 QString("Обновляется отображение модели"));
//    qDebug() << "_model" << _model << _model->rowCount();
    if(_model!=nullptr)
    {
        _model->select();
        emit selectedRows(_model->rowCount());
    }
    else
        emit selectedRows(0);
}
Esempio n. 11
0
void Database::removeConnection()
{
//    qDebug() << "removeConnection()";
    if(!_connected)
        return;
    clear();
    QStringList cNames = QSqlDatabase::connectionNames();
    if(!cNames.isEmpty())
    {
        emit toDebug(objectName(),
                     QString("Удаляем соединение к базе '%1'.").arg(cNames.first()));
        QSqlDatabase::removeDatabase(cNames.first());
    }
    _connected=false;
}
Esempio n. 12
0
void Database::openBase(QString filename)
{
//    qDebug() << "Database openBase" << filename << this->thread()->currentThreadId();
    emit baseOpening();
    emit toDebug(objectName(),
                 QString("Открывается база данных '%1'.").arg(filename));
    if(filename!=baseName())
        removeConnection();
    setBaseName(filename);
    if(!_connected)
        createConnection();
    if(!_connected)
        return;
    createTable();
    createModel();
    emit baseOpened();
}
Esempio n. 13
0
QString Tester::test(const InputDataSet &dataSet) {
    if (target->getRecArea() == "")
        throw NetNotTuted();

    QString answer("Ответы для образов: ");
    for(int i = 0; i < dataSet.size(); ++i) {
        InputData in = *dataSet[i];
        if(dataSet[i]->values.size() != target->getInSize())
            throw InputsNeuNetInLayerSizeMismatch();
        OutputData out = target->getResponse(in);

        int maxPos = findMax(out);
        answer.append(target->getRecArea()[maxPos]);
        answer.append(' ');
    }
    emit toDebug(answer);
    return answer;
}
Esempio n. 14
0
        void visit(EnumDeclaration *ed)
        {
            if (ed->semanticRun >= PASSobj)  // already written
                return;
            //printf("EnumDeclaration::toObjFile('%s')\n", ed->toChars());

            if (ed->errors || ed->type->ty == Terror)
            {
                ed->error("had semantic errors when compiling");
                return;
            }

            if (ed->isAnonymous())
                return;

            if (global.params.symdebug)
                toDebug(ed);

            genTypeInfo(ed->type, NULL);

            TypeEnum *tc = (TypeEnum *)ed->type;
            if (!tc->sym->members || ed->type->isZeroInit())
                ;
            else
            {
                enum_SC scclass = SCglobal;
                if (ed->isInstantiated())
                    scclass = SCcomdat;

                // Generate static initializer
                toInitializer(ed);
                ed->sinit->Sclass = scclass;
                ed->sinit->Sfl = FLdata;
                DtBuilder dtb;
                Expression_toDt(tc->sym->defaultval, &dtb);
                ed->sinit->Sdt = dtb.finish();
                outdata(ed->sinit);
            }
            ed->semanticRun = PASSobj;
        }
Esempio n. 15
0
void EnumDeclaration::toObjFile(int multiobj)
{
    if (semanticRun >= PASSobj)  // already written
        return;
    //printf("EnumDeclaration::toObjFile('%s')\n", toChars());

    if (errors || type->ty == Terror)
    {   error("had semantic errors when compiling");
        return;
    }

    if (isAnonymous())
        return;

    if (global.params.symdebug)
        toDebug(this);

    type->genTypeInfo(NULL);

    TypeEnum *tc = (TypeEnum *)type;
    if (!tc->sym->members || type->isZeroInit())
        ;
    else
    {
        enum_SC scclass = SCglobal;
        if (isInstantiated())
            scclass = SCcomdat;

        // Generate static initializer
        toInitializer();
        sinit->Sclass = scclass;
        sinit->Sfl = FLdata;
        tc->sym->defaultval->toDt(&sinit->Sdt);
        outdata(sinit);
    }
    semanticRun = PASSobj;
}
Esempio n. 16
0
        void visit(InterfaceDeclaration *id)
        {
            //printf("InterfaceDeclaration::toObjFile('%s')\n", id->toChars());

            if (id->type->ty == Terror)
            {
                id->error("had semantic errors when compiling");
                return;
            }

            if (!id->members)
                return;

            if (global.params.symdebug)
                toDebug(id);

            enum_SC scclass = SCglobal;
            if (id->isInstantiated())
                scclass = SCcomdat;

            // Put out the members
            for (size_t i = 0; i < id->members->dim; i++)
            {
                Dsymbol *member = (*id->members)[i];
                visitNoMultiObj(member);
            }

            // Generate C symbols
            toSymbol(id);

            //////////////////////////////////////////////

            // Put out the TypeInfo
            genTypeInfo(id->type, NULL);
            id->type->vtinfo->accept(this);

            //////////////////////////////////////////////

            // Put out the ClassInfo
            id->csym->Sclass = scclass;
            id->csym->Sfl = FLdata;

            /* The layout is:
               {
                    void **vptr;
                    monitor_t monitor;
                    byte[] initializer;         // static initialization data
                    char[] name;                // class name
                    void *[] vtbl;
                    Interface[] interfaces;
                    Object *base;               // base class
                    void *destructor;
                    void *invariant;            // class invariant
                    uint flags;
                    void *deallocator;
                    OffsetTypeInfo[] offTi;
                    void *defaultConstructor;
                    //const(MemberInfo[]) function(string) xgetMembers;   // module getMembers() function
                    void* xgetRTInfo;
                    //TypeInfo typeinfo;
               }
             */
            dt_t *dt = NULL;

            if (Type::typeinfoclass)
                dtxoff(&dt, toVtblSymbol(Type::typeinfoclass), 0, TYnptr); // vtbl for ClassInfo
            else
                dtsize_t(&dt, 0);                // BUG: should be an assert()
            dtsize_t(&dt, 0);                    // monitor

            // initializer[]
            dtsize_t(&dt, 0);                    // size
            dtsize_t(&dt, 0);                    // initializer

            // name[]
            const char *name = id->toPrettyChars();
            size_t namelen = strlen(name);
            dtsize_t(&dt, namelen);
            dtabytes(&dt, TYnptr, 0, namelen + 1, name);

            // vtbl[]
            dtsize_t(&dt, 0);
            dtsize_t(&dt, 0);

            // (*vtblInterfaces)[]
            unsigned offset;
            dtsize_t(&dt, id->vtblInterfaces->dim);
            if (id->vtblInterfaces->dim)
            {
                offset = Target::classinfosize;    // must be ClassInfo.size
                if (Type::typeinfoclass)
                {
                    if (Type::typeinfoclass->structsize != offset)
                    {
                        id->error("mismatch between dmd and object.d or object.di found. Check installation and import paths with -v compiler switch.");
                        fatal();
                    }
                }
                dtxoff(&dt, id->csym, offset, TYnptr);      // (*)
            }
            else
            {
                offset = 0;
                dtsize_t(&dt, 0);
            }

            // base
            assert(!id->baseClass);
            dtsize_t(&dt, 0);

            // dtor
            dtsize_t(&dt, 0);

            // invariant
            dtsize_t(&dt, 0);

            // flags
            ClassFlags::Type flags = ClassFlags::hasOffTi | ClassFlags::hasTypeInfo;
            if (id->isCOMinterface()) flags |= ClassFlags::isCOMclass;
            dtsize_t(&dt, flags);

            // deallocator
            dtsize_t(&dt, 0);

            // offTi[]
            dtsize_t(&dt, 0);
            dtsize_t(&dt, 0);            // null for now, fix later

            // defaultConstructor
            dtsize_t(&dt, 0);

            // xgetMembers
            //dtsize_t(&dt, 0);

            // xgetRTInfo
            // xgetRTInfo
            if (id->getRTInfo)
                Expression_toDt(id->getRTInfo, &dt);
            else
                dtsize_t(&dt, 0);       // no pointers

            //dtxoff(&dt, toSymbol(id->type->vtinfo), 0, TYnptr); // typeinfo

            //////////////////////////////////////////////

            // Put out (*vtblInterfaces)[]. Must immediately follow csym, because
            // of the fixup (*)

            offset += id->vtblInterfaces->dim * (4 * Target::ptrsize);
            for (size_t i = 0; i < id->vtblInterfaces->dim; i++)
            {
                BaseClass *b = (*id->vtblInterfaces)[i];
                ClassDeclaration *base = b->sym;

                // ClassInfo
                dtxoff(&dt, toSymbol(base), 0, TYnptr);

                // vtbl[]
                dtsize_t(&dt, 0);
                dtsize_t(&dt, 0);

                // this offset
                dtsize_t(&dt, b->offset);
            }

            id->csym->Sdt = dt;
            out_readonly(id->csym);
            outdata(id->csym);
            if (id->isExport())
                objmod->export_symbol(id->csym, 0);
        }
Esempio n. 17
0
        void visit(ClassDeclaration *cd)
        {
            //printf("ClassDeclaration::toObjFile('%s')\n", cd->toChars());

            if (cd->type->ty == Terror)
            {
                cd->error("had semantic errors when compiling");
                return;
            }

            if (!cd->members)
                return;

            if (multiobj && !cd->hasStaticCtorOrDtor())
            {
                obj_append(cd);
                return;
            }

            if (global.params.symdebug)
                toDebug(cd);

            assert(!cd->scope);     // semantic() should have been run to completion

            enum_SC scclass = SCglobal;
            if (cd->isInstantiated())
                scclass = SCcomdat;

            // Put out the members
            for (size_t i = 0; i < cd->members->dim; i++)
            {
                Dsymbol *member = (*cd->members)[i];
                /* There might be static ctors in the members, and they cannot
                 * be put in separate obj files.
                 */
                member->accept(this);
            }

            // Generate C symbols
            toSymbol(cd);
            toVtblSymbol(cd);
            Symbol *sinit = toInitializer(cd);

            //////////////////////////////////////////////

            // Generate static initializer
            sinit->Sclass = scclass;
            sinit->Sfl = FLdata;
            ClassDeclaration_toDt(cd, &sinit->Sdt);
            out_readonly(sinit);
            outdata(sinit);

            //////////////////////////////////////////////

            // Put out the TypeInfo
            genTypeInfo(cd->type, NULL);
            //toObjFile(cd->type->vtinfo, multiobj);

            //////////////////////////////////////////////

            // Put out the ClassInfo
            cd->csym->Sclass = scclass;
            cd->csym->Sfl = FLdata;

            /* The layout is:
               {
                    void **vptr;
                    monitor_t monitor;
                    byte[] initializer;         // static initialization data
                    char[] name;                // class name
                    void *[] vtbl;
                    Interface[] interfaces;
                    ClassInfo *base;            // base class
                    void *destructor;
                    void *invariant;            // class invariant
                    ClassFlags flags;
                    void *deallocator;
                    OffsetTypeInfo[] offTi;
                    void *defaultConstructor;
                    //const(MemberInfo[]) function(string) xgetMembers;   // module getMembers() function
                    void *xgetRTInfo;
                    //TypeInfo typeinfo;
               }
             */
            dt_t *dt = NULL;
            unsigned offset = Target::classinfosize;    // must be ClassInfo.size
            if (Type::typeinfoclass)
            {
                if (Type::typeinfoclass->structsize != Target::classinfosize)
                {
        #ifdef DEBUG
                    printf("Target::classinfosize = x%x, Type::typeinfoclass->structsize = x%x\n", offset, Type::typeinfoclass->structsize);
        #endif
                    cd->error("mismatch between dmd and object.d or object.di found. Check installation and import paths with -v compiler switch.");
                    fatal();
                }
            }

            if (Type::typeinfoclass)
                dtxoff(&dt, toVtblSymbol(Type::typeinfoclass), 0, TYnptr); // vtbl for ClassInfo
            else
                dtsize_t(&dt, 0);                // BUG: should be an assert()
            dtsize_t(&dt, 0);                    // monitor

            // initializer[]
            assert(cd->structsize >= 8 || (cd->cpp && cd->structsize >= 4));
            dtsize_t(&dt, cd->structsize);           // size
            dtxoff(&dt, sinit, 0, TYnptr);      // initializer

            // name[]
            const char *name = cd->ident->toChars();
            size_t namelen = strlen(name);
            if (!(namelen > 9 && memcmp(name, "TypeInfo_", 9) == 0))
            {
                name = cd->toPrettyChars();
                namelen = strlen(name);
            }
            dtsize_t(&dt, namelen);
            dtabytes(&dt, TYnptr, 0, namelen + 1, name);

            // vtbl[]
            dtsize_t(&dt, cd->vtbl.dim);
            dtxoff(&dt, cd->vtblsym, 0, TYnptr);

            // interfaces[]
            dtsize_t(&dt, cd->vtblInterfaces->dim);
            if (cd->vtblInterfaces->dim)
                dtxoff(&dt, cd->csym, offset, TYnptr);      // (*)
            else
                dtsize_t(&dt, 0);

            // base
            if (cd->baseClass)
                dtxoff(&dt, toSymbol(cd->baseClass), 0, TYnptr);
            else
                dtsize_t(&dt, 0);

            // destructor
            if (cd->dtor)
                dtxoff(&dt, toSymbol(cd->dtor), 0, TYnptr);
            else
                dtsize_t(&dt, 0);

            // invariant
            if (cd->inv)
                dtxoff(&dt, toSymbol(cd->inv), 0, TYnptr);
            else
                dtsize_t(&dt, 0);

            // flags
            ClassFlags::Type flags = ClassFlags::hasOffTi;
            if (cd->isCOMclass()) flags |= ClassFlags::isCOMclass;
            if (cd->isCPPclass()) flags |= ClassFlags::isCPPclass;
            flags |= ClassFlags::hasGetMembers;
            flags |= ClassFlags::hasTypeInfo;
            if (cd->ctor)
                flags |= ClassFlags::hasCtor;
            for (ClassDeclaration *pc = cd; pc; pc = pc->baseClass)
            {
                if (pc->dtor)
                {
                    flags |= ClassFlags::hasDtor;
                    break;
                }
            }
            if (cd->isabstract)
                flags |= ClassFlags::isAbstract;
            for (ClassDeclaration *pc = cd; pc; pc = pc->baseClass)
            {
                if (pc->members)
                {
                    for (size_t i = 0; i < pc->members->dim; i++)
                    {
                        Dsymbol *sm = (*pc->members)[i];
                        //printf("sm = %s %s\n", sm->kind(), sm->toChars());
                        if (sm->hasPointers())
                            goto L2;
                    }
                }
            }
            flags |= ClassFlags::noPointers;
          L2:
            dtsize_t(&dt, flags);


            // deallocator
            if (cd->aggDelete)
                dtxoff(&dt, toSymbol(cd->aggDelete), 0, TYnptr);
            else
                dtsize_t(&dt, 0);

            // offTi[]
            dtsize_t(&dt, 0);
            dtsize_t(&dt, 0);            // null for now, fix later

            // defaultConstructor
            if (cd->defaultCtor && !(cd->defaultCtor->storage_class & STCdisable))
                dtxoff(&dt, toSymbol(cd->defaultCtor), 0, TYnptr);
            else
                dtsize_t(&dt, 0);

            // xgetRTInfo
            if (cd->getRTInfo)
                Expression_toDt(cd->getRTInfo, &dt);
            else if (flags & ClassFlags::noPointers)
                dtsize_t(&dt, 0);
            else
                dtsize_t(&dt, 1);

            //dtxoff(&dt, toSymbol(type->vtinfo), 0, TYnptr); // typeinfo

            //////////////////////////////////////////////

            // Put out (*vtblInterfaces)[]. Must immediately follow csym, because
            // of the fixup (*)

            offset += cd->vtblInterfaces->dim * (4 * Target::ptrsize);
            for (size_t i = 0; i < cd->vtblInterfaces->dim; i++)
            {
                BaseClass *b = (*cd->vtblInterfaces)[i];
                ClassDeclaration *id = b->sym;

                /* The layout is:
                 *  struct Interface
                 *  {
                 *      ClassInfo *interface;
                 *      void *[] vtbl;
                 *      size_t offset;
                 *  }
                 */

                // Fill in vtbl[]
                b->fillVtbl(cd, &b->vtbl, 1);

                dtxoff(&dt, toSymbol(id), 0, TYnptr);         // ClassInfo

                // vtbl[]
                dtsize_t(&dt, id->vtbl.dim);
                dtxoff(&dt, cd->csym, offset, TYnptr);

                dtsize_t(&dt, b->offset);                        // this offset

                offset += id->vtbl.dim * Target::ptrsize;
            }

            // Put out the (*vtblInterfaces)[].vtbl[]
            // This must be mirrored with ClassDeclaration::baseVtblOffset()
            //printf("putting out %d interface vtbl[]s for '%s'\n", vtblInterfaces->dim, toChars());
            for (size_t i = 0; i < cd->vtblInterfaces->dim; i++)
            {
                BaseClass *b = (*cd->vtblInterfaces)[i];
                ClassDeclaration *id = b->sym;

                //printf("    interface[%d] is '%s'\n", i, id->toChars());
                size_t j = 0;
                if (id->vtblOffset())
                {
                    // First entry is ClassInfo reference
                    //dtxoff(&dt, toSymbol(id), 0, TYnptr);

                    // First entry is struct Interface reference
                    dtxoff(&dt, cd->csym, Target::classinfosize + i * (4 * Target::ptrsize), TYnptr);
                    j = 1;
                }
                assert(id->vtbl.dim == b->vtbl.dim);
                for (; j < id->vtbl.dim; j++)
                {
                    assert(j < b->vtbl.dim);
        #if 0
                    RootObject *o = b->vtbl[j];
                    if (o)
                    {
                        printf("o = %p\n", o);
                        assert(o->dyncast() == DYNCAST_DSYMBOL);
                        Dsymbol *s = (Dsymbol *)o;
                        printf("s->kind() = '%s'\n", s->kind());
                    }
        #endif
                    FuncDeclaration *fd = b->vtbl[j];
                    if (fd)
                        dtxoff(&dt, toThunkSymbol(fd, b->offset), 0, TYnptr);
                    else
                        dtsize_t(&dt, 0);
                }
            }

            // Put out the overriding interface vtbl[]s.
            // This must be mirrored with ClassDeclaration::baseVtblOffset()
            //printf("putting out overriding interface vtbl[]s for '%s' at offset x%x\n", toChars(), offset);
            ClassDeclaration *pc;
            for (pc = cd->baseClass; pc; pc = pc->baseClass)
            {
                for (size_t k = 0; k < pc->vtblInterfaces->dim; k++)
                {
                    BaseClass *bs = (*pc->vtblInterfaces)[k];
                    FuncDeclarations bvtbl;
                    if (bs->fillVtbl(cd, &bvtbl, 0))
                    {
                        //printf("\toverriding vtbl[] for %s\n", bs->sym->toChars());
                        ClassDeclaration *id = bs->sym;

                        size_t j = 0;
                        if (id->vtblOffset())
                        {
                            // First entry is ClassInfo reference
                            //dtxoff(&dt, toSymbol(id), 0, TYnptr);

                            // First entry is struct Interface reference
                            dtxoff(&dt, toSymbol(pc), Target::classinfosize + k * (4 * Target::ptrsize), TYnptr);
                            j = 1;
                        }

                        for (; j < id->vtbl.dim; j++)
                        {
                            assert(j < bvtbl.dim);
                            FuncDeclaration *fd = bvtbl[j];
                            if (fd)
                                dtxoff(&dt, toThunkSymbol(fd, bs->offset), 0, TYnptr);
                            else
                                dtsize_t(&dt, 0);
                        }
                    }
                }
            }

            cd->csym->Sdt = dt;
            // ClassInfo cannot be const data, because we use the monitor on it
            outdata(cd->csym);
            if (cd->isExport())
                objmod->export_symbol(cd->csym, 0);

            //////////////////////////////////////////////

            // Put out the vtbl[]
            //printf("putting out %s.vtbl[]\n", toChars());
            dt = NULL;
            if (cd->vtblOffset())
                dtxoff(&dt, cd->csym, 0, TYnptr);           // first entry is ClassInfo reference
            for (size_t i = cd->vtblOffset(); i < cd->vtbl.dim; i++)
            {
                FuncDeclaration *fd = cd->vtbl[i]->isFuncDeclaration();

                //printf("\tvtbl[%d] = %p\n", i, fd);
                if (fd && (fd->fbody || !cd->isAbstract()))
                {
                    // Ensure function has a return value (Bugzilla 4869)
                    fd->functionSemantic();

                    Symbol *s = toSymbol(fd);

                    if (cd->isFuncHidden(fd))
                    {
                        /* fd is hidden from the view of this class.
                         * If fd overlaps with any function in the vtbl[], then
                         * issue 'hidden' error.
                         */
                        for (size_t j = 1; j < cd->vtbl.dim; j++)
                        {
                            if (j == i)
                                continue;
                            FuncDeclaration *fd2 = cd->vtbl[j]->isFuncDeclaration();
                            if (!fd2->ident->equals(fd->ident))
                                continue;
                            if (fd->leastAsSpecialized(fd2) || fd2->leastAsSpecialized(fd))
                            {
                                TypeFunction *tf = (TypeFunction *)fd->type;
                                if (tf->ty == Tfunction)
                                    cd->error("use of %s%s is hidden by %s; use 'alias %s = %s.%s;' to introduce base class overload set",
                                        fd->toPrettyChars(),
                                        parametersTypeToChars(tf->parameters, tf->varargs),
                                        cd->toChars(),

                                        fd->toChars(),
                                        fd->parent->toChars(),
                                        fd->toChars());
                                else
                                    cd->error("use of %s is hidden by %s", fd->toPrettyChars(), cd->toChars());
                                break;
                            }
                        }
                    }

                    dtxoff(&dt, s, 0, TYnptr);
                }
                else
                    dtsize_t(&dt, 0);
            }
            cd->vtblsym->Sdt = dt;
            cd->vtblsym->Sclass = scclass;
            cd->vtblsym->Sfl = FLdata;
            out_readonly(cd->vtblsym);
            outdata(cd->vtblsym);
            if (cd->isExport())
                objmod->export_symbol(cd->vtblsym,0);
        }
 //-------------------------------------------------------------------------
 Log::Params RTPReceiverChannelAudio::debug(const char *message) const
 {
   return Log::Params(message, toDebug());
 }
Esempio n. 19
0
void Database::createTable()
{
    QStringList tables=QSqlDatabase::database().tables();
    if(tables.isEmpty() || !tables.contains(TableName))
    {
        QSqlQuery query;
        QString str =
                QString("CREATE TABLE IF NOT EXISTS %18 ( "
                        "'%1' INTEGER PRIMARY KEY NOT NULL, "
                        "'%2' TEXT, "
                        "'%3' TEXT, "
                        "'%4' TEXT, "
                        "'%5' TEXT, "
                        "'%6' TEXT, "
                        "'%7' TEXT, "
                        "'%8' TEXT, "
                        "'%9' TEXT, "
                        "'%10' TEXT, "
                        "'%11' TEXT, "
                        "'%12' TEXT, "
                        "'%13' TEXT, "
                        "'%14' TEXT, "
                        "'%15' TEXT, "
                        "'%16' TEXT, "
                        "'%17' TEXT "
                        ")"
                        )
                .arg(MapColumnNames[BUILD_ID])
                .arg(MapColumnNames[STREET])
                .arg(MapColumnNames[STREET_ID])
                .arg(MapColumnNames[KORP])
                .arg(MapColumnNames[BUILD])
                .arg(MapColumnNames[TYPE_OF_STREET])
                .arg(MapColumnNames[ADDITIONAL])
                .arg(MapColumnNames[TYPE_OF_CITY1])
                .arg(MapColumnNames[CITY1])
                .arg(MapColumnNames[TYPE_OF_CITY2])
                .arg(MapColumnNames[CITY2])
                .arg(MapColumnNames[DISTRICT])
                .arg(MapColumnNames[FSUBJ])
                .arg(MapColumnNames[RAW_ADDR])
                .arg(MapColumnNames[LITERA])
                .arg(MapColumnNames[CORRECT])
                .arg(MapColumnNames[TYPE_OF_FSUBJ])
                .arg(TableName);

        if(!query.exec(str))
            emit toDebug(objectName(),
                         QString("Невозможно создать таблицу '%1'. Ошибка: '%2'.")
                         .arg(TableName)
                         .arg(query.lastError().text()));
        else
            emit toDebug(objectName(),
                         QString("Таблица '%1' была создана.").arg(TableName));

        str =
        "PRAGMA synchronous = OFF;"
        "PRAGMA journal_mode = OFF;"
        "CREATE INDEX bid_indx ON base1(BUILD_ID);"
        "CREATE INDEX sid_indx ON base1(STREET_ID);"
        "CREATE INDEX tof_indx ON base1(TYPE_OF_FSUBJ);"
        "CREATE INDEX fs_indx ON base1(FSUBJ);"
        "CREATE INDEX d_indx ON base1(DISTRICT);"
        "CREATE INDEX toc1_indx ON base1(TYPE_OF_CITY1);"
        "CREATE INDEX c1_indx ON base1(CITY1);"
        "CREATE INDEX toc2_indx ON base1(TYPE_OF_CITY2);"
        "CREATE INDEX c2_indx ON base1(CITY2);"
        "CREATE INDEX tos_indx ON base1(TYPE_OF_STREET);"
        "CREATE INDEX s_indx ON base1(STREET);"
        "CREATE INDEX b_indx ON base1(BUILD);"
        "CREATE INDEX k_indx ON base1(KORP);"
        "CREATE INDEX l_indx ON base1(LITERA);"
        "CREATE INDEX c_indx ON base1(CORRECT);"
        "CREATE INDEX a_indx ON base1(ADDITIONAL);"
        "CREATE INDEX all_indx ON base1(STREET, STREET_ID, KORP, BUILD, BUILD_ID, ADDITIONAL, DISTRICT, FSUBJ, TYPE_OF_CITY1, CITY1, TYPE_OF_CITY2, CITY2, TYPE_OF_STREET, LITERA, CORRECT, TYPE_OF_FSUBJ);"
        "CREATE INDEX all2_indx ON base1(TYPE_OF_FSUBJ, FSUBJ, DISTRICT, TYPE_OF_CITY1, CITY1, TYPE_OF_CITY2, CITY2, TYPE_OF_STREET, STREET, BUILD, KORP, LITERA, CORRECT);";
        QStringList queries = str.split(";");
        foreach (QString q, queries) {
            if(q.isEmpty())
                continue;
            if(!query.exec(q))
                emit toDebug(objectName(),
                             QString("Невозможно выполнить '%1'. Ошибка: '%2'.")
                             .arg(q)
                             .arg(query.lastError().text()));
            else
                emit toDebug(objectName(),
                             QString("Выполнен запрос '%1'").arg(q));
        }
    }