summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/netlist/plib/pfunction.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/netlist/plib/pfunction.h')
-rw-r--r--src/lib/netlist/plib/pfunction.h70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/lib/netlist/plib/pfunction.h b/src/lib/netlist/plib/pfunction.h
new file mode 100644
index 00000000000..2ad32106569
--- /dev/null
+++ b/src/lib/netlist/plib/pfunction.h
@@ -0,0 +1,70 @@
+// license:GPL-2.0+
+// copyright-holders:Couriersud
+/*
+ * pfunction.h
+ *
+ */
+
+#ifndef PFUNCTION_H_
+#define PFUNCTION_H_
+
+#include <vector>
+
+#include "pconfig.h"
+#include "pstring.h"
+
+namespace plib {
+
+ //============================================================
+ // function evaluation - reverse polish notation
+ //============================================================
+
+ /*! Class providing support for precompiled rpn expressions
+ *
+ */
+ class pfunction
+ {
+ enum rpn_cmd
+ {
+ ADD,
+ MULT,
+ SUB,
+ DIV,
+ POW,
+ SIN,
+ COS,
+ PUSH_CONST,
+ PUSH_INPUT
+ };
+ struct rpn_inst
+ {
+ rpn_inst() : m_cmd(ADD), m_param(0.0) { }
+ rpn_cmd m_cmd;
+ double m_param;
+ };
+ public:
+ pfunction()
+ {
+ }
+
+ /*! Compile a rpn expression
+ *
+ * @param inputs Vector of input variables, e.g. {"A","B"}
+ * @param expr Reverse polish notation expression, e.g. "A B + 1.3 /"
+ */
+ void compile_postfix(const std::vector<pstring> &inputs, const pstring expr);
+ /*! Evaluate the expression
+ *
+ * @param values for input variables, e.g. {1.1, 2.2}
+ * @return value of expression
+ */
+ double evaluate(const std::vector<double> &values);
+
+ private:
+ std::vector<rpn_inst> m_precompiled; //!< precompiled expression
+ };
+
+
+}
+
+#endif /* PEXCEPTION_H_ */