UI.h Source File

Back to the index.

UI.h
Go to the documentation of this file.
1 #ifndef UI_H
2 #define UI_H
3 
4 /*
5  * Copyright (C) 2007-2010 Anders Gavare. All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  * 3. The name of the author may not be used to endorse or promote products
16  * derived from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  */
30 
31 #include "misc.h"
32 
33 class Component;
34 class GXemul;
35 
36 
37 /**
38  * \brief Base class for a User Interface.
39  */
40 class UI
41  : public ReferenceCountable
42 {
43 public:
45  {
46  public:
47  SetIndentationMessageHelper(UI* ui, const string& msg)
48  : m_UI(ui)
49  {
50  m_oldMsg = m_UI->GetIndentationMessage();
51  m_UI->SetIndentationMessage(msg);
52  }
53 
55  {
56  m_UI->SetIndentationMessage(m_oldMsg);
57  }
58 
59  private:
60  UI * m_UI;
61  string m_oldMsg;
62  };
63 
64 public:
65  /**
66  * \brief Constructs a User Interface.
67  *
68  * @param gxemul A pointer to the GXemul owner instance.
69  */
70  UI(GXemul* gxemul)
71  : m_gxemul(gxemul)
72  {
73  }
74 
75  virtual ~UI()
76  {
77  }
78 
79  /**
80  * \brief Initializes the UI.
81  */
82  virtual void Initialize() = 0;
83 
84  /**
85  * \brief Shows a startup banner.
86  */
87  virtual void ShowStartupBanner() = 0;
88 
89  /**
90  * \brief Updates various UI elements.
91  *
92  * Called whenever:
93  * <ul>
94  * <li>the undo/redo-applicability changes
95  * <li>the name of the emulation changes
96  * <li>the RunState changes
97  * </ul>
98  */
99  virtual void UpdateUI() = 0;
100 
101  /**
102  * \brief Sets an indentation message, which indents all debug output.
103  *
104  * Note: An UI implementation may change the indentation string. E.g.
105  * from "step X: " to " ".
106  *
107  * @param msg The indentation message. If the message is an empty
108  * string, indentation is not used.
109  */
110  void SetIndentationMessage(const string& msg)
111  {
112  m_indentationMsg = msg;
113  }
114 
115  /**
116  * \brief Gets the indentation message.
117  *
118  * @return The indentation message. If the message is an empty
119  * string, indentation is not used.
120  */
121  string GetIndentationMessage() const
122  {
123  return m_indentationMsg;
124  }
125 
126  /**
127  * \brief Shows a debug message.
128  *
129  * @param msg The message to show.
130  */
131  virtual void ShowDebugMessage(const string& msg) = 0;
132 
133  /**
134  * \brief Shows a debug message for a Component.
135  *
136  * Usually, this involves formatting the debug message using
137  * Component::GenerateShortestPossiblePath().
138  *
139  * If the runstate is GXemul::Running, the debug message
140  * is encapsulated by "[ ]" brackets, making the debug message very
141  * similar to pre-0.6.0 debug output style.
142  *
143  * @param component A pointer to the Component.
144  * @param msg The message to show.
145  */
146  virtual void ShowDebugMessage(Component* component, const string& msg) = 0;
147 
148  /**
149  * \brief Shows a command being executed.
150  *
151  * @param command The command being executed.
152  */
153  virtual void ShowCommandMessage(const string& command) = 0;
154 
155  /**
156  * \brief Shows a fatal error message.
157  *
158  * After showing the fatal error message, the application
159  * is expected to terminate. In a GUI implementation, it
160  * is therefore good to wait for the user to acknowledge
161  * the error message before returning.
162  *
163  * @param msg The message to show.
164  */
165  virtual void FatalError(const string& msg) = 0;
166 
167  /**
168  * \brief Redisplays the interactive command input line.
169  *
170  * This function generally displays a prompt (e.g. "GXemul> ")
171  * followed by the input line, placing the cursor position at
172  * the correct position on the input line.
173  *
174  * @param inputline The entire input line.
175  * @param cursorPosition The current cursor position. 0 is at the
176  * leftmost position.
177  */
178  virtual void RedisplayInputLine(const string& inputline,
179  size_t cursorPosition) = 0;
180 
181  /**
182  * \brief Executed by the CommandInterpreter when a line has been
183  * completed (with a newline).
184  *
185  * Usually this clears the current line, and (if possible) moves
186  * down to a new line.
187  */
188  virtual void InputLineDone() = 0;
189 
190  /**
191  * \brief Runs the UI's main loop.
192  *
193  * The return code should be the exit code that the gxemul binary
194  * should return.
195  *
196  * @return 0 on success, non-zero on failure.
197  */
198  virtual int MainLoop() = 0;
199 
200  /**
201  * \brief Shuts down the UI.
202  *
203  * Called from e.g. the "quit" command.
204  */
205  virtual void Shutdown() = 0;
206 
207 protected:
210 };
211 
212 
213 #endif // UI_H
UI::~UI
virtual ~UI()
Definition: UI.h:75
UI::UpdateUI
virtual void UpdateUI()=0
Updates various UI elements.
UI::ShowCommandMessage
virtual void ShowCommandMessage(const string &command)=0
Shows a command being executed.
UI::MainLoop
virtual int MainLoop()=0
Runs the UI's main loop.
UI::m_gxemul
GXemul * m_gxemul
Definition: UI.h:208
GXemul
The main emulator class.
Definition: GXemul.h:54
UI::SetIndentationMessageHelper::SetIndentationMessageHelper
SetIndentationMessageHelper(UI *ui, const string &msg)
Definition: UI.h:47
UI::GetIndentationMessage
string GetIndentationMessage() const
Gets the indentation message.
Definition: UI.h:121
UI::SetIndentationMessageHelper
Definition: UI.h:44
UI::SetIndentationMessage
void SetIndentationMessage(const string &msg)
Sets an indentation message, which indents all debug output.
Definition: UI.h:110
UI
Base class for a User Interface.
Definition: UI.h:40
misc.h
UI::ShowDebugMessage
virtual void ShowDebugMessage(const string &msg)=0
Shows a debug message.
UI::Shutdown
virtual void Shutdown()=0
Shuts down the UI.
UI::FatalError
virtual void FatalError(const string &msg)=0
Shows a fatal error message.
UI::UI
UI(GXemul *gxemul)
Constructs a User Interface.
Definition: UI.h:70
UI::ShowStartupBanner
virtual void ShowStartupBanner()=0
Shows a startup banner.
Component
A Component is a node in the configuration tree that makes up an emulation setup.
Definition: Component.h:62
UI::m_indentationMsg
string m_indentationMsg
Definition: UI.h:209
ReferenceCountable
Base class for reference countable objects.
Definition: refcount_ptr.h:62
UI::Initialize
virtual void Initialize()=0
Initializes the UI.
UI::SetIndentationMessageHelper::~SetIndentationMessageHelper
~SetIndentationMessageHelper()
Definition: UI.h:54
UI::InputLineDone
virtual void InputLineDone()=0
Executed by the CommandInterpreter when a line has been completed (with a newline).
UI::RedisplayInputLine
virtual void RedisplayInputLine(const string &inputline, size_t cursorPosition)=0
Redisplays the interactive command input line.

Generated on Tue Mar 24 2020 14:04:48 for GXemul by doxygen 1.8.17