Skip to content

Commit 3e4791b

Browse files
committed
Updates to ExprTk
1 parent 8ac8348 commit 3e4791b

File tree

1 file changed

+42
-48
lines changed

1 file changed

+42
-48
lines changed

exprtk/exprtk.hpp

Lines changed: 42 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -35361,15 +35361,17 @@ namespace exprtk
3536135361
std::set<std::string>& symbol_set,
3536235362
const bool collect_variables,
3536335363
const bool collect_functions,
35364-
const bool vector_pass = false)
35364+
const bool vector_pass,
35365+
symbol_table_t& ext_symbol_table = symbol_table_t())
3536535366
{
3536635367
symbol_table_t symbol_table;
3536735368
expression_t expression;
3536835369
parser_t parser;
3536935370

3537035371
resolve_as_vector vect_resolver;
3537135372

35372-
expression.register_symbol_table(symbol_table);
35373+
expression.register_symbol_table(symbol_table );
35374+
expression.register_symbol_table(ext_symbol_table);
3537335375

3537435376
if (vector_pass)
3537535377
parser.enable_unknown_symbol_resolver(&vect_resolver);
@@ -35384,6 +35386,8 @@ namespace exprtk
3538435386

3538535387
bool pass_result = false;
3538635388

35389+
details::disable_type_checking(parser);
35390+
3538735391
if (parser.compile(expression_string, expression))
3538835392
{
3538935393
pass_result = true;
@@ -35410,10 +35414,14 @@ namespace exprtk
3541035414
typedef double T;
3541135415
typedef details::collector_helper<T> collect_t;
3541235416

35417+
collect_t::symbol_table_t null_symbol_table;
35418+
3541335419
std::set<std::string> symbol_set;
3541435420

35415-
const bool variable_pass = collect_t::collection_pass(expression, symbol_set, true, false, false);
35416-
const bool vector_pass = collect_t::collection_pass(expression, symbol_set, true, false, true);
35421+
const bool variable_pass = collect_t::collection_pass
35422+
(expression, symbol_set, true, false, false, null_symbol_table);
35423+
const bool vector_pass = collect_t::collection_pass
35424+
(expression, symbol_set, true, false, true, null_symbol_table);
3541735425

3541835426
if (!variable_pass && !vector_pass)
3541935427
return false;
@@ -35432,37 +35440,28 @@ namespace exprtk
3543235440
template <typename T,
3543335441
typename Allocator,
3543435442
template <typename, typename> class Sequence>
35435-
inline bool collect_variables(const std::string& expr_str,
35443+
inline bool collect_variables(const std::string& expression,
3543635444
exprtk::symbol_table<T>& extrnl_symbol_table,
3543735445
Sequence<std::string, Allocator>& symbol_list)
3543835446
{
35439-
typedef exprtk::symbol_table<T> symbol_table_t;
35440-
typedef exprtk::expression<T> expression_t;
35441-
typedef exprtk::parser<T> parser_t;
35442-
typedef typename parser_t::dependent_entity_collector::symbol_t symbol_t;
35443-
35444-
symbol_table_t symbol_table;
35445-
expression_t expression;
35446-
parser_t parser;
35447-
35448-
expression.register_symbol_table(symbol_table);
35449-
expression.register_symbol_table(extrnl_symbol_table);
35447+
typedef details::collector_helper<T> collect_t;
3545035448

35451-
parser.enable_unknown_symbol_resolver();
35452-
parser.dec().collect_variables() = true;
35449+
std::set<std::string> symbol_set;
3545335450

35454-
details::disable_type_checking(parser);
35451+
const bool variable_pass = collect_t::collection_pass
35452+
(expression, symbol_set, true, false, false, extrnl_symbol_table);
35453+
const bool vector_pass = collect_t::collection_pass
35454+
(expression, symbol_set, true, false, true, extrnl_symbol_table);
3545535455

35456-
if (!parser.compile(expr_str, expression))
35456+
if (!variable_pass && !vector_pass)
3545735457
return false;
3545835458

35459-
std::deque<symbol_t> symb_list;
35460-
35461-
parser.dec().symbols(symb_list);
35459+
std::set<std::string>::iterator itr = symbol_set.begin();
3546235460

35463-
for (std::size_t i = 0; i < symb_list.size(); ++i)
35461+
while (symbol_set.end() != itr)
3546435462
{
35465-
symbol_list.push_back(symb_list[i].first);
35463+
symbol_list.push_back(*itr);
35464+
++itr;
3546635465
}
3546735466

3546835467
return true;
@@ -35476,10 +35475,14 @@ namespace exprtk
3547635475
typedef double T;
3547735476
typedef details::collector_helper<T> collect_t;
3547835477

35478+
collect_t::symbol_table_t null_symbol_table;
35479+
3547935480
std::set<std::string> symbol_set;
3548035481

35481-
const bool variable_pass = collect_t::collection_pass(expression, symbol_set, false, true, false);
35482-
const bool vector_pass = collect_t::collection_pass(expression, symbol_set, false, true, true);
35482+
const bool variable_pass = collect_t::collection_pass
35483+
(expression, symbol_set, false, true, false, null_symbol_table);
35484+
const bool vector_pass = collect_t::collection_pass
35485+
(expression, symbol_set, false, true, true, null_symbol_table);
3548335486

3548435487
if (!variable_pass && !vector_pass)
3548535488
return false;
@@ -35498,37 +35501,28 @@ namespace exprtk
3549835501
template <typename T,
3549935502
typename Allocator,
3550035503
template <typename, typename> class Sequence>
35501-
inline bool collect_functions(const std::string& expr_str,
35504+
inline bool collect_functions(const std::string& expression,
3550235505
exprtk::symbol_table<T>& extrnl_symbol_table,
3550335506
Sequence<std::string, Allocator>& symbol_list)
3550435507
{
35505-
typedef exprtk::symbol_table<T> symbol_table_t;
35506-
typedef exprtk::expression<T> expression_t;
35507-
typedef exprtk::parser<T> parser_t;
35508-
typedef typename parser_t::dependent_entity_collector::symbol_t symbol_t;
35509-
35510-
symbol_table_t symbol_table;
35511-
expression_t expression;
35512-
parser_t parser;
35513-
35514-
expression.register_symbol_table(symbol_table);
35515-
expression.register_symbol_table(extrnl_symbol_table);
35508+
typedef details::collector_helper<T> collect_t;
3551635509

35517-
parser.enable_unknown_symbol_resolver();
35518-
parser.dec().collect_functions() = true;
35510+
std::set<std::string> symbol_set;
3551935511

35520-
details::disable_type_checking(parser);
35512+
const bool variable_pass = collect_t::collection_pass
35513+
(expression, symbol_set, false, true, false, extrnl_symbol_table);
35514+
const bool vector_pass = collect_t::collection_pass
35515+
(expression, symbol_set, false, true, true, extrnl_symbol_table);
3552135516

35522-
if (!parser.compile(expr_str, expression))
35517+
if (!variable_pass && !vector_pass)
3552335518
return false;
3552435519

35525-
std::deque<symbol_t> symb_list;
35526-
35527-
parser.dec().symbols(symb_list);
35520+
std::set<std::string>::iterator itr = symbol_set.begin();
3552835521

35529-
for (std::size_t i = 0; i < symb_list.size(); ++i)
35522+
while (symbol_set.end() != itr)
3553035523
{
35531-
symbol_list.push_back(symb_list[i].first);
35524+
symbol_list.push_back(*itr);
35525+
++itr;
3553235526
}
3553335527

3553435528
return true;

0 commit comments

Comments
 (0)