Restructured calling of callback functions
This commit is contained in:
parent
10cf41d138
commit
e8c7f7b5da
@ -23,12 +23,12 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
|
|
||||||
#include <luabind/luabind.hpp>
|
#include <luabind/luabind.hpp>
|
||||||
|
|
||||||
template<typename NodeT, typename RestrictionT, typename WayT>
|
template<class ExternalMemoryT, typename NodeT, typename RestrictionT, typename WayT>
|
||||||
class BaseParser {
|
class BaseParser {
|
||||||
public:
|
public:
|
||||||
virtual ~BaseParser() {}
|
virtual ~BaseParser() {}
|
||||||
virtual bool Init() = 0;
|
virtual bool Init() = 0;
|
||||||
virtual bool RegisterCallbacks(bool (*nodeCallbackPointer)(NodeT), bool (*restrictionCallbackPointer)(RestrictionT), bool (*wayCallbackPointer)(WayT)) = 0;
|
virtual void RegisterCallbacks(ExternalMemoryT * externalMemory) = 0;
|
||||||
virtual void RegisterLUAState(lua_State *myLuaState) = 0;
|
virtual void RegisterLUAState(lua_State *myLuaState) = 0;
|
||||||
virtual bool Parse() = 0;
|
virtual bool Parse() = 0;
|
||||||
|
|
||||||
|
@ -32,13 +32,14 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
#include "../typedefs.h"
|
#include "../typedefs.h"
|
||||||
|
|
||||||
#include "BaseParser.h"
|
#include "BaseParser.h"
|
||||||
|
#include "ExtractorCallbacks.h"
|
||||||
#include "ExtractorStructs.h"
|
#include "ExtractorStructs.h"
|
||||||
#include "../DataStructures/HashTable.h"
|
#include "../DataStructures/HashTable.h"
|
||||||
#include "../DataStructures/ConcurrentQueue.h"
|
#include "../DataStructures/ConcurrentQueue.h"
|
||||||
|
|
||||||
class PBFParser : public BaseParser<_Node, _RawRestrictionContainer, _Way> {
|
class PBFParser : public BaseParser<ExtractorCallbacks, _Node, _RawRestrictionContainer, _Way> {
|
||||||
|
|
||||||
typedef BaseParser<_Node, _RawRestrictionContainer, _Way> super;
|
typedef BaseParser<ExtractorCallbacks, _Node, _RawRestrictionContainer, _Way> super;
|
||||||
|
|
||||||
enum EntityType {
|
enum EntityType {
|
||||||
TypeNode = 1,
|
TypeNode = 1,
|
||||||
@ -67,7 +68,7 @@ class PBFParser : public BaseParser<_Node, _RawRestrictionContainer, _Way> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PBFParser(const char * fileName) : myLuaState(NULL) {
|
PBFParser(const char * fileName) : externalMemory(NULL), myLuaState(NULL) {
|
||||||
GOOGLE_PROTOBUF_VERIFY_VERSION;
|
GOOGLE_PROTOBUF_VERIFY_VERSION;
|
||||||
//TODO: What is the bottleneck here? Filling the queue or reading the stuff from disk?
|
//TODO: What is the bottleneck here? Filling the queue or reading the stuff from disk?
|
||||||
threadDataQueue = boost::make_shared<ConcurrentQueue<_ThreadData*> >( 2500 ); /* Max 2500 items in queue, hardcoded. */
|
threadDataQueue = boost::make_shared<ConcurrentQueue<_ThreadData*> >( 2500 ); /* Max 2500 items in queue, hardcoded. */
|
||||||
@ -81,16 +82,13 @@ public:
|
|||||||
groupCount = 0;
|
groupCount = 0;
|
||||||
|
|
||||||
//Dummy initialization
|
//Dummy initialization
|
||||||
wayCallback = NULL;
|
// wayCallback = NULL;
|
||||||
nodeCallback = NULL;
|
// nodeCallback = NULL;
|
||||||
restrictionCallback = NULL;
|
// restrictionCallback = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RegisterCallbacks(bool (*nodeCallbackPointer)(_Node), bool (*restrictionCallbackPointer)(_RawRestrictionContainer), bool (*wayCallbackPointer)(_Way) ) {
|
void RegisterCallbacks(ExtractorCallbacks * em) {
|
||||||
nodeCallback = *nodeCallbackPointer;
|
externalMemory = em;
|
||||||
wayCallback = *wayCallbackPointer;
|
|
||||||
restrictionCallback = *restrictionCallbackPointer;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegisterLUAState(lua_State *ml) {
|
void RegisterLUAState(lua_State *ml) {
|
||||||
@ -244,7 +242,7 @@ private:
|
|||||||
"node_function",
|
"node_function",
|
||||||
boost::ref(n)
|
boost::ref(n)
|
||||||
);
|
);
|
||||||
if(!(*nodeCallback)(n))
|
if(!externalMemory->nodeFunction(n))
|
||||||
std::cerr << "[PBFParser] dense node not parsed" << std::endl;
|
std::cerr << "[PBFParser] dense node not parsed" << std::endl;
|
||||||
} catch (const luabind::error &er) {
|
} catch (const luabind::error &er) {
|
||||||
cerr << er.what() << endl;
|
cerr << er.what() << endl;
|
||||||
@ -332,7 +330,7 @@ private:
|
|||||||
// cout << "node " << currentRestriction.viaNode;
|
// cout << "node " << currentRestriction.viaNode;
|
||||||
// cout << " to " << currentRestriction.to << endl;
|
// cout << " to " << currentRestriction.to << endl;
|
||||||
// }
|
// }
|
||||||
if(!(*restrictionCallback)(currentRestrictionContainer))
|
if(!externalMemory->restrictionFunction(currentRestrictionContainer))
|
||||||
std::cerr << "[PBFParser] relation not parsed" << std::endl;
|
std::cerr << "[PBFParser] relation not parsed" << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -364,7 +362,7 @@ private:
|
|||||||
boost::ref(w),
|
boost::ref(w),
|
||||||
w.path.size()
|
w.path.size()
|
||||||
);
|
);
|
||||||
if(!(*wayCallback)(w)) {
|
if(!externalMemory->wayFunction(w)) {
|
||||||
std::cerr << "[PBFParser] way not parsed" << std::endl;
|
std::cerr << "[PBFParser] way not parsed" << std::endl;
|
||||||
}
|
}
|
||||||
} catch (const luabind::error &er) {
|
} catch (const luabind::error &er) {
|
||||||
@ -566,9 +564,10 @@ private:
|
|||||||
unsigned blockCount;
|
unsigned blockCount;
|
||||||
|
|
||||||
/* Function pointer for nodes */
|
/* Function pointer for nodes */
|
||||||
bool (*nodeCallback)(_Node);
|
// bool (*nodeCallback)(_Node);
|
||||||
bool (*wayCallback)(_Way);
|
// bool (*wayCallback)(_Way);
|
||||||
bool (*restrictionCallback)(_RawRestrictionContainer);
|
// bool (*restrictionCallback)(_RawRestrictionContainer);
|
||||||
|
ExtractorCallbacks * externalMemory;
|
||||||
/* the input stream to parse */
|
/* the input stream to parse */
|
||||||
std::fstream input;
|
std::fstream input;
|
||||||
|
|
||||||
|
@ -27,22 +27,20 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
#include "../typedefs.h"
|
#include "../typedefs.h"
|
||||||
#include "BaseParser.h"
|
#include "BaseParser.h"
|
||||||
#include "ExtractorStructs.h"
|
#include "ExtractorStructs.h"
|
||||||
|
#include "ExtractorCallbacks.h"
|
||||||
#include "../DataStructures/HashTable.h"
|
#include "../DataStructures/HashTable.h"
|
||||||
#include "../DataStructures/InputReaderFactory.h"
|
#include "../DataStructures/InputReaderFactory.h"
|
||||||
|
|
||||||
class XMLParser : public BaseParser<_Node, _RawRestrictionContainer, _Way> {
|
class XMLParser : public BaseParser<ExtractorCallbacks, _Node, _RawRestrictionContainer, _Way> {
|
||||||
public:
|
public:
|
||||||
XMLParser(const char * filename) : nodeCallback(NULL), wayCallback(NULL), restrictionCallback(NULL), myLuaState(NULL){
|
XMLParser(const char * filename) : externalMemory(NULL), myLuaState(NULL){
|
||||||
WARN("Parsing plain .osm/.osm.bz2 is deprecated. Switch to .pbf");
|
WARN("Parsing plain .osm/.osm.bz2 is deprecated. Switch to .pbf");
|
||||||
inputReader = inputReaderFactory(filename);
|
inputReader = inputReaderFactory(filename);
|
||||||
}
|
}
|
||||||
virtual ~XMLParser() {}
|
virtual ~XMLParser() {}
|
||||||
|
|
||||||
bool RegisterCallbacks(bool (*nodeCallbackPointer)(_Node), bool (*restrictionCallbackPointer)(_RawRestrictionContainer), bool (*wayCallbackPointer)(_Way)) {
|
void RegisterCallbacks(ExtractorCallbacks * em) {
|
||||||
nodeCallback = *nodeCallbackPointer;
|
externalMemory = em;
|
||||||
wayCallback = *wayCallbackPointer;
|
|
||||||
restrictionCallback = *restrictionCallbackPointer;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegisterLUAState(lua_State *ml) {
|
void RegisterLUAState(lua_State *ml) {
|
||||||
@ -73,7 +71,7 @@ public:
|
|||||||
"node_function",
|
"node_function",
|
||||||
boost::ref(n)
|
boost::ref(n)
|
||||||
);
|
);
|
||||||
if(!(*nodeCallback)(n))
|
if(!externalMemory->nodeFunction(n))
|
||||||
std::cerr << "[XMLParser] dense node not parsed" << std::endl;
|
std::cerr << "[XMLParser] dense node not parsed" << std::endl;
|
||||||
} catch (const luabind::error &er) {
|
} catch (const luabind::error &er) {
|
||||||
cerr << er.what() << endl;
|
cerr << er.what() << endl;
|
||||||
@ -98,7 +96,7 @@ public:
|
|||||||
boost::ref(way),
|
boost::ref(way),
|
||||||
way.path.size()
|
way.path.size()
|
||||||
);
|
);
|
||||||
if(!(*wayCallback)(way)) {
|
if(!externalMemory->wayFunction(way)) {
|
||||||
std::cerr << "[PBFParser] way not parsed" << std::endl;
|
std::cerr << "[PBFParser] way not parsed" << std::endl;
|
||||||
}
|
}
|
||||||
} catch (const luabind::error &er) {
|
} catch (const luabind::error &er) {
|
||||||
@ -114,7 +112,7 @@ public:
|
|||||||
if ( xmlStrEqual( currentName, ( const xmlChar* ) "relation" ) == 1 ) {
|
if ( xmlStrEqual( currentName, ( const xmlChar* ) "relation" ) == 1 ) {
|
||||||
_RawRestrictionContainer r = _ReadXMLRestriction();
|
_RawRestrictionContainer r = _ReadXMLRestriction();
|
||||||
if(r.fromWay != UINT_MAX) {
|
if(r.fromWay != UINT_MAX) {
|
||||||
if(!(*restrictionCallback)(r)) {
|
if(!externalMemory->restrictionFunction(r)) {
|
||||||
std::cerr << "[XMLParser] restriction not parsed" << std::endl;
|
std::cerr << "[XMLParser] restriction not parsed" << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -301,9 +299,11 @@ private:
|
|||||||
xmlTextReaderPtr inputReader;
|
xmlTextReaderPtr inputReader;
|
||||||
|
|
||||||
/* Function pointer for nodes */
|
/* Function pointer for nodes */
|
||||||
bool (*nodeCallback)(_Node);
|
// bool (*nodeCallback)(_Node);
|
||||||
bool (*wayCallback)(_Way);
|
// bool (*wayCallback)(_Way);
|
||||||
bool (*restrictionCallback)(_RawRestrictionContainer);
|
// bool (*restrictionCallback)(_RawRestrictionContainer);
|
||||||
|
|
||||||
|
ExtractorCallbacks * externalMemory;
|
||||||
|
|
||||||
lua_State *myLuaState;
|
lua_State *myLuaState;
|
||||||
};
|
};
|
||||||
|
@ -45,10 +45,6 @@ extern "C" {
|
|||||||
typedef BaseConfiguration ExtractorConfiguration;
|
typedef BaseConfiguration ExtractorConfiguration;
|
||||||
|
|
||||||
ExtractorCallbacks * extractCallBacks;
|
ExtractorCallbacks * extractCallBacks;
|
||||||
//
|
|
||||||
bool nodeFunction(_Node n);
|
|
||||||
bool restrictionFunction(_RawRestrictionContainer r);
|
|
||||||
bool wayFunction(_Way w);
|
|
||||||
|
|
||||||
int main (int argc, char *argv[]) {
|
int main (int argc, char *argv[]) {
|
||||||
if(argc < 2) {
|
if(argc < 2) {
|
||||||
@ -157,27 +153,19 @@ int main (int argc, char *argv[]) {
|
|||||||
if(installedRAM < 2048264) {
|
if(installedRAM < 2048264) {
|
||||||
WARN("Machine has less than 2GB RAM.");
|
WARN("Machine has less than 2GB RAM.");
|
||||||
}
|
}
|
||||||
/* if(testDataFile("extractor.ini")) {
|
|
||||||
ExtractorConfiguration extractorConfig("extractor.ini");
|
|
||||||
unsigned memoryAmountFromFile = atoi(extractorConfig.GetParameter("Memory").c_str());
|
|
||||||
if( memoryAmountFromFile != 0 && memoryAmountFromFile <= installedRAM/(1024*1024))
|
|
||||||
amountOfRAM = memoryAmountFromFile;
|
|
||||||
INFO("Using " << amountOfRAM << " GB of RAM for buffers");
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
StringMap stringMap;
|
StringMap stringMap;
|
||||||
ExtractionContainers externalMemory;
|
ExtractionContainers externalMemory;
|
||||||
|
|
||||||
stringMap[""] = 0;
|
stringMap[""] = 0;
|
||||||
extractCallBacks = new ExtractorCallbacks(&externalMemory, &stringMap);
|
extractCallBacks = new ExtractorCallbacks(&externalMemory, &stringMap);
|
||||||
BaseParser<_Node, _RawRestrictionContainer, _Way> * parser;
|
BaseParser<ExtractorCallbacks, _Node, _RawRestrictionContainer, _Way> * parser;
|
||||||
if(isPBF) {
|
if(isPBF) {
|
||||||
parser = new PBFParser(argv[1]);
|
parser = new PBFParser(argv[1]);
|
||||||
} else {
|
} else {
|
||||||
parser = new XMLParser(argv[1]);
|
parser = new XMLParser(argv[1]);
|
||||||
}
|
}
|
||||||
parser->RegisterCallbacks(&nodeFunction, &restrictionFunction, &wayFunction);
|
parser->RegisterCallbacks(extractCallBacks);
|
||||||
parser->RegisterLUAState(myLuaState);
|
parser->RegisterLUAState(myLuaState);
|
||||||
|
|
||||||
if(!parser->Init())
|
if(!parser->Init())
|
||||||
@ -194,16 +182,3 @@ int main (int argc, char *argv[]) {
|
|||||||
"./osrm-prepare " << outputFileName << " " << restrictionsFileName << std::endl;
|
"./osrm-prepare " << outputFileName << " " << restrictionsFileName << std::endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool nodeFunction(_Node n) {
|
|
||||||
extractCallBacks->nodeFunction(n);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
bool restrictionFunction(_RawRestrictionContainer r) {
|
|
||||||
extractCallBacks->restrictionFunction(r);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
bool wayFunction(_Way w) {
|
|
||||||
extractCallBacks->wayFunction(w);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user