From 868ef551f926bdb110e5f84fb3395b8553205914 Mon Sep 17 00:00:00 2001 From: deva Date: Mon, 5 Jul 2010 07:02:30 +0000 Subject: Partial commit: Move automap code to LUAQueryMapper (from widgetgenerator). --- server/src/luaquerymapper.cc | 33 +++++++++++++++++++++++++++++++++ server/src/luaquerymapper.h | 2 ++ 2 files changed, 35 insertions(+) diff --git a/server/src/luaquerymapper.cc b/server/src/luaquerymapper.cc index 7ee43ff..fdb1248 100644 --- a/server/src/luaquerymapper.cc +++ b/server/src/luaquerymapper.cc @@ -162,6 +162,39 @@ void LUAQueryMapper::error(std::string message) throw(Exception) throw Exception("ERROR in LUAQueryMapper: " + message); } +std::string LUAQueryMapper::automap(const std::string &name) +{ + std::string group; + std::string groupcheck = "if("; + + for(size_t i = 0; i < name.length(); i++) { + group += name[i]; + if(name[i] == '.') groupcheck += " and " + group; + else groupcheck += name[i]; + } + groupcheck += " and " + name + ".value and " + name + ".timestamp and " + name + ".source"; + groupcheck += ")\n"; + + std::string automapstring = + "-- Returning 0, 0 invalidates the result\n" + "value = 0\n" + "timestamp = 0\n" + "source = 0\n" + "\n" + + groupcheck + + "then\n" + " value = " + name + ".value\n" + " timestamp = " + name + ".timestamp\n" + " source = " + name + ".source\n" + "end\n" + "return value, timestamp, source\n"; + + PRACRO_DEBUG(widget, "Automap:\n%s\n", automapstring.c_str()); + + return automapstring; +} + + #ifdef TEST_LUAQUERYMAPPER int main() diff --git a/server/src/luaquerymapper.h b/server/src/luaquerymapper.h index e8a25f8..2d3e72d 100644 --- a/server/src/luaquerymapper.h +++ b/server/src/luaquerymapper.h @@ -71,6 +71,8 @@ public: */ void addQueryResult(QueryResult &result) throw(Exception); + std::string automap(const std::string &name); + private: void error(std::string message) throw(Exception); -- cgit v1.2.3