OpenASIP  2.0
BaseLineReader.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 BaseLineReader.hh
26  *
27  * Declaration of BaseLineReader class.
28  *
29  * @author Jussi Nykänen 2004 (nykanen-no.spam-cs.tut.fi)
30  * @note rating: red
31  */
32 
33 #ifndef TTA_BASE_LINE_READER_HH
34 #define TTA_BASE_LINE_READER_HH
35 
36 #include <string>
37 
38 #include "LineReader.hh"
39 
40 /**
41  * Handles the basic line reading without a use of any fancy libraries.
42  *
43  * This LineReader is used only when nothing else is available. This
44  * LineReader supports only reading from std::cin and outputing to
45  * std::cout.
46  */
47 class BaseLineReader : public LineReader {
48 public:
50  std::istream& iStream = std::cin, std::ostream& oStream = std::cout);
51  virtual ~BaseLineReader();
52 
53  virtual void initialize(
54  std::string defPrompt = "",
55  FILE* in = stdin,
56  FILE* out = stdout,
57  FILE* err = stderr);
58 
59  virtual void setPromptPrinting(bool flag);
60 
61  virtual std::string readLine(std::string prompt = "");
62 
63  virtual char charQuestion(
64  std::string question, std::string allowedChars,
65  bool caseSensitive = false, char defaultAnswer = '\0');
66 
67 private:
68  /// Copying not allowed.
70  /// Assignment not allowed.
72 
73  void printPrompt() const;
74 
75  static const int MAX_LINE_LENGTH;
76 
77  /// Prompt of the reader.
78  std::string prompt_;
79  /// Input stream.
80  FILE* in_;
81  /// Output stream.
82  FILE* out_;
83  /// Error stream.
84  FILE* error_;
85  /// Input stream.
86  std::istream& iStream_;
87  /// Output stream.
88  std::ostream& oStream_;
89  /// Prompt printing flag.
91 };
92 
93 #endif
BaseLineReader::setPromptPrinting
virtual void setPromptPrinting(bool flag)
Definition: BaseLineReader.cc:82
BaseLineReader::oStream_
std::ostream & oStream_
Output stream.
Definition: BaseLineReader.hh:88
BaseLineReader::iStream_
std::istream & iStream_
Input stream.
Definition: BaseLineReader.hh:86
BaseLineReader::out_
FILE * out_
Output stream.
Definition: BaseLineReader.hh:82
BaseLineReader::MAX_LINE_LENGTH
static const int MAX_LINE_LENGTH
Definition: BaseLineReader.hh:75
BaseLineReader::BaseLineReader
BaseLineReader(std::istream &iStream=std::cin, std::ostream &oStream=std::cout)
Definition: BaseLineReader.cc:45
BaseLineReader
Definition: BaseLineReader.hh:47
BaseLineReader::prompt_
std::string prompt_
Prompt of the reader.
Definition: BaseLineReader.hh:78
LineReader.hh
BaseLineReader::printPrompt
void printPrompt() const
Definition: BaseLineReader.cc:177
BaseLineReader::readLine
virtual std::string readLine(std::string prompt="")
Definition: BaseLineReader.cc:96
BaseLineReader::~BaseLineReader
virtual ~BaseLineReader()
Definition: BaseLineReader.cc:53
BaseLineReader::in_
FILE * in_
Input stream.
Definition: BaseLineReader.hh:80
LineReader
Definition: LineReader.hh:52
BaseLineReader::operator=
BaseLineReader & operator=(const BaseLineReader &)
Assignment not allowed.
BaseLineReader::promptPrinting_
bool promptPrinting_
Prompt printing flag.
Definition: BaseLineReader.hh:90
BaseLineReader::charQuestion
virtual char charQuestion(std::string question, std::string allowedChars, bool caseSensitive=false, char defaultAnswer='\0')
Definition: BaseLineReader.cc:132
BaseLineReader::error_
FILE * error_
Error stream.
Definition: BaseLineReader.hh:84
BaseLineReader::initialize
virtual void initialize(std::string defPrompt="", FILE *in=stdin, FILE *out=stdout, FILE *err=stderr)
Definition: BaseLineReader.cc:65