bool QSymSQLResult::fetch(int i) { //Single return point modified according to review bool retVal = true; if (i < 0 || !isActive()) { retVal = false; } else { if (at() <= -1 || i < at()) { d->stmt.Reset(); setAt(-1); d->skipRow = false; } while (at() < i) { if (!d->fetchNext(false)) { retVal = false; break; } setAt(at() + 1); } } return retVal; }
bool QtSqlCachedResult::fetch(int i) { if ((!isActive()) || (i < 0)) return FALSE; if (at() == i) return TRUE; if (d->forwardOnly) { // speed hack - do not copy values if not needed if (at() > i || at() == QSql::AfterLast) return FALSE; while(at() < i - 1) { if (!gotoNext(0)) return FALSE; setAt(at() + 1); } if (!gotoNext(d->current)) return FALSE; setAt(at() + 1); return TRUE; } if (d->seek(i)) { setAt(i); return TRUE; } setAt(d->rowCacheEnd - 1); while (at() < i) { if (!cacheNext()) return FALSE; } return TRUE; }
void fj::Image::setAt(const int x, const int y, const int R, const int G, const int B, const int A) { if (m_coord == CoordY::kDown) { setAt(x, getHeight() - y, fj::NormalizedColor(R, G, B, A)); } else { setAt(x, y, fj::NormalizedColor(R, G, B, A)); } }
bool QSymSQLResult::fetchLast() { if (!isActive()) return false; if (at() <= -1) { if (!fetchFirst()) return false; } TInt res; do { res = d->stmt.Next(); setAt(at()+1); } while (res == KSqlAtRow); if (res != KSqlAtEnd) return false; d->skippedStatus = false; d->skipRow = false; return fetchPrevious(); }
//-------------------------------------------------------------------- // grow the table void mgMapXYZToPtr::grow() { int newSize = 1+2*m_tableSize; mgMapXYZToPtrEntry* newEntries = new mgMapXYZToPtrEntry[newSize]; for (int i = 0; i < newSize; i++) { newEntries[i].x = 0; newEntries[i].y = 0; newEntries[i].z = 0; newEntries[i].value = NULL; } mgMapXYZToPtrEntry* oldEntries = m_entries; int oldSize = m_tableSize; m_entries = newEntries; m_tableSize = newSize; m_tableCount = 0; for (int i = 0; i < oldSize; i++) { mgMapXYZToPtrEntry *entry = &oldEntries[i]; if (entry->value != NULL) setAt(entry->x, entry->y, entry->z, entry->value); } // done with old table delete oldEntries; }
bool embeddedResult::fetchNext() { if(!d->driver) return false; if (d->preparedQuery) { #if MYSQL_VERSION_ID >= 40108 int nRC = mysql_stmt_fetch(d->stmt); if (nRC) { #ifdef MYSQL_DATA_TRUNCATED if (nRC == 1 || nRC == MYSQL_DATA_TRUNCATED) #else if (nRC == 1) #endif // MYSQL_DATA_TRUNCATED setLastError(qMakeStmtError(QCoreApplication::translate("embeddedResult", "Unable to fetch data"), QSqlError::StatementError, d->stmt)); return false; } #else return false; #endif } else { d->row = mysql_fetch_row(d->result); if (!d->row) return false; } setAt(at() + 1); return true; }
long MainPlayer::edgeStabilityHeuristic(const GameBoard &gameBoard, Tile tile) const { auto gameSize = gameBoard.getGameSize(); std::vector<Direction> directions{{0, 1}, {0, -1}, {1, 0}, {-1, 0}}; std::vector<Cell> corners{{0, 0}, {0, gameSize - 1}, {gameSize - 1, 0}, {gameSize - 1, gameSize - 1}}; auto board = gameBoard; // board.print(std::cerr); long stableCellsCount = 0; for (Cell corner : corners) { if (board.getAt(corner) != tile) { continue; } ++stableCellsCount; for (Direction direction : directions) { auto current = corner; current.move(direction); while (board.isCorrect(current) && board.getAt(current) == tile) { ++stableCellsCount; board.setAt(current, EMPTY); // board.print(std::cerr); current.move(direction); } } } return stableCellsCount; }
/** @brief 説明、引数、戻り値はMonapi2リファレンス参照。 @date 2005/08/20 junjunn 作成 */ void IniManager::setAt(cpchar1 cszDir,cpchar1 cszKey,float fValue) { char1 szValue[32]; StringFn::format(szValue,"%f",fValue); setAt(cszDir,cszKey,szValue); }
/** @brief 説明、引数、戻り値はMonapi2リファレンス参照。 @date 2005/08/20 junjunn 作成 */ void IniManager::setAt(cpchar1 cszDir,cpchar1 cszKey,int iValue) { char1 szValue[32]; StringFn::toString(szValue,iValue); setAt(cszDir,cszKey,szValue); }
bool ZSqliteCipherCachedResult::fetchNext() { if (d->canSeek(at() + 1)) { setAt(at() + 1); return true; } return cacheNext(); }
void Camera::rotateYaw(double angle) { // rotate the camera left/right (around the up vector) Matrix4 rot = Matrix4::rotation(Up_Vector, angle); Vector4 temp = Vector4(eye[0], eye[1], eye[2], 1) + rot*Vector4(Look_Vector[0], Look_Vector[1], Look_Vector[2], 1); Point3 at = Point3(temp[0],temp[1],temp[2]); setAt(at); setUp(Up); }
bool QtSqlCachedResult::fetchNext() { if (d->seek(at() + 1)) { setAt(at() + 1); return TRUE; } return cacheNext(); }
void Camera::rotatePitch(double angle) { // rotate the camera up/down (pitch angle) Matrix4 rot = Matrix4::rotation(getRight(), angle); Vector4 temp = Vector4(eye[0], eye[1], eye[2], 1) + rot*Vector4(Look_Vector[0], Look_Vector[1], Look_Vector[2], 1); Point3 at = Point3(temp[0], temp[1], temp[2]); setAt(at); setUp(Up); }
bool QMYSQLResult::fetchNext() { d->row = mysql_fetch_row( d->result ); if ( !d->row ) return FALSE; setAt( at() + 1 ); return TRUE; }
bool QTDSResult::gotoNext(QSqlCachedResult::ValueCache &values, int index) { STATUS stat = dbnextrow(d->dbproc); if (stat == NO_MORE_ROWS) { setAt(QSql::AfterLastRow); return false; } if ((stat == FAIL) || (stat == BUF_FULL)) { setLastError(d->lastError); return false; } if (index < 0) return true; for (int i = 0; i < d->rec.count(); ++i) { int idx = index + i; switch (d->rec.field(i).type()) { case QVariant::DateTime: if (qIsNull(d->buffer.at(i * 2 + 1))) { values[idx] = QVariant(QVariant::DateTime); } else { DBDATETIME *bdt = (DBDATETIME*) d->buffer.at(i * 2); QDate date = QDate::fromString(QLatin1String("1900-01-01"), Qt::ISODate); QTime time = QTime::fromString(QLatin1String("00:00:00"), Qt::ISODate); values[idx] = QDateTime(date.addDays(bdt->dtdays), time.addMSecs(int(bdt->dttime / 0.3))); } break; case QVariant::Int: if (qIsNull(d->buffer.at(i * 2 + 1))) values[idx] = QVariant(QVariant::Int); else values[idx] = *((int*)d->buffer.at(i * 2)); break; case QVariant::Double: case QVariant::String: if (qIsNull(d->buffer.at(i * 2 + 1))) values[idx] = QVariant(QVariant::String); else values[idx] = QString::fromLocal8Bit((const char*)d->buffer.at(i * 2)).trimmed(); break; case QVariant::ByteArray: { if (qIsNull(d->buffer.at(i * 2 + 1))) values[idx] = QVariant(QVariant::ByteArray); else values[idx] = QByteArray((const char*)d->buffer.at(i * 2)); break; } default: // should never happen, and we already fired // a warning while binding. values[idx] = QVariant(); break; } } return true; }
bool QtSqlCachedResult::cacheNext() { if (!gotoNext(d->next())) { d->revertLast(); return FALSE; } setAt(at() + 1); return TRUE; }
void QPSQLResult::cleanup() { if (d->result) PQclear(d->result); d->result = 0; setAt(QSql::BeforeFirstRow); d->currentSize = -1; setActive(false); }
bool QSymSQLResult::fetchNext() { bool res = d->fetchNext(false); if (res) { setAt(at()+1); } return res; }
bool SqliteResult::reset(const QString &q) { if (!driver) return false; if (!driver->isOpen() || driver->isOpenError()) return false; setActive(false); setAt(QSql::BeforeFirst); query = q.stripWhiteSpace(); if (q.find("select", 0, false) == 0) setSelect(true); else setSelect(false); query.replace("'true'", "'1'"); query.replace("'false'", "'0'"); query.replace("=;", "= NULL;"); while (query.endsWith(";")) query.truncate(query.length() - 1); if (query.upper().endsWith("NOWAIT")) query.truncate(query.length() - 6); if (query.upper().endsWith("FOR UPDATE")) query.truncate(query.length() - 10); if (!isSelect()) { if (query.find("CREATE TABLE", 0, false) == 0) { Dataset *ds = ((SqliteDriver *) driver) ->dataBase() ->CreateDataset(); if (!ds) return false; if (!ds->exec(query.latin1())) { delete ds; return false; } delete ds; } else { if (dataSet) delete dataSet; dataSet = ((SqliteDriver *) driver) ->dataBase() ->CreateDataset(); if (!dataSet->exec(query.latin1())) return false; } return true; } if (dataSet) delete dataSet; dataSet = ((SqliteDriver *) driver) ->dataBase() ->CreateDataset(); if (dataSet->query(query.latin1())) { setActive(true); return true; } else return false; }
void QMYSQLResult::cleanup() { if ( d->result ) { mysql_free_result( d->result ); } d->result = NULL; d->row = NULL; setAt( -1 ); setActive( FALSE ); }
void fj::Image::fillIn(const fj::NormalizedColor &color) { for (int i = 0; i < getWidth(); i++){ for (int j = 0; j < getHeight(); j++) { setAt(i, j, color); } } }
bool QtSqlCachedResult::fetchFirst() { if (d->forwardOnly && at() != QSql::BeforeFirst) { return FALSE; } if (d->seek(0)) { setAt(0); return TRUE; } return cacheNext(); }
bool ZSqliteCipherCachedResult::fetchFirst() { if (d->forwardOnly && at() != QSql::BeforeFirstRow) { return false; } if (d->canSeek(0)) { setAt(0); return true; } return cacheNext(); }
bool QPSQLResult::fetch(int i) { if (!isActive()) return false; if (i < 0) return false; if (i >= d->currentSize) return false; if (at() == i) return true; setAt(i); return true; }
Camera::Camera() { // initialize your data here aspect_ratio = 1.0; height = 600; width = 800; setFrom(Point3(3.0, 2.0, 6.0)); setAt(Point3(0.0, 0.0, 0.0)); setUp(Vector3(0.0, 1.0, 0.0)); setZoom(90.0); setNearFar(0.1, 30.0); }
int main() { List ls; ls.count = 0; ls.first = NULL; int number = 0; scanf("%d", &number); int i = 0, temp; while (i < number) { scanf("%d", &temp); insertAt(&ls, i, temp); i++; } print(&ls, stdout); printf("\n"); i = 1; while (i < 6) { insertFront(&ls, i); i++; } print(&ls, stdout); printf("\n"); i = 1; int nums = getSize(&ls); while (i < nums) { deleteAt(&ls, i); i++; nums--; } print(&ls, stdout); printf("\n"); i = 0; nums = getSize(&ls); while (i < getSize(&ls)) { if (getAt(&ls, i) < 3) { deleteAt(&ls, i); i--; } else { setAt(&ls, i, getAt(&ls, i) * 10); } i++; } print(&ls, stdout); return 0; }
bool ZSqliteCipherCachedResult::fetch(int i) { if ((!isActive()) || (i < 0)) return false; if (at() == i) return true; if (d->forwardOnly) { // speed hack - do not copy values if not needed if (at() > i || at() == QSql::AfterLastRow) return false; while(at() < i - 1) { if (!gotoNext(d->cache, -1)) return false; setAt(at() + 1); } if (!gotoNext(d->cache, 0)) return false; setAt(at() + 1); return true; } if (d->canSeek(i)) { setAt(i); return true; } if (d->rowCacheEnd > 0) setAt(d->cacheCount()); while (at() < i + 1) { if (!cacheNext()) { if (d->canSeek(i)) break; return false; } } setAt(i); return true; }
//-------------------------------------------------------------- // get a character. returns NULL if not found const mgGenCharDefn* mgGenCharCache::getChar( void* font, DWORD letter) { mgGenCharDefn* defn; if (lookup(font, letter, defn)) return defn; // look for the character in the font FT_Face face = (FT_Face) font; FT_UInt glyphIndex = FT_Get_Char_Index(face, letter); int error = FT_Load_Glyph(face, glyphIndex, FT_LOAD_RENDER ); if (error != 0) { mgDebug("FT_Load_Glyph returns %d", error); return NULL; } FT_GlyphSlot slot = face->glyph; FT_Bitmap bitmap = slot->bitmap; defn = new mgGenCharDefn(); defn->m_advanceX = (slot->advance.x+31)/64; defn->m_advanceY = (slot->advance.y+31)/64; defn->m_bitmapX = slot->bitmap_left; defn->m_bitmapY = slot->bitmap_top; defn->m_bitmapWidth = bitmap.width; defn->m_bitmapHeight = bitmap.rows; // =-= for now, just allocate memory for bitmap defn->m_bitmapData = new BYTE[defn->m_bitmapWidth * defn->m_bitmapHeight]; // copy data from FreeType bitmap for (int i = 0; i < bitmap.rows; i++) { BYTE* defnLine = defn->m_bitmapData + defn->m_bitmapWidth * i; BYTE* bitmapLine = bitmap.buffer + bitmap.pitch * i; memcpy(defnLine, bitmapLine, defn->m_bitmapWidth); } // save in hash table setAt(font, letter, defn); return defn; }
void embeddedResult::cleanup() { if (d->result) mysql_free_result(d->result); // must iterate trough leftover result sets from multi-selects or stored procedures // if this isn't done subsequent queries will fail with "Commands out of sync" #if MYSQL_VERSION_ID >= 40100 while (d->driver && d->driver->d->mysql && mysql_next_result(d->driver->d->mysql) == 0) { MYSQL_RES *res = mysql_store_result(d->driver->d->mysql); if (res) mysql_free_result(res); } #endif #if MYSQL_VERSION_ID >= 40108 if (d->stmt) { if (mysql_stmt_close(d->stmt)) printf("embeddedResult::cleanup: unable to free statement handle"); d->stmt = 0; } if (d->meta) { mysql_free_result(d->meta); d->meta = 0; } int i; for (i = 0; i < d->fields.count(); ++i) delete[] d->fields[i].outField; if (d->outBinds) { delete[] d->outBinds; d->outBinds = 0; } if (d->inBinds) { delete[] d->inBinds; d->inBinds = 0; } #endif d->hasBlobs = false; d->fields.clear(); d->result = NULL; d->row = NULL; setAt(-1); setActive(false); }
//-------------------------------------------------------------------- // set/change a key void mgMapXYZToPtr::setAt( int x, int y, int z, const void* value) { if (m_tableCount * 100 > m_tableSize * GROW_LIMIT) grow(); // hash the key for first probe into table int index = hash(x, y, z) % m_tableSize; int startIndex = index; while (true) { mgMapXYZToPtrEntry *entry = (mgMapXYZToPtrEntry *) &m_entries[index]; if (entry->value == NULL) { // set entry entry->x = x; entry->y = y; entry->z = z; entry->value = value; m_tableCount++; return; } if (entry->x == x && entry->y == y && entry->z == z) { // existing key changed entry->value = value; return; } // look in next entry index++; if (index >= m_tableSize) index = 0; // if we've wrapped if (index == startIndex) { // table is full. shouldn't happen with grow test at top grow(); setAt(x, y, z, value); return; } } }