Files
ResInsight/Fwk/AppFwk/cafProjectDataModel/cafPdmXml/cafInternalPdmFilePathStreamOperators.cpp
T
Magne Sjaastad ef637e3053 Move stream operator from AppEnum header
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.
2024-03-25 15:14:04 +01:00

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;
}