Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
Don't fiddle with function pointers, don't have a near-duplicate
inPostScanRelations flag.
  • Loading branch information
cldellow committed Jan 13, 2024
1 parent 24fc676 commit 7344945
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion include/osm_lua_processing.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ class OsmLuaProcessing {

struct luaProcessingException :std::exception {};
const TagMap* currentTags;
bool isPostScanRelation; // processing a relation in postScanRelation

private:
/// Internal: clear current cached state
Expand Down Expand Up @@ -290,7 +291,6 @@ class OsmLuaProcessing {
bool relationAccepted; // in scanRelation, whether we're using a non-MP relation
std::vector<std::pair<WayID, uint16_t>> relationList; // in processNode/processWay, list of relations this entity is in, and its role
int relationSubscript = -1; // in processWay, position in the relation list
bool isPostScanRelation; // processing a relation in postScanRelation

int32_t lon,latp; ///< Node coordinates
LatpLonVec const *llVecPtr;
Expand Down
26 changes: 14 additions & 12 deletions src/osm_lua_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ using namespace std;
const std::string EMPTY_STRING = "";
thread_local kaguya::State *g_luaState = nullptr;
thread_local OsmLuaProcessing* osmLuaProcessing = nullptr;
thread_local bool inPostScanRelations = false;

void handleOsmLuaProcessingUserSignal(int signum) {
osmLuaProcessing->handleUserSignal(signum);
Expand Down Expand Up @@ -68,7 +67,10 @@ template<> struct kaguya::lua_type_traits<KnownTagKey> {
size_t size = 0;
const char* buffer = lua_tolstring(l, index, &size);

if (inPostScanRelations) {
if (osmLuaProcessing->isPostScanRelation) {
// In this phase, the Holds/Find functions directly query a
// traditional string->string map, so just ensure we expose
// the string.
rv.stringValue = std::string(buffer, size);
return rv;
}
Expand Down Expand Up @@ -134,21 +136,26 @@ template<> struct kaguya::lua_type_traits<PossiblyKnownTagValue> {
};

std::string rawId() { return osmLuaProcessing->Id(); }
bool rawHolds(const KnownTagKey& key) { return key.found; }
bool rawHoldsPostScanRelations(const KnownTagKey& key) { return key.found; }
bool rawHolds(const KnownTagKey& key) {
if (osmLuaProcessing->isPostScanRelation) {
return osmLuaProcessing->Holds(key.stringValue);
}

return key.found;
}
bool rawHasTags() { return osmLuaProcessing->HasTags(); }
void rawSetTag(const std::string &key, const std::string &value) { return osmLuaProcessing->SetTag(key, value); }
const std::string rawFind(const KnownTagKey& key) {
if (osmLuaProcessing->isPostScanRelation)
return osmLuaProcessing->Find(key.stringValue);

if (key.found) {
auto value = *(osmLuaProcessing->currentTags->getValueFromKey(key.index));
return std::string(value.data(), value.size());
}

return EMPTY_STRING;
}
const std::string rawFindPostScanRelations(const KnownTagKey& key) {
return osmLuaProcessing->Find(key.stringValue);
}
std::vector<std::string> rawFindIntersecting(const std::string &layerName) { return osmLuaProcessing->FindIntersecting(layerName); }
bool rawIntersects(const std::string& layerName) { return osmLuaProcessing->Intersects(layerName); }
std::vector<std::string> rawFindCovering(const std::string& layerName) { return osmLuaProcessing->FindCovering(layerName); }
Expand Down Expand Up @@ -951,11 +958,6 @@ bool OsmLuaProcessing::scanRelation(WayID id, const TagMap& tags) {
void OsmLuaProcessing::postScanRelations() {
if (!supportsPostScanRelations) return;

// Adjust the function pointers for tag-related functions
inPostScanRelations = true;
luaState["Holds"] = &rawHoldsPostScanRelations;
luaState["Find"] = &rawFindPostScanRelations;

for (const auto &relp : osmStore.scannedRelations.relationsForRelations) {
reset();
isPostScanRelation = true;
Expand Down

0 comments on commit 7344945

Please sign in to comment.