C++ Mathematical Expression Library (ExprTk) http://www.partow.net/programming/exprtk/index.html

This commit is contained in:
Arash Partow 2014-12-06 12:35:39 +11:00
parent 552d75682b
commit b6cdf0d2f9
1 changed files with 60 additions and 36 deletions

View File

@ -4410,9 +4410,9 @@ namespace exprtk
construct_branch_pair<T,9,(N > 9)>::process(branch,b9); construct_branch_pair<T,9,(N > 9)>::process(branch,b9);
} }
template <typename T, std::size_t N>
struct cleanup_branches struct cleanup_branches
{ {
template <typename T, std::size_t N>
static inline void execute(std::pair<expression_node<T>*,bool> (&branch)[N]) static inline void execute(std::pair<expression_node<T>*,bool> (&branch)[N])
{ {
for (std::size_t i = 0; i < N; ++i) for (std::size_t i = 0; i < N; ++i)
@ -4424,6 +4424,21 @@ namespace exprtk
} }
} }
} }
template <typename T,
typename Allocator,
template <typename,typename> class Sequence>
static inline void execute(Sequence<std::pair<expression_node<T>*,bool>,Allocator>& branch)
{
for (std::size_t i = 0; i < branch.size(); ++i)
{
if (branch[i].first && branch[i].second)
{
delete branch[i].first;
branch[i].first = 0;
}
}
}
}; };
template <typename T> template <typename T>
@ -4444,7 +4459,7 @@ namespace exprtk
~binary_node() ~binary_node()
{ {
cleanup_branches<T,2>::execute(branch_); cleanup_branches::execute<T,2>(branch_);
} }
inline T value() const inline T value() const
@ -4495,7 +4510,7 @@ namespace exprtk
~binary_ext_node() ~binary_ext_node()
{ {
cleanup_branches<T,2>::execute(branch_); cleanup_branches::execute<T,2>(branch_);
} }
inline T value() const inline T value() const
@ -4549,7 +4564,7 @@ namespace exprtk
~trinary_node() ~trinary_node()
{ {
cleanup_branches<T,3>::execute(branch_); cleanup_branches::execute<T,3>(branch_);
} }
inline T value() const inline T value() const
@ -4603,7 +4618,7 @@ namespace exprtk
~quaternary_node() ~quaternary_node()
{ {
cleanup_branches<T,4>::execute(branch_); cleanup_branches::execute<T,4>(branch_);
} }
inline T value() const inline T value() const
@ -4653,7 +4668,7 @@ namespace exprtk
~quinary_node() ~quinary_node()
{ {
cleanup_branches<T,5>::execute(branch_); cleanup_branches::execute<T,5>(branch_);
} }
inline T value() const inline T value() const
@ -4705,7 +4720,7 @@ namespace exprtk
~senary_node() ~senary_node()
{ {
cleanup_branches<T,6>::execute(branch_); cleanup_branches::execute<T,6>(branch_);
} }
inline T value() const inline T value() const
@ -8150,7 +8165,7 @@ namespace exprtk
~function_N_node() ~function_N_node()
{ {
cleanup_branches<T,N>::execute(branch_); cleanup_branches::execute<T,N>(branch_);
} }
template <std::size_t NumBranches> template <std::size_t NumBranches>
@ -8555,14 +8570,7 @@ namespace exprtk
~generic_function_node() ~generic_function_node()
{ {
for (std::size_t i = 0; i < branch_.size(); ++i) cleanup_branches::execute(branch_);
{
if (branch_[i].first && branch_[i].second)
{
delete branch_[i].first;
branch_[i].first = 0;
}
}
} }
bool init_branches() bool init_branches()
@ -8743,9 +8751,21 @@ namespace exprtk
struct OpName##_op \ struct OpName##_op \
{ \ { \
typedef typename functor_t<T>::Type Type; \ typedef typename functor_t<T>::Type Type; \
static inline T process(Type v) { return numeric:: OpName (v); } \ \
static inline typename expression_node<T>::node_type type() { return expression_node<T>::e_##OpName; } \ static inline T process(Type v) \
static inline details::operator_type operation() { return details::e_##OpName; } \ { \
return numeric:: OpName (v); \
} \
\
static inline typename expression_node<T>::node_type type()\
{ \
return expression_node<T>::e_##OpName; \
} \
\
static inline details::operator_type operation() \
{ \
return details::e_##OpName; \
} \
}; \ }; \
exprtk_define_unary_op(abs ) exprtk_define_unary_op(abs )
@ -11093,7 +11113,7 @@ namespace exprtk
~vob_node() ~vob_node()
{ {
cleanup_branches<T,1>::execute(branch_); cleanup_branches::execute<T,1>(branch_);
} }
inline T value() const inline T value() const
@ -11143,7 +11163,7 @@ namespace exprtk
~bov_node() ~bov_node()
{ {
cleanup_branches<T,1>::execute(branch_); cleanup_branches::execute<T,1>(branch_);
} }
inline T value() const inline T value() const
@ -11193,7 +11213,7 @@ namespace exprtk
~cob_node() ~cob_node()
{ {
cleanup_branches<T,1>::execute(branch_); cleanup_branches::execute<T,1>(branch_);
} }
inline T value() const inline T value() const
@ -11254,7 +11274,7 @@ namespace exprtk
~boc_node() ~boc_node()
{ {
cleanup_branches<T,1>::execute(branch_); cleanup_branches::execute<T,1>(branch_);
} }
inline T value() const inline T value() const
@ -19202,7 +19222,7 @@ namespace exprtk
expression_node_ptr& branch, expression_node_ptr& branch,
const bool brkcont = false) const const bool brkcont = false) const
{ {
if (details::is_constant_node(condition)) if (!brkcont && details::is_constant_node(condition))
{ {
expression_node_ptr result = error_node(); expression_node_ptr result = error_node();
if (details::is_true(condition)) if (details::is_true(condition))
@ -19236,7 +19256,7 @@ namespace exprtk
expression_node_ptr branch, expression_node_ptr branch,
const bool brkcont = false) const const bool brkcont = false) const
{ {
if (details::is_constant_node(condition)) if (!brkcont && details::is_constant_node(condition))
{ {
if (details::is_true(condition) && details::is_constant_node(branch)) if (details::is_true(condition) && details::is_constant_node(branch))
{ {
@ -19272,7 +19292,7 @@ namespace exprtk
expression_node_ptr loop_body, expression_node_ptr loop_body,
bool brkcont = false) const bool brkcont = false) const
{ {
if (details::is_constant_node(condition)) if (!brkcont && details::is_constant_node(condition))
{ {
expression_node_ptr result = error_node(); expression_node_ptr result = error_node();
@ -26375,8 +26395,10 @@ namespace exprtk
inline void load_binary_operations_map(binary_op_map_t& m) inline void load_binary_operations_map(binary_op_map_t& m)
{ {
typedef typename binary_op_map_t::value_type value_type;
#define register_binary_op(Op,BinaryFunctor) \ #define register_binary_op(Op,BinaryFunctor) \
m.insert(typename binary_op_map_t::value_type(Op,BinaryFunctor<T>::process)); \ m.insert(value_type(Op,BinaryFunctor<T>::process)); \
register_binary_op(details:: e_add,details:: add_op) register_binary_op(details:: e_add,details:: add_op)
register_binary_op(details:: e_sub,details:: sub_op) register_binary_op(details:: e_sub,details:: sub_op)
@ -26401,8 +26423,10 @@ namespace exprtk
inline void load_inv_binary_operations_map(inv_binary_op_map_t& m) inline void load_inv_binary_operations_map(inv_binary_op_map_t& m)
{ {
typedef typename inv_binary_op_map_t::value_type value_type;
#define register_binary_op(Op,BinaryFunctor) \ #define register_binary_op(Op,BinaryFunctor) \
m.insert(typename inv_binary_op_map_t::value_type(BinaryFunctor<T>::process,Op)); \ m.insert(value_type(BinaryFunctor<T>::process,Op)); \
register_binary_op(details:: e_add,details:: add_op) register_binary_op(details:: e_add,details:: add_op)
register_binary_op(details:: e_sub,details:: sub_op) register_binary_op(details:: e_sub,details:: sub_op)