Restructured calling of callback functions

This commit is contained in:
DennisOSRM
2012-11-02 17:15:51 +01:00
parent 10cf41d138
commit e8c7f7b5da
4 changed files with 33 additions and 59 deletions
+2 -2
View File
@@ -23,12 +23,12 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include <luabind/luabind.hpp>
template<typename NodeT, typename RestrictionT, typename WayT>
template<class ExternalMemoryT, typename NodeT, typename RestrictionT, typename WayT>
class BaseParser {
public:
virtual ~BaseParser() {}
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 bool Parse() = 0;
+16 -17
View File
@@ -32,13 +32,14 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include "../typedefs.h"
#include "BaseParser.h"
#include "ExtractorCallbacks.h"
#include "ExtractorStructs.h"
#include "../DataStructures/HashTable.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 {
TypeNode = 1,
@@ -67,7 +68,7 @@ class PBFParser : public BaseParser<_Node, _RawRestrictionContainer, _Way> {
};
public:
PBFParser(const char * fileName) : myLuaState(NULL) {
PBFParser(const char * fileName) : externalMemory(NULL), myLuaState(NULL) {
GOOGLE_PROTOBUF_VERIFY_VERSION;
//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. */
@@ -81,16 +82,13 @@ public:
groupCount = 0;
//Dummy initialization
wayCallback = NULL;
nodeCallback = NULL;
restrictionCallback = NULL;
// wayCallback = NULL;
// nodeCallback = NULL;
// restrictionCallback = NULL;
}
bool RegisterCallbacks(bool (*nodeCallbackPointer)(_Node), bool (*restrictionCallbackPointer)(_RawRestrictionContainer), bool (*wayCallbackPointer)(_Way) ) {
nodeCallback = *nodeCallbackPointer;
wayCallback = *wayCallbackPointer;
restrictionCallback = *restrictionCallbackPointer;
return true;
void RegisterCallbacks(ExtractorCallbacks * em) {
externalMemory = em;
}
void RegisterLUAState(lua_State *ml) {
@@ -244,7 +242,7 @@ private:
"node_function",
boost::ref(n)
);
if(!(*nodeCallback)(n))
if(!externalMemory->nodeFunction(n))
std::cerr << "[PBFParser] dense node not parsed" << std::endl;
} catch (const luabind::error &er) {
cerr << er.what() << endl;
@@ -332,7 +330,7 @@ private:
// cout << "node " << currentRestriction.viaNode;
// cout << " to " << currentRestriction.to << endl;
// }
if(!(*restrictionCallback)(currentRestrictionContainer))
if(!externalMemory->restrictionFunction(currentRestrictionContainer))
std::cerr << "[PBFParser] relation not parsed" << std::endl;
}
}
@@ -364,7 +362,7 @@ private:
boost::ref(w),
w.path.size()
);
if(!(*wayCallback)(w)) {
if(!externalMemory->wayFunction(w)) {
std::cerr << "[PBFParser] way not parsed" << std::endl;
}
} catch (const luabind::error &er) {
@@ -566,9 +564,10 @@ private:
unsigned blockCount;
/* Function pointer for nodes */
bool (*nodeCallback)(_Node);
bool (*wayCallback)(_Way);
bool (*restrictionCallback)(_RawRestrictionContainer);
// bool (*nodeCallback)(_Node);
// bool (*wayCallback)(_Way);
// bool (*restrictionCallback)(_RawRestrictionContainer);
ExtractorCallbacks * externalMemory;
/* the input stream to parse */
std::fstream input;
+13 -13
View File
@@ -27,22 +27,20 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include "../typedefs.h"
#include "BaseParser.h"
#include "ExtractorStructs.h"
#include "ExtractorCallbacks.h"
#include "../DataStructures/HashTable.h"
#include "../DataStructures/InputReaderFactory.h"
class XMLParser : public BaseParser<_Node, _RawRestrictionContainer, _Way> {
class XMLParser : public BaseParser<ExtractorCallbacks, _Node, _RawRestrictionContainer, _Way> {
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");
inputReader = inputReaderFactory(filename);
}
virtual ~XMLParser() {}
bool RegisterCallbacks(bool (*nodeCallbackPointer)(_Node), bool (*restrictionCallbackPointer)(_RawRestrictionContainer), bool (*wayCallbackPointer)(_Way)) {
nodeCallback = *nodeCallbackPointer;
wayCallback = *wayCallbackPointer;
restrictionCallback = *restrictionCallbackPointer;
return true;
void RegisterCallbacks(ExtractorCallbacks * em) {
externalMemory = em;
}
void RegisterLUAState(lua_State *ml) {
@@ -73,7 +71,7 @@ public:
"node_function",
boost::ref(n)
);
if(!(*nodeCallback)(n))
if(!externalMemory->nodeFunction(n))
std::cerr << "[XMLParser] dense node not parsed" << std::endl;
} catch (const luabind::error &er) {
cerr << er.what() << endl;
@@ -98,7 +96,7 @@ public:
boost::ref(way),
way.path.size()
);
if(!(*wayCallback)(way)) {
if(!externalMemory->wayFunction(way)) {
std::cerr << "[PBFParser] way not parsed" << std::endl;
}
} catch (const luabind::error &er) {
@@ -114,7 +112,7 @@ public:
if ( xmlStrEqual( currentName, ( const xmlChar* ) "relation" ) == 1 ) {
_RawRestrictionContainer r = _ReadXMLRestriction();
if(r.fromWay != UINT_MAX) {
if(!(*restrictionCallback)(r)) {
if(!externalMemory->restrictionFunction(r)) {
std::cerr << "[XMLParser] restriction not parsed" << std::endl;
}
}
@@ -301,9 +299,11 @@ private:
xmlTextReaderPtr inputReader;
/* Function pointer for nodes */
bool (*nodeCallback)(_Node);
bool (*wayCallback)(_Way);
bool (*restrictionCallback)(_RawRestrictionContainer);
// bool (*nodeCallback)(_Node);
// bool (*wayCallback)(_Way);
// bool (*restrictionCallback)(_RawRestrictionContainer);
ExtractorCallbacks * externalMemory;
lua_State *myLuaState;
};