void BFS()
{
    rear=0,front=1;
    queue[0]=getAddress(square);
    father[0]=-1,operation[0]=0;
    setRecord(square);
    while(rear<front)
    {
        getSquare(queue[rear]);
        for(int i=1; i<=3; i++)
        {
            copy();
            operate(i,temp);
            if(setRecord(temp))
            {
                queue[front]=getAddress(temp);
                father[front]=rear;
                operation[front]=i;
                if(check())
                {
                    getResult(front);
                    return;
                }
                front++;
            }
        }
        rear++;
    }
}
Ejemplo n.º 2
0
// TODO: see if we can make this one command
static void bulkSetRecords(stKVDatabase *database, stList *records) {
    startTransaction(database);
    stTry {
        for(int32_t i=0; i<stList_length(records); i++) {
            stKVDatabaseBulkRequest *request = stList_get(records, i);
            switch(request->type) {
                case UPDATE:
                updateRecord(database, request->key, request->value, request->size);
                break;
                case INSERT:
                insertRecord(database, request->key, request->value, request->size);
                break;
                case SET:
                setRecord(database, request->key, request->value, request->size);
                break;
            }
        }
        commitTransaction(database);
    }stCatch(ex) {
        abortTransaction(database);
        stThrowNewCause(
                ex,
                ST_KV_DATABASE_EXCEPTION_ID,
                "MySQL bulk set records failed");
    }stTryEnd;
}
Ejemplo n.º 3
0
void QSDLEditor::loadBlob(plVaultBlob blob)
{
    fSDLList->clear();
    fSDLVersion = -1;
    if (blob.getSize() == 0)
        return;

    hsRAMStream S;
    S.setVer(PlasmaVer::pvPots);
    S.copyFrom(blob.getData(), blob.getSize());

    plStateDataRecord::ReadStreamHeader(&S, fSDLName, fSDLVersion, NULL);
    plStateDescriptor* desc = fSDLMgr->GetDescriptor(fSDLName, fSDLVersion);
    if (desc == NULL) {
        QMessageBox msgBox(QMessageBox::Critical, tr("Error"),
                           tr("No SDL Descriptor for %1 (version %2)")
                           .arg(~fSDLName).arg(fSDLVersion),
                           QMessageBox::Ok, this);
        msgBox.exec();
        return;
    }
    plStateDataRecord* rec = new plStateDataRecord();
    rec->setDescriptor(desc);
    rec->read(&S, fResMgr);
    if (S.size() != S.pos()) {
        plDebug::Debug("[%s] SDL size-read difference: %d",
                       fSDLName.cstr(), S.size() - S.pos());
    }
    setRecord(rec, true);
}
Ejemplo n.º 4
0
void QDeclarativeNdefTextRecord::setText(const QString &text)
{
    QNdefNfcTextRecord textRecord(record());

    if (textRecord.text() == text)
        return;

    textRecord.setText(text);
    setRecord(textRecord);
    emit textChanged();
}
void QDeclarativeNdefUriRecord::setUri(const QString &uri)
{
    QNdefNfcUriRecord uriRecord(record());

    if (uriRecord.uri() == uri)
        return;

    uriRecord.setUri(uri);
    setRecord(uriRecord);
    emit uriChanged();
}
Ejemplo n.º 6
0
bool CulistGui::loadTrace(QString tf)
{    
	if( !tf.isEmpty() )
	{
		QFile f(tf);
		if(!f.open(QIODevice::ReadOnly))
			return false;
		_lastTraceFile = tf;
		QTextStream ts(&f);
		while(!ts.atEnd())
		{
			QStringList sl = ts.readAll().split(QRegExp("[\n\r]"));
			//QStringList traceData;
			foreach( QString l, sl )
			{
				if( !l.isEmpty() )
				{
					//traceData << l;

					PAstm prec = ASTMFactory::instance().parse(l);

					if (!prec.isNull())
					{
						switch( prec->_type )
						{
							case EHeader:
								on_actionAdd_Session_triggered();
								on_actionAdd_Message_triggered();
//								on_actionAdd_Header_triggered();
								break;
/*							case EPatient:
								on_actionInsert_Patient_triggered();
								break;
							case EOrder:
								on_actionAdd_Order_triggered();
								break;
							case EResult:
								on_actionAdd_Result_triggered();
								break;
							case EComment:
								on_actionAdd_Comment_triggered();
								break;
							case ETerminator:
								on_actionAdd_Terminator_triggered();
								break;
*/
						}
						setRecord( prec );
					}
				}				
			}
			//_records.setStringList(traceData);
		}
	}
Ejemplo n.º 7
0
/*!
    Inserts the \a record at position \a row. If \a row is negative,
    the record will be appended to the end. Calls insertRows() and
    setRecord() internally.

    Returns \c true if the record could be inserted, otherwise false.

    Changes are submitted immediately for OnFieldChange and
    OnRowChange. Failure does not leave a new row in the model.

    \sa insertRows(), removeRows(), setRecord()
*/
bool QSqlTableModel::insertRecord(int row, const QSqlRecord &record)
{
    if (row < 0)
        row = rowCount();
    if (!insertRow(row, QModelIndex()))
        return false;
    if (!setRecord(row, record)) {
        revertRow(row);
        return false;
    }
    return true;
}
Ejemplo n.º 8
0
bool Table::setData(int row, int column, const QVariant &data)
{
    QSqlRecord r = record(row);
    r.setValue(column, data);

    bool ret = setRecord(row, r);

    if(!ret && lastError().isValid())
        qWarning() << lastError();

    return ret;
}
Ejemplo n.º 9
0
	void CsvSerializer::writeHeader() {
		values.resize(record->size());
		if (record->size() == 0) {
			throw std::runtime_error("Record has no fields");
		}
		else {
			int i = 0;
			for (Record::const_iterator it = record->begin(); it != record->end(); ++it)
				values.at(i++) = it->getName();
			setRecord();
		}
	}
Ejemplo n.º 10
0
  /**
   * Push solutions into the solution container
   * 
   * @param sv solution vector
   * @param info informational parameter 
   */
  void pushSolutions (GVector < Solution > &sv, BNBBranchInfo * info = NULL)
  {
    while (!sv.empty ()) {
      Solution s;
      s = sv.back ();
      sv.pop_back ();
      
      if(!mSetFactory->discard (s, getRecord())){
	setRecord(s.getValue());
      }
      mSolutionContainer->push(s); 
    }
  }
Ejemplo n.º 11
0
void XModel::editRecordById(QString id, QSqlRecord rec){
	setFilter(QString("%1.id = '%2'").arg(m_tbl).arg(id));
	if (rowCount() == 1) {
		bool b = setRecord(0, rec);
	    if(b == false){
	    	QSqlError err = lastError();
	    	yERROR(err.text());
	    }
	    submit();
	} else {
		yERROR(QString("Can't find %1 to edit.").arg(id));
	}
}
Ejemplo n.º 12
0
/*!
    Inserts the \a record after \a row. If \a row is negative, the
    record will be appended to the end. Calls insertRows() and
    setRecord() internally.

    Returns true if the row could be inserted, otherwise false.

    \sa insertRows(), removeRows()
*/
bool QSqlTableModel::insertRecord(int row, const QSqlRecord &record)
{
    Q_D(QSqlTableModel);
    if (row < 0)
        row = rowCount();
    if (!insertRow(row, QModelIndex()))
        return false;
    if (!setRecord(row, record))
        return false;
    if (d->strategy == OnFieldChange || d->strategy == OnRowChange)
        return submit();
    return true;
}
Ejemplo n.º 13
0
void CSMWorld::InfoCollection::load (const Info& record, bool base)
{
    int index = searchId (record.mId);

    if (index==-1)
    {
        // new record
        Record<Info> record2;
        record2.mState = base ? RecordBase::State_BaseOnly : RecordBase::State_ModifiedOnly;
        (base ? record2.mBase : record2.mModified) = record;

        int index = -1;

        std::string topic = Misc::StringUtils::lowerCase (record2.get().mTopicId);

        if (!record2.get().mPrev.empty())
        {
            index = getInfoIndex (record2.get().mPrev, topic);

            if (index!=-1)
                ++index;
        }

        if (index==-1 && !record2.get().mNext.empty())
        {
            index = getInfoIndex (record2.get().mNext, topic);
        }

        if (index==-1)
        {
            Range range = getTopicRange (topic);

            index = std::distance (getRecords().begin(), range.second);
        }

        insertRecord (record2, index);
    }
    else
    {
        // old record
        Record<Info> record2 = getRecord (index);

        if (base)
            record2.mBase = record;
        else
            record2.setModified (record);

        setRecord (index, record2);
    }
}
Ejemplo n.º 14
0
/*
名称|运转|备注
名称|运转|备注
*/
void GasSysDlg::OnInitList()
{
	initList(m_permCListCtrl,m_permDataModel);
	initList(m_tempCListCtrl,m_tempDataModel);
	ArrayVector datasVector;

	//获取地面系统数据
	ReportDataHelper::ReadDatas(PERMENT_OBJCT_NAME,datasVector,3);
	m_numPermSys = _T("");
	m_permRecords.clear();
	if(datasVector.size() > 0) 
	{
		setRecord(m_permRecords,datasVector,m_numPermSys);
	}

	datasVector.clear();
	//获取井下系统数据
	ReportDataHelper::ReadDatas(TEMPGAS_OBJCT_NAME,datasVector,3);
	m_numTempSys = _T("");
	m_tempRecords.clear();
	if(datasVector.size() > 0) 
	{
		setRecord(m_tempRecords,datasVector,m_numTempSys);
	}

	UpdateData(FALSE);
	if(IsNum(m_numPermSys))
	{ 
		SetPermItems(_ttoi(m_numPermSys));
	}
	if(IsNum(m_numTempSys))
	{ 
		SetTempItems(_ttoi(m_numTempSys));
	}

}
Ejemplo n.º 15
0
void FilmModel::updateFilm(int row, Film f)
{
    QSqlRecord r = record(row);
    r.setValue("name", f.name);
    r.setValue("country", f.country);
    r.setValue("year", f.year);
    r.setValue("actors", f.actors);
    r.setValue("director", f.director);
    r.setValue("type", f.type == serial ? 1 : 0);
    r.setValue("genre", f.genre);
    r.setValue("score", f.score);
    r.setValue("poster", "");
    setRecord(row,r);
    submitAll();
}
Ejemplo n.º 16
0
bool SoundCloudAccountModel::addAccount(const QString &userId, const QString &username, const QString &accessToken,
                                         const QString &refreshToken, const QString &scopes) {
    Logger::log(QString("SoundCloudAccountModel::addAccount(). User ID: %1, Username: %2, Access token: %3, Refresh token: %4, Scopes: %5").arg(userId).arg(username).arg(accessToken).arg(refreshToken).arg(scopes), Logger::LowVerbosity);
    QSqlField userIdField("userId", QVariant::String);
    userIdField.setValue(userId);
    
    QSqlField usernameField("username", QVariant::String);
    usernameField.setValue(username);
        
    QSqlField accessTokenField("accessToken", QVariant::String);
    accessTokenField.setValue(accessToken);
    
    QSqlField refreshTokenField("refreshToken", QVariant::String);
    refreshTokenField.setValue(refreshToken);
    
    QSqlField scopesField("scopes", QVariant::String);
    scopesField.setValue(scopes);

    QSqlRecord record;
    record.append(userIdField);
    record.append(usernameField);
    record.append(accessTokenField);
    record.append(refreshTokenField);
    record.append(scopesField);
        
    const int count = rowCount();
    
    for (int i = 0; i < count; i++) {
        if (data(index(i, 0)) == userId) {
            if (setRecord(i, record)) {
                SoundCloud::setUserId(userId);
                return true;
            }
            
            return false;
        }
    }
    
    if (insertRecord(-1, record)) {
        SoundCloud::setUserId(userId);
        const int count = rowCount();
        emit dataChanged(index(0, 0), index(count - 1, columnCount() - 1));
        emit countChanged(count);
        return true;
    }
    
    return false;
}
Ejemplo n.º 17
0
void QDeclarativeNdefTextRecord::setLocale(const QString &locale)
{
    QNdefNfcTextRecord textRecord(record());

    if (textRecord.locale() == locale)
        return;

    LocaleMatch previous = localeMatch();

    textRecord.setLocale(locale);
    setRecord(textRecord);
    emit localeChanged();

    if (previous != localeMatch())
        emit localeMatchChanged();
}
void MobileTableModel::refreshMobileTable(const QVector<int> mobileMsg)
{
    int fixId,mode,dstAddr,period,selfAddr;
    QString dst,self;
    dst.fill('0',4);
    self.fill('0',4);
    fixId = mobileMsg.at(M_FIXID);
    mode = mobileMsg.at(M_LOC_MODE);
    dstAddr = mobileMsg.at(M_DST_ADDR_LO);
    dstAddr |= (mobileMsg.at(M_DST_ADDR_HI) << 8);
    dst.append(QString::number(dstAddr,16).toUpper());//转为十六进制
    period = mobileMsg.at(M_LOC_PERIOD);
    selfAddr = mobileMsg.at(M_SELF_ADDR_LO);
    selfAddr |= (mobileMsg.at(M_SELF_ADDR_HI) << 8);
    self.append(QString::number(selfAddr,16).toUpper());
    //添加或者更新参考节点配置信息数据表
    setFilter("fixId = " + QString::number(fixId));
    select();
    if(rowCount() == 1)//已经存在,更新数据
    {
        QSqlRecord record = this->record(0);
        record.setValue("fixId",fixId);
        record.setValue("mode", mode);
        record.setValue("dstAddr", dst.right(4));
        record.setValue("period", period);
        record.setValue("selfAddr", self.right(4));
        setRecord(0, record);
        submitAll();
        setFilter("");//清除过滤条件,否则只显示更新的一条
    }
    else if(rowCount() == 0)//不存在,添加新移动节点配置信息
    {
        int row = 0;
        insertRows(row, 1);
        setData(index(row, 1), fixId);
        setData(index(row, 2), mode);
        setData(index(row, 3), dst.right(4));
        setData(index(row, 4), period);
        setData(index(row, 5), self.right(4));
        submitAll();
        setFilter("");//清楚过滤条件,否则只显示更新的一条
        submitAll();
    }
}
Ejemplo n.º 19
0
IOReturn WLCard::setValue(UInt16 rid, UInt16 v)
{
    UInt16 value = v;
    IOReturn ret = setRecord(rid, &value, 2);

    if (ret != kIOReturnSuccess)
        return ret;

    ret = getValue(rid, &value);

    if (ret != kIOReturnSuccess)
        return ret;

    if (value != v) {
        WLLogErr("WLCard::setValue: Failed to set value (0x%x != 0x%x)\n",
                 value, v);
        return kIOReturnError;
    }

    return kIOReturnSuccess;
}
Ejemplo n.º 20
0
void CSMWorld::InfoCollection::load (ESM::ESMReader& reader, bool base, const ESM::Dialogue& dialogue)
{
    std::string id = Misc::StringUtils::lowerCase (dialogue.mId) + "#" +
        reader.getHNOString ("INAM");

    if (reader.isNextSub ("DELE"))
    {
        int index = searchId (id);

        reader.skipRecord();

        if (index==-1)
        {
            // deleting a record that does not exist

            // ignore it for now

            /// \todo report the problem to the user
        }
        else if (base)
        {
            removeRows (index, 1);
        }
        else
        {
            Record<Info> record = getRecord (index);
            record.mState = RecordBase::State_Deleted;
            setRecord (index, record);
        }
    }
    else
    {
        Info record;
        record.mTopicId = dialogue.mId;
        record.mId = id;
        record.load (reader);

        load (record, base);
    }
}
void ReferTableModel::refreshReferTable(const QVector<int> referenceMsg)
{
    QString hexNetId;
    int floor,number;
    hexNetId.fill('0',4);//用于补充不够4位netID的前面的0

    int netId,tmpPeriod;
    floor = referenceMsg.at(R_ROOM_FLOOR);
    number = referenceMsg.at(R_ROOM_NUMBER);
    netId = referenceMsg.at(R_NETID_LO);
    netId |= (referenceMsg.at(R_NETID_HI) << 8);
    hexNetId.append(QString::number(netId,16).toUpper());
    tmpPeriod = referenceMsg.at(R_TEMP_PERIOD);
    //添加或者更新参考节点配置信息数据表
    setFilter(QString("floor=%1 AND number=%2").arg(floor).arg(number));
    select();
    if(rowCount() == 1)//已经存在,更新netId
    {
        QSqlRecord record = this->record(0);
        record.setValue("netId",hexNetId.right(4));
        record.setValue("tempPeriod", tmpPeriod);
        setRecord(0,record);
        submitAll();
        setFilter("");//清楚过滤条件,否则只显示更新的一条
    }
    else if(rowCount() == 0)//不存在,添加netId
    {
        int row = 0;
        insertRows(row, 1);
        setData(index(row, 1),hexNetId.right(4));
        setData(index(row, 2), floor);
        setData(index(row, 3),number);
        setData(index(row, 4), tmpPeriod);
        submitAll();
        setFilter("");//清楚过滤条件,否则只显示更新的一条
        submitAll();
    }
}
/*
 * infile: filename of the input file
 * outfile: filename of the output file
 * field: which field will be used for sorting
 * buffer: the buffer used
 * nmem_blocks: size of buffer
 * nunique: number of unique values
 * nios: number of ios
 * 
 * when the input file size is equal to buffer, the whole file is loaded and
 * sorted. then the first block is used as output where only unique values are
 * written
 */
void useFirstBlock(char *infile, char *outfile, unsigned char field, block_t *buffer, uint nmem_blocks, uint *nunique, uint *nios) {
    int out = open(outfile, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU);
    (*nios) += readBlocks(infile, buffer, nmem_blocks);
    if (sortBuffer(buffer, nmem_blocks, field)) {
        // all the unique values of the first block are shifted to the start
        // of it. the rest are marked as invalid
        recordPtr i = newPtr(1);
        recordPtr j = newPtr(1);
        (*nunique) += 1;
        buffer[0].nreserved = 1;
        for (; j.block < 1; incr(j)) {
            record_t record = getRecord(buffer, j);
            if (record.valid && compareRecords(record, getRecord(buffer, i - 1), field) != 0) {
                setRecord(buffer, record, i);
                (*nunique) += 1;
                incr(i);
                buffer[0].nreserved += 1;
            }
        }

        j = newPtr(i, 0);
        for (; j.block < 1; incr(j)) {
            buffer[j.block].entries[j.record].valid = false;
        }

        record_t *lastRecordAdded = (record_t*) malloc(sizeof (record_t));
        record_t lastUnique = getRecord(buffer, i - 1);
        memcpy(lastRecordAdded, &lastUnique, sizeof (record_t));
        // if the first block is full after the shifting (meaning that all its
        // values were actually unique), writes it to the outfile and empties it
        if (buffer[0].nreserved == MAX_RECORDS_PER_BLOCK) {
            i.block -= 1;
            (*nios) += writeBlocks(out, buffer, 1);
            emptyBlock(buffer);
            buffer[0].blockid += 1;
        }

        // write the unique values of the other blocks to the first one. if it
        // becomes full writes it to outfile and empties it. at the end, if it
        // has records not writtend yet, writes them to the outfile as well.
        j = newPtr(MAX_RECORDS_PER_BLOCK);
        while (buffer[j.block].valid && j.block < nmem_blocks) {
            record_t record = getRecord(buffer, j);
            if (!record.valid) {
                break;
            }
            if (compareRecords(record, (*lastRecordAdded), field) != 0) {
                setRecord(buffer, record, i);
                memcpy(lastRecordAdded, &record, sizeof (record_t));
                (*nunique) += 1;
                incr(i);
                buffer[0].nreserved += 1;
            }
            if (buffer[0].nreserved == MAX_RECORDS_PER_BLOCK) {
                i.block -= 1;
                (*nios) += writeBlocks(out, buffer, 1);
                emptyBlock(buffer);
                buffer[0].blockid += 1;
            }
            incr(j);
        }
        if (buffer[0].nreserved != 0) {
            (*nios) += writeBlocks(out, buffer, 1);
        }
        free(lastRecordAdded);
    }
    close(out);
}
Ejemplo n.º 23
0
void PropertyModel::updateRecord()
{
	setRecord(mRecord);
}
Ejemplo n.º 24
0
void CSMWorld::RefCollection::load (ESM::ESMReader& reader, int cellIndex, bool base,
    std::map<ESM::RefNum, std::string>& cache, CSMDoc::Messages& messages)
{
    Record<Cell> cell = mCells.getRecord (cellIndex);

    Cell& cell2 = base ? cell.mBase : cell.mModified;

    CellRef ref;
    ESM::MovedCellRef mref;
    bool isDeleted = false;

    // hack to initialise mindex
    while (!(mref.mRefNum.mIndex = 0) && ESM::Cell::getNextRef(reader, ref, isDeleted, true, &mref))
    {
        // Keep mOriginalCell empty when in modified (as an indicator that the
        // original cell will always be equal the current cell).
        ref.mOriginalCell = base ? cell2.mId : "";

        if (cell.get().isExterior())
        {
            // ignoring moved references sub-record; instead calculate cell from coordinates
            std::pair<int, int> index = ref.getCellIndex();

            std::ostringstream stream;
            stream << "#" << index.first << " " << index.second;

            ref.mCell = stream.str();

            if (!base &&                  // don't try to update base records
                mref.mRefNum.mIndex != 0) // MVRF tag found
            {
                // there is a requirement for a placeholder where the original object was
                //
                // see the forum discussions here for more details:
                // https://forum.openmw.org/viewtopic.php?f=6&t=577&start=30
                ref.mOriginalCell = cell2.mId;

                // It is not always possibe to ignore moved references sub-record and
                // calculate from coordinates. Some mods may place the ref in positions
                // outside normal bounds, resulting in non sensical cell id's.  This often
                // happens if the moved ref was deleted.
                //
                // Use the target cell from the MVRF tag but if different output an error
                // message
                if (index.first != mref.mTarget[0] || index.second != mref.mTarget[1])
                {
                    std::cerr << "The Position of moved ref "
                        << ref.mRefID << " does not match the target cell" << std::endl;
                    std::cerr << "Position: #" << index.first << " " << index.second
                        <<", Target #"<< mref.mTarget[0] << " " << mref.mTarget[1] << std::endl;

                    std::ostringstream stream;
                    stream << "#" << mref.mTarget[0] << " " << mref.mTarget[1];
                    ref.mCell = stream.str(); // overwrite
                }
            }
        }
        else
            ref.mCell = cell2.mId;

        // ignore content file number
        std::map<ESM::RefNum, std::string>::iterator iter = cache.begin();
        for (; iter != cache.end(); ++iter)
        {
            if (ref.mRefNum.mIndex == iter->first.mIndex)
                break;
        }

        if (isDeleted)
        {
            if (iter==cache.end())
            {
                CSMWorld::UniversalId id (CSMWorld::UniversalId::Type_Cell,
                    mCells.getId (cellIndex));

                messages.add (id, "Attempt to delete a non-existing reference");
                continue;
            }

            int index = getIndex (iter->second);

            Record<CellRef> record = getRecord (index);

            if (base)
            {
                removeRows (index, 1);
                cache.erase (iter);
            }
            else
            {
                record.mState = RecordBase::State_Deleted;
                setRecord (index, record);
            }

            continue;
        }

        if (iter==cache.end())
        {
            // new reference
            ref.mId = getNewId();

            Record<CellRef> record;
            record.mState = base ? RecordBase::State_BaseOnly : RecordBase::State_ModifiedOnly;
            (base ? record.mBase : record.mModified) = ref;

            appendRecord (record);

            cache.insert (std::make_pair (ref.mRefNum, ref.mId));
        }
        else
        {
            // old reference -> merge
            ref.mId = iter->second;

            int index = getIndex (ref.mId);

            Record<CellRef> record = getRecord (index);
            record.mState = base ? RecordBase::State_BaseOnly : RecordBase::State_Modified;
            (base ? record.mBase : record.mModified) = ref;

            setRecord (index, record);
        }
    }
}
Ejemplo n.º 25
0
void MainWindow::toggleRecordingActive()
{
   setRecord(m_recordAnimationAction->isChecked());
}
Ejemplo n.º 26
0
bool LS3Datastore::setCurrentRecord(const QMap<QString, QVariant> &data) {
    return setRecord(currentRecordNum(), data);
}
Ejemplo n.º 27
0
void Q3DataView::refresh(QSqlRecord* buf)
{
    if (buf && buf != record())
        setRecord(buf);
    readFields();
}