source: src/clientcommandline/inputoutputhandler.cpp@ 93ea008

Last change on this file since 93ea008 was 93ea008, checked in by Joachim Langenbach <joachim.langenbach@…>, 11 years ago

Command line client is now (nearly) able to register a station

  • Property mode set to 100644
File size: 1.8 KB
RevLine 
[93ea008]1/*
2 Copyright (C) 2015 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 MA 02110-1301 USA.
18*/
19
20#include "inputoutputhandler.h"
21#include "moc_inputoutputhandler.cpp"
22
23#include <QTextStream>
24
25#include <iostream>
26#include <string>
27
28InputOutputHandler::InputOutputHandler(QObject* parent)
29 : QObject(parent)
30{
31 _out = new QTextStream(stdout);
32 _in = new QTextStream(stdin);
33}
34
35InputOutputHandler::~InputOutputHandler()
36{
37 if(_out)
38 delete _out;
39 if(_in)
40 delete _in;
41}
42
43QString InputOutputHandler::readLine()
44{
45 if(!_in)
46 return QString();
47
48 _in->skipWhiteSpace(); //Important line!
49 return _in->readLine();
50}
51
52bool InputOutputHandler::print(const QString& content)
53{
54 if(!_out)
55 return false;
56 *_out << content << flush;
57 return true;
58}
59
60InputOutputHandler& InputOutputHandler::operator<<(const QString& output)
61{
62 print(output);
63 return *this;
64}
65
66InputOutputHandler& InputOutputHandler::operator>>(QString& input)
67{
68 input = readLine();
69 return *this;
70}
71
72InputOutputHandler& endl(InputOutputHandler &handler)
73{
74 return handler << "\n";
75}
Note: See TracBrowser for help on using the repository browser.