summaryrefslogtreecommitdiffstats
path: root/src/muparserx-test.cpp
diff options
context:
space:
mode:
authorTony Theodore <tonyt@logyst.com>2015-11-21 05:26:30 (GMT)
committerTony Theodore <tonyt@logyst.com>2015-11-21 05:26:30 (GMT)
commitf939f4a9b785277a24556584d302aa251e9e932c (patch)
treebcb8fafb02e36bd91ead6b1430f9399c6ce97248 /src/muparserx-test.cpp
parent3465e4db8a5004569c0bfe9f58b82a3c34234eb0 (diff)
downloadmxe-f939f4a9b785277a24556584d302aa251e9e932c.zip
mxe-f939f4a9b785277a24556584d302aa251e9e932c.tar.gz
mxe-f939f4a9b785277a24556584d302aa251e9e932c.tar.bz2
add package muparserx
Diffstat (limited to 'src/muparserx-test.cpp')
-rw-r--r--src/muparserx-test.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/muparserx-test.cpp b/src/muparserx-test.cpp
new file mode 100644
index 0000000..ebc6770
--- /dev/null
+++ b/src/muparserx-test.cpp
@@ -0,0 +1,48 @@
+/*
+ * This file is part of MXE.
+ * See index.html for further information.
+ *
+ * based on:
+ * http://articles.beltoforion.de/article.php?a=muparserx&hl=en&p=using&s=idInclude#idEval
+ */
+
+#include "mpParser.h"
+
+using namespace mup;
+
+int main(int argc, char *argv[])
+{
+ (void)argc;
+ (void)argv;
+
+ // Create the parser instance
+ ParserX p;
+
+ // Create an array of mixed type
+ Value arr(3, 0);
+ arr.At(0) = 2.0;
+ arr.At(1) = "this is a string";
+
+ // Create some basic values
+ Value cVal(cmplx_type(1, 1));
+ Value sVal("Hello World");
+ Value fVal(1.1);
+
+ // Now add the variable to muParser
+ p.DefineVar("va", Variable(&arr));
+ p.DefineVar("a", Variable(&cVal));
+ p.DefineVar("b", Variable(&sVal));
+ p.DefineVar("c", Variable(&fVal));
+
+ p.SetExpr("va[0]+a*strlen(b)-c");
+ for (int i=0; i<<10; ++i)
+ {
+ // evaluate the expression and change the value of
+ // the variable c in each turn
+ cVal = 1.1 * i;
+ Value result = p.Eval();
+
+ // print the result
+ console() << result << "\n";
+ }
+}