summaryrefslogtreecommitdiff
path: root/noncore/tools/calc2/instruction.h
Unidiff
Diffstat (limited to 'noncore/tools/calc2/instruction.h') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/tools/calc2/instruction.h69
1 files changed, 69 insertions, 0 deletions
diff --git a/noncore/tools/calc2/instruction.h b/noncore/tools/calc2/instruction.h
new file mode 100644
index 0000000..6077bf0
--- a/dev/null
+++ b/noncore/tools/calc2/instruction.h
@@ -0,0 +1,69 @@
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#ifndef INSTRUCTION_H
21#define INSTRUCTION_H
22
23/* Internal representation of data
24The first four types indicate an int,
25that is, Data.i, and are incompatible
26with the other two types.
27
28- Plugin is responsible for telling engine
29which Rep to use at any given time
30- Instructions from that plugin only
31have to handle that representation
32- Engine is responsible for error-checking
33according to its current rep and display */
34enum Representation {
35 rBin,
36 rOct,
37 rDec,
38 rHex,
39 rDouble,
40 rFraction
41};
42
43// An atom of data
44union Data {
45 int i;
46 double dbl;
47 struct Fraction {
48 int numerator, denominator;
49 } fraction;
50};
51
52// Instruction base class
53class Instruction {
54public:
55 Instruction (int p = 0) {
56 precedence = p;
57 };
58
59 virtual ~ Instruction () {};
60
61 virtual Data eval(Data) = 0;
62 void setRep(Representation r) { rep = r; };
63
64 Representation rep;
65 Data acc;
66 int precedence;
67};
68
69#endif