Skip to content

Commit 1214d4e

Browse files
committed
Updates to ExprTk
1 parent 9c5164c commit 1214d4e

File tree

2 files changed

+152
-32
lines changed

2 files changed

+152
-32
lines changed

exprtk/exprtk.hpp

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2305,8 +2305,8 @@ namespace exprtk
23052305

23062306
inline std::string substr(const std::size_t& begin, const std::size_t& end)
23072307
{
2308-
details::char_cptr begin_itr = ((base_itr_ + begin) < s_end_) ? (base_itr_ + begin) : s_end_;
2309-
details::char_cptr end_itr = ((base_itr_ + end) < s_end_) ? (base_itr_ + end) : s_end_;
2308+
const details::char_cptr begin_itr = ((base_itr_ + begin) < s_end_) ? (base_itr_ + begin) : s_end_;
2309+
const details::char_cptr end_itr = ((base_itr_ + end) < s_end_) ? (base_itr_ + end) : s_end_;
23102310

23112311
return std::string(begin_itr,end_itr);
23122312
}
@@ -3655,7 +3655,7 @@ namespace exprtk
36553655

36563656
bool operator() (const lexer::token& t0, const lexer::token& t1)
36573657
{
3658-
set_t::value_type p = std::make_pair(t0.type,t1.type);
3658+
const set_t::value_type p = std::make_pair(t0.type,t1.type);
36593659

36603660
if (invalid_bracket_check(t0.type,t1.type))
36613661
{
@@ -3669,7 +3669,7 @@ namespace exprtk
36693669
return true;
36703670
}
36713671

3672-
std::size_t error_count()
3672+
std::size_t error_count() const
36733673
{
36743674
return error_list_.size();
36753675
}
@@ -4757,8 +4757,8 @@ namespace exprtk
47574757

47584758
static inline std::size_t min_size(control_block* cb0, control_block* cb1)
47594759
{
4760-
std::size_t size0 = cb0->size;
4761-
std::size_t size1 = cb1->size;
4760+
const std::size_t size0 = cb0->size;
4761+
const std::size_t size1 = cb1->size;
47624762

47634763
if (size0 && size1)
47644764
return std::min(size0,size1);
@@ -8677,7 +8677,7 @@ namespace exprtk
86778677

86788678
range_t& range = str0_range_ptr_->range_ref();
86798679

8680-
if (range(r0,r1,str0_base_ptr_->size()))
8680+
if (range(r0, r1, str0_base_ptr_->size()))
86818681
{
86828682
const std::size_t size = (r1 - r0) + 1;
86838683

@@ -8695,7 +8695,7 @@ namespace exprtk
86958695

86968696
range_t& range = str1_range_ptr_->range_ref();
86978697

8698-
if (range(r0,r1,str1_base_ptr_->size()))
8698+
if (range(r0, r1, str1_base_ptr_->size()))
86998699
{
87008700
const std::size_t size = (r1 - r0) + 1;
87018701

@@ -8815,7 +8815,7 @@ namespace exprtk
88158815
std::size_t r0 = 0;
88168816
std::size_t r1 = 0;
88178817

8818-
if (range(r0,r1,str0_base_ptr_->size()))
8818+
if (range(r0, r1, str0_base_ptr_->size()))
88198819
{
88208820
const std::size_t size = (r1 - r0) + 1;
88218821

@@ -16631,11 +16631,11 @@ namespace exprtk
1663116631
#ifndef exprtk_disable_string_capabilities
1663216632
type_store<typename details::stringvar_node<T>,std::string> stringvar_store;
1663316633
#endif
16634-
type_store<ifunction<T>,ifunction<T> > function_store;
16634+
type_store<ifunction<T>,ifunction<T> > function_store;
1663516635
type_store<ivararg_function <T>,ivararg_function <T> > vararg_function_store;
1663616636
type_store<igeneric_function<T>,igeneric_function<T> > generic_function_store;
1663716637
type_store<igeneric_function<T>,igeneric_function<T> > string_function_store;
16638-
type_store<vector_holder_t,vector_holder_t> vector_store;
16638+
type_store<vector_holder_t,vector_holder_t> vector_store;
1663916639

1664016640
st_data()
1664116641
{
@@ -17337,8 +17337,8 @@ namespace exprtk
1733717337
{
1733817338
/*
1733917339
Function will return true if symbol_name exists as either a
17340-
reserved symbol, variable, stringvar or function name in any
17341-
of the type stores.
17340+
reserved symbol, variable, stringvar, vector or function name
17341+
in any of the type stores.
1734217342
*/
1734317343
if (!valid())
1734417344
return false;
@@ -17348,6 +17348,8 @@ namespace exprtk
1734817348
else if (local_data().stringvar_store.symbol_exists(symbol_name))
1734917349
return true;
1735017350
#endif
17351+
else if (local_data().vector_store.symbol_exists(symbol_name))
17352+
return true;
1735117353
else if (local_data().function_store.symbol_exists(symbol_name))
1735217354
return true;
1735317355
else if (check_reserved_symb && local_data().is_reserved_symbol(symbol_name))
@@ -17903,7 +17905,7 @@ namespace exprtk
1790317905
control_block_->
1790417906
local_data_list.push_back(
1790517907
typename expression<T>::control_block::
17906-
data_pack(reinterpret_cast<void*>(data),dt,size));
17908+
data_pack(reinterpret_cast<void*>(data), dt, size));
1790717909
}
1790817910
}
1790917911
}
@@ -22664,7 +22666,6 @@ namespace exprtk
2266422666
exprtk_error_location));
2266522667

2266622668
return false;
22667-
2266822669
}
2266922670
else if (is_constant_node(r0))
2267022671
{
@@ -22730,7 +22731,6 @@ namespace exprtk
2273022731
rp.free();
2273122732

2273222733
return false;
22733-
2273422734
}
2273522735
else if (is_constant_node(r1))
2273622736
{
@@ -26102,29 +26102,29 @@ namespace exprtk
2610226102
}
2610326103

2610426104
#ifndef exprtk_disable_sc_andor
26105-
inline bool is_shortcircuit_expression(const details::operator_type& operation)
26105+
inline bool is_shortcircuit_expression(const details::operator_type& operation) const
2610626106
{
2610726107
return (
2610826108
(details::e_scand == operation) ||
2610926109
(details::e_scor == operation)
2611026110
);
2611126111
}
2611226112
#else
26113-
inline bool is_shortcircuit_expression(const details::operator_type&)
26113+
inline bool is_shortcircuit_expression(const details::operator_type&) const
2611426114
{
2611526115
return false;
2611626116
}
2611726117
#endif
2611826118

26119-
inline bool is_null_present(expression_node_ptr (&branch)[2])
26119+
inline bool is_null_present(expression_node_ptr (&branch)[2]) const
2612026120
{
2612126121
return (
2612226122
details::is_null_node(branch[0]) ||
2612326123
details::is_null_node(branch[1])
2612426124
);
2612526125
}
2612626126

26127-
inline bool is_vector_eqineq_logic_operation(const details::operator_type& operation, expression_node_ptr (&branch)[2])
26127+
inline bool is_vector_eqineq_logic_operation(const details::operator_type& operation, expression_node_ptr (&branch)[2]) const
2612826128
{
2612926129
if (!is_ivector_node(branch[0]) && !is_ivector_node(branch[1]))
2613026130
return false;
@@ -26146,7 +26146,7 @@ namespace exprtk
2614626146
);
2614726147
}
2614826148

26149-
inline bool is_vector_arithmetic_operation(const details::operator_type& operation, expression_node_ptr (&branch)[2])
26149+
inline bool is_vector_arithmetic_operation(const details::operator_type& operation, expression_node_ptr (&branch)[2]) const
2615026150
{
2615126151
if (!is_ivector_node(branch[0]) && !is_ivector_node(branch[1]))
2615226152
return false;
@@ -36290,8 +36290,8 @@ namespace exprtk
3629036290
{
3629136291
static const T lower_bound = T(-20);
3629236292
static const T upper_bound = T(+20);
36293+
static const T delta = T(0.1);
3629336294

36294-
T delta = T(0.1);
3629536295
T total = T(0);
3629636296

3629736297
for (x = lower_bound; x <= upper_bound; x += delta)
@@ -36315,7 +36315,7 @@ namespace exprtk
3631536315
{
3631636316
for (std::size_t i = 0; i < 10000; ++i)
3631736317
{
36318-
T v = T(123.456 + i);
36318+
const T v = T(123.456 + i);
3631936319

3632036320
if (details::is_true(details::numeric::nequal(details::numeric::fast_exp<T, 1>::result(v),details::numeric::pow(v,T( 1)))))
3632136321
return false;
@@ -37877,7 +37877,7 @@ namespace exprtk
3787737877

3787837878
if ((1 == ps_index) && !helper::load_vector_range<T>::process(parameters, r0, r1, 3, 4, 1))
3787937879
return std::numeric_limits<T>::quiet_NaN();
37880-
else if (helper::invalid_range(y,r0,r1))
37880+
else if (helper::invalid_range(y, r0, r1))
3788137881
return std::numeric_limits<T>::quiet_NaN();
3788237882

3788337883
T a = scalar_t(parameters[0])();
@@ -37924,7 +37924,7 @@ namespace exprtk
3792437924

3792537925
if ((1 == ps_index) && !helper::load_vector_range<T>::process(parameters, r0, r1, 4, 5, 1))
3792637926
return std::numeric_limits<T>::quiet_NaN();
37927-
else if (helper::invalid_range(y,r0,r1))
37927+
else if (helper::invalid_range(y, r0, r1))
3792837928
return std::numeric_limits<T>::quiet_NaN();
3792937929

3793037930
const T a = scalar_t(parameters[0])();
@@ -37973,9 +37973,9 @@ namespace exprtk
3797337973

3797437974
if ((1 == ps_index) && !helper::load_vector_range<T>::process(parameters, r0, r1, 3, 4, 1))
3797537975
return std::numeric_limits<T>::quiet_NaN();
37976-
else if (helper::invalid_range(y,r0,r1))
37976+
else if (helper::invalid_range(y, r0, r1))
3797737977
return std::numeric_limits<T>::quiet_NaN();
37978-
else if (helper::invalid_range(z,r0,r1))
37978+
else if (helper::invalid_range(z, r0, r1))
3797937979
return std::numeric_limits<T>::quiet_NaN();
3798037980

3798137981
T a = scalar_t(parameters[0])();
@@ -38023,9 +38023,9 @@ namespace exprtk
3802338023

3802438024
if ((1 == ps_index) && !helper::load_vector_range<T>::process(parameters, r0, r1, 4, 5, 1))
3802538025
return std::numeric_limits<T>::quiet_NaN();
38026-
else if (helper::invalid_range(y,r0,r1))
38026+
else if (helper::invalid_range(y, r0, r1))
3802738027
return std::numeric_limits<T>::quiet_NaN();
38028-
else if (helper::invalid_range(z,r0,r1))
38028+
else if (helper::invalid_range(z, r0, r1))
3802938029
return std::numeric_limits<T>::quiet_NaN();
3803038030

3803138031
const T a = scalar_t(parameters[0])();
@@ -38073,7 +38073,7 @@ namespace exprtk
3807338073

3807438074
if ((1 == ps_index) && !helper::load_vector_range<T>::process(parameters, r0, r1, 4, 5, 1))
3807538075
return std::numeric_limits<T>::quiet_NaN();
38076-
else if (helper::invalid_range(z,r0,r1))
38076+
else if (helper::invalid_range(z, r0, r1))
3807738077
return std::numeric_limits<T>::quiet_NaN();
3807838078

3807938079
const T a = scalar_t(parameters[0])();
@@ -38120,7 +38120,7 @@ namespace exprtk
3812038120

3812138121
if ((1 == ps_index) && !helper::load_vector_range<T>::process(parameters, r0, r1, 2, 3, 0))
3812238122
return std::numeric_limits<T>::quiet_NaN();
38123-
else if (helper::invalid_range(y,r0,r1))
38123+
else if (helper::invalid_range(y, r0, r1))
3812438124
return std::numeric_limits<T>::quiet_NaN();
3812538125

3812638126
T result = T(0);
@@ -38166,7 +38166,7 @@ namespace exprtk
3816638166

3816738167
if ((1 == ps_index) && !helper::load_vector_range<T>::process(parameters, r0, r1, 2, 3, 0))
3816838168
return std::numeric_limits<T>::quiet_NaN();
38169-
else if (helper::invalid_range(y,r0,r1))
38169+
else if (helper::invalid_range(y, r0, r1))
3817038170
return std::numeric_limits<T>::quiet_NaN();
3817138171

3817238172
T result = T(0);

exprtk/exprtk_test.cpp

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7904,6 +7904,126 @@ inline bool run_test20()
79047904
}
79057905
}
79067906

7907+
{
7908+
T var;
7909+
std::string str;
7910+
std::vector<T> vec(10,0.0);
7911+
7912+
typedef exprtk::symbol_table<T> symbol_table_t;
7913+
7914+
bool result = true;
7915+
7916+
{
7917+
symbol_table_t symbol_table;
7918+
7919+
symbol_table.add_variable ("val",var);
7920+
symbol_table.add_stringvar("str",str);
7921+
symbol_table.add_vector ("vec",vec);
7922+
7923+
if (symbol_table.get_variable("val") == 0 || !symbol_table.symbol_exists("val"))
7924+
{
7925+
printf("run_test20() - [3] Failed to get 'val' from symbol_table\n");
7926+
result = false;
7927+
}
7928+
7929+
if (symbol_table.get_stringvar("str") == 0 || !symbol_table.symbol_exists("str"))
7930+
{
7931+
printf("run_test20() - [3] Failed to get 'str' from symbol_table\n");
7932+
result = false;
7933+
}
7934+
7935+
if (symbol_table.get_vector("vec") == 0 || !symbol_table.symbol_exists("vec"))
7936+
{
7937+
printf("run_test20() - [3] Failed to get 'vec' from symbol_table\n");
7938+
result = false;
7939+
}
7940+
}
7941+
7942+
if (!result)
7943+
return result;
7944+
7945+
{
7946+
symbol_table_t symbol_table;
7947+
7948+
symbol_table.add_variable("val",var);
7949+
7950+
if (symbol_table.get_variable("val") == 0 || !symbol_table.symbol_exists("val"))
7951+
{
7952+
printf("run_test20() - [4] Failed to get 'val' from symbol_table\n");
7953+
result = false;
7954+
}
7955+
7956+
if (symbol_table.get_stringvar("str") != 0 || symbol_table.symbol_exists("str"))
7957+
{
7958+
printf("run_test20() - [4] Failed to get 'str' from symbol_table\n");
7959+
result = false;
7960+
}
7961+
7962+
if (symbol_table.get_vector("vec") != 0 || symbol_table.symbol_exists("vec"))
7963+
{
7964+
printf("run_test20() - [4] Failed to get 'vec' from symbol_table\n");
7965+
result = false;
7966+
}
7967+
}
7968+
7969+
if (!result)
7970+
return result;
7971+
7972+
{
7973+
symbol_table_t symbol_table;
7974+
7975+
symbol_table.add_stringvar("str",str);
7976+
7977+
if (symbol_table.get_stringvar("str") == 0 || !symbol_table.symbol_exists("str"))
7978+
{
7979+
printf("run_test20() - [5] Failed to get 'str' from symbol_table\n");
7980+
result = false;
7981+
}
7982+
7983+
if (symbol_table.get_variable("val") != 0 || symbol_table.symbol_exists("val"))
7984+
{
7985+
printf("run_test20() - [5] Failed to get 'val' from symbol_table\n");
7986+
result = false;
7987+
}
7988+
7989+
if (symbol_table.get_vector("vec") != 0 || symbol_table.symbol_exists("vec"))
7990+
{
7991+
printf("run_test20() - [5] Failed to get 'vec' from symbol_table\n");
7992+
result = false;
7993+
}
7994+
}
7995+
7996+
if (!result)
7997+
return result;
7998+
7999+
{
8000+
symbol_table_t symbol_table;
8001+
8002+
symbol_table.add_vector("vec",vec);
8003+
8004+
if (symbol_table.get_vector("vec") == 0 || !symbol_table.symbol_exists("vec"))
8005+
{
8006+
printf("run_test20() - [6] Failed to get 'vec' from symbol_table\n");
8007+
result = false;
8008+
}
8009+
8010+
if (symbol_table.get_variable("val") != 0 || symbol_table.symbol_exists("val"))
8011+
{
8012+
printf("run_test20() - [6] Failed to get 'val' from symbol_table\n");
8013+
result = false;
8014+
}
8015+
8016+
if (symbol_table.get_stringvar("str") != 0 || symbol_table.symbol_exists("str"))
8017+
{
8018+
printf("run_test20() - [6] Failed to get 'str' from symbol_table\n");
8019+
result = false;
8020+
}
8021+
}
8022+
8023+
if (!result)
8024+
return result;
8025+
}
8026+
79078027
return true;
79088028
}
79098029

0 commit comments

Comments
 (0)