OpenASIP
2.0
|
#include <EditLineReader.hh>
Public Member Functions | |
EditLineReader (std::string program="") | |
virtual | ~EditLineReader () |
virtual void | initialize (std::string defPrompt="", FILE *in=stdin, FILE *out=stdout, FILE *err=stderr) |
virtual std::string | readLine (std::string prompt="") |
virtual char | charQuestion (std::string question, std::string allowedChars, bool caseSensitive=false, char defaultAnswer='\0') |
Public Member Functions inherited from LineReader | |
LineReader (std::istream &iStream=std::cin, std::ostream &oStream=std::cout) | |
virtual | ~LineReader () |
virtual std::ostream & | outputStream () |
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 |
Private Types | |
typedef std::map< EditLine *, EditLineReader * >::value_type | ValType |
value_type for map. More... | |
typedef std::map< EditLine *, EditLineReader * >::iterator | MapIt |
Iterator for map. More... | |
Private Member Functions | |
EditLineReader (const EditLineReader &) | |
Copying not allowed. More... | |
EditLineReader & | operator= (const EditLineReader &) |
Assignment not allowed. More... | |
char * | prompt () |
void | updateHistory (const char *c) |
Static Private Member Functions | |
static char * | wrapperToCallPrompt (EditLine *edit) |
Private Attributes | |
char * | prompt_ |
Line reader prompt. More... | |
std::string | program_ |
The name of the invocating program. More... | |
EditLine * | editLine_ |
EditLine instance. More... | |
History * | history_ |
History instance. More... | |
FILE * | in_ |
Input stream is saved for end-of-file checking. More... | |
Static Private Attributes | |
static std::map< EditLine *, EditLineReader * > | lineReaders_ |
Map containing all (EditLine*, EditLineReader*) pairs to make prompt printing possible. This map offers to callback function 'wrapperToCallPrompt' a right instance of EditLineReader. This instance then returns the right prompt. More... | |
Additional Inherited Members | |
Protected Member Functions inherited from LineReader | |
void | setInitialized () |
bool | initialized () const |
void | putInInputHistory (const std::string &inputLine) |
LineReader implementation using libedit library.
libedit offers functionality to edit a line as well as command history browsing functionality. In other words, user can edit the line he is writing as well as browse history of commands.
Definition at line 53 of file EditLineReader.hh.
|
private |
Iterator for map.
Definition at line 72 of file EditLineReader.hh.
|
private |
value_type for map.
Definition at line 70 of file EditLineReader.hh.
|
explicit |
Constructor.
program | The name of the invocating program. |
Definition at line 56 of file EditLineReader.cc.
|
virtual |
Destructor.
Definition at line 64 of file EditLineReader.cc.
References editLine_, history_, lineReaders_, and prompt_.
|
private |
Copying not allowed.
|
virtual |
Asks user a question and expects that answer is given as char.
Prompt is temporarily changed to 'question' during the execution of this function.
question | The asked question. |
allowedChars | The chars that are legal answers. |
caseSensitive | Flag indicating whether answer is read case sensitive or not. |
defaultAnswer | The default answer. |
ObjectNotInitialized | If LineReader is not initialized. |
Implements LineReader.
Definition at line 180 of file EditLineReader.cc.
References assert, editLine_, LineReader::initialized(), prompt_, StringTools::stringToCharPtr(), and updateHistory().
|
virtual |
Initializes LineReader.
Sets the prompt printing function and initializes history.
defPrompt | The prompt for the program. |
in | Input file stream. |
out | Output file stream. |
err | Error file stream. |
Implements LineReader.
Definition at line 92 of file EditLineReader.cc.
References assert, editLine_, history_, in_, lineReaders_, program_, prompt_, LineReader::setInitialized(), StringTools::stringToCharPtr(), and wrapperToCallPrompt().
|
private |
Assignment not allowed.
|
private |
Returns the used prompt.
Definition at line 259 of file EditLineReader.cc.
References prompt_.
Referenced by readLine(), and wrapperToCallPrompt().
|
virtual |
Reads line from input stream.
If prompt is given, it is used as a prompt only for reading this one line.
prompt | The prompt. |
ObjectNotInitialized | If LineReader is not initialized. |
EndOfFile | When end of file mark (ctrl-d) is received. |
Implements LineReader.
Definition at line 135 of file EditLineReader.cc.
References __func__, editLine_, in_, LineReader::initialized(), prompt(), prompt_, StringTools::stringToCharPtr(), and updateHistory().
|
private |
Inserts a new entry to history.
Only non-empty strings are saved to history.
newEntry | A new entry to be added. |
Definition at line 271 of file EditLineReader.cc.
References history_, LineReader::putInInputHistory(), and StringTools::trim().
Referenced by charQuestion(), and readLine().
|
staticprivate |
Static wrapper function that calls function that returns the prompt.
If correct EditLine* instance is not found in the map, an empty string (null char*) is returned.
edit | EditLine which prompt is needed. |
Definition at line 243 of file EditLineReader.cc.
References lineReaders_, and prompt().
Referenced by initialize().
|
private |
EditLine instance.
Definition at line 88 of file EditLineReader.hh.
Referenced by charQuestion(), initialize(), readLine(), and ~EditLineReader().
|
private |
History instance.
Definition at line 90 of file EditLineReader.hh.
Referenced by initialize(), updateHistory(), and ~EditLineReader().
|
private |
Input stream is saved for end-of-file checking.
Definition at line 98 of file EditLineReader.hh.
Referenced by initialize(), and readLine().
|
staticprivate |
Map containing all (EditLine*, EditLineReader*) pairs to make prompt printing possible. This map offers to callback function 'wrapperToCallPrompt' a right instance of EditLineReader. This instance then returns the right prompt.
Definition at line 95 of file EditLineReader.hh.
Referenced by initialize(), wrapperToCallPrompt(), and ~EditLineReader().
|
private |
The name of the invocating program.
Definition at line 86 of file EditLineReader.hh.
Referenced by initialize().
|
private |
Line reader prompt.
Definition at line 84 of file EditLineReader.hh.
Referenced by charQuestion(), initialize(), prompt(), readLine(), and ~EditLineReader().