bool Pumping::initializeSettings(std::shared_ptr<geometry::Geometry> geometry) { if (geometry->hasOption("pumping_ts")) { this->pumpingTs = geometry->getOrCreateTimeseries(geometry->getOption("pumping_ts")); } else { if (geometry->hasOption("pumping_rate")) { if (!tryParse(geometry->getOption("pumping_rate"), this->pumpingRate)) { setErrorMessage("Unable to parse pumping_rate option"); return false; } } else { return false; } if (geometry->hasOption("days_before_pumping")) { if (!tryParse(geometry->getOption("days_before_pumping"), this->daysBeforePumping)) { setErrorMessage("Unable to parse days_before_pumping option"); return false; } } else { return false; } if (geometry->hasOption("pumping_threshold")) { if (!tryParse(geometry->getOption("pumping_threshold"), this->pumpingThreshold)) { setErrorMessage("Unable to parse pumping_threshold option"); return false; } } else { return false; } } // Start out the event-to-pumping interval counter with the correct duration to allow for // pumping from the start of a simulation. this->secondsSinceLastInflow = SECS_PER_DAY * this->daysBeforePumping; return true; }
DateTime DateTimeParser::parse(const std::string& str, int& timeZoneDifferential) { DateTime result; if (tryParse(str, result, timeZoneDifferential)) return result; else throw SyntaxException("Unsupported or invalid date/time format"); }
int NumberParser::parse(const std::string& s, char thSep) { int result; if (tryParse(s, result, thSep)) return result; else throw SyntaxException("Not a valid integer", s); }
bool DateTimeParser::tryParse(const std::string& str, DateTime& dateTime, int& timeZoneDifferential) { if (str.length() < 4) return false; if (str[3] == ',') return tryParse(DateTimeFormat::RFC822_FORMAT, str, dateTime, timeZoneDifferential); else if (str[3] == ' ') return tryParse(DateTimeFormat::ASCTIME_FORMAT, str, dateTime, timeZoneDifferential); else if (str.find(',') != std::string::npos) return tryParse(DateTimeFormat::RFC850_FORMAT, str, dateTime, timeZoneDifferential); else if (std::isdigit(str[0])) { if (str.find(' ') != std::string::npos || str.length() == 10) return tryParse(DateTimeFormat::SORTABLE_FORMAT, str, dateTime, timeZoneDifferential); else return tryParse(DateTimeFormat::ISO8601_FORMAT, str, dateTime, timeZoneDifferential); } else return false; }
void SAXWeightsHandler::myStartElement(int element, const SUMOSAXAttributes& attrs) { switch (element) { case SUMO_TAG_INTERVAL: { bool ok = true; myCurrentTimeBeg = attrs.get<SUMOReal>(SUMO_ATTR_BEGIN, 0, ok); myCurrentTimeEnd = attrs.get<SUMOReal>(SUMO_ATTR_END, 0, ok); } break; case SUMO_TAG_EDGE: { bool ok = true; myCurrentEdgeID = attrs.getOpt<std::string>(SUMO_ATTR_ID, 0, ok, ""); tryParse(attrs, true); } break; case SUMO_TAG_LANE: { tryParse(attrs, false); } break; default: break; } }
bool Circular::setParameters(std::vector<std::string>::const_iterator firstPart, std::vector<std::string>::const_iterator end) { if (firstPart == end) { return false; } if (!tryParse(*firstPart, this->diameter)) { setErrorMessage("Unable to parse max depth"); return false; } return true; }
JSON parse() { bool bPositive = (!tryParse(L'-')); if (bPositive) tryParse(L'+'); SInt64 iBase; UInt8 iFirstDigit; if (Character::decDigit(peek(), iFirstDigit) == Character::eCodingFailure) return JSON(1); iBase = iFirstDigit; pop(); if (iBase != 0) { UInt8 iNextDigit; while (Character::decDigit(peek(), iNextDigit) == Character::eCodingSuccess) { pop(); iBase *= 10; iBase += iNextDigit; } } Real64 fBase = Real64(iBase); bool bPoint = tryParse(L'.'); if (bPoint) { Real64 fFactor = 0.1; UInt8 iNextDigit; while (Character::decDigit(peek(), iNextDigit) == Character::eCodingSuccess) { pop(); fBase += (fFactor * iNextDigit); fFactor /= 10; } } bool bExponent = (tryParse(L'e') || tryParse(L'E')); if (bExponent) { bool bPositiveExponent = (!tryParse(L'-')); if (bPositiveExponent) tryParse(L'+'); SInt64 iExponent; UInt8 iFirstDigit; if (Character::decDigit(peek(), iFirstDigit) == Character::eCodingSuccess) { iExponent = iFirstDigit; pop(); UInt8 iNextDigit; while (Character::decDigit(peek(), iNextDigit) == Character::eCodingSuccess) { pop(); iExponent *= 10; iExponent += iNextDigit; } if (bPositiveExponent) fBase *= std::pow(Real64(10),Real64(iExponent)); else fBase *= std::pow(Real64(10),Real64(-iExponent)); } else bExponent = false; } if (bPoint || bExponent) { if (bPositive) return JSON(fBase); else return JSON(-fBase); } else { if (bPositive) return JSON(iBase); else return JSON(-iBase); } }
void DateTimeParser::parse(const std::string& str, DateTime& dateTime, int& timeZoneDifferential) { if (!tryParse(str, dateTime, timeZoneDifferential)) throw SyntaxException("Unsupported or invalid date/time format"); }
QNetString::QNetString(QObject *parent) : QObject(parent) { // Connect to our internal signals connect(this, SIGNAL(tryParse()), this, SLOT(onTryParse())); } // end QNetString
void QNetString::addData(QByteArray data) { this->buffer.append(data); emit tryParse(); } // end addData
void UUID::parse(const std::string& uuid) { if (!tryParse(uuid)) throw SyntaxException(uuid); }
virtual bool tryParse_(const std::string& str) { return tryParse(value, str); }
pStatement Statement::parse() { if (currentToken().type == TT_NAMESPACE) { nextToken(); _namespace = new_Namespace()->parse(); } else if(currentToken().type == TT_TYPEDEF) { } else if(currentToken().type == TT_STRUCT || currentToken().type == TT_CLASS) { isClass = true; if(currentToken().type == TT_STRUCT) { isStruct = true; } nextToken(); _namespace = new_Namespace(); _namespace->statementsBlock = new_StatementsBlock(); _namespace->id = currentToken().strVal; pType newType = pType(new Type(owner, false) ); pExprResult res = owner->new_ExprResult(); res->evalType = ERT_TYPE; res->type = newType; newType->definition = this; owner->parsingStatementsBlockStack.back()->vars[_namespace->id] = res; _namespace->parse(); if(currentToken().type != TT_SEMICOLON) { Parser::get()->parsingException(__FUNCTION__, __FILE__, __LINE__, currentToken(), "Expected semicolon"); } nextToken(); } else if (currentToken().type == TT_BRACE_OPEN) { this->sb = new_StatementsBlock()->parse(); } else if (currentToken().type == TT_BREAK || currentToken().type == TT_RETURN || currentToken().type == TT_ECHO || currentToken().type == TT_CONTINUE) { isSpecial = true; specialType = currentToken().type; nextToken(); if (specialType == TT_RETURN || specialType == TT_ECHO) { expr = new_Expr()->parse(); } if (currentToken().type != TT_SEMICOLON) { throwTokenExpected(TT_SEMICOLON); } nextToken(); } else if (currentToken().type == TT_IF) { isSpecial = true; specialType = currentToken().type; nextToken(); expr = new_Expr()->parse(); statement1 = new_Statement()->parse(); if (currentToken().type == TT_ELSE) { nextToken(); statement2 = new_Statement()->parse(); } } else if (currentToken().type == TT_WHILE) { localStatementsBlock = new_StatementsBlock(); owner->parsingStatementsBlockStack.push_back(localStatementsBlock); isSpecial = true; specialType = currentToken().type; if (nextToken().type != TT_PARENTHESIS_OPEN) { Parser::get()->parsingException(__FUNCTION__, __FILE__, __LINE__, currentToken() ); } nextToken(); expr = new_Expr()->parse(); if (currentToken().type != TT_PARENTHESIS_CLOSE) { Parser::get()->parsingException(__FUNCTION__, __FILE__, __LINE__, currentToken() ); } nextToken(); statement1 = new_Statement()->parse(); owner->parsingStatementsBlockStack.pop_back(); } else if (currentToken().type == TT_FOR) { localStatementsBlock = new_StatementsBlock(); owner->parsingStatementsBlockStack.push_back(localStatementsBlock); isSpecial = true; specialType = currentToken().type; if (nextToken().type != TT_PARENTHESIS_OPEN) { Parser::get()->parsingException(__FUNCTION__, __FILE__, __LINE__, currentToken() ); } nextToken(); statement1 = new_Statement()->parse(); expr = new_Expr()->parse(); if (currentToken().type != TT_SEMICOLON) { Parser::get()->parsingException(__FUNCTION__, __FILE__, __LINE__, currentToken() ); } nextToken(); expr2 = new_Expr()->parse(); if (currentToken().type != TT_PARENTHESIS_CLOSE) { Parser::get()->parsingException(__FUNCTION__, __FILE__, __LINE__, currentToken() ); } nextToken(); statement2 = new_Statement()->parse(); owner->parsingStatementsBlockStack.pop_back(); } else { tryParse([this]() { tn = new_Typename()->parse(); pVarDeclarationAllowDefault vd = new_VarDeclarationAllowDefault()->parse(); if (owner->currentToken().type == TT_PARENTHESIS_OPEN) { if (!vd->canBeFunctionDeclaration() ) { Parser::get()->parsingException(__FUNCTION__, __FILE__, __LINE__, currentToken() ); } nextToken(); this->function = pFunction(new Function(owner, vd->vd->id) ); this->function->args = new_FunctionArgs()->parse(); if (currentToken().type == TT_PARENTHESIS_CLOSE) { if (nextToken().type == ';') { this->function->statementsBlock = nullptr; } else { this->function->statementsBlock = new_StatementsBlock()->parse(); for (auto vd: this->function->args->vds) { this->function->statementsBlock->vars[vd->vd->id] = nullptr; } } } else { Parser::get()->parsingException(__FUNCTION__, __FILE__, __LINE__, currentToken(), "Unexpeted token"); } } else { if (currentToken().type == TT_COMMA || currentToken().type == TT_SEMICOLON) { vds.push_back(vd); } while (currentToken().type == TT_COMMA) { nextToken(); vds.push_back(new_VarDeclarationAllowDefault()->parse() ); } if (currentToken().type != TT_SEMICOLON) { Parser::get()->parsingException(__FUNCTION__, __FILE__, __LINE__, currentToken() ); } nextToken(); } }, [this](exception &e) { vds.clear(); tn = nullptr; expr = new_Expr()->parse(); this->function = nullptr; if (currentToken().type != TT_SEMICOLON) { Parser::get()->parsingException(__FUNCTION__, __FILE__, __LINE__, currentToken() ); } nextToken(); }); } return pStatement(this); }