OpcUaCanOpen
CANopen OPC-UA server
exprtk_simple_example_07.cpp
Go to the documentation of this file.
1 /*
2  **************************************************************
3  * C++ Mathematical Expression Toolkit Library *
4  * *
5  * Simple Example 7 *
6  * Author: Arash Partow (1999-2019) *
7  * URL: http://www.partow.net/programming/exprtk/index.html *
8  * *
9  * Copyright notice: *
10  * Free use of the Mathematical Expression Toolkit Library is *
11  * permitted under the guidelines and in accordance with the *
12  * most current version of the MIT License. *
13  * http://www.opensource.org/licenses/MIT *
14  * *
15  **************************************************************
16 */
17 
18 
19 #include <cstdio>
20 #include <string>
21 
22 #include "exprtk.hpp"
23 
24 
25 template <typename T>
26 void logic()
27 {
31 
32  std::string expression_string = "not(A and B) or C";
33 
34  symbol_table_t symbol_table;
35  symbol_table.create_variable("A");
36  symbol_table.create_variable("B");
37  symbol_table.create_variable("C");
38 
39  expression_t expression;
40  expression.register_symbol_table(symbol_table);
41 
43  parser.compile(expression_string,expression);
44 
45  printf(" # | A | B | C | %s\n"
46  "---+---+---+---+-%s\n",
47  expression_string.c_str(),
48  std::string(expression_string.size(),'-').c_str());
49 
50  for (int i = 0; i < 8; ++i)
51  {
52  symbol_table.get_variable("A")->ref() = T((i & 0x01) ? 1 : 0);
53  symbol_table.get_variable("B")->ref() = T((i & 0x02) ? 1 : 0);
54  symbol_table.get_variable("C")->ref() = T((i & 0x04) ? 1 : 0);
55 
56  int result = static_cast<int>(expression.value());
57 
58  printf(" %d | %d | %d | %d | %d \n",
59  i,
60  static_cast<int>(symbol_table.get_variable("A")->value()),
61  static_cast<int>(symbol_table.get_variable("B")->value()),
62  static_cast<int>(symbol_table.get_variable("C")->value()),
63  result);
64  }
65 }
66 
67 int main()
68 {
69  logic<double>();
70  return 0;
71 }