kstars
ksfilereader.cpp
Go to the documentation of this file.00001 /*************************************************************************** 00002 ksfilereader.cpp - description 00003 ------------------- 00004 begin : Tue Jan 28 2003 00005 copyright : (C) 2003 by Heiko Evermann 00006 email : heiko@evermann.de 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 00018 #include <qfile.h> 00019 #include <qstring.h> 00020 00021 #include "ksfilereader.h" 00022 00023 KSFileReader::KSFileReader(QFile& file) { 00024 // read the whole file at once. This works well at least for the smaller files. 00025 QByteArray data = file.readAll(); 00026 QString sAll = QString::fromUtf8( data.data(), data.size() ); 00027 // split into list of lines 00028 lines = QStringList::split( "\n", sAll ); 00029 // how many lines did we get? 00030 numLines = lines.size(); 00031 // set index to start 00032 curLine = 0; 00033 // we do not need the file any more 00034 file.close(); 00035 } 00036 00037 KSFileReader::~KSFileReader(){ 00038 } 00039 00040 bool KSFileReader::hasMoreLines() { 00041 return (curLine < numLines); 00042 } 00043 00044 QString& KSFileReader::readLine(){ 00045 // hint: use curLine as index, after that increment curLine 00046 // This means that the programming language c++ should better be renamed to ++c, 00047 // otherwise the name means: improve the c programming language, but use it the 00048 // way it was before the improvements... 00049 return lines[curLine++]; 00050 } 00051 00052 bool KSFileReader::setLine(int i) { 00053 if (i <= numLines) { 00054 curLine = i; 00055 return true; 00056 } else { 00057 return false; 00058 } 00059 } 00060 00061 #include "ksfilereader.moc"