OpenASIP
2.0
|
#include <LineReader.hh>
Public Member Functions | |
LineReader (std::istream &iStream=std::cin, std::ostream &oStream=std::cout) | |
virtual | ~LineReader () |
virtual void | initialize (std::string defPrompt="", FILE *in=stdin, FILE *out=stdout, FILE *err=stderr)=0 |
virtual std::string | readLine (std::string prompt="")=0 |
virtual std::ostream & | outputStream () |
virtual char | charQuestion (std::string question, std::string allowedChars, bool caseSensitive=false, char defaultAnswer='\0')=0 |
bool | confirmation (std::string question, char defaultAnswer='n', char yesChar='y', char noChar='n') |
virtual void | setSaveInputHistoryToFile (bool flag) |
virtual bool | saveInputHistoryToFile () const |
virtual void | setInputHistoryLog (const std::string &historyFilename) |
virtual void | setInputHistoryLength (std::size_t length) |
virtual size_t | inputHistoryMaxLength () const |
virtual std::size_t | inputsInHistory () const |
virtual std::string | inputHistoryEntry (std::size_t age) const |
Protected Member Functions | |
void | setInitialized () |
bool | initialized () const |
void | putInInputHistory (const std::string &inputLine) |
Private Member Functions | |
LineReader (const LineReader &) | |
Copying not allowed. More... | |
LineReader & | operator= (const LineReader &) |
Assignment not allowed. More... | |
Private Attributes | |
bool | initialized_ |
Flag indicating whether LineReader is initialized. More... | |
std::deque< std::string > | inputHistory_ |
The input history. More... | |
std::size_t | inputHistorySize_ |
The maximum size for input history. More... | |
bool | saveHistoryToFile_ |
Should the history be appended in a file? More... | |
std::ofstream * | historyFile_ |
The output stream to write the command history to. More... | |
std::string | historyFilename_ |
The filename to write the command history to. More... | |
std::istream & | iStream_ |
The input stream. More... | |
std::ostream & | oStream_ |
The output stream. More... | |
Abstract base class for line readers.
LineReader's purpose is to handle reading from command line and to make it possible for the user to edit the input given to program.
Definition at line 52 of file LineReader.hh.
LineReader::LineReader | ( | std::istream & | iStream = std::cin , |
std::ostream & | oStream = std::cout |
||
) |
|
virtual |
|
private |
Copying not allowed.
|
pure virtual |
Implemented in ProximLineReader, EditLineReader, and BaseLineReader.
Referenced by confirmation().
bool LineReader::confirmation | ( | std::string | question, |
char | defaultAnswer = 'n' , |
||
char | yesChar = 'y' , |
||
char | noChar = 'n' |
||
) |
Asks confirmation from the user.
Question is asked from user, who should answer with a single character.
question | The question that is asked from the user. |
defaultAnswer | The default answer. |
yesChar | Character meaning "yes" answer. |
noChar | Character meaning "no" answer. |
ObjectNotInitialized | If LineReader is not initialized. |
Definition at line 79 of file LineReader.cc.
References charQuestion(), and initialized_.
|
pure virtual |
Implemented in ProximLineReader, EditLineReader, and BaseLineReader.
Referenced by main(), and SimulatorCLI::SimulatorCLI().
|
protected |
|
virtual |
Returns the string at input history log with the given age.
In case the given age is 0, the newest entry is returned, if it's 1, the 2nd newest, and so on.
age | The age of the requested history entry. An empty string is is returned in case there's no entry with the given age. |
Definition at line 165 of file LineReader.cc.
References inputHistory_.
Referenced by ConsoleWindow::onInputKey(), ProximCmdHistoryWindow::onSave(), and ProximCmdHistoryWindow::updateCommandList().
|
virtual |
Referenced by SimulatorSettingsDialog::onOK(), and SimulatorSettingsDialog::TransferDataToWindow().
|
virtual |
Returns the count of entries in the input history log.
Definition at line 150 of file LineReader.cc.
References inputHistory_.
Referenced by ConsoleWindow::onInputKey(), ProximCmdHistoryWindow::onSave(), and ProximCmdHistoryWindow::updateCommandList().
|
private |
Assignment not allowed.
|
virtual |
Returns the output stream which can be used to print information to the user.
This stream should be used to ask confirmation, etc. from the user.
Reimplemented in ProximLineReader.
Definition at line 102 of file LineReader.cc.
References oStream_.
Referenced by SetHistoryFilename::execute(), and SimControlLanguageCommand::outputStream().
|
protected |
Puts an input to the input history log.
Also writes the input to the input history log stream, if there's one, and input history logging to a file is enabled.
Expects that the terminating '
' is in place in case it's wanted to be stored in the log.
inputLine | The line to store. |
Definition at line 184 of file LineReader.cc.
References debugLog, historyFile_, historyFilename_, inputHistory_, inputHistorySize_, and saveHistoryToFile_.
Referenced by ProximLineReader::readLine(), and EditLineReader::updateHistory().
|
pure virtual |
Implemented in ProximLineReader, EditLineReader, and BaseLineReader.
Referenced by TclInterpreter::interpret(), main(), and SimulatorCLI::run().
|
virtual |
Referenced by SimulatorSettingsDialog::onOK(), and SimulatorSettingsDialog::TransferDataToWindow().
|
protected |
Referenced by BaseLineReader::initialize(), EditLineReader::initialize(), and ProximLineReader::initialize().
|
virtual |
Sets the maximum size of the command history log.
length | New length for the command history log. |
Definition at line 140 of file LineReader.cc.
References inputHistorySize_.
Referenced by SetHistorySize::execute().
|
virtual |
Sets the output file name to save the command history to.
historyFilename | The command log stream. |
Reimplemented in ProximLineReader.
Definition at line 124 of file LineReader.cc.
References historyFile_, and historyFilename_.
Referenced by SetHistoryFilename::execute(), ProximLineReader::setInputHistoryLog(), and SimulatorCLI::SimulatorCLI().
|
virtual |
Sets whether command history should be also saved to a stream.
The file name should be set with setInputHistoryLog().
flag | Status of this option. |
Definition at line 114 of file LineReader.cc.
References saveHistoryToFile_.
Referenced by SetHistorySave::execute().
|
private |
The output stream to write the command history to.
Definition at line 103 of file LineReader.hh.
Referenced by putInInputHistory(), setInputHistoryLog(), and ~LineReader().
|
private |
The filename to write the command history to.
Definition at line 105 of file LineReader.hh.
Referenced by putInInputHistory(), and setInputHistoryLog().
|
private |
Flag indicating whether LineReader is initialized.
Definition at line 95 of file LineReader.hh.
Referenced by confirmation().
|
private |
The input history.
Definition at line 97 of file LineReader.hh.
Referenced by inputHistoryEntry(), inputsInHistory(), and putInInputHistory().
|
private |
The maximum size for input history.
Definition at line 99 of file LineReader.hh.
Referenced by putInInputHistory(), and setInputHistoryLength().
|
private |
The input stream.
Definition at line 107 of file LineReader.hh.
|
private |
|
private |
Should the history be appended in a file?
Definition at line 101 of file LineReader.hh.
Referenced by putInInputHistory(), and setSaveInputHistoryToFile().