summaryrefslogtreecommitdiff
path: root/server/src/luaquerymapper.cc
diff options
context:
space:
mode:
authordeva <deva>2010-07-05 07:02:30 +0000
committerdeva <deva>2010-07-05 07:02:30 +0000
commit868ef551f926bdb110e5f84fb3395b8553205914 (patch)
tree9c64c15df229be205670981ca185a31d94cd0cb2 /server/src/luaquerymapper.cc
parentca15ae4d605a3bcd11435d92eda0800d28edceb8 (diff)
Partial commit: Move automap code to LUAQueryMapper (from widgetgenerator).
Diffstat (limited to 'server/src/luaquerymapper.cc')
-rw-r--r--server/src/luaquerymapper.cc33
1 files changed, 33 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()