|
From: Gustavo P. B. <gb...@us...> - 2005-06-28 22:15:27
|
Update of /cvsroot/kimageprocess/kimageprocess/src/plugins/snns In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1645 Modified Files: snns.cpp snns.h Log Message: No need for two files now (we know how many patterns the file will have before writing the header) Index: snns.cpp =================================================================== RCS file: /cvsroot/kimageprocess/kimageprocess/src/plugins/snns/snns.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- snns.cpp 27 Jun 2005 19:51:06 -0000 1.8 +++ snns.cpp 28 Jun 2005 22:15:15 -0000 1.9 @@ -53,23 +53,18 @@ if (!dest.isEmpty()) { m_sampleImage = dest; - KTempFile tmpHeaderFile; - tmpHeaderFile.setAutoDelete(false); m_tempFile = new KTempFile(); m_tempFile->setAutoDelete(false); - if (tmpHeaderFile.file()->isOpen() && m_tempFile->file()->isOpen()) + if (m_tempFile->file()->isOpen()) { - QTextStream streamData(tmpHeaderFile.file()); - QString temp; - m_contents = "SNNS pattern definition file V3.2\n"; - m_contents += "generated at " + QDateTime::currentDateTime().toString(); - m_contents += "\n\n\n"; - m_contents += "No. of patterns : %1\n"; - m_contents += "No. of input units : " + QString::number( inputs ); - m_contents += "\n"; - m_contents += "No. of output units : " + QString::number( outputs ); - m_contents += "\n\n"; + m_stream.setDevice(m_tempFile->file()); + + m_stream << "SNNS pattern definition file V3.2" << endl; + m_stream << "generated at " << QDateTime::currentDateTime().toString() << endl << endl << endl; + m_stream << "No. of patterns : " << data.count() << endl; + m_stream << "No. of input units : " << inputs << endl; + m_stream << "No. of output units : " << outputs << endl << endl; QStringList names = KTImageManager::self()->activeFeatureNames(); QString features; @@ -77,10 +72,8 @@ { features += (*it) + " "; } - m_contents += "#" + features + "\n\n"; + m_stream << "#" << features << endl << endl; - m_stream.setDevice(m_tempFile->file()); - QValueList<dataEntry>::ConstIterator end = data.constEnd(); for (QValueList<dataEntry>::ConstIterator it = data.constBegin(); it != end; ++it) @@ -104,18 +97,8 @@ } //save the pattern file - QTextStream streamHeader(tmpHeaderFile.file()); - streamHeader << m_contents.arg(data.count()); - m_tempFile->file()->reset(); // place the cursor in the beginning of file - while (!m_stream.atEnd()) - { - temp = m_stream.readLine(); - streamHeader << temp << endl; - } - tmpHeaderFile.close(); m_tempFile->close(); - KIO::NetAccess::upload(tmpHeaderFile.name(),dest,0); - KIO::NetAccess::removeTempFile(tmpHeaderFile.name()); + KIO::NetAccess::upload(m_tempFile->name(),dest,0); KIO::NetAccess::removeTempFile(m_tempFile->name()); delete m_tempFile; } @@ -129,8 +112,6 @@ if (!dest.isEmpty()) { m_sampleImage = dest; - KTempFile tmpHeaderFile; - tmpHeaderFile.setAutoDelete(false); m_tempFile = new KTempFile(); m_tempFile->setAutoDelete(false); @@ -142,18 +123,15 @@ for (int i=0; i < height; ++i) lines[i] = ""; int h = 0; - if (tmpHeaderFile.file()->isOpen() && m_tempFile->file()->isOpen()) + if (m_tempFile->file()->isOpen()) { - QTextStream streamData(tmpHeaderFile.file()); - QString temp; - m_contents = "SNNS pattern definition file V3.2\n"; - m_contents += "generated at " + QDateTime::currentDateTime().toString(); - m_contents += "\n\n\n"; - m_contents += "No. of patterns : %1\n"; - m_contents += "No. of input units : " + QString::number( inputs ); - m_contents += "\n"; - m_contents += "No. of output units : 0\n"; - m_contents += "\n\n"; + m_stream.setDevice(m_tempFile->file()); + + m_stream << "SNNS pattern definition file V3.2" << endl; + m_stream << "generated at " << QDateTime::currentDateTime().toString() << endl << endl << endl; + m_stream << "No. of patterns : " << data.count() << endl; + m_stream << "No. of input units : " << inputs << endl; + m_stream << "No. of output units : 0" << endl << endl << endl; QStringList names = KTImageManager::self()->activeFeatureNames(); QString features; @@ -161,9 +139,7 @@ { features += (*it) + " "; } - m_contents += "#" + features + "\n\n"; - - m_stream.setDevice(m_tempFile->file()); + m_stream << "#" << features << endl << endl; QValueList<dataEntry>::ConstIterator end = data.constEnd(); int m_patternCount = 0; @@ -188,17 +164,9 @@ for (int i = 0; i < height; ++i) m_stream << lines[i]; //save the pattern file - QTextStream streamHeader(tmpHeaderFile.file()); - streamHeader << m_contents.arg(data.count()); - m_tempFile->file()->reset(); // place the cursor in the beginning of file - while (!m_stream.atEnd()) { - temp = m_stream.readLine(); - streamHeader << temp << endl; - } - tmpHeaderFile.close(); + m_tempFile->close(); - KIO::NetAccess::upload(tmpHeaderFile.name(),dest,0); - KIO::NetAccess::removeTempFile(tmpHeaderFile.name()); + KIO::NetAccess::upload(m_tempFile->name(),dest,0); KIO::NetAccess::removeTempFile(m_tempFile->name()); delete m_tempFile; } Index: snns.h =================================================================== RCS file: /cvsroot/kimageprocess/kimageprocess/src/plugins/snns/snns.h,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- snns.h 23 Jun 2005 23:19:44 -0000 1.7 +++ snns.h 28 Jun 2005 22:15:15 -0000 1.8 @@ -58,7 +58,6 @@ KURL m_sampleImage; KURL m_testingImage; - QString m_contents; int m_patternCount; KTempFile *m_tempFile; |