From f6e93867452d78eca4ba42e4837f0a36d7822340 Mon Sep 17 00:00:00 2001 From: couriersud Date: Fri, 3 Jul 2020 20:36:25 +0200 Subject: netlist: add more constructors and () operator to pfunction. --- src/lib/netlist/plib/pfunction.h | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/lib/netlist/plib/pfunction.h b/src/lib/netlist/plib/pfunction.h index 00206afe677..6b5e94b2900 100644 --- a/src/lib/netlist/plib/pfunction.h +++ b/src/lib/netlist/plib/pfunction.h @@ -70,27 +70,45 @@ namespace plib { { } + /// \brief Constructor with compile + /// + pfunction(const pstring &expr, const inputs_container &inputs = inputs_container()) + : m_lfsr(0xace1U) // NOLINT + { + compile(expr, inputs); + } + + /// \brief Evaluate the expression + /// + /// \param values for input variables, e.g. {1.1, 2.2} + /// \return value of expression + /// + value_type operator()(const values_container &values = values_container()) noexcept + { + return evaluate(values); + } + /// \brief Compile an expression /// /// \param expr infix or postfix expression. default is infix, postrix /// to be prefixed with rpn, e.g. "rpn:A B + 1.3 /" /// \param inputs Vector of input variables, e.g. {"A","B"} /// - void compile(const pstring &expr, const inputs_container &inputs) noexcept(false); + void compile(const pstring &expr, const inputs_container &inputs = inputs_container()) noexcept(false); /// \brief Compile a rpn expression /// /// \param expr Reverse polish notation expression, e.g. "A B + 1.3 /" /// \param inputs Vector of input variables, e.g. {"A","B"} /// - void compile_postfix(const pstring &expr, const inputs_container &inputs) noexcept(false); + void compile_postfix(const pstring &expr, const inputs_container &inputs = inputs_container()) noexcept(false); /// \brief Compile an infix expression /// /// \param expr Infix expression, e.g. "(A+B)/1.3" /// \param inputs Vector of input variables, e.g. {"A","B"} /// - void compile_infix(const pstring &expr, const inputs_container &inputs) noexcept(false); + void compile_infix(const pstring &expr, const inputs_container &inputs = inputs_container()) noexcept(false); /// \brief Evaluate the expression /// -- cgit v1.2.3