mirror of
https://github.com/OPM/ResInsight.git
synced 2026-11-03 20:56:45 -06:00
This PR will reduce the compile time of code using AppEnum. * AppEnum: Move QTextStream operator to avoid include of QTextStream * Avoid use of iostream in cafAssert rator to avoid include of QTextStream Include file profiling shows that include of QTextStream is a performance issue. Create a non-templated base class for AppEnum. Implement the QTextStream operator for this interface.
66 lines
1.7 KiB
C++
66 lines
1.7 KiB
C++
#include "cafInternalPdmFilePathStreamOperators.h"
|
|
|
|
#include <QStringList>
|
|
#include <QTextStream>
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
QTextStream& operator<<( QTextStream& str, const std::vector<caf::FilePath>& filePathObjects )
|
|
{
|
|
QStringList trimmedEntries;
|
|
|
|
for ( const auto& filePath : filePathObjects )
|
|
{
|
|
QString text = filePath.path().trimmed();
|
|
|
|
if ( text.isEmpty() ) continue;
|
|
|
|
trimmedEntries.push_back( text );
|
|
}
|
|
|
|
for ( int i = 0; i < trimmedEntries.size(); i++ )
|
|
{
|
|
str << trimmedEntries[i];
|
|
|
|
if ( i < trimmedEntries.size() - 1 )
|
|
{
|
|
str << ";";
|
|
}
|
|
}
|
|
|
|
return str;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
QTextStream& operator>>( QTextStream& str, std::vector<caf::FilePath>& filePathObjects )
|
|
{
|
|
QString stringSeparatedBySemicolon;
|
|
|
|
while ( str.status() == QTextStream::Ok )
|
|
{
|
|
// Read QChar to avoid white space trimming when reading QString
|
|
QChar singleChar;
|
|
str >> singleChar;
|
|
|
|
if ( !singleChar.isNull() )
|
|
{
|
|
stringSeparatedBySemicolon += singleChar;
|
|
}
|
|
}
|
|
|
|
QStringList splitBySemicolon = stringSeparatedBySemicolon.split( ";" );
|
|
for ( const auto& s : splitBySemicolon )
|
|
{
|
|
QString trimmed = s.trimmed();
|
|
if ( !trimmed.isEmpty() )
|
|
{
|
|
filePathObjects.push_back( trimmed );
|
|
}
|
|
}
|
|
|
|
return str;
|
|
}
|