source: src/clientcommandline/inputoutputhandler.cpp@ f8c242e

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

command line client is now able to register stations. All entered data could be reviewed by the user and edited again, before sending it

  • Property mode set to 100644
File size: 1.9 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
[17ef75d]48 QString line = _in->readLine();
49 return line.trimmed();
50}
51
52void InputOutputHandler::setFieldWidth(int columns)
53{
54 if(!_out)
55 return;
56 _out->setFieldWidth(columns);
57 _out->setFieldAlignment(QTextStream::AlignLeft);
[93ea008]58}
59
60bool InputOutputHandler::print(const QString& content)
61{
62 if(!_out)
63 return false;
64 *_out << content << flush;
65 return true;
66}
67
68InputOutputHandler& InputOutputHandler::operator<<(const QString& output)
69{
70 print(output);
71 return *this;
72}
73
74InputOutputHandler& InputOutputHandler::operator>>(QString& input)
75{
76 input = readLine();
77 return *this;
78}
79
80InputOutputHandler& endl(InputOutputHandler &handler)
81{
82 return handler << "\n";
83}
Note: See TracBrowser for help on using the repository browser.