本文整理汇总了C++中BaseParser::Parse方法的典型用法代码示例。如果您正苦于以下问题:C++ BaseParser::Parse方法的具体用法?C++ BaseParser::Parse怎么用?C++ BaseParser::Parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BaseParser
的用法示例。
在下文中一共展示了BaseParser::Parse方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
SimpleLogger().Write(logWARNING) << "No input file specified";
SimpleLogger().Write() << visible_options;
return -1;
}
if(1 > requested_num_threads) {
SimpleLogger().Write(logWARNING) << "Number of threads must be 1 or larger";
return -1;
}
SimpleLogger().Write() << "Input file: " << input_path.filename().string();
SimpleLogger().Write() << "Profile: " << profile_path.filename().string();
SimpleLogger().Write() << "Threads: " << requested_num_threads;
/*** Setup Scripting Environment ***/
ScriptingEnvironment scriptingEnvironment(profile_path.c_str());
omp_set_num_threads( std::min( omp_get_num_procs(), requested_num_threads) );
bool file_has_pbf_format(false);
std::string output_file_name(input_path.c_str());
std::string restrictionsFileName(input_path.c_str());
std::string::size_type pos = output_file_name.find(".osm.bz2");
if(pos==std::string::npos) {
pos = output_file_name.find(".osm.pbf");
if(pos!=std::string::npos) {
file_has_pbf_format = true;
}
}
if(pos==std::string::npos) {
pos = output_file_name.find(".pbf");
if(pos!=std::string::npos) {
file_has_pbf_format = true;
}
}
if(pos!=std::string::npos) {
output_file_name.replace(pos, 8, ".osrm");
restrictionsFileName.replace(pos, 8, ".osrm.restrictions");
} else {
pos=output_file_name.find(".osm");
if(pos!=std::string::npos) {
output_file_name.replace(pos, 5, ".osrm");
restrictionsFileName.replace(pos, 5, ".osrm.restrictions");
} else {
output_file_name.append(".osrm");
restrictionsFileName.append(".osrm.restrictions");
}
}
StringMap stringMap;
ExtractionContainers externalMemory;
stringMap[""] = 0;
extractCallBacks = new ExtractorCallbacks(&externalMemory, &stringMap);
BaseParser* parser;
if(file_has_pbf_format) {
parser = new PBFParser(input_path.c_str(), extractCallBacks, scriptingEnvironment);
} else {
parser = new XMLParser(input_path.c_str(), extractCallBacks, scriptingEnvironment);
}
if(!parser->ReadHeader()) {
throw OSRMException("Parser not initialized!");
}
SimpleLogger().Write() << "Parsing in progress..";
double parsing_start_time = get_timestamp();
parser->Parse();
SimpleLogger().Write() << "Parsing finished after " <<
(get_timestamp() - parsing_start_time) <<
" seconds";
if( externalMemory.all_edges_list.empty() ) {
SimpleLogger().Write(logWARNING) << "The input data is empty, exiting.";
return -1;
}
externalMemory.PrepareData(output_file_name, restrictionsFileName);
delete parser;
delete extractCallBacks;
SimpleLogger().Write() <<
"extraction finished after " << get_timestamp() - startup_time <<
"s";
SimpleLogger().Write() << "To prepare the data for routing, run: "
<< "./osrm-prepare " << output_file_name << std::endl;
} catch(boost::program_options::too_many_positional_options_error& e) {
SimpleLogger().Write(logWARNING) << "Only one input file can be specified";
return -1;
} catch(boost::program_options::error& e) {
SimpleLogger().Write(logWARNING) << e.what();
return -1;
} catch(std::exception & e) {
SimpleLogger().Write(logWARNING) << "Unhandled exception: " << e.what();
return -1;
}
return 0;
}
示例2: Run
int Extractor::Run(int argc, char *argv[])
{
try
{
LogPolicy::GetInstance().Unmute();
TIMER_START(extracting);
if (!ParseArguments(argc, argv))
return 0;
if (1 > requested_num_threads)
{
SimpleLogger().Write(logWARNING) << "Number of threads must be 1 or larger";
return 1;
}
if (!boost::filesystem::is_regular_file(input_path))
{
SimpleLogger().Write(logWARNING) << "Input file " << input_path.string()
<< " not found!";
return 1;
}
if (!boost::filesystem::is_regular_file(profile_path))
{
SimpleLogger().Write(logWARNING) << "Profile " << profile_path.string()
<< " not found!";
return 1;
}
const unsigned recommended_num_threads = tbb::task_scheduler_init::default_num_threads();
SimpleLogger().Write() << "Input file: " << input_path.filename().string();
SimpleLogger().Write() << "Profile: " << profile_path.filename().string();
SimpleLogger().Write() << "Threads: " << requested_num_threads;
if (recommended_num_threads != requested_num_threads)
{
SimpleLogger().Write(logWARNING) << "The recommended number of threads is "
<< recommended_num_threads
<< "! This setting may have performance side-effects.";
}
tbb::task_scheduler_init init(requested_num_threads);
/*** Setup Scripting Environment ***/
ScriptingEnvironment scripting_environment(profile_path.string().c_str());
GenerateOutputFilesNames();
std::unordered_map<std::string, NodeID> string_map;
ExtractionContainers extraction_containers;
string_map[""] = 0;
auto extractor_callbacks = new ExtractorCallbacks(extraction_containers, string_map);
BaseParser *parser;
if (file_has_pbf_format)
{
parser = new PBFParser(input_path.string().c_str(),
extractor_callbacks,
scripting_environment,
requested_num_threads);
}
else
{
parser = new XMLParser(input_path.string().c_str(),
extractor_callbacks,
scripting_environment);
}
if (!parser->ReadHeader())
{
throw OSRMException("Parser not initialized!");
}
SimpleLogger().Write() << "Parsing in progress..";
TIMER_START(parsing);
parser->Parse();
delete parser;
delete extractor_callbacks;
TIMER_STOP(parsing);
SimpleLogger().Write() << "Parsing finished after " << TIMER_SEC(parsing) << " seconds";
if (extraction_containers.all_edges_list.empty())
{
SimpleLogger().Write(logWARNING) << "The input data is empty, exiting.";
return 1;
}
extraction_containers.PrepareData(output_file_name, restriction_file_name);
TIMER_STOP(extracting);
SimpleLogger().Write() << "extraction finished after " << TIMER_SEC(extracting) << "s";
SimpleLogger().Write() << "To prepare the data for routing, run: "
<< "./osrm-prepare " << output_file_name << std::endl;
}
catch (boost::program_options::too_many_positional_options_error &)
{
//.........这里部分代码省略.........