C++ Mathematical Expression Toolkit (ExprTk) release
Loading...
Searching...
No Matches
exprtk::function_compositor< T > Class Template Reference

#include <exprtk.hpp>

Classes

struct  function
struct  base_func
struct  scoped_bft
struct  func_0param
struct  func_1param
struct  func_2param
struct  func_3param
struct  func_4param
struct  func_5param
struct  func_6param
struct  func_0param_retval
struct  func_1param_retval
struct  func_2param_retval
struct  func_3param_retval
struct  func_4param_retval
struct  func_5param_retval
struct  func_6param_retval

Public Types

typedef exprtk::expression< T > expression_t
typedef exprtk::symbol_table< T > symbol_table_t
typedef exprtk::parser< T > parser_t
typedef parser_t::settings_store settings_t

Public Member Functions

 function_compositor ()
 function_compositor (const symbol_table_t &st)
 ~function_compositor ()
symbol_table_tsymbol_table ()
const symbol_table_tsymbol_table () const
void add_auxiliary_symtab (symbol_table_t &symtab)
void load_variables (const bool load=true)
void load_vectors (const bool load=true)
void register_loop_runtime_check (loop_runtime_check &lrtchk)
void register_vector_access_runtime_check (vector_access_runtime_check &vartchk)
void register_compilation_timeout_check (compilation_check &compchk)
void clear_loop_runtime_check ()
void clear_vector_access_runtime_check ()
void clear_compilation_timeout_check ()
void clear ()
bool add (const function &f, const bool override=false)
std::string error () const
std::size_t error_count () const
parser_error::type get_error (const std::size_t &index) const

Private Types

typedef std::map< std::string, base_func * > funcparam_t
typedef const T & type

Private Member Functions

template<typename Allocator, template< typename, typename > class Sequence>
bool add (const std::string &name, const std::string &expression, const Sequence< std::string, Allocator > &var_list, const bool override=false)
template<typename Allocator, template< typename, typename > class Sequence>
bool compile_expression (const std::string &name, const std::string &expression, const Sequence< std::string, Allocator > &input_var_list, bool return_present=false)
bool symbol_used (const std::string &symbol) const
bool valid (const std::string &name, const std::size_t &arg_count) const
bool forward (const std::string &name, const std::size_t &arg_count, symbol_table_t &sym_table, const bool ret_present=false)
void remove (const std::string &name, const std::size_t &arg_count)

Static Private Member Functions

static T return_value (expression_t &e)

Private Attributes

symbol_table_t symbol_table_
parser_t parser_
std::map< std::string, expression_texpr_map_
std::vector< funcparam_tfp_map_
std::vector< symbol_table_t * > auxiliary_symtab_list_
std::deque< parser_error::typeerror_list_
bool load_variables_
bool load_vectors_

Detailed Description

template<typename T>
class exprtk::function_compositor< T >

Definition at line 43056 of file exprtk.hpp.

Member Typedef Documentation

◆ expression_t

template<typename T>
typedef exprtk::expression<T> exprtk::function_compositor< T >::expression_t

Definition at line 43060 of file exprtk.hpp.

◆ funcparam_t

template<typename T>
typedef std::map<std::string,base_func*> exprtk::function_compositor< T >::funcparam_t
private

Definition at line 43492 of file exprtk.hpp.

◆ parser_t

template<typename T>
typedef exprtk::parser<T> exprtk::function_compositor< T >::parser_t

Definition at line 43062 of file exprtk.hpp.

◆ settings_t

template<typename T>
typedef parser_t::settings_store exprtk::function_compositor< T >::settings_t

Definition at line 43063 of file exprtk.hpp.

◆ symbol_table_t

template<typename T>
typedef exprtk::symbol_table<T> exprtk::function_compositor< T >::symbol_table_t

Definition at line 43061 of file exprtk.hpp.

◆ type

template<typename T>
typedef const T& exprtk::function_compositor< T >::type
private

Definition at line 43494 of file exprtk.hpp.

Constructor & Destructor Documentation

◆ function_compositor() [1/2]

template<typename T>
exprtk::function_compositor< T >::function_compositor ( )
inline

Definition at line 43694 of file exprtk.hpp.

References fp_map_, load_variables_, load_vectors_, and parser_.

◆ function_compositor() [2/2]

template<typename T>
exprtk::function_compositor< T >::function_compositor ( const symbol_table_t & st)
inlineexplicit

◆ ~function_compositor()

template<typename T>
exprtk::function_compositor< T >::~function_compositor ( )
inline

Definition at line 43711 of file exprtk.hpp.

43712 {
43713 clear();
43714 }

References clear().

Here is the call graph for this function:

Member Function Documentation

◆ add() [1/2]

template<typename T>
bool exprtk::function_compositor< T >::add ( const function & f,
const bool override = false )
inline

Definition at line 43795 of file exprtk.hpp.

43796 {
43797 return add(f.name_, f.expression_, f.v_,override);
43798 }
bool add(const std::string &name, const std::string &expression, const Sequence< std::string, Allocator > &var_list, const bool override=false)
Definition exprtk.hpp:43655

References add(), exprtk::function_compositor< T >::function::expression_, exprtk::function_compositor< T >::function::name_, and exprtk::function_compositor< T >::function::v_.

Here is the call graph for this function:

◆ add() [2/2]

template<typename T>
template<typename Allocator, template< typename, typename > class Sequence>
bool exprtk::function_compositor< T >::add ( const std::string & name,
const std::string & expression,
const Sequence< std::string, Allocator > & var_list,
const bool override = false )
inlineprivate

Definition at line 43655 of file exprtk.hpp.

43659 {
43661
43662 if (expr_map_.end() != itr)
43663 {
43664 if (!override)
43665 {
43666 exprtk_debug(("Compositor error(add): function '%s' already defined\n",
43667 name.c_str()));
43668
43669 return false;
43670 }
43671
43672 remove(name, var_list.size());
43673 }
43674
43676 {
43677 const std::size_t n = var_list.size();
43678
43679 fp_map_[n][name]->setup(expr_map_[name]);
43680
43681 return true;
43682 }
43683 else
43684 {
43685 exprtk_debug(("Compositor error(add): Failed to compile function '%s'\n",
43686 name.c_str()));
43687
43688 return false;
43689 }
43690 }
std::map< std::string, expression_t > expr_map_
Definition exprtk.hpp:44028
bool compile_expression(const std::string &name, const std::string &expression, const Sequence< std::string, Allocator > &input_var_list, bool return_present=false)
Definition exprtk.hpp:43829
void remove(const std::string &name, const std::size_t &arg_count)
Definition exprtk.hpp:44001
#define exprtk_debug(params)
Definition exprtk.hpp:64

References compile_expression(), expr_map_, exprtk_debug, fp_map_, and remove().

Referenced by add(), and primes_via_naive_method().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_auxiliary_symtab()

template<typename T>
void exprtk::function_compositor< T >::add_auxiliary_symtab ( symbol_table_t & symtab)
inline

Definition at line 43726 of file exprtk.hpp.

43727 {
43728 auxiliary_symtab_list_.push_back(&symtab);
43729 }
std::vector< symbol_table_t * > auxiliary_symtab_list_
Definition exprtk.hpp:44030

References auxiliary_symtab_list_.

◆ clear()

template<typename T>
void exprtk::function_compositor< T >::clear ( )
inline

Definition at line 43771 of file exprtk.hpp.

43772 {
43773 symbol_table_.clear();
43774 expr_map_ .clear();
43775
43776 for (std::size_t i = 0; i < fp_map_.size(); ++i)
43777 {
43778 typename funcparam_t::iterator itr = fp_map_[i].begin();
43779 typename funcparam_t::iterator end = fp_map_[i].end ();
43780
43781 while (itr != end)
43782 {
43783 delete itr->second;
43784 ++itr;
43785 }
43786
43787 fp_map_[i].clear();
43788 }
43789
43793 }

References clear_compilation_timeout_check(), clear_loop_runtime_check(), clear_vector_access_runtime_check(), expr_map_, fp_map_, and symbol_table_.

Referenced by ~function_compositor().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clear_compilation_timeout_check()

template<typename T>
void exprtk::function_compositor< T >::clear_compilation_timeout_check ( )
inline

Definition at line 43766 of file exprtk.hpp.

43767 {
43768 parser_.clear_compilation_timeout_check();
43769 }

References parser_.

Referenced by clear().

Here is the caller graph for this function:

◆ clear_loop_runtime_check()

template<typename T>
void exprtk::function_compositor< T >::clear_loop_runtime_check ( )
inline

Definition at line 43756 of file exprtk.hpp.

43757 {
43758 parser_.clear_loop_runtime_check();
43759 }

References parser_.

Referenced by clear().

Here is the caller graph for this function:

◆ clear_vector_access_runtime_check()

template<typename T>
void exprtk::function_compositor< T >::clear_vector_access_runtime_check ( )
inline

Definition at line 43761 of file exprtk.hpp.

43762 {
43763 parser_.clear_vector_access_runtime_check();
43764 }

References parser_.

Referenced by clear().

Here is the caller graph for this function:

◆ compile_expression()

template<typename T>
template<typename Allocator, template< typename, typename > class Sequence>
bool exprtk::function_compositor< T >::compile_expression ( const std::string & name,
const std::string & expression,
const Sequence< std::string, Allocator > & input_var_list,
bool return_present = false )
inlineprivate

Definition at line 43829 of file exprtk.hpp.

43833 {
43836
43838 local_symbol_table.add_constants();
43839
43840 if (load_variables_)
43841 {
43842 local_symbol_table.load_variables_from(symbol_table_);
43843 }
43844
43845 if (load_vectors_)
43846 {
43847 local_symbol_table.load_vectors_from(symbol_table_);
43848 }
43849
43850 error_list_.clear();
43851
43852 if (!valid(name,input_var_list.size()))
43853 {
43857 lexer::token(),
43858 "ERR285 - Function '" + name + "' is an invalid overload",
43860
43861 error_list_.push_back(error);
43862 return false;
43863 }
43864
43865 if (!forward(name,
43866 input_var_list.size(),
43869 return false;
43870
43871 compiled_expression.register_symbol_table(local_symbol_table);
43872
43873 for (std::size_t i = 0; i < auxiliary_symtab_list_.size(); ++i)
43874 {
43875 compiled_expression.register_symbol_table((*auxiliary_symtab_list_[i]));
43876 }
43877
43879
43880 for (std::size_t i = 0; i < input_var_list.size(); ++i)
43881 {
43882 mod_expression += " var " + input_var_list[i] + "{};\n";
43883 }
43884
43885 if (
43886 ('{' == details::front(expression)) &&
43887 ('}' == details::back (expression))
43888 )
43889 mod_expression += "~" + expression + ";";
43890 else
43891 mod_expression += "~{" + expression + "};";
43892
43894 {
43895 exprtk_debug(("Compositor Error: %s\n", parser_.error().c_str()));
43896 exprtk_debug(("Compositor modified expression: \n%s\n", mod_expression.c_str()));
43897
43898 remove(name,input_var_list.size());
43899
43900 for (std::size_t err_index = 0; err_index < parser_.error_count(); ++err_index)
43901 {
43902 error_list_.push_back(parser_.get_error(err_index));
43903 }
43904
43905 return false;
43906 }
43907
43908 if (!return_present && parser_.dec().return_present())
43909 {
43910 remove(name,input_var_list.size());
43912 }
43913
43914 // Make sure every return point has a scalar as its first parameter
43915 if (parser_.dec().return_present())
43916 {
43918
43919 str_list_t ret_param_list = parser_.dec().return_param_type_list();
43920
43921 for (std::size_t i = 0; i < ret_param_list.size(); ++i)
43922 {
43924
43925 if (params.empty() || ('T' != params[0]))
43926 {
43927 exprtk_debug(("Compositor Error: Return statement in function '%s' is invalid\n",
43928 name.c_str()));
43929
43930 remove(name,input_var_list.size());
43931
43932 return false;
43933 }
43934 }
43935 }
43936
43938
43940
43941 if (symbol_table_.add_function(name,ifunc))
43942 return true;
43943 else
43944 {
43945 exprtk_debug(("Compositor Error: Failed to add function '%s' to symbol table\n",
43946 name.c_str()));
43947 return false;
43948 }
43949 }
bool forward(const std::string &name, const std::size_t &arg_count, symbol_table_t &sym_table, const bool ret_present=false)
Definition exprtk.hpp:43975
exprtk::symbol_table< T > symbol_table_t
Definition exprtk.hpp:43061
std::string error() const
Definition exprtk.hpp:43800
std::deque< parser_error::type > error_list_
Definition exprtk.hpp:44031
exprtk::expression< T > expression_t
Definition exprtk.hpp:43060
bool valid(const std::string &name, const std::size_t &arg_count) const
Definition exprtk.hpp:43962
type make_error(const error_mode mode, const std::string &diagnostic="", const std::string &src_location="")
Definition exprtk.hpp:22420

References exprtk::symbol_table< T >::add_constants(), auxiliary_symtab_list_, exprtk::details::back(), compile_expression(), exprtk::parser_error::e_parser, error(), error_list_, expr_map_, exprtk_debug, exprtk_error_location, forward(), fp_map_, exprtk::details::front(), exprtk::symbol_table< T >::load_from(), load_variables_, exprtk::symbol_table< T >::load_variables_from(), load_vectors_, exprtk::symbol_table< T >::load_vectors_from(), exprtk::parser_error::make_error(), parser_, exprtk::expression< T >::register_symbol_table(), remove(), symbol_table_, and valid().

Referenced by add(), and compile_expression().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ error()

template<typename T>
std::string exprtk::function_compositor< T >::error ( ) const
inline

Definition at line 43800 of file exprtk.hpp.

43801 {
43802 if (!error_list_.empty())
43803 {
43804 return error_list_[0].diagnostic;
43805 }
43806 else
43807 return std::string("No Error");
43808 }

References error_list_.

Referenced by compile_expression().

Here is the caller graph for this function:

◆ error_count()

template<typename T>
std::size_t exprtk::function_compositor< T >::error_count ( ) const
inline

Definition at line 43810 of file exprtk.hpp.

43811 {
43812 return error_list_.size();
43813 }

References error_list_.

◆ forward()

template<typename T>
bool exprtk::function_compositor< T >::forward ( const std::string & name,
const std::size_t & arg_count,
symbol_table_t & sym_table,
const bool ret_present = false )
inlineprivate

Definition at line 43975 of file exprtk.hpp.

43979 {
43980 switch (arg_count)
43981 {
43982 #define case_stmt(N) \
43983 case N : (fp_map_[arg_count])[name] = \
43984 (!ret_present) ? static_cast<base_func*> \
43985 (new func_##N##param) : \
43986 static_cast<base_func*> \
43987 (new func_##N##param_retval) ; \
43988 break; \
43989
43992 case_stmt(6)
43993 #undef case_stmt
43994 }
43995
43997
43998 return sym_table.add_function(name,ifunc);
43999 }
#define case_stmt(N)
Definition exprtk.hpp:33330

References exprtk::symbol_table< T >::add_function(), case_stmt, and fp_map_.

Referenced by compile_expression().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_error()

template<typename T>
parser_error::type exprtk::function_compositor< T >::get_error ( const std::size_t & index) const
inline

Definition at line 43815 of file exprtk.hpp.

43816 {
43817 if (index < error_list_.size())
43818 {
43819 return error_list_[index];
43820 }
43821
43822 throw std::invalid_argument("compositor::get_error() - Invalid error index specified");
43823 }

References error_list_.

◆ load_variables()

template<typename T>
void exprtk::function_compositor< T >::load_variables ( const bool load = true)
inline

Definition at line 43731 of file exprtk.hpp.

43732 {
43734 }

References load_variables_.

◆ load_vectors()

template<typename T>
void exprtk::function_compositor< T >::load_vectors ( const bool load = true)
inline

Definition at line 43736 of file exprtk.hpp.

43737 {
43739 }

References load_vectors_.

◆ register_compilation_timeout_check()

template<typename T>
void exprtk::function_compositor< T >::register_compilation_timeout_check ( compilation_check & compchk)
inline

Definition at line 43751 of file exprtk.hpp.

43752 {
43753 parser_.register_compilation_timeout_check(compchk);
43754 }

References parser_.

◆ register_loop_runtime_check()

template<typename T>
void exprtk::function_compositor< T >::register_loop_runtime_check ( loop_runtime_check & lrtchk)
inline

Definition at line 43741 of file exprtk.hpp.

43742 {
43743 parser_.register_loop_runtime_check(lrtchk);
43744 }

References parser_.

◆ register_vector_access_runtime_check()

template<typename T>
void exprtk::function_compositor< T >::register_vector_access_runtime_check ( vector_access_runtime_check & vartchk)
inline

Definition at line 43746 of file exprtk.hpp.

43747 {
43748 parser_.register_vector_access_runtime_check(vartchk);
43749 }

References parser_.

◆ remove()

template<typename T>
void exprtk::function_compositor< T >::remove ( const std::string & name,
const std::size_t & arg_count )
inlineprivate

Definition at line 44001 of file exprtk.hpp.

44002 {
44003 if (arg_count > 6)
44004 return;
44005
44007
44008 if (expr_map_.end() != em_itr)
44009 {
44010 expr_map_.erase(em_itr);
44011 }
44012
44013 const typename funcparam_t::iterator fp_itr = fp_map_[arg_count].find(name);
44014
44015 if (fp_map_[arg_count].end() != fp_itr)
44016 {
44017 delete fp_itr->second;
44018 fp_map_[arg_count].erase(fp_itr);
44019 }
44020
44021 symbol_table_.remove_function(name);
44022 }

References expr_map_, fp_map_, and symbol_table_.

Referenced by add(), and compile_expression().

Here is the caller graph for this function:

◆ return_value()

template<typename T>
T exprtk::function_compositor< T >::return_value ( expression_t & e)
inlinestaticprivate

Definition at line 43615 of file exprtk.hpp.

43616 {
43618 typedef typename results_context_t::type_store_t type_t;
43619 typedef typename type_t::scalar_view scalar_t;
43620
43621 const T result = e.value();
43622
43623 if (e.return_invoked())
43624 {
43625 // Due to the post compilation checks, it can be safely
43626 // assumed that there will be at least one parameter
43627 // and that the first parameter will always be scalar.
43628 return scalar_t(e.results()[0])();
43629 }
43630
43631 return result;
43632 }

◆ symbol_table() [1/2]

template<typename T>
symbol_table_t & exprtk::function_compositor< T >::symbol_table ( )
inline

Definition at line 43716 of file exprtk.hpp.

43717 {
43718 return symbol_table_;
43719 }

References symbol_table_.

◆ symbol_table() [2/2]

template<typename T>
const symbol_table_t & exprtk::function_compositor< T >::symbol_table ( ) const
inline

Definition at line 43721 of file exprtk.hpp.

43722 {
43723 return symbol_table_;
43724 }

References symbol_table_.

◆ symbol_used()

template<typename T>
bool exprtk::function_compositor< T >::symbol_used ( const std::string & symbol) const
inlineprivate

Definition at line 43951 of file exprtk.hpp.

43952 {
43953 return (
43954 symbol_table_.is_variable (symbol) ||
43955 symbol_table_.is_stringvar (symbol) ||
43956 symbol_table_.is_function (symbol) ||
43957 symbol_table_.is_vector (symbol) ||
43958 symbol_table_.is_vararg_function(symbol)
43959 );
43960 }

References symbol_table_.

Referenced by valid().

Here is the caller graph for this function:

◆ valid()

template<typename T>
bool exprtk::function_compositor< T >::valid ( const std::string & name,
const std::size_t & arg_count ) const
inlineprivate

Definition at line 43962 of file exprtk.hpp.

43964 {
43965 if (arg_count > 6)
43966 return false;
43967 else if (symbol_used(name))
43968 return false;
43969 else if (fp_map_[arg_count].end() != fp_map_[arg_count].find(name))
43970 return false;
43971 else
43972 return true;
43973 }
bool symbol_used(const std::string &symbol) const
Definition exprtk.hpp:43951

References fp_map_, and symbol_used().

Referenced by compile_expression().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ auxiliary_symtab_list_

template<typename T>
std::vector<symbol_table_t*> exprtk::function_compositor< T >::auxiliary_symtab_list_
private

Definition at line 44030 of file exprtk.hpp.

Referenced by add_auxiliary_symtab(), and compile_expression().

◆ error_list_

template<typename T>
std::deque<parser_error::type> exprtk::function_compositor< T >::error_list_
private

Definition at line 44031 of file exprtk.hpp.

Referenced by compile_expression(), error(), error_count(), and get_error().

◆ expr_map_

template<typename T>
std::map<std::string,expression_t> exprtk::function_compositor< T >::expr_map_
private

Definition at line 44028 of file exprtk.hpp.

Referenced by add(), clear(), compile_expression(), and remove().

◆ fp_map_

template<typename T>
std::vector<funcparam_t> exprtk::function_compositor< T >::fp_map_
private

◆ load_variables_

template<typename T>
bool exprtk::function_compositor< T >::load_variables_
private

◆ load_vectors_

template<typename T>
bool exprtk::function_compositor< T >::load_vectors_
private

◆ parser_

◆ symbol_table_

template<typename T>
symbol_table_t exprtk::function_compositor< T >::symbol_table_
private

The documentation for this class was generated from the following file: