KoMo2  1.0.0
A modern ARM emulator GUI.
Model.h
Go to the documentation of this file.
1 
10 #include <gtkmm.h>
11 #include <gtkmm/button.h>
12 #include <gtkmm/image.h>
13 #include <string>
14 #include "../jimulatorInterface.h"
15 
19 enum class JimulatorState : int {
20  INITIAL = -1, // Jimulator starting state
21  UNLOADED, // Jimulator idle; needs a program to be loaded in.
22  LOADED, // File just loaded for first time (not yet run)
23  RUNNING, // Jimulator is running
24  PAUSED, // Jimulator is paused
25 };
26 
27 class KoMo2Model;
28 
35 class Model {
36  friend class KoMo2Model; // Only KoMo2Model can access setJimulatorState()
37 
38  public:
39  Model(KoMo2Model* const parent);
40  KoMo2Model* const getParent() const;
41 
42  protected:
51  template <class T1, class T2>
52  void setButtonListener(Gtk::Button* const button, const T1 b, const T2 c) {
53  button->signal_clicked().connect(sigc::mem_fun(*b, c));
54  }
55 
56  void setButtonState(Gtk::Button* const button,
57  const bool state,
58  Gtk::Image* const img = nullptr,
59  const std::string newTooltip = "",
60  const std::string newLabelText = "") const;
61 
67  virtual const bool handleKeyPress(const GdkEventKey* const e) = 0;
68 
76  virtual void changeJimulatorState(const JimulatorState newState) = 0;
77 
78  // Getters and setters
79 
81 
82  private:
88 
96 
97  // Only friends can access
98  void setJimulatorState(const JimulatorState val);
99 
100  // ! Deleted special member functions
101  // stops these functions from being misused, creates a sensible error
102  Model(const Model&) = delete;
103  Model(const Model&&) = delete;
104  Model& operator=(const Model&) = delete;
105  Model& operator=(const Model&&) = delete;
106 };
void setButtonState(Gtk::Button *const button, const bool state, Gtk::Image *const img=nullptr, const std::string newTooltip="", const std::string newLabelText="") const
Sets the state of a button to some boolean - the assumption is that if a button is not meant to be se...
Definition: Model.cpp:37
KoMo2Model *const getParent() const
Returns the parent pointer.
Definition: Model.cpp:67
JimulatorState getJimulatorState() const
Return the jimulatorState member object.
Definition: Model.cpp:75
KoMo2Model *const parent
All models have a parent model - KoMo2Model, the most senior model in the hierarchy, sets its parent to self.
Definition: Model.h:87
JimulatorState
Describe the 5 states of Jimulator.
Definition: Model.h:19
void setButtonListener(Gtk::Button *const button, const T1 b, const T2 c)
Connect any button to any member function of.
Definition: Model.h:52
void setJimulatorState(const JimulatorState val)
set the JimulatorState member object.
Definition: Model.cpp:83
The superclass for all other Model classes. Uses a pure virtual function, so is abastract. Keeps KoMo2Model as a friend so it alone can call setJimulatorState. This class provides basic data that are needed by all other.
Definition: Model.h:35
virtual const bool handleKeyPress(const GdkEventKey *const e) override
Passes the key press event off to other child models.
Definition: KoMo2Model.cpp:84
The logical model of the entire application. All other models should be member variables of this mode...
Definition: KoMo2Model.h:34
Model(KoMo2Model *const parent)
Constructs a new Model object - just assigns the parent variable.
Definition: Model.cpp:22
static JimulatorState jimulatorState
JimulatorState reflects the state in which Jimulator is operating, which in turn affects the model of...
Definition: Model.h:95
virtual void changeJimulatorState(const JimulatorState newState) override
Changes the Jimulator state and calls each child models own changeJimulatorState function.
Definition: KoMo2Model.cpp:97