OpenASIP 2.2
Loading...
Searching...
No Matches
EditLineReader.hh
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2009 Tampere University.
3
4 This file is part of TTA-Based Codesign Environment (TCE).
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23 */
24/**
25 * @file EditLineReader.hh
26 *
27 * Declaration of EditLineReader class.
28 *
29 * @author Jussi Nykänen 2004 (nykanen-no.spam-cs.tut.fi)
30 * @author Pekka Jääskeläinen (pjaaskel-no.spam-cs.tut.fi)
31 * @note reviewed 2 June 2004 by jm, pj, tr, jn
32 * @note rating: yellow
33 */
34
35#ifndef TTA_EDIT_LINE_READER_HH
36#define TTA_EDIT_LINE_READER_HH
37
38extern "C" {
39#include <histedit.h>
40}
41#include <string>
42#include <map>
43
44#include "LineReader.hh"
45
46/**
47 * LineReader implementation using libedit library.
48 *
49 * libedit offers functionality to edit a line as well as command history
50 * browsing functionality. In other words, user can edit the line he is
51 * writing as well as browse history of commands.
52 */
53class EditLineReader : public LineReader {
54public:
55 explicit EditLineReader(std::string program = "");
56 virtual ~EditLineReader();
57
58 virtual void initialize(
59 std::string defPrompt = "",
60 FILE* in = stdin,
61 FILE* out = stdout,
62 FILE* err = stderr);
63 virtual std::string readLine(std::string prompt = "");
64 virtual char charQuestion(
65 std::string question, std::string allowedChars,
66 bool caseSensitive = false, char defaultAnswer = '\0');
67
68private:
69 /// value_type for map.
70 typedef std::map<EditLine*, EditLineReader*>::value_type ValType;
71 /// Iterator for map.
72 typedef std::map<EditLine*, EditLineReader*>::iterator MapIt;
73
74 /// Copying not allowed.
76 /// Assignment not allowed.
78
79 static char* wrapperToCallPrompt(EditLine* edit);
80 char* prompt();
81 void updateHistory(const char* c);
82
83 /// Line reader prompt.
84 char* prompt_;
85 /// The name of the invocating program.
86 std::string program_;
87 /// EditLine instance.
88 EditLine* editLine_;
89 /// History instance.
90 History* history_;
91 /// Map containing all (EditLine*, EditLineReader*) pairs to make prompt
92 /// printing possible. This map offers to callback function
93 /// 'wrapperToCallPrompt' a right instance of EditLineReader. This
94 /// instance then returns the right prompt.
95 static std::map<EditLine*, EditLineReader*> lineReaders_;
96
97 /// Input stream is saved for end-of-file checking.
98 FILE* in_;
99};
100
101#endif
find Finds info of the inner loops in the program
char * prompt_
Line reader prompt.
std::map< EditLine *, EditLineReader * >::value_type ValType
value_type for map.
virtual ~EditLineReader()
virtual char charQuestion(std::string question, std::string allowedChars, bool caseSensitive=false, char defaultAnswer='\0')
FILE * in_
Input stream is saved for end-of-file checking.
EditLine * editLine_
EditLine instance.
static std::map< EditLine *, EditLineReader * > lineReaders_
Map containing all (EditLine*, EditLineReader*) pairs to make prompt printing possible....
void updateHistory(const char *c)
EditLineReader(const EditLineReader &)
Copying not allowed.
History * history_
History instance.
EditLineReader & operator=(const EditLineReader &)
Assignment not allowed.
virtual std::string readLine(std::string prompt="")
std::map< EditLine *, EditLineReader * >::iterator MapIt
Iterator for map.
virtual void initialize(std::string defPrompt="", FILE *in=stdin, FILE *out=stdout, FILE *err=stderr)
static char * wrapperToCallPrompt(EditLine *edit)
std::string program_
The name of the invocating program.