static std::string loadFile (boost::property_tree::ptree &config, const boost::filesystem::path &file) { boost::filesystem::path extension = file.extension(); boost::filesystem::path extension2 = file.stem().extension(); std::string fileName = file.filename().string(); boost::property_tree::ptree readConfig; if (extension2.string() == ".conf") { if (extension.string() == ".json") { boost::property_tree::read_json (file.string(), readConfig); } else if (extension.string() == ".info") { boost::property_tree::read_info (file.string(), readConfig); } else if (extension.string() == ".ini") { boost::property_tree::read_ini (file.string(), readConfig); } else if (extension.string() == ".xml") { boost::property_tree::read_xml (file.string(), readConfig); } else { throw ParseException ("Unknonw file format"); } } else { throw ParseException ("Unknonw file format"); } mergePropertyTrees (config, readConfig); config.put ("configPath", file.parent_path().string() ); fileName = fileName.substr (0, fileName.size() - extension.string().size() ); fileName = fileName.substr (0, fileName.size() - extension2.string().size() ); return fileName; }
bool EntTokenizer::NextKV() { while(currentPtr != strEnd) { switch(*currentPtr) { case '\"': *currentPtr = 0; currentPtr++; return true; case '{': if(bInBlock) { throw ParseException("Unexpected start of block.", GetCharNum()); } bInBlock = true; break; case '}': if(!bInBlock) { throw ParseException("Unexpected end of block.", GetCharNum()); } bInBlock = false; blocksRead++; break; default: break; } currentPtr++; } currentPtr = NULL; return false; }
// _____________________________________________________________________________ ParsedQuery SparqlParser::parse(const string& query) { ParsedQuery result; result._originalString = query; // Split prologue size_t i = query.find("SELECT"); if (i == string::npos) { throw ParseException("Missing keyword \"SELECT\", " "currently only select queries are supported."); } size_t j = query.find("WHERE"); if (j == string::npos) { throw ParseException("Missing keyword \"WHERE\", " "currently only select queries are supported."); } if (i >= j) { throw ParseException("Keyword \"WHERE\" " "found after keyword \"SELECT\". Invalid query."); } size_t k = query.find("}", j); if (k == string::npos) { throw ParseException("Missing \"}\" symbol after \"WHERE\"."); } parsePrologue(ad_utility::strip(query.substr(0, i), " \n\t"), result); parseSelect(ad_utility::strip(query.substr(i, j - i), " \n\t"), result); parseWhere(ad_utility::strip(query.substr(j, k - j + 1), " \n\t"), result); parseSolutionModifiers(ad_utility::strip(query.substr(k + 1), " \n\t"), result); return result; }
void CommandLineParser::parseDuration() { QString durationString; QString choppedDurationString; assignOptionArgument(maxDurationoption(), durationString); choppedDurationString = durationString; const char suffix = durationString.at(durationString.count() - 1).toLatin1(); const bool hasSuffix = !std::isdigit(suffix); if (hasSuffix) choppedDurationString.chop(1); bool ok; m_maxDuration = choppedDurationString.toInt(&ok); if (!ok || m_maxDuration <= 0) { throw ParseException(QString::fromLocal8Bit("Invalid duration argument '%1'.") .arg(durationString)); } if (hasSuffix) { switch (suffix) { case 'm': break; case 'd': m_maxDuration *= 24; // Fall-through. case 'h': m_maxDuration *= 60; break; default: throw ParseException(QString::fromLocal8Bit("Invalid duration suffix '%1'.") .arg(suffix)); } } }
void CommandLineParser::parse(const QStringList &commandLine) { m_profile.clear(); m_startCommit.clear(); m_maxDuration = 0; m_jobCount = 0; m_log = false; m_commandLine = commandLine; Q_ASSERT(!m_commandLine.isEmpty()); m_command = m_commandLine.takeFirst(); while (!m_commandLine.isEmpty()) { const QString arg = m_commandLine.takeFirst(); if (arg == profileOption()) assignOptionArgument(arg, m_profile); else if (arg == startCommitOption()) assignOptionArgument(arg, m_startCommit); else if (arg == jobCountOption()) assignOptionArgument(arg, m_jobCount); else if (arg == maxDurationoption()) parseDuration(); else if (arg == logOption()) m_log = true; else throw ParseException(QString::fromLocal8Bit("Unknown parameter '%1'").arg(arg)); } if (m_profile.isEmpty()) throw ParseException("No profile given."); if (m_startCommit.isEmpty()) throw ParseException("No start commit given."); }
string WKTReader::getNextWord(StringTokenizer *tokenizer) { int type=tokenizer->nextToken(); switch(type){ case StringTokenizer::TT_EOF: throw ParseException("Expected word but encountered end of stream"); case StringTokenizer::TT_EOL: throw ParseException("Expected word but encountered end of line"); case StringTokenizer::TT_NUMBER: throw ParseException("Expected word but encountered number", tokenizer->getNVal()); case StringTokenizer::TT_WORD: { string word = tokenizer->getSVal(); int i = word.size(); while( --i >= 0 ) { word[i] = static_cast<char>(toupper(word[i])); } return word; } case '(': return "("; case ')': return ")"; case ',': return ","; } assert(0); //throw ParseException("Encountered unexpected StreamTokenizer type"); return ""; }
float WalkingEngineKick::readFloat(char*& buf) { while(*buf == ' ' || *buf == '\t') ++buf; char* result = buf; if(*buf == '-') ++buf; while(isdigit(*buf)) ++buf; if(buf == result) throw ParseException("expected float"); if(*buf == '.') { ++buf; while(isdigit(*buf)) ++buf; if(*buf && *buf != ' ' && *buf != '\t' && *buf != '\r' && *buf != '\n') throw ParseException("expected float"); } char c = *buf; *buf = '\0'; float f = float(atof(result)); *buf = c; return f; }
void SchemaItem::processUniqueAttributeValueSetReferences(const std::map<std::string, std::vector<std::shared_ptr<SchemaValue>>> &uniqueAttributeValueSets) { for (auto setRefIt = m_uniqueAttributeValueSetReferences.begin(); setRefIt != m_uniqueAttributeValueSetReferences.end(); ++setRefIt) { auto keyIt = uniqueAttributeValueSets.find(setRefIt->second.m_setName); if (keyIt != uniqueAttributeValueSets.end()) { for (auto cfgIt = keyIt->second.begin(); cfgIt != keyIt->second.end(); ++cfgIt) { std::shared_ptr<SchemaValue> pKeyRefAttribute = *cfgIt; // this is the reference attribute from which attributeName must be a member std::string cfgValuePath = ((setRefIt->second.m_elementPath != ".") ? setRefIt->second.m_elementPath : "") + "@" + setRefIt->second.m_attributeName; std::vector<std::shared_ptr<SchemaValue>> cfgValues; fetchSchemaValues(cfgValuePath, cfgValues); if (!cfgValues.empty()) { for (auto attrIt = cfgValues.begin(); attrIt != cfgValues.end(); ++attrIt) { (*attrIt)->setUniqueValueSetRef(pKeyRefAttribute); } } else { throw(ParseException("Attribute " + (setRefIt->second.m_attributeName + " not found when adding keyRef for key " + (setRefIt->second.m_setName)))); } } } else { throw(ParseException("Keyref to key '" + (setRefIt->second.m_setName + "' was not found"))); } } }
void DocumentConverter::characters(const XMLCh* const chars, const unsigned int length) { // Should we just ignore these characters? if (ignoreDepth > 0) return; // Ignore pure whitespace unsigned int l; for (l = 0; l < length; ++l) { XMLCh c = chars[l]; if (c == ' ' || c == '\n' || c == '\r' || c == '\t') continue; break; } if (l == length) return; try { // This conversion should be safe. CDATA may only contain valid XML // characters. These are defined in the XML 1.0 specification as the set // 0x9, 0xA, 0xD, 0x20-0xD7FF, 0xE000-0xFFFD, 0x10000-0x10FFFF. XMLChToVXIchar data(chars); doc->AddContent(data.c_str(), wcslen(data.c_str())); } catch (const VXMLDocumentModel::OutOfMemory &) { ParseException(L"unable to allocate memory for content"); } catch (const VXMLDocumentModel::InternalError &) { ParseException(L"corrupted document tree; unable to add content"); } }
void CommandLineParser::parseArgs(const std::vector<StringView>& args, CommandLineFlags& result) const { size_t numPositionalConsumed = 0; size_t numFlagConsumed = 0; while (numFlagConsumed < args.size()) { auto flag = args[numFlagConsumed]; if (!isOption(flag)) // Positional arguments { if (numPositionalConsumed >= posFlagMap.size()) throw ParseException("too many positional arguments"); auto inserted = result.addFlag(posFlagMap[numPositionalConsumed].first, flag); assert(inserted && "Insertion failed"); ++numPositionalConsumed; } else // Optional arguments { flag.remove_prefix(1); // See if flag is "-help" if (flag == "help") throw HelpException(); auto itr = optFlagMap.find(flag); if (itr == optFlagMap.end()) throw ParseException("Option not recognized: " + flag.to_string()); if (itr->second.defaultValue) { ++numFlagConsumed; if (numFlagConsumed >= args.size()) throw ParseException("More argument needs to be provided after option " + flag.to_string()); auto flagArg = args[numFlagConsumed]; if (isOption(flagArg)) throw ParseException("Found another option instead of an argument after option " + flag.to_string()); auto inserted = result.addFlag(flag, flagArg); assert(inserted && "Insertion failed"); } else { auto inserted = result.addFlag(flag, ""); assert(inserted && "Insertion failed"); } } ++numFlagConsumed; } if (numPositionalConsumed < posFlagMap.size()) throw ParseException("Not enough positional arguments are provided"); for (auto const& mapping: optFlagMap) { if (mapping.second.defaultValue && result.lookup(mapping.first) == nullptr) result.addFlag(mapping.first, *mapping.second.defaultValue); } }
int StringBuilder::parseInt() const { if( m_pos == 0 ) throw ParseException("StringBuilder::parseInt(): Cannot parse a '0' length string!"); if( m_pos == m_alloc ) growCapacity((size_t)1); // make sure we have enough room for the following temproary '/0' termination int lvalue; if(sscanf(m_buffer,"%d",&lvalue)!=1) throw ParseException("StringBuilder::parseInt()"); return lvalue; }
void SchemaItem::processDefinedUniqueAttributeValueSets(std::map<std::string, std::vector<std::shared_ptr<SchemaValue>>> &uniqueAttributeValueSets) { for (auto setIt = m_uniqueAttributeValueSetDefs.begin(); setIt != m_uniqueAttributeValueSetDefs.end(); ++setIt) { auto it = uniqueAttributeValueSets.find(setIt->first); bool keyDefExists = it != uniqueAttributeValueSets.end(); if (!keyDefExists || setIt->second.m_duplicateOk) { std::string cfgValuePath = ((setIt->second.m_elementPath != ".") ? setIt->second.m_elementPath : "") + "@" + setIt->second.m_attributeName; std::vector<std::shared_ptr<SchemaValue>> cfgValues; fetchSchemaValues(cfgValuePath, cfgValues); if (!cfgValues.empty()) { // // For each attribute, if it does not already exist in the list of attributes making up this // key value, add it. for (auto attrIt = cfgValues.begin(); attrIt != cfgValues.end(); ++attrIt) { (*attrIt)->setUniqueValue(true); if (!keyDefExists) { std::vector<std::shared_ptr<SchemaValue>> values; values.push_back(*attrIt); it = uniqueAttributeValueSets.insert({ setIt->second.m_setName, values }).first; // so the else condition will work keyDefExists = true; // Now, it does exist } else { std::vector<std::shared_ptr<SchemaValue>> &values = it->second; bool found = false; for (auto cfgIt = values.begin(); cfgIt != values.end() && !found; ++cfgIt) { found = (*cfgIt) == (*attrIt); } if (!found) values.push_back(*attrIt); } } } else { throw(ParseException("Attribute " + setIt->second.m_attributeName + " not found for key " + setIt->second.m_setName)); } } else { throw(ParseException("Duplicate key (" + setIt->second.m_setName + ") found for element " + m_properties["name"])); } } // // Post process all of our children now for (auto it = m_children.begin(); it != m_children.end(); ++it) { it->second->processDefinedUniqueAttributeValueSets(uniqueAttributeValueSets); } }
double StringBuilder::parseDouble( size_t _index ) const { if( m_pos == 0 || _index >= m_pos-1 ) throw ParseException("StringBuilder::parseDouble( size_t _index )"); if( m_pos == m_alloc ) growCapacity((size_t)1); // make sure we have enough room for the following temproary '/0' termination m_buffer[m_pos] = 0; // ensure a '0' terminated string for sscanf() but do not increase the size of the string double lvalue; if(sscanf(&m_buffer[_index],"%lf",&lvalue)!=1) throw ParseException("StringBuilder::parseDouble()"); return lvalue; }
void CommandLineParser::assignOptionArgument(const QString &option, QString &argument) { if (m_commandLine.isEmpty()) throw ParseException(QString::fromLocal8Bit("Option '%1' needs an argument.").arg(option)); argument = m_commandLine.takeFirst(); if (argument.isEmpty()) { throw ParseException(QString::fromLocal8Bit("Argument for option '%1' must not be empty.") .arg(option)); } }
void SchemaItem::postProcessConfig(const std::map<std::string, std::vector<std::shared_ptr<SchemaValue>>> &uniqueAttributeValueSets) { // // Make sure that the item type value for all children that are insertable (minRequired = 0 or maxAllowed > minRequired) std::set<std::string> itemTypes; for (auto it = m_children.begin(); it != m_children.end(); ++it) { if (it->second->isInsertable()) { auto rc = itemTypes.insert(it->second->getItemType()); if (!rc.second) { throw(ParseException("Duplicate itemType(" + it->second->getItemType() + ") found for element " + m_properties["name"])); } } } processUniqueAttributeValueSetReferences(uniqueAttributeValueSets); // // Post process the attributes for (auto it = m_attributes.begin(); it != m_attributes.end(); ++it) { // // If this is a mirroed value, go find the source and attach ourselves so that if that value changes, // it is replicated to us. if (it->second->isMirroredValue()) { std::vector<std::shared_ptr<SchemaValue>> cfgValues; fetchSchemaValues(it->second->getMirrorFromPath(), cfgValues); if (!cfgValues.empty() && cfgValues.size() == 1) { if (cfgValues.size() == 1) { it->second->addMirroredSchemaValue(cfgValues[0]); } else { throw(ParseException("Multiple sources found for mirror from path for attribute " + it->second->getName() + " (path=" + it->second->getMirrorFromPath())); } } else { throw(ParseException("Mirrored from source not found for attribute " + it->second->getName() + " path=" + it->second->getMirrorFromPath())); } } } // // Post process all of our children now for (auto it = m_children.begin(); it!= m_children.end(); ++it) { it->second->postProcessConfig(uniqueAttributeValueSets); } }
// _____________________________________________________________________________ void SparqlParser::addPrefix(const string& str, ParsedQuery& query) { auto parts = ad_utility::split(ad_utility::strip(str, ' '), ' '); if (parts.size() != 3) { throw ParseException(string("Invalid PREFIX statement: ") + str); } string uri = ad_utility::strip(parts[2], " \t\n"); if (uri.size() == 0 || uri[0] != '<' || uri[uri.size() - 1] != '>') { throw ParseException(string("Invalid URI in PREFIX: ") + uri); } SparqlPrefix p{ad_utility::strip(parts[1], " :\t\n"), uri}; query._prefixes.emplace_back(p); };
double StringBuilder::parseDouble( size_t _index, size_t _length ) const { size_t tempTerminatorIndex = _index + _length; if( _length == 0 || tempTerminatorIndex > m_pos ) throw ParseException("StringBuilder::parseDouble(): Cannot parse a '0' length string!"); if( tempTerminatorIndex+1 > m_alloc ) growCapacity((size_t)(tempTerminatorIndex+1 - m_alloc)); // make sure we have enough room for the following temproary '/0' termination char cache = m_buffer[tempTerminatorIndex]; // store what was here before m_buffer[tempTerminatorIndex] = 0; // ensure a '0' terminated string for sscanf() but do not increase the size of the string double lvalue; int result = sscanf(&m_buffer[_index],"%lf",&lvalue); m_buffer[tempTerminatorIndex] = cache; // put it back! if(result!=1) throw ParseException("StringBuilder::parseInt()"); else return lvalue; }
void PopsDat::parse( const std::string& _Line ) { std::vector<std::string> parts = chopstr( _Line, TOKEN_WHITESPACE.c_str() ); if( parts.size() != 5 ) throw ParseException("POPS: Atom set initial line contains the wrong number of elements"); if( 0 != str2int( parts[0], expectedAtomTypeCount ) || 0 != str2double( parts[1], b12 ) || 0 != str2double( parts[2], b13 ) || 0 != str2double( parts[3], b14 ) || 0 != str2double( parts[4], bOther ) ) throw ParseException("POPS: Invalid value in atom set initial line"); return; }
novatel_gps_msgs::TrackstatPtr novatel_gps_driver::TrackstatParser::ParseAscii(const novatel_gps_driver::NovatelSentence& sentence) throw(ParseException) { if (sentence.body.size() < ASCII_BODY_FIELDS) { std::stringstream error; error << "Unexpected number of body fields in TRACKSTAT log: " << sentence.body.size(); throw ParseException(error.str()); } uint32_t n_channels = 0; ParseUInt32(sentence.body[3], n_channels, 10); if (sentence.body.size() != ASCII_BODY_FIELDS + n_channels * ASCII_CHANNEL_FIELDS) { std::stringstream error; error << "Size of TRACKSTAT log did not match expected size."; throw ParseException(error.str()); } bool valid = true; novatel_gps_msgs::TrackstatPtr msg = boost::make_shared<novatel_gps_msgs::Trackstat>(); msg->solution_status = sentence.body[0]; msg->position_type = sentence.body[1]; valid &= ParseFloat(sentence.body[2], msg->cutoff); msg->channels.resize(n_channels); for (size_t i = 0; i < static_cast<size_t>(n_channels); ++i) { size_t offset = 4 + i * ASCII_CHANNEL_FIELDS; novatel_gps_msgs::TrackstatChannel& channel = msg->channels[i]; valid &= ParseInt16(sentence.body[offset], channel.prn); valid &= ParseInt16(sentence.body[offset+1], channel.glofreq); valid &= ParseUInt32(sentence.body[offset+2], channel.ch_tr_status, 16); valid &= ParseDouble(sentence.body[offset+3], channel.psr); valid &= ParseFloat(sentence.body[offset+4], channel.doppler); valid &= ParseFloat(sentence.body[offset+5], channel.c_no); valid &= ParseFloat(sentence.body[offset+6], channel.locktime); valid &= ParseFloat(sentence.body[offset+7], channel.psr_res); channel.reject = sentence.body[offset+8]; valid &= ParseFloat(sentence.body[offset+9], channel.psr_weight); } if (!valid) { std::stringstream error; error << "Error parsing TRACKSTAT log."; throw ParseException(error.str()); } return msg; }
int ConfigMapParser::parse(bool noThrow) { int returnValue = 0; ASSERT(lexer); ASSERT(configMap); try { if(!lexer->isValid()) { returnValue = ConfigMap::E_FILE; throw ParseException(0, 0, "Cannot read file."); } nextToken(); // get the first token return file(configMap); } catch(ParseException& pe) { // If the returnValue indicates not that the file connot be opened, there // has to be a syntax error. if (returnValue != ConfigMap::E_FILE) returnValue = ConfigMap::E_SYNTAX; if(verbose) pe.printError(lexer->getFilename()); std::stringstream buf; std::cout<<"[EXCEPTION ERROR ] ConfigMapParser.cpp 3"<<std::endl; buf << lexer->getFilename() << ":" << pe.line << "," << pe.column << ": " << pe.what(); ParseException e = ParseException(pe.line, pe.column, buf.str()); if (noThrow) setError(e); else throw e; } catch(invalid_key) { if(verbose) OUTPUT_ERROR("ConfigMapParser::parse catched a invalid_key exception.\n" "This indicates, that there is a bug into the parser."); ASSERT(false); } catch(std::invalid_argument) { if(verbose) OUTPUT_ERROR("ConfigMapParser::parse catched a invalid_argument exception.\n" "This indicates, that there is a bug into the parser."); ASSERT(false); } return returnValue; }
ASTNode* ASTExpressionBuilder::shuntingYardAlgorithm() { _operators.clear(); _results.clear(); while (!_tokens.empty()) { _token = _tokens.front(); _tokens.pop_front(); if (isKeyword("+") || isKeyword("-") || isKeyword("*") || isKeyword("/")) { while (!_operators.empty() && getOprPriority(_token) <= getOprPriority(_operators.back())) { buildOperators(); } _operators.push_back(_token); } else if (isKeyword("(")) { _operators.push_back("("); } else if (isKeyword(")")) { while (!_operators.empty() && _operators.back() != "(") { buildOperators(); } if (_operators.empty()) { throw ParseException(_token, "Mismatched parentheses"); } _operators.pop_back(); } else if (isDigits() || isName()) { buildOperands(); } else { throw ParseException(_token, "Unable to parse expression"); } getToken(); } while (!_operators.empty()) { if (_operators.back() == "(") { throw ParseException(_token, "Mismatched parentheses"); } buildOperators(); } ASTNode* expNode = _results.back(); _results.pop_back(); return expNode; }
std::set<AAMutation> readMutations(std::istream& mutationFile, std::string prefix) throw (ParseException) { std::set<AAMutation> result; std::string line; typedef boost::tokenizer<boost::escaped_list_separator<char> > csv_tok; getline(mutationFile, line); csv_tok tok(line); for (csv_tok::iterator i = tok.begin(); i != tok.end(); ++i) { std::string mutation = *i; if (mutation.length() < prefix.length() + 2) throw ParseException("", "Error while parsing mutation '" + mutation + "': too short for mutation with " "prefix '" + prefix + "'", false); if (mutation.substr(0, prefix.length()) != prefix) throw ParseException("", "Error while parsing mutation '" + mutation + "': expected to start with '" + prefix + "'", false); try { AminoAcid aa(mutation[mutation.length() - 1]); char *endptr; std::string posStr = mutation.substr(prefix.length(), mutation.length() - prefix.length() - 1); int pos = strtol(posStr.c_str(), &endptr, 10); if (*endptr != 0) throw ParseException("", "could not parse position", false); result.insert(AAMutation(pos, aa)); } catch (ParseException& e) { throw ParseException("", "Error while parsing mutation '" + mutation + "': " + e.message(), false); } } return result; }
XMLTree::XMLTree(bool validate, const char *docBuffer, std::size_t bufferLen) : docPtr(NULL) { if (static_cast<const char *> (NULL) == docBuffer) { throw std::invalid_argument("XMLTree(docBuffer) is NULL"); } if (0 == bufferLen) { bufferLen = std::strlen(docBuffer); if (0 == bufferLen) { throw std::invalid_argument("XMLTree(docBuffer) is empty"); } } if (INT_MAX < bufferLen) { throw std::invalid_argument("XMLTree(docBuffer) too long"); } docPtr = xmlReadMemory(docBuffer, static_cast<int> (bufferLen), NULL, NULL, XML_PARSE_NONET); if (static_cast<xmlDocPtr> (NULL) == docPtr) { throw ParseException("XMLTree() unable to parse docBuffer"); } if (validate) { // // Now, try to validate the document. // XMLErrorData errorData("XMLTree() "); xmlValidCtxt cvp; cvp.userData = &errorData; cvp.error = reinterpret_cast<xmlValidityErrorFunc> (XMLErrorHandler); cvp.warning = reinterpret_cast<xmlValidityErrorFunc> (XMLErrorHandler); if (!xmlValidateDocument(&cvp, docPtr)) { xmlFreeDoc(docPtr); if (errorData.errorDetected) { throw ParseException(errorData.message); } else { throw ParseException("XMLTree() docBuffer does not validate"); } } } if (static_cast<xmlNodePtr> (NULL) == xmlDocGetRootElement(docPtr)) { xmlFreeDoc(docPtr); throw ParseException("XMLTree() empty document"); } }
std::string HttpRequest::GetRequestAsString() { std::ostringstream out; std::string method; if (this->method >= 0 && this->method < (int)HttpMethodString.size()) { method = HttpMethodString[this->method]; } else { throw ParseException(); } out << method << " " << uri << " "; out << "HTTP/" << version << endLine; for (const auto field : fields) { out << field.first << ": " << field.second << endLine; } out << endLine; out << body; return out.str(); }
novatel_gps_msgs::GpgsaPtr novatel_gps_driver::GpgsaParser::ParseAscii(const novatel_gps_driver::NmeaSentence& sentence) throw(ParseException) { // Check the length first -- should be 18 elements long const size_t LENGTH = 18; if (sentence.body.size() != LENGTH) { std::stringstream error; error << "Expected GPGSA length " << LENGTH << ", actual length " << sentence.body.size(); throw ParseException(error.str()); } novatel_gps_msgs::GpgsaPtr msg = boost::make_shared<novatel_gps_msgs::Gpgsa>(); msg->message_id = sentence.body[0]; msg->auto_manual_mode = sentence.body[1]; ParseUInt8(sentence.body[2], msg->fix_mode); // Words 3-14 of the sentence are SV IDs. Copy only the non-null strings. msg->sv_ids.resize(12, 0); size_t n_svs = 0; for (std::vector<std::string>::const_iterator id = sentence.body.begin()+3; id < sentence.body.begin()+15; ++id) { if (! id->empty()) { ParseUInt8(*id, msg->sv_ids[n_svs]); ++n_svs; } } msg->sv_ids.resize(n_svs); ParseFloat(sentence.body[15], msg->pdop); ParseFloat(sentence.body[16], msg->hdop); ParseFloat(sentence.body[17], msg->vdop); return msg; }
// Stand-alone helper parsing function inline void obtainLine( std::ifstream& _stream, std::string& line ) { // Pump lines out of the file, discarding those which are comments and empty // Verify we are not at EOF at each case while(std::getline(_stream,line)) { if( _stream.fail() ) throw ParseException("POPS: Unexpected 'stream error' whilst parsing data"); line = trim( line, TOKEN_WHITESPACE ); if( line.size() == 0 || line[0] == '#' ) { if( _stream.eof() ) throw ParseException("POPS: Unexpected 'end of file' whilst parsing data"); continue; // ignore blank lines and comments } break; } }
void Parser::parse(char* http, int nbytes) { int nparsed = http_parser_execute(m_parser, &m_settings, http, nbytes); if (nparsed != nbytes) { ERR("Parse error! expected size = %i, actual size = %i, %s", nbytes, nparsed, http); throw ParseException(); } }
void parse (StringParser& p, std::complex<F>& out) { size_t start = p.pos (); F real, imag; parse (p, real); size_t pos = p.pos (); p.skipWs (); size_t pos2 = p.pos (); char sign = p.read (); if (sign == '+' || sign == '-') { p.skipWs (); if (p.peek () == 'i' || p.peek () == 'I') { p.read (); imag = sign == '+' ? 1 : -1; } else { p.seek (pos2); parse (p, imag); p.skipWs (); char c = p.read (); if (c != 'i' && c != 'I') { throw ParseException (typeid (std::complex<F>), p.value (), start, p.pos () - 1, "Expected `i' oder `I' after imaginary part"); } } out = std::complex<F> (real, imag); } else { p.seek (pos); out = std::complex<F> (real, 0); } }
void parse (const std::string& s, T& out) { StringParser p (s); parse (p, out); p.skipWs (); if (!p.eof ()) throw ParseException (typeid (T), p.value (), 0, p.pos (), "Got garbage at end of string"); }
novatel_gps_msgs::InscovPtr novatel_gps_driver::InscovParser::ParseBinary(const BinaryMessage& bin_msg) throw(ParseException) { if (bin_msg.data_.size() != BINARY_LENGTH) { std::stringstream error; error << "Unexpected inscov message size: " << bin_msg.data_.size(); throw ParseException(error.str()); } novatel_gps_msgs::InscovPtr ros_msg = boost::make_shared<novatel_gps_msgs::Inscov>(); HeaderParser h_parser; ros_msg->novatel_msg_header = h_parser.ParseBinary(bin_msg); ros_msg->novatel_msg_header.message_name = GetMessageName(); ros_msg->week = ParseUInt32(&bin_msg.data_[0]); ros_msg->seconds = ParseDouble(&bin_msg.data_[4]); int offset = 12; for (int i = 0; i < 9; i++, offset += 8) { ros_msg->position_covariance[i] = ParseDouble(&bin_msg.data_[offset]); } for (int i = 0; i < 9; i++, offset += 8) { ros_msg->attitude_covariance[i] = ParseDouble(&bin_msg.data_[offset]); } for (int i = 0; i < 9; i++, offset += 8) { ros_msg->velocity_covariance[i] = ParseDouble(&bin_msg.data_[offset]); } return ros_msg; }