本文整理汇总了C++中StringTokenizer::hasNext方法的典型用法代码示例。如果您正苦于以下问题:C++ StringTokenizer::hasNext方法的具体用法?C++ StringTokenizer::hasNext怎么用?C++ StringTokenizer::hasNext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringTokenizer
的用法示例。
在下文中一共展示了StringTokenizer::hasNext方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetQuery
LanguageModel::LanguageModel(Index *index, offset start, offset end, bool stemmed) {
char line[Query::MAX_RESPONSELINE_LENGTH + 4];
initialize();
this->corpusSize = (end - start + 1);
this->documentCount = 1;
this->stemmed = stemmed;
char queryBody[64];
sprintf(queryBody, OFFSET_FORMAT " " OFFSET_FORMAT, start, end);
const char *modifiers[2] = { "filtered", NULL };
GetQuery *query = new GetQuery(index, "get", modifiers, queryBody, Index::GOD, -1);
if (query->parse()) {
line[sizeof(line) - 1] = 0;
while (query->getNextLine(line)) {
assert(line[sizeof(line) - 1] == 0);
StringTokenizer *tok = new StringTokenizer(line, " ");
while (tok->hasNext()) {
char *t = tok->getNext();
if ((strchr(t, '<') == NULL) && (strchr(t, '>') == NULL)) {
if (getTermID(t) < 0)
addTerm(t, 1, 1);
else
updateTerm(t, 1, 0);
}
}
delete tok;
}
}
else {
log(LOG_ERROR, LOG_ID, "Parsing failed in LanguageModel(Index*, offset, offset, bool)");
fprintf(stderr, "%lld %lld\n", static_cast<long long>(start), static_cast<long long>(end));
}
delete query;
this->corpusSize = 0;
for (int i = 0; i < termSlotsUsed; i++)
this->corpusSize += terms[i].termFrequency;
} //end of LanguageModel(Index*, offset, offset, bool)
示例2: pos
void
NIImporter_OpenStreetMap::insertEdge(Edge* e, int index, NBNode* from, NBNode* to,
const std::vector<int> &passed, NBEdgeCont& ec, NBTypeCont& tc) {
// patch the id
std::string id = e->id;
if (index >= 0) {
id = id + "#" + toString(index);
}
// convert the shape
PositionVector shape;
for (std::vector<int>::const_iterator i = passed.begin(); i != passed.end(); ++i) {
NIOSMNode* n = myOSMNodes.find(*i)->second;
Position pos(n->lon, n->lat);
if (!NILoader::transformCoordinates(pos, true)) {
throw ProcessError("Unable to project coordinates for edge " + id + ".");
}
shape.push_back_noDoublePos(pos);
}
std::string type = e->myHighWayType;
if (!tc.knows(type)) {
if (type.find(compoundTypeSeparator) != std::string::npos) {
// this edge has a combination type which does not yet exist in the TypeContainer
StringTokenizer tok = StringTokenizer(type, compoundTypeSeparator);
std::set<std::string> types;
while (tok.hasNext()) {
std::string t = tok.next();
if (tc.knows(t)) {
types.insert(t);
} else {
WRITE_WARNING("Discarding edge " + id + " with type \"" + type + "\" (unknown compound \"" + t + "\").");
return;
}
}
if (types.size() == 2 &&
types.count("railway.tram") == 1) {
// compound types concern mostly the special case of tram tracks on a normal road.
// in this case we simply discard the tram information since the default for road is to allow all vclasses
types.erase("railway.tram");
std::string otherCompound = *(types.begin());
// XXX if otherCompound does not allow all vehicles (e.g. SVC_DELIVERY), tram will still not be allowed
type = otherCompound;
} else {
// other cases not implemented yet
WRITE_WARNING("Discarding edge " + id + " with unknown type \"" + type + "\".");
return;
}
} else {
// we do not know the type -> something else, ignore
//WRITE_WARNING("Discarding edge " + id + " with unknown type \"" + type + "\".");
return;
}
}
// otherwise it is not an edge and will be ignored
int noLanes = tc.getNumLanes(type);
SUMOReal speed = tc.getSpeed(type);
bool defaultsToOneWay = tc.getIsOneWay(type);
SUMOVehicleClasses allowedClasses = tc.getAllowedClasses(type);
SUMOVehicleClasses disallowedClasses = tc.getDisallowedClasses(type);
// check directions
bool addSecond = true;
if (e->myIsOneWay == "true" || e->myIsOneWay == "yes" || e->myIsOneWay == "1" || (defaultsToOneWay && e->myIsOneWay != "no" && e->myIsOneWay != "false" && e->myIsOneWay != "0")) {
addSecond = false;
}
// if we had been able to extract the number of lanes, override the highway type default
if (e->myNoLanes >= 0) {
if (!addSecond) {
noLanes = e->myNoLanes;
} else {
noLanes = e->myNoLanes / 2;
}
}
// if we had been able to extract the maximum speed, override the type's default
if (e->myMaxSpeed != MAXSPEED_UNGIVEN) {
speed = (SUMOReal)(e->myMaxSpeed / 3.6);
}
if (noLanes != 0 && speed != 0) {
if (e->myIsOneWay != "" && e->myIsOneWay != "false" && e->myIsOneWay != "no" && e->myIsOneWay != "true" && e->myIsOneWay != "yes" && e->myIsOneWay != "-1" && e->myIsOneWay != "1") {
WRITE_WARNING("New value for oneway found: " + e->myIsOneWay);
}
LaneSpreadFunction lsf = addSecond ? LANESPREAD_RIGHT : LANESPREAD_CENTER;
if (e->myIsOneWay != "-1") {
NBEdge* nbe = new NBEdge(id, from, to, type, speed, noLanes, tc.getPriority(type),
tc.getWidth(type), NBEdge::UNSPECIFIED_OFFSET, shape, e->streetName, lsf);
nbe->setVehicleClasses(allowedClasses, disallowedClasses);
if (!ec.insert(nbe)) {
delete nbe;
throw ProcessError("Could not add edge '" + id + "'.");
}
}
if (addSecond) {
if (e->myIsOneWay != "-1") {
id = "-" + id;
}
NBEdge* nbe = new NBEdge(id, to, from, type, speed, noLanes, tc.getPriority(type),
//.........这里部分代码省略.........
示例3: main
int main (int argc, char * const argv[]) {
StringTokenizer st;
fstream infile;
infile.open(DB_FILE_PATH);
bool fromFile = true;
while (true) {
fromFile = !infile.eof();
if (fromFile)
getline(infile, input, '\n');
else
getline(cin, input, '\n');
st.setInput(input);
cmd = st.next();//get command
////////////////////////////////SELECT///////////////////////////////////////
if (eq(cmd,SELECT_CMD)) {
////////////////TEST
fstream File;
File.open(SELECT_TEST_PATH, ios::out);
////////////////END TEST
vector<string> rowNames;
token = st.next();
while (!ueq(token,FROM_EXPR)) {
rowNames.push_back(token);
token = st.next();
}
tableName = st.next();
Table t = db.tables[tableName];
if (rowNames.size() == 1 && eq(rowNames.at(0), ALL_LITERAL)) { //add all if *
rowNames.clear();
for (int i = 0; i < t.nameOfCols.size(); i++ ){
rowNames.push_back(t.nameOfCols[i]);
}
}
vector<string> conditions;
if (st.hasNext()) {
token = st.next();
}
if (eq(token, WHERE_EXPR)) {
while (st.hasNext()) {
token = st.next();
if(!ueq(token, AND_STATEMENT))
conditions.push_back(token);
}
}
for (int i = 0; i < t.rows.size(); i++) {
db.r = t.rows.at(i);
bool showRow = true;
for (int j = 0; j < conditions.size(); j++) {
string colName = conditions.at(j); j++;
string condType = conditions.at(j); j++;
string condValue = conditions.at(j);
string cellValue = db.r.at(t.colNames[colName]);
if (eq(condType, CND_EQ)) {
showRow = eq(condValue, db.r.at(t.colNames[colName]));
}
if (eq(condType, CND_GE) || eq(condType, CND_LE)) {
istringstream s0(cellValue);
int i0;
s0 >> i0;
istringstream s1(condValue);
int i1;
s1 >> i1;
if (eq(condType, CND_GE)) {
showRow = (i0 > i1);
}
if (eq(condType, CND_LE)) {
showRow = (i0 < i1);
}
}
if (!showRow)
break;
}
if(showRow){
for (int j = 0; j < rowNames.size(); j++) {
cout << rowNames.at(j) << " = " << db.r.at(t.colNames[rowNames.at(j)]) << " ";
}
//.........这里部分代码省略.........