int64_t peek() { input_type word; if ( peekNext(word) ) return word; else return -1; }
// ******************************************* // Position the scan cursor to the record with the given rid. // Returns OK if successful, non-OK otherwise. Status Scan::position(RID rid) { Status st; RID nxtrid; st = peekNext(nxtrid); if (nxtrid == rid) return OK; // This is kinda lame, but otherwise it will take all day. PageId pgid = rid.pageNo; if (datapageId != pgid) { // reset everything and start over from the beginning reset(); st = firstDataPage(); if (st != OK) return MINIBASE_CHAIN_ERROR(HEAPFILE, st); while (datapageId != pgid) { st = nextDataPage(); if (st != OK) return MINIBASE_CHAIN_ERROR(HEAPFILE, st); } } // Now we are on the correct page. st = datapage->firstRecord(userrid); if (st != OK) return MINIBASE_CHAIN_ERROR(HEAPFILE, st); st = peekNext(nxtrid); while ((st == OK) && (nxtrid != rid)) st = mvNext(nxtrid); return st; }
void JuickDownloader::get(const JuickDownloadItem &item) { if(waitTimer_->isActive()) waitTimer_->stop(); items_.enqueue(item); Proxy prx = appInfo_->getProxyFor(constPluginName); setProxyHostPort(prx.host, prx.port, prx.user, prx.pass, prx.type); if(!inProgress_) { peekNext(); } }
void Scanner::number() { while (isDigit(peek())) advance(); if (peek() == '.' && isDigit(peekNext())) { advance(); while (isDigit(peek())) advance(); } addToken(NUMBER, source_.substr(start_, current_ - start_)); }
void JuickDownloader::requestFinished(QNetworkReply *reply) { if (reply->error() == QNetworkReply::NoError ) { QByteArray ba = reply->readAll(); JuickDownloadItem it = reply->property("jdi").value<JuickDownloadItem>(); dataReady(ba, it); } else { qDebug() << reply->errorString(); } reply->deleteLater(); peekNext(); }
bool Lexer::checkNext(char ch) { peekNext(); if(endOfFile) { return false; } if(peek == ch) { return true; } putBack(peek); return false; }
TreeRef TreeIterator2D::getNext() { TreeRef tree = peekNext(); moveNext(); return tree; }
//return face count MCInline void processMtlLine(BAMtlLibrary* lib, const char* linebuff) { //debug_log("processMtlLine:%s\n", linebuff); //MCToken token; MCToken token; char word[256] = {0}; const char* remain = linebuff; while (!isNewLine(remain) && *remain != NUL) { token = tokenize(nextWord(&remain, word)); switch (token.type) { case MCTokenIdentifier: if (MCStringEqualN(word, "newmtl", 6)) { token = tokenize(nextWord(&remain, word)); if (token.type == MCTokenIdentifier || token.type == MCTokenFilename) { if (!BAFindMaterial(lib, token.value.Word)) { BAAddMaterial(lib, token.value.Word); } continue; } } //texture else if (MCStringEqualN(word, "map_Ka", 6)) { return;//next line } else if (MCStringEqualN(word, "map_Kd", 6)) { char name[256] = {0}; BAMaterial* material = lib->materialsList; if (material && MCString_filenameFromPath(remain, &name)) { MCStringFill(material->diffuseMapName, name); lib->diffuse_map_count++; } else { error_log("BAMtlParser - can not get filename form path: %s\n", remain); } return;//next line } else if (MCStringEqualN(word, "map_Ks", 6)) { char name[256] = {0}; BAMaterial* material = lib->materialsList; if (material && MCString_filenameFromPath(remain, &name)) { MCStringFill(material->specularMapName, name); } else { error_log("BAMtlParser - can not get filename form path: %s\n", remain); } return;//next line } else if (MCStringEqualN(word, "map_Ns", 6)) { char name[256] = {0}; BAMaterial* material = lib->materialsList; if (material && MCString_filenameFromPath(remain, &name)) { MCStringFill(material->normalMapName, name); lib->normal_map_count++; } else { error_log("BAMtlParser - can not get filename form path: %s\n", remain); } return;//next line } else if (MCStringEqualN(word, "map_Ke", 6)) { return;//next line } //LSLightColor else if (MCStringEqualN(word, "illum", 5)) { token = tokenize(nextWord(&remain, word)); BAMaterial* material = lib->materialsList; if (material) { if (token.type == MCTokenIdentifier) { if (MCStringEqualN(token.value.Word, "illum_", 6)) { char* num = &token.value.Word[6]; int n = atoi(num); if (n >= 0 && n <= 10) { material->illumModelNum = n; } } } else if (token.type == MCTokenInteger) { int n = (int)token.value.Integer; if (n >= 0 && n <= 10) { material->illumModelNum = n; } } } } //Ka|Kd|Ks|Tf [xyz|spectral] rx gy bz | [file.rfl factor] else if (MCStringEqualN(word, "K", 1) || MCStringEqualN(word, "Tf", 2)) { BALightColor* light = null; if (MCStringEqualN(word, "Tf", 2)) { light = &(lib->materialsList->lightColors[TFilter]); } else if (MCStringEqualN(word, "Ka", 2)) { light = &(lib->materialsList->lightColors[Ambient]); } else if (MCStringEqualN(word, "Kd", 2)) { light = &(lib->materialsList->lightColors[Diffuse]); } else if (MCStringEqualN(word, "Ks", 2)) { light = &(lib->materialsList->lightColors[Specular]); } else if (MCStringEqualN(word, "Ke", 2)) { light = &(lib->materialsList->lightColors[Emissive]); } if (!light) { error_log("BAMtlParser - [%s] not light Ka/Kd/Ks\n", word); return; } light->Ctype = RGB; //option next token = tokenize(peekNext(&remain, word)); if (token.type == MCTokenIdentifier) { if (MCStringEqualN(token.value.Word, "xyz", 3)) { light->Ctype = XYZ; } else if (MCStringEqualN(token.value.Word, "spectral", 8)) { light->Ctype = SpectralFile; //filename next skipNext(&remain);//skip token = tokenize(nextWord(&remain, word)); if (token.type == MCTokenIdentifier) { MCStringFill(light->data.spectral, token.value.Word); //factor next token = tokenize(nextWord(&remain, word)); if (token.type == MCTokenFloat) { light->factor = token.value.Double; } } //end line return; } } //float value next else if (token.type == MCTokenFloat || token.type == MCTokenInteger) { if (light->Ctype != SpectralFile) { double buff[3] = {0}; size_t n = nextNumbersAsFloat(&remain, buff); if (n >= 3) { light->data.rgbxyz[0] = buff[0]; light->data.rgbxyz[1] = buff[1]; light->data.rgbxyz[2] = buff[2]; } else { error_log("MC3DMtlParser [%s] value count less than 3\n", linebuff); } } } } //LSScalar else if (MCStringEqualN(word, "Ns", 2)) { token = tokenize(nextWord(&remain, word)); if (token.type == MCTokenInteger) { lib->materialsList->specularExponent = (double)token.value.Integer; } if (token.type == MCTokenFloat) { lib->materialsList->specularExponent = (double)token.value.Double; } continue; } else if (MCStringEqualN(word, "decal", 5)) { //state = LSScalar; } else if (MCStringEqualN(word, "disp", 4)) { //state = LSScalar; } else if (MCStringEqualN(word, "bump", 4)) { //state = LSScalar; } else if (MCStringEqualN(word, "d", 1)) { token = tokenize(nextWord(&remain, word)); if (lib->materialsList) { if (token.type == MCTokenFloat) { lib->materialsList->dissolveFactor = (double)token.value.Double; } if (token.type == MCTokenInteger) { lib->materialsList->dissolveFactor = (double)token.value.Integer; } } continue; } //BohdiEngine extensions else if (MCStringEqualN(word, "ext_hidden", 10)) { token = tokenize(nextWord(&remain, word)); if (lib->materialsList) { if (token.type == MCTokenIdentifier && MCStringEqualN(token.value.Word, "off", 3)) { lib->materialsList->hidden = 0; }else{ lib->materialsList->hidden = 1; } } } else if (MCStringEqualN(word, "ext_tex_file", 12)) { token = tokenize(nextWord(&remain, word)); if(!BAFindTextureByFilename(lib, token.value.Word)) { BAAddTexture(lib, token.value.Word, null, null); } } else if (MCStringEqualN(word, "ext_tex_group", 13)) { token = tokenize(nextWord(&remain, word)); BATexture* tex = lib->texturesList; MCStringFill(tex->attachedGroup, token.value.Word); } else if (MCStringEqualN(word, "ext_tex_object", 14)) { token = tokenize(nextWord(&remain, word)); BATexture* tex = lib->texturesList; MCStringFill(tex->attachedObject, token.value.Word); } else { } break; case MCTokenComment: case MCTokenUnknown: default: nextWord(&remain, word); continue; } } return; }
bool Lexer::getNextToken(Tokener &tokener) { bool isComment = false; bool loopMark = true; while(loopMark) { peekNext(); if(endOfFile) { if(isComment) { cout << line << ',' << row << " 文件末尾出错:缺少'}\n'" << endl; exit(1); } tokener.putToken(new Token(-1),line,row); return false; } switch(peek) { case ' ': case '\t': case '\n': break; case '{': if (isComment) { cout << line << ',' << row << " 错误的输入:嵌套的注释\n" << endl; exit(1); } else { isComment = true; } break; case '}': if (isComment) { isComment = false; } else { cout << line << ',' << row << " 错误的输入:嵌套的注释\n" << endl; exit(1); } break; default: if (!isComment) { loopMark = false; break; } } } // 2.识别复合词法符号 ":=" switch(peek) { case ':': if (!checkNext('=')) { tokener.putToken(new Symbol(':'), line, row); return true; } else { tokener.putToken(&Operator::OP_ASSIGN, line, row - 1); return true; } } //识别各种符号 switch(peek) { case '+': tokener.putToken(&Operator::OP_PLUS, line, row); return true; case '-': tokener.putToken(&Operator::OP_MINUS, line, row); return true; case '*': tokener.putToken(&Operator::OP_MUTL, line, row); return true; case '/': tokener.putToken(&Operator::OP_DIV, line, row); return true; case '=': tokener.putToken(&Operator::OP_EQUAL, line, row); return true; case '<': tokener.putToken(&Operator::OP_LESS, line, row); return true; } //读取整数常量 if(isDigit(peek)) { int startRow = row; int value = peek - '0'; while(true) { peekNext(); if(endOfFile) { break; } if(!isDigit(peek)) { putBack(peek); break; } value = value * 10 + peek - '0'; } tokener.putToken(new Int(value),line,startRow); return true; } //读取标识符 if(isLetter(peek)) { int startrow = row; string str; str.append(string(&peek)); while(true) { peekNext(); if(endOfFile) { break; } if(!isLetterOrDigit(peek)) { putBack(peek); break; } str.append(string(&peek)); } Word *word = Word::getReserve(str); if( word == NULL) { word = new Word(Token::TAG_VARIABLE,str); } tokener.putToken((Word*)word,line,startrow); return true; } //剩余的情况 tokener.putToken(new Token(peek),line,row); return true; }