C++ Mathematical Expression Toolkit (ExprTk) release
Loading...
Searching...
No Matches
Classes | Functions
exprtk_compilation_timeout.cpp File Reference
#include <chrono>
#include <cstdio>
#include <string>
#include "exprtk.hpp"
Include dependency graph for exprtk_compilation_timeout.cpp:

Go to the source code of this file.

Classes

struct  compilation_timeout_check
 

Functions

template<typename T >
void compilation_timeout_check_example ()
 
int main ()
 

Function Documentation

◆ compilation_timeout_check_example()

template<typename T >
void compilation_timeout_check_example ( )

Definition at line 59 of file exprtk_compilation_timeout.cpp.

60{
61 typedef exprtk::symbol_table<T> symbol_table_t;
62 typedef exprtk::expression<T> expression_t;
63 typedef exprtk::parser<T> parser_t;
64
65 const std::string base_expression_string =
66 "x := "
67 "((1 /1) * sin( 2 * pi * f * t) + (1 /3) * sin( 6 * pi * f * t)+"
68 " (1 /5) * sin(10 * pi * f * t) + (1 /7) * sin(14 * pi * f * t)+"
69 " (1 /9) * sin(18 * pi * f * t) + (1/11) * sin(22 * pi * f * t)+"
70 " (1/13) * sin(26 * pi * f * t) + (1/15) * sin(30 * pi * f * t)+"
71 " (1/17) * sin(34 * pi * f * t) + (1/19) * sin(38 * pi * f * t)+"
72 " (1/21) * sin(42 * pi * f * t) + (1/23) * sin(46 * pi * f * t)+"
73 " (1/25) * sin(50 * pi * f * t) + (1/27) * sin(54 * pi * f * t));";
74
75 std::string large_expression_string = "var x := 0;";
76
77 for (std::size_t i = 0; i < 60000; ++i)
78 {
79 large_expression_string += base_expression_string;
80 }
81
82 static const T pi = T(3.141592653589793238462643383279502);
83
84 const T f = pi / T(10);
85 const T a = T(10);
86 T t = T(0);
87
88 symbol_table_t symbol_table;
89 symbol_table.add_variable("t",t);
90 symbol_table.add_constant("f",f);
91 symbol_table.add_constant("a",a);
92 symbol_table.add_constants();
93
94 expression_t expression;
95 expression.register_symbol_table(symbol_table);
96
97 compilation_timeout_check compilation_timeout_chck;
98
99 parser_t parser;
100 parser.register_compilation_timeout_check(compilation_timeout_chck);
101
102 const auto max_duration = std::chrono::seconds(8);
103 const auto timeout_tp = std::chrono::steady_clock::now() + max_duration;
104 compilation_timeout_chck.set_timeout_time(timeout_tp);
105
106 if (!parser.compile(large_expression_string, expression))
107 {
108 printf("Error: %s\t\n", parser.error().c_str());
109 return;
110 }
111}
const double pi
void set_timeout_time(const time_point_t &timeout_tp)

References pi, and compilation_timeout_check::set_timeout_time().

Here is the call graph for this function:

◆ main()

int main ( )

Definition at line 113 of file exprtk_compilation_timeout.cpp.

114{
115 compilation_timeout_check_example<double>();
116 return 0;
117}