OpenASIP 2.2
Loading...
Searching...
No Matches
LineReader.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 LineReader.hh
26 *
27 * Declaration of LineReader class.
28 *
29 * @author Jussi Nykänen 2004 (nykanen-no.spam-cs.tut.fi)
30 * @author Pekka Jääskeläinen 2005 (pjaaskel-no.spam-cs.tut.fi)
31 * @note reviewed 2 June 2004 by jm, pj, tr, jn
32 * @note rating: red
33 */
34
35#ifndef TTA_LINE_READER_HH
36#define TTA_LINE_READER_HH
37
38#include <cstdio>
39#include <string>
40#include <iostream>
41#include <deque>
42#include <fstream>
43
44#include "Exception.hh"
45
46/**
47 * Abstract base class for line readers.
48 *
49 * LineReader's purpose is to handle reading from command line and to make it
50 * possible for the user to edit the input given to program.
51 */
53public:
55 std::istream& iStream = std::cin, std::ostream& oStream = std::cout);
56 virtual ~LineReader();
57
58 virtual void initialize(
59 std::string defPrompt = "",
60 FILE* in = stdin,
61 FILE* out = stdout,
62 FILE* err = stderr) = 0;
63
64 virtual std::string readLine(std::string prompt = "") = 0;
65
66 virtual std::ostream& outputStream();
67
68 virtual char charQuestion(
69 std::string question, std::string allowedChars,
70 bool caseSensitive = false, char defaultAnswer = '\0') = 0;
71
72 bool confirmation(
73 std::string question, char defaultAnswer = 'n', char yesChar = 'y',
74 char noChar = 'n');
75
76 virtual void setSaveInputHistoryToFile(bool flag);
77 virtual bool saveInputHistoryToFile() const;
78 virtual void setInputHistoryLog(const std::string& historyFilename);
79 virtual void setInputHistoryLength(std::size_t length);
80 virtual size_t inputHistoryMaxLength() const;
81 virtual std::size_t inputsInHistory() const;
82 virtual std::string inputHistoryEntry(std::size_t age) const;
83
84protected:
86 bool initialized() const;
87 void putInInputHistory(const std::string& inputLine);
88
89private:
90 /// Copying not allowed.
92 /// Assignment not allowed.
94 /// Flag indicating whether LineReader is initialized.
96 /// The input history.
97 std::deque<std::string> inputHistory_;
98 /// The maximum size for input history.
99 std::size_t inputHistorySize_;
100 /// Should the history be appended in a file?
102 /// The output stream to write the command history to.
103 std::ofstream* historyFile_;
104 /// The filename to write the command history to.
105 std::string historyFilename_;
106 /// The input stream.
107 std::istream& iStream_;
108 /// The output stream.
109 std::ostream& oStream_;
110};
111
112#define DEFAULT_INPUT_HISTORY_SIZE 50
113
114#include "LineReader.icc"
115
116#endif
virtual void setInputHistoryLength(std::size_t length)
void putInInputHistory(const std::string &inputLine)
virtual ~LineReader()
Definition LineReader.cc:58
bool initialized_
Flag indicating whether LineReader is initialized.
Definition LineReader.hh:95
virtual void setInputHistoryLog(const std::string &historyFilename)
std::string historyFilename_
The filename to write the command history to.
std::ofstream * historyFile_
The output stream to write the command history to.
virtual void initialize(std::string defPrompt="", FILE *in=stdin, FILE *out=stdout, FILE *err=stderr)=0
void setInitialized()
virtual size_t inputHistoryMaxLength() const
virtual std::size_t inputsInHistory() const
virtual std::string readLine(std::string prompt="")=0
bool confirmation(std::string question, char defaultAnswer='n', char yesChar='y', char noChar='n')
Definition LineReader.cc:79
virtual bool saveInputHistoryToFile() const
virtual void setSaveInputHistoryToFile(bool flag)
bool saveHistoryToFile_
Should the history be appended in a file?
virtual std::ostream & outputStream()
virtual std::string inputHistoryEntry(std::size_t age) const
std::deque< std::string > inputHistory_
The input history.
Definition LineReader.hh:97
virtual char charQuestion(std::string question, std::string allowedChars, bool caseSensitive=false, char defaultAnswer='\0')=0
LineReader & operator=(const LineReader &)
Assignment not allowed.
std::size_t inputHistorySize_
The maximum size for input history.
Definition LineReader.hh:99
std::ostream & oStream_
The output stream.
LineReader(const LineReader &)
Copying not allowed.
bool initialized() const
std::istream & iStream_
The input stream.