aboutsummaryrefslogtreecommitdiff
path: root/src/old/formula.h
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2009-02-11 05:29:41 +0000
committerMike Buland <eichlan@xagasoft.com>2009-02-11 05:29:41 +0000
commitf4b191f0ea396b58465bfba40749977780a3af58 (patch)
tree891490e91ab3b67524be67b2b71c85d84fd2f92a /src/old/formula.h
parent292ae9453e7fdb2f1023ed9dfc99cbcd751f8b90 (diff)
downloadlibbu++-f4b191f0ea396b58465bfba40749977780a3af58.tar.gz
libbu++-f4b191f0ea396b58465bfba40749977780a3af58.tar.bz2
libbu++-f4b191f0ea396b58465bfba40749977780a3af58.tar.xz
libbu++-f4b191f0ea396b58465bfba40749977780a3af58.zip
Just removing some things that are cluttering up the source tree.
Diffstat (limited to 'src/old/formula.h')
-rw-r--r--src/old/formula.h77
1 files changed, 0 insertions, 77 deletions
diff --git a/src/old/formula.h b/src/old/formula.h
deleted file mode 100644
index 939eb09..0000000
--- a/src/old/formula.h
+++ /dev/null
@@ -1,77 +0,0 @@
1#ifndef FORMULA_H
2#define FORMULA_H
3
4#include <stdint.h>
5
6#include <math.h>
7#include <stack>
8#include "sbuffer.h"
9
10#include "exceptionbase.h"
11#include "hash.h"
12
13subExceptionDecl( ParseException );
14
15/**
16 * Implements a very simple formula parser that allows use of variables and
17 * custom functions. This is based on a simple calculator-type parser that
18 * executes as it processes, accounting for operator precedence and grouping.
19 */
20class Formula
21{
22public:
23 Formula();
24 virtual ~Formula();
25
26 double run( char *sFormula );
27
28 typedef Hash<std::string, double> varHash;
29 varHash hVars;
30
31 typedef struct Func
32 {
33 double operator()( double x )
34 {
35 return 0.0;
36 }
37 } Func;
38
39 typedef Hash<std::string, Func> funcHash;
40 funcHash hFunc;
41
42 typedef struct FuncSin : Func
43 {
44 double operator()( double x )
45 {
46 return sin( x );
47 }
48 } FuncSin;
49
50private:
51 enum
52 {
53 symEOS,
54 symAdd,
55 symSubtract,
56 symMultiply,
57 symDivide,
58 symOpenParen,
59 symCloseParen,
60 symNumber,
61 symVariable,
62 symExponent,
63 symModulus
64 };
65
66 typedef uint8_t symType;
67
68 std::stack<symType> sOper;
69 std::stack<double> sValue;
70
71private:
72 symType getPrec( symType nOper );
73 symType nextToken( char **sBuf );
74 void reduce( bool bCloseParen = false );
75};
76
77#endif