Almetare  1.15
Alle meine Taschenrechner - Eine C++-Bibliothek zur Entwicklung von Taschenrechnern
symbols.h
gehe zur Dokumentation dieser Datei
1 //******************************************************************************
2 // Copyright (c) 2002-2004 by Friedemann Seebass, Germany.
3 // Dieses Programm ist freie Software. Siehe GNU GPL Notiz in Datei main.cpp.
4 // This program is free software. See the GNU GPL notice in file main.cpp.
5 // Projekt: Almetare - Alle meine Taschenrechner
6 //******************************************************************************
9 //******************************************************************************
10 // Wann Wer Was
11 // ---------- -------- ---------------------------------------------------------
12 // 23.03.2002 fse erzeugt
13 //******************************************************************************
14 
15 #ifndef SYMBOLS_H
16 #define SYMBOLS_H
17 
18 #ifndef __cplusplus
19 #error symbols.h is only for C++!
20 #endif
21 
22 //******************************************************************************
23 
24 #include <string>
25 
26 #include <math.h>
27 #include "number.h"
28 
29 using namespace std;
30 
31 //******************************************************************************
32 
33 class ComputerBase; // Forward-Deklaration
34 class DisplayBase; // Forward-Deklaration
35 
36 //******************************************************************************
37 // Klasse Symbol und Ableitungen:
38 //******************************************************************************
39 
44 // fse, 06.10.01
45 
46 class Symbol
47 {
48 protected:
49  string mSym;
50  string mHlp;
51  static ComputerBase* mCompP;
52  static DisplayBase* mDsplP;
53  static Symbol* getLastInP();
54  static Symbol* getLastOpP();
55  static Symbol* getLastButOneOpP();
56 public:
57  explicit Symbol(string sym = "", string hlp = "no help available") : mSym(sym), mHlp(hlp) {}
58  string getSym() const { return mSym; }
59  string getHlp() const { return mHlp; }
60  virtual ~Symbol() {}
61  virtual void process() = 0;
62  static void setCompP(ComputerBase* cP) { mCompP = cP; }
63  static void setDsplP(DisplayBase* cP) { mDsplP = cP; }
64  friend ostream& operator<<(ostream& os, const Symbol& s);
65  friend ostream& operator<<(ostream& os, const Symbol* s);
66 };
67 
68 //************************************** ***************************************
69 
72 
73 class SymNumber : public Symbol
74 {
75 protected:
76  explicit SymNumber(string sym = "", string hlp = "any number")
77  : Symbol(sym, hlp) {}
78 public:
79  void processCommon() const;
80 };
81 
82 //************************* ************************* **************************
83 
88 
89 class NumDmy : public SymNumber
90 {
91 public:
92  explicit NumDmy(string num = "0", string hlp = "any number") : SymNumber(num) { hlp = hlp; }
93  void setSym(const string& num) { mSym = num; }
94  void process();
95  static bool isFraction(const string& sym, double& val, long& numr, long& dnom);
96 };
97 
98 //************************************** ***************************************
99 
101 // fse, 06.10.01
102 
103 class SymOperator : public Symbol
104 {
105 protected:
106  int mPrio;
107 public:
108  explicit SymOperator(string op = "", int prio = 2, string hlp = "no help available")
109  : Symbol(op, hlp), mPrio(prio) {}
110  int getPrio() const { return mPrio; }
111  void processCommon();
112  void processAddSub();
113  void processAddSubCasioSci();
114  SymOperator* checkConstMode(const SymOperator* lastSymP) const;
115  virtual Number calcVal(const Number& a, const Number& b) = 0;
116 };
117 
118 //************************* ************************* **************************
119 
121 
122 class OpAdd : public SymOperator
123 {
124 public:
125  OpAdd() : SymOperator("+", 2, "adding operator") {};
126  Number calcVal(const Number& a, const Number& b) { return a + b; }
127  void process() { processAddSub(); }
128 };
129 
130 //****************** ******************* ******************* *******************
131 
133 
134 class OpAddCasioSci : public OpAdd
135 {
136 public:
137  OpAddCasioSci() : OpAdd() {};
138  void process() { processAddSubCasioSci(); }
139 };
140 
141 //************************* ************************* **************************
142 
144 
145 class OpSub : public SymOperator
146 {
147 public:
148  OpSub() : SymOperator("-", 2, "subtracting operator") {}
149  Number calcVal(const Number& a, const Number& b) { return a - b; }
150  void process() { processAddSub(); }
151 };
152 
153 //****************** ******************* ******************* *******************
154 
156 
157 class OpSubCasioSci : public OpSub
158 {
159 public:
160  OpSubCasioSci() : OpSub() {};
161  void process() { processAddSubCasioSci(); }
162 };
163 
164 //************************* ************************* **************************
165 
167 
168 class OpMul : public SymOperator
169 {
170 public:
171  OpMul() : SymOperator("*", 4, "multiplying operator") {}
172 
173  Number calcVal(const Number& a, const Number& b) { return a * b; }
174  void process() { processCommon(); }
175 };
176 
177 //************************* ************************* **************************
178 
180 
181 class OpDiv : public SymOperator
182 {
183 public:
184  OpDiv() : SymOperator("/", 4, "dividing operator") {}
185  Number calcVal(const Number& a, const Number& b) { return a / b; }
186  void process() { processCommon(); }
187 };
188 
189 //************************************** ***************************************
190 
192 // fse, 06.10.01
193 
194 class SymOther : public Symbol
195 {
196 protected:
197  static int mBraLev;
198 public:
199  explicit SymOther(string sym = "", string hlp = "no help available")
200  : Symbol(sym, hlp) {}
201  static int getBraLev() { return mBraLev; }
202 };
203 
204 //************************* ************************* **************************
205 
207 
208 class OthBra : public SymOther
209 {
210 public:
211  OthBra() : SymOther("(", "parentheses open") {}
212  void process();
213 };
214 
215 //************************* ************************* **************************
216 
218 
219 class OthKet : public SymOther
220 {
221 public:
222  OthKet() : SymOther(")", "parentheses close") {}
223  void process();
224 };
225 
226 //************************* ************************* **************************
227 
229 
230 class OthEqu : public SymOther
231 {
232 public:
233  OthEqu() : SymOther("#") {}
234  void process();
235 };
236 
237 //************************************** ***************************************
238 
240 
241 class SymFunction : public Symbol
242 {
243 public:
244  explicit SymFunction(string sym = "", string hlp = "no help available")
245  : Symbol(sym, hlp) {}
246 };
247 
248 //************************* ************************* **************************
249 
251 
253 {
254 public:
255  explicit SymOtherFunction(string sym = "", string hlp = "no help available")
256  : SymFunction(sym, hlp) {}
257  void process();
258  virtual Number calcVal(const Number& a) = 0;
259 };
260 
261 //****************** ******************* ******************* *******************
262 
264 
265 class FnSqrt : public SymOtherFunction
266 {
267 public:
268  FnSqrt() : SymOtherFunction("sqrt", "square root") {}
269  Number calcVal(const Number& a) { return sqrt(a.getVal()); }
270 };
271 
272 //************************************** ***************************************
273 
275 // fse, 06.10.01
276 
277 class SymAction : public Symbol
278 {
279 public:
280  explicit SymAction(string sym = "", string hlp = "no help available")
281  : Symbol(sym, hlp) {}
282 };
283 
284 //************************* ************************* **************************
285 
287 
288 class AcHelp : public SymAction
289 {
290 public:
291  AcHelp() : SymAction("help", "print this help page") {}
292  void process();
293 };
294 
295 //************************* ************************* **************************
296 
298 // fse, 30.06.02
299 
300 class AcC : public SymAction
301 {
302 public:
303  AcC() : SymAction("c", "clear") {}
304  void process();
305 };
306 
307 //************************* ************************* **************************
308 
310 // fse, 30.06.02
311 
312 class AcAc : public SymAction
313 {
314 public:
315  AcAc() : SymAction("ac", "clear all") {}
316  void process();
317 };
318 
319 //************************* ************************* **************************
320 
322 
323 class AcEqu : public SymAction
324 {
325 public:
326  AcEqu() : SymAction("=", "execute calculation") {}
327  void process();
328 };
329 
330 //************************* ************************* **************************
331 
333 
334 class AcPrc : public SymAction
335 {
336 public:
337  AcPrc() : SymAction("%", "percent calculation") {}
338  void process();
339 };
340 
341 //************************* ************************* **************************
342 
344 
345 class AcSto : public SymAction
346 {
347 public:
348  AcSto() : SymAction("sto", "store display in memory") {}
349  void process();
350 };
351 
352 //************************* ************************* **************************
353 
355 
356 class AcRcl : public SymAction
357 {
358 public:
359  AcRcl() : SymAction("rcl", "recall memory to display") {}
360  void process();
361 };
362 
363 //************************* ************************* **************************
364 
366 
367 class AcSum : public SymAction
368 {
369 public:
370  AcSum() : SymAction("sum", "sum display to memory") {}
371  void process();
372 };
373 
374 //************************* ************************* **************************
375 
377 
378 class AcSub : public SymAction
379 {
380 public:
381  AcSub() : SymAction("sub", "subtract display from memory") {}
382  void process();
383 };
384 
385 //************************* ************************* **************************
386 
388 
389 class AcExc : public SymAction
390 {
391 public:
392  AcExc() : SymAction("exc", "exchange memory and display") {}
393  void process();
394 };
395 
396 //************************* ************************* **************************
397 
399 
400 class AcInit : public SymAction
401 {
402 public:
403  AcInit() : SymAction("init", "initialize calculator") {}
404  void process();
405 };
406 
407 //************************* ************************* **************************
408 
410 
411 class AcInitWoMem : public SymAction
412 {
413 public:
414  AcInitWoMem() : SymAction("initwomem", "initialize without clearing memory") {}
415  void process();
416 };
417 
418 //************************* ************************* **************************
419 
421 
422 class AcSign : public SymAction
423 {
424 public:
425  AcSign() : SymAction("sign", "change sign of display") {}
426  void process();
427 };
428 
429 //******************************************************************************
430 //************************************** ***************************************
431 //************************* ************************* **************************
432 
433 #endif // !SYMBOLS_H
434 
Basisklasse aller Funktionen.
Definition: symbols.h:241
Symbol "=".
Definition: symbols.h:230
Speicher wieder in die Anzeige holen (recall).
Definition: symbols.h:356
static ComputerBase * mCompP
Zeiger auf Computer mit der Symboltabelle.
Definition: symbols.h:51
Prozent.
Definition: symbols.h:334
Operator fuer Subtraktion.
Definition: symbols.h:145
Im Speicher subtrahieren.
Definition: symbols.h:378
Symbol "(" ("Bra" von Bracket).
Definition: symbols.h:208
Loeschen der letzten Eingabe.
Definition: symbols.h:300
Rechner initialisieren, ohne Speicher zu loeschen (init without memory).
Definition: symbols.h:411
Basisklasse fuer weitere Symbole ("(", etc.)
Definition: symbols.h:194
Operator fuer Multiplikation.
Definition: symbols.h:168
ostream & operator<<(ostream &os, const Error &e)
Ausgabeoperator, wandelt enum ErrId in Strings.
Definition: calculator.cpp:68
string mSym
das Symbol als String ("+", "sto", ...)
Definition: symbols.h:49
Vorzeichenwechsel.
Definition: symbols.h:422
Im Speicher addieren.
Definition: symbols.h:367
Basisklasse der Nicht-Winkelfunktionen.
Definition: symbols.h:252
Operator fuer Addition.
Definition: symbols.h:134
Rechner initialisieren.
Definition: symbols.h:400
Operator fuer Subtraktion.
Definition: symbols.h:157
Die Klasse Number repraesentiert Zahlen.
Definition: number.h:48
Anzeige und Speicher austauschen (exchange).
Definition: symbols.h:389
Operator fuer Division.
Definition: symbols.h:181
Basisklasse fuer die Operatoren.
Definition: symbols.h:103
Basisklasse fuer alle Aktionen ("=", "%", ...).
Definition: symbols.h:277
Klasse der Zahlen (Kombination aus double und Bruechen) (Modul base)
Klasse der "normalen" Zahlen.
Definition: symbols.h:89
Anzeige speichern (store).
Definition: symbols.h:345
static DisplayBase * mDsplP
Zeiger auf Display (f. wissenschftl. Rechner)
Definition: symbols.h:52
Berechnung durchfuehren.
Definition: symbols.h:323
string mHlp
kurzer Hilfetext
Definition: symbols.h:50
Basisklasse aller Displays.
Definition: calculator.h:189
Operator fuer Addition.
Definition: symbols.h:122
Basisklasse fuer Zahlen.
Definition: symbols.h:73
Basisklasse aller Computer.
Definition: calculator.h:84
Wurzelfunktion.
Definition: symbols.h:265
Symbol ")" ("ket" von Bracket).
Definition: symbols.h:219
Gesamtloeschung.
Definition: symbols.h:312
Basisklasse fuer saemtliche Symbole.
Definition: symbols.h:46
Symbol fuer Ausgabe der Hilfe.
Definition: symbols.h:288