Boost Property Tree provides the speed profile from an ini file
Memory leak fixed, issue #11, thanks sivetic Typo fixed for loop replaced by boost's FOREACH
This commit is contained in:
parent
c4fb8f74ac
commit
109279d0b5
@ -27,6 +27,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
#include <climits>
|
#include <climits>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
#include <exception>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
@ -34,6 +35,9 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <libxml/xmlreader.h>
|
#include <libxml/xmlreader.h>
|
||||||
|
#include <boost/foreach.hpp>
|
||||||
|
#include <boost/property_tree/ptree.hpp>
|
||||||
|
#include <boost/property_tree/ini_parser.hpp>
|
||||||
#include <google/sparse_hash_map>
|
#include <google/sparse_hash_map>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stxxl.h>
|
#include <stxxl.h>
|
||||||
@ -48,6 +52,8 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
#include "Util/InputFileUtil.h"
|
#include "Util/InputFileUtil.h"
|
||||||
#include "Util/MachineInfo.h"
|
#include "Util/MachineInfo.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
typedef BaseConfiguration ExtractorConfiguration;
|
typedef BaseConfiguration ExtractorConfiguration;
|
||||||
|
|
||||||
unsigned globalRestrictionCounter = 0;
|
unsigned globalRestrictionCounter = 0;
|
||||||
@ -61,6 +67,7 @@ bool wayFunction(_Way w);
|
|||||||
template<class ClassT>
|
template<class ClassT>
|
||||||
bool removeIfUnused(ClassT n) { return (false == n.used); }
|
bool removeIfUnused(ClassT n) { return (false == n.used); }
|
||||||
|
|
||||||
|
|
||||||
int main (int argc, char *argv[]) {
|
int main (int argc, char *argv[]) {
|
||||||
if(argc <= 1) {
|
if(argc <= 1) {
|
||||||
cerr << "usage: " << endl << argv[0] << " <file.osm/.osm.bz2/.osm.pbf>" << endl;
|
cerr << "usage: " << endl << argv[0] << " <file.osm/.osm.bz2/.osm.pbf>" << endl;
|
||||||
@ -92,6 +99,31 @@ int main (int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
string adressFileName(outputFileName);
|
string adressFileName(outputFileName);
|
||||||
|
Settings settings;
|
||||||
|
|
||||||
|
boost::property_tree::ptree pt;
|
||||||
|
try {
|
||||||
|
INFO("Loading speed profiles")
|
||||||
|
boost::property_tree::ini_parser::read_ini("speedprofile.ini", pt);
|
||||||
|
INFO("Found the following speed profiles: ");
|
||||||
|
int profileCounter(0);
|
||||||
|
BOOST_FOREACH(boost::property_tree::ptree::value_type &v, pt.get_child("")) {
|
||||||
|
string name = v.first;
|
||||||
|
cout << " [" << profileCounter << "]" << name << endl;
|
||||||
|
++profileCounter;
|
||||||
|
}
|
||||||
|
string usedSpeedProfile(pt.get_child("").begin()->first);
|
||||||
|
INFO("Using profile \"" << usedSpeedProfile << "\"")
|
||||||
|
BOOST_FOREACH(boost::property_tree::ptree::value_type &v, pt.get_child(usedSpeedProfile)) {
|
||||||
|
string name = v.first;
|
||||||
|
int value = v.second.get<int>("");
|
||||||
|
DEBUG("inserting " << name << "=" << value);
|
||||||
|
settings.speedProfile.names.push_back(name);
|
||||||
|
settings.speedProfile.speed.push_back(value);
|
||||||
|
}
|
||||||
|
} catch(std::exception& e) {
|
||||||
|
ERR("caught: " << e.what() );
|
||||||
|
}
|
||||||
|
|
||||||
unsigned amountOfRAM = 1;
|
unsigned amountOfRAM = 1;
|
||||||
unsigned installedRAM = GetPhysicalmemory();
|
unsigned installedRAM = GetPhysicalmemory();
|
||||||
@ -111,17 +143,13 @@ int main (int argc, char *argv[]) {
|
|||||||
unsigned usedNodeCounter = 0;
|
unsigned usedNodeCounter = 0;
|
||||||
unsigned usedEdgeCounter = 0;
|
unsigned usedEdgeCounter = 0;
|
||||||
|
|
||||||
StringMap * stringMap = new StringMap();
|
StringMap stringMap;
|
||||||
Settings settings;
|
|
||||||
settings.speedProfile.names.insert(settings.speedProfile.names.begin(), names, names+14);
|
|
||||||
settings.speedProfile.speed.insert(settings.speedProfile.speed.begin(), speeds, speeds+14);
|
|
||||||
|
|
||||||
double time = get_timestamp();
|
double time = get_timestamp();
|
||||||
|
|
||||||
stringMap->set_empty_key(GetRandomString());
|
stringMap.set_empty_key(GetRandomString());
|
||||||
stringMap->insert(make_pair("", 0));
|
stringMap.insert(make_pair("", 0));
|
||||||
extractCallBacks = new ExtractorCallbacks(&externalMemory, settings, stringMap);
|
extractCallBacks = new ExtractorCallbacks(&externalMemory, settings, &stringMap);
|
||||||
|
|
||||||
BaseParser<_Node, _RawRestrictionContainer, _Way> * parser;
|
BaseParser<_Node, _RawRestrictionContainer, _Way> * parser;
|
||||||
if(isPBF) {
|
if(isPBF) {
|
||||||
parser = new PBFParser(argv[1]);
|
parser = new PBFParser(argv[1]);
|
||||||
@ -136,6 +164,7 @@ int main (int argc, char *argv[]) {
|
|||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
delete parser;
|
delete parser;
|
||||||
|
stringMap.clear();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// INFO("raw no. of names: " << externalMemory.nameVector.size());
|
// INFO("raw no. of names: " << externalMemory.nameVector.size());
|
||||||
@ -404,10 +433,10 @@ int main (int argc, char *argv[]) {
|
|||||||
unsigned sizeOfNameIndex = nameIndex->size();
|
unsigned sizeOfNameIndex = nameIndex->size();
|
||||||
nameOutFile.write((char *)&(sizeOfNameIndex), sizeof(unsigned));
|
nameOutFile.write((char *)&(sizeOfNameIndex), sizeof(unsigned));
|
||||||
|
|
||||||
for(STXXLStringVector::iterator it = externalMemory.nameVector.begin(); it != externalMemory.nameVector.end(); it++) {
|
BOOST_FOREACH(string str, externalMemory.nameVector) {
|
||||||
unsigned lengthOfRawString = strlen(it->c_str());
|
unsigned lengthOfRawString = strlen(str.c_str());
|
||||||
nameOutFile.write((char *)&(lengthOfRawString), sizeof(unsigned));
|
nameOutFile.write((char *)&(lengthOfRawString), sizeof(unsigned));
|
||||||
nameOutFile.write(it->c_str(), lengthOfRawString);
|
nameOutFile.write(str.c_str(), lengthOfRawString);
|
||||||
}
|
}
|
||||||
|
|
||||||
nameOutFile.close();
|
nameOutFile.close();
|
||||||
|
Loading…
Reference in New Issue
Block a user