diff options
author | deva <deva> | 2010-07-05 07:02:30 +0000 |
---|---|---|
committer | deva <deva> | 2010-07-05 07:02:30 +0000 |
commit | 868ef551f926bdb110e5f84fb3395b8553205914 (patch) | |
tree | 9c64c15df229be205670981ca185a31d94cd0cb2 /server | |
parent | ca15ae4d605a3bcd11435d92eda0800d28edceb8 (diff) |
Partial commit: Move automap code to LUAQueryMapper (from widgetgenerator).
Diffstat (limited to 'server')
-rw-r--r-- | server/src/luaquerymapper.cc | 33 | ||||
-rw-r--r-- | server/src/luaquerymapper.h | 2 |
2 files changed, 35 insertions, 0 deletions
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); |