Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

engine.h

Go to the documentation of this file.
00001 /**********************************************************************
00002 ** Copyright (C) 2000 Trolltech AS.  All rights reserved.
00003 **
00004 ** This file is part of Qtopia Environment.
00005 **
00006 ** This file may be distributed and/or modified under the terms of the
00007 ** GNU General Public License version 2 as published by the Free Software
00008 ** Foundation and appearing in the file LICENSE.GPL included in the
00009 ** packaging of this file.
00010 **
00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 **
00014 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00015 **
00016 ** Contact info@trolltech.com if any conditions of this licensing are
00017 ** not clear to you.
00018 **
00019 **********************************************************************/
00020 
00021 #ifndef ENGINE_H
00022 #define ENGINE_H
00023 
00024 #include <qwidget.h>
00025 #include <qstack.h>     // Instruction stack
00026 #include <qstring.h>    // Display
00027 #include "instruction.h"
00028 
00029 // Possible states
00030 enum State {
00031   sStart,       // start inputting a new number
00032   sAppend,      // continue inputting a number
00033   sError
00034 };
00035 
00036 // State machine
00037 class Engine:public QWidget {
00038 
00039 Q_OBJECT
00040 public:
00041   Engine (QWidget * parent = 0, const char *name = 0):QWidget (parent, name) {
00042     hardReset();
00043     setRepresentation(rDec);
00044   };
00045 
00046   ~Engine () { };
00047 
00048   void immediateInstruction (Instruction *);
00049   void pushInstruction (Instruction *);
00050   void eval ();
00051 
00052   void pushValue (char);
00053   void del ();
00054 
00055   void openBrace ();
00056   void closeBrace ();
00057 
00058   void softReset () {   // clears the number being inputted
00059     decimalPlaces = -1;
00060     clearData(&num);
00061     displayData(num);
00062     state = sStart;
00063   };
00064   void hardReset () {   // a "real" reset of the stack
00065     stack.clear ();
00066     memClear();
00067     braces = 0;
00068     softReset ();
00069   };
00070 
00071   void memSave () {
00072     mem = num;
00073   };
00074   void memRecall () {
00075     num = mem;
00076     state = sStart;
00077     displayData(num);
00078   };
00079   void memClear () {
00080     clearData(&mem);
00081   };
00082 
00083   // rFraction will require a special display enabled here
00084   void setRepresentation(Representation);
00085 
00086   // you dont want to call this
00087   void decBraces(void){ braces--; };
00088 
00089 private:
00090   void displayData(Data d);
00091   void clearData(Data *d);
00092   int calcBase();
00093   Data evalStack (Data, bool);
00094   Data num,mem;
00095   State state;
00096   QStack < Instruction > stack;
00097   Representation currentRep;
00098   int braces, decimalPlaces; // count of finishing 0's in num
00099   QString displayString; // saves instatiating it over and over
00100 
00101 signals:
00102   void display(const QString &);
00103   void display(double); // could get rid of this and
00104   // use a QLabel instead.
00105   void setHexMode();
00106   void setBinMode();
00107   void setDecMode();
00108   void setOctMode();
00109 };
00110 
00111 #endif

Generated on Sat Nov 5 16:18:01 2005 for OPIE by  doxygen 1.4.2