summaryrefslogtreecommitdiff
path: root/noncore/tools/calc2/engine.h
authorkergoth <kergoth>2002-01-25 22:14:26 (UTC)
committer kergoth <kergoth>2002-01-25 22:14:26 (UTC)
commit15318cad33835e4e2dc620d033e43cd930676cdd (patch) (unidiff)
treec2fa0399a2c47fda8e2cd0092c73a809d17f68eb /noncore/tools/calc2/engine.h
downloadopie-15318cad33835e4e2dc620d033e43cd930676cdd.zip
opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.gz
opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.bz2
Initial revision
Diffstat (limited to 'noncore/tools/calc2/engine.h') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/tools/calc2/engine.h111
1 files changed, 111 insertions, 0 deletions
diff --git a/noncore/tools/calc2/engine.h b/noncore/tools/calc2/engine.h
new file mode 100644
index 0000000..15c9aa1
--- a/dev/null
+++ b/noncore/tools/calc2/engine.h
@@ -0,0 +1,111 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#ifndef ENGINE_H
22#define ENGINE_H
23
24#include <qwidget.h>
25 #include <qstack.h>// Instruction stack
26 #include <qstring.h>// Display
27#include "instruction.h"
28
29// Possible states
30enum State {
31 sStart,// start inputting a new number
32 sAppend,// continue inputting a number
33 sError
34};
35
36// State machine
37class Engine:public QWidget {
38
39Q_OBJECT
40public:
41 Engine (QWidget * parent = 0, const char *name = 0):QWidget (parent, name) {
42 hardReset();
43 setRepresentation(rDec);
44 };
45
46 ~Engine () { };
47
48 void immediateInstruction (Instruction *);
49 void pushInstruction (Instruction *);
50 void eval ();
51
52 void pushValue (char);
53 void del ();
54
55 void openBrace ();
56 void closeBrace ();
57
58 void softReset () {// clears the number being inputted
59 decimalPlaces = -1;
60 clearData(&num);
61 displayData(num);
62 state = sStart;
63 };
64 void hardReset () {// a "real" reset of the stack
65 stack.clear ();
66 memClear();
67 braces = 0;
68 softReset ();
69 };
70
71 void memSave () {
72 mem = num;
73 };
74 void memRecall () {
75 num = mem;
76 state = sStart;
77 displayData(num);
78 };
79 void memClear () {
80 clearData(&mem);
81 };
82
83 // rFraction will require a special display enabled here
84 void setRepresentation(Representation);
85
86 // you dont want to call this
87 void decBraces(void){ braces--; };
88
89private:
90 void displayData(Data d);
91 void clearData(Data *d);
92 int calcBase();
93 Data evalStack (Data, bool);
94 Data num,mem;
95 State state;
96 QStack < Instruction > stack;
97 Representation currentRep;
98 int braces, decimalPlaces; // count of finishing 0's in num
99 QString displayString; // saves instatiating it over and over
100
101signals:
102 void display(const QString &);
103 void display(double); // could get rid of this and
104 // use a QLabel instead.
105 void setHexMode();
106 void setBinMode();
107 void setDecMode();
108 void setOctMode();
109};
110
111#endif