OpenASIP  2.0
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 
38 extern "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  */
53 class EditLineReader : public LineReader {
54 public:
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 
68 private:
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
EditLineReader::program_
std::string program_
The name of the invocating program.
Definition: EditLineReader.hh:86
EditLineReader::initialize
virtual void initialize(std::string defPrompt="", FILE *in=stdin, FILE *out=stdout, FILE *err=stderr)
Definition: EditLineReader.cc:92
EditLineReader::history_
History * history_
History instance.
Definition: EditLineReader.hh:90
EditLineReader::prompt
char * prompt()
Definition: EditLineReader.cc:259
EditLineReader::updateHistory
void updateHistory(const char *c)
Definition: EditLineReader.cc:271
EditLineReader::editLine_
EditLine * editLine_
EditLine instance.
Definition: EditLineReader.hh:88
EditLineReader::operator=
EditLineReader & operator=(const EditLineReader &)
Assignment not allowed.
EditLineReader::ValType
std::map< EditLine *, EditLineReader * >::value_type ValType
value_type for map.
Definition: EditLineReader.hh:70
EditLineReader::wrapperToCallPrompt
static char * wrapperToCallPrompt(EditLine *edit)
Definition: EditLineReader.cc:243
LineReader.hh
EditLineReader::MapIt
std::map< EditLine *, EditLineReader * >::iterator MapIt
Iterator for map.
Definition: EditLineReader.hh:72
EditLineReader::readLine
virtual std::string readLine(std::string prompt="")
Definition: EditLineReader.cc:135
EditLineReader::in_
FILE * in_
Input stream is saved for end-of-file checking.
Definition: EditLineReader.hh:98
EditLineReader::~EditLineReader
virtual ~EditLineReader()
Definition: EditLineReader.cc:64
LineReader
Definition: LineReader.hh:52
EditLineReader::EditLineReader
EditLineReader(std::string program="")
Definition: EditLineReader.cc:56
EditLineReader::prompt_
char * prompt_
Line reader prompt.
Definition: EditLineReader.hh:84
EditLineReader
Definition: EditLineReader.hh:53
program
find Finds info of the inner loops in the program
Definition: InnerLoopFinder.cc:80
EditLineReader::charQuestion
virtual char charQuestion(std::string question, std::string allowedChars, bool caseSensitive=false, char defaultAnswer='\0')
Definition: EditLineReader.cc:180
EditLineReader::lineReaders_
static std::map< EditLine *, EditLineReader * > lineReaders_
Map containing all (EditLine*, EditLineReader*) pairs to make prompt printing possible....
Definition: EditLineReader.hh:95