mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
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.
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
#include <QAction>
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
#include <QTextStream>
|
||||
|
||||
CAF_CMD_SOURCE_INIT( RicRunCommandFileFeature, "RicRunCommandFileFeature" );
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
|
||||
class RigEclipseCaseData;
|
||||
class QFile;
|
||||
class QTextStream;
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Structure used to cache file position of keywords
|
||||
|
||||
@@ -30,6 +30,8 @@
|
||||
#include <QDateTime>
|
||||
#include <QString>
|
||||
|
||||
#include <chrono>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -27,11 +27,12 @@
|
||||
#include "RigEclipseCaseData.h"
|
||||
#include "RigMainGrid.h"
|
||||
|
||||
#include "cvfGeometryTools.h"
|
||||
#include "cafAssert.h"
|
||||
|
||||
#include "opm/io/eclipse/EGrid.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
|
||||
@@ -46,6 +46,8 @@
|
||||
#include "opm/output/eclipse/VectorItems/intehead.hpp"
|
||||
#include "opm/output/eclipse/VectorItems/well.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using namespace Opm;
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#include <QString>
|
||||
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <map>
|
||||
|
||||
class RigCell;
|
||||
class RimStreamline;
|
||||
|
||||
@@ -23,12 +23,13 @@
|
||||
#include "cvfStructGrid.h"
|
||||
#include "cvfVector3.h"
|
||||
|
||||
#include <QString>
|
||||
|
||||
#include <array>
|
||||
#include <map>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <QString>
|
||||
|
||||
class RigFault;
|
||||
class RigMainGrid;
|
||||
class RigGriddedPart3d;
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
#include "RiaEclipseUnitTools.h"
|
||||
#include "RiaLogging.h"
|
||||
|
||||
#include "cafAssert.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -43,6 +43,8 @@
|
||||
|
||||
#include "cafPdmXmlMat4d.h"
|
||||
|
||||
#include <QTextStream>
|
||||
|
||||
namespace caf
|
||||
{
|
||||
template <>
|
||||
|
||||
@@ -43,6 +43,8 @@
|
||||
|
||||
#include "cafPdmXmlVec3d.h"
|
||||
|
||||
#include <QTextStream>
|
||||
|
||||
Q_DECLARE_METATYPE( cvf::Vec3d );
|
||||
|
||||
namespace caf
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
#include "cafPdmScriptIOMessages.h"
|
||||
|
||||
#include <QIODevice>
|
||||
#include <QTextStream>
|
||||
|
||||
#define CAF_PDM_InitScriptableField( field, keyword, default, uiName, ... ) \
|
||||
{ \
|
||||
|
||||
@@ -40,7 +40,6 @@
|
||||
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QTextStream>
|
||||
|
||||
#include <vector>
|
||||
|
||||
@@ -98,8 +97,18 @@ namespace caf
|
||||
/// }
|
||||
//==================================================================================================
|
||||
|
||||
class AppEnumInterface
|
||||
{
|
||||
// This non-templated base class is used in cafInternalPdmStreamOperators.h to create a QTextStream operator. Having
|
||||
// the QTextStream operator working on each templated type was seen as a performance issue when profiling use of
|
||||
// include files
|
||||
public:
|
||||
virtual QString textForSerialization() const = 0;
|
||||
virtual void setTextForSerialization( const QString& text ) = 0;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class AppEnum
|
||||
class AppEnum : public AppEnumInterface
|
||||
{
|
||||
public:
|
||||
AppEnum() { m_value = EnumMapper::instance()->defaultValue(); }
|
||||
@@ -123,6 +132,9 @@ public:
|
||||
bool setFromText( const QString& text ) { return EnumMapper::instance()->enumVal( m_value, text ); }
|
||||
bool setFromIndex( size_t index ) { return EnumMapper::instance()->enumVal( m_value, index ); }
|
||||
|
||||
QString textForSerialization() const override { return text(); }
|
||||
void setTextForSerialization( const QString& text ) override { setFromText( text ); }
|
||||
|
||||
// Static interface to access the properties of the enum definition
|
||||
|
||||
static bool isValid( const QString& text ) { return EnumMapper::instance()->isValid( text ); }
|
||||
@@ -343,29 +355,3 @@ private:
|
||||
};
|
||||
|
||||
} // namespace caf
|
||||
|
||||
//==================================================================================================
|
||||
/// Implementation of stream operators to make PdmField<AppEnum<> > work smoothly
|
||||
/// Assumes that the stream ends at the end of the enum text
|
||||
//==================================================================================================
|
||||
|
||||
template <typename T>
|
||||
QTextStream& operator>>( QTextStream& str, caf::AppEnum<T>& appEnum )
|
||||
{
|
||||
QString text;
|
||||
str >> text;
|
||||
|
||||
// Make sure the text parsed from a text stream is trimmed
|
||||
// https://github.com/OPM/ResInsight/issues/7829
|
||||
appEnum.setFromText( text.trimmed() );
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
QTextStream& operator<<( QTextStream& str, const caf::AppEnum<T>& appEnum )
|
||||
{
|
||||
str << appEnum.text();
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
@@ -1,62 +1,15 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
|
||||
#define CAF_ASSERT( expr ) \
|
||||
do \
|
||||
{ \
|
||||
if ( !( expr ) ) /* NOLINT */ \
|
||||
{ \
|
||||
std::cout << __FILE__ << ":" << __LINE__ << ": CAF_ASSERT(" << #expr << ") failed" << std::endl; \
|
||||
std::printf( "%s : %i : CAF_ASSERT( %s ) failed\n", __FILE__, __LINE__, #expr ); \
|
||||
std::abort(); \
|
||||
} \
|
||||
} while ( false )
|
||||
|
||||
#if 0 // Bits and pieces for reference to improve the assert
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning( push )
|
||||
#pragma warning( disable : 4668 )
|
||||
#include <windows.h>
|
||||
#pragma warning( pop )
|
||||
#endif
|
||||
|
||||
|
||||
void openDebugWindow()
|
||||
{
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning( push )
|
||||
#pragma warning( disable : 4996 )
|
||||
AllocConsole();
|
||||
freopen("conin$", "r", stdin);
|
||||
freopen("conout$", "w", stdout);
|
||||
freopen("conout$", "w", stderr);
|
||||
#pragma warning( pop )
|
||||
#endif
|
||||
}
|
||||
|
||||
void assertAbort()
|
||||
{
|
||||
#ifdef _MSC_VER
|
||||
#if ( _MSC_VER >= 1600 )
|
||||
//if (::IsDebuggerPresent())
|
||||
#endif
|
||||
{
|
||||
__debugbreak();
|
||||
}
|
||||
#endif
|
||||
|
||||
std::terminate();
|
||||
}
|
||||
|
||||
#define ASSERT_TEST( expr ) \
|
||||
do \
|
||||
{ \
|
||||
if ( !( expr ) ) \
|
||||
{ \
|
||||
std::cout << __FILE__ << ":" << __LINE__ << ": CAF_ASSERT(" << #expr << ") failed" << std::endl; \
|
||||
assertAbort(); \
|
||||
} \
|
||||
} while ( false )
|
||||
#endif
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "cafInternalPdmFilePathStreamOperators.h"
|
||||
|
||||
#include <QStringList>
|
||||
#include <QTextStream>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
|
||||
#include "cafFilePath.h"
|
||||
|
||||
#include <QTextStream>
|
||||
|
||||
#include <vector>
|
||||
|
||||
QTextStream& operator<<( QTextStream& str, const std::vector<caf::FilePath>& sobj );
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include <QString>
|
||||
#include <QTextStream>
|
||||
|
||||
#include "cafAppEnum.h"
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Specialized read operation for Bool`s
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -83,3 +85,21 @@ QTextStream& operator<<( QTextStream& str, const QTime& value )
|
||||
str << text;
|
||||
return str;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Specialized read operation for AppEnum
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QTextStream& operator>>( QTextStream& str, caf::AppEnumInterface& value )
|
||||
{
|
||||
QString text;
|
||||
str >> text;
|
||||
value.setTextForSerialization( text );
|
||||
return str;
|
||||
}
|
||||
|
||||
QTextStream& operator<<( QTextStream& str, const caf::AppEnumInterface& value )
|
||||
{
|
||||
QString text = value.textForSerialization();
|
||||
str << text;
|
||||
return str;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <QTextStream>
|
||||
|
||||
//==================================================================================================
|
||||
/// QTextStream Stream operator overloading for bool`s
|
||||
/// Prints bool`s as "True"/"False", and reads them too
|
||||
@@ -34,6 +32,15 @@ QTextStream& operator<<( QTextStream& str, const QDate& value );
|
||||
QTextStream& operator>>( QTextStream& str, QTime& value );
|
||||
QTextStream& operator<<( QTextStream& str, const QTime& value );
|
||||
|
||||
// AppEnum
|
||||
namespace caf
|
||||
{
|
||||
class AppEnumInterface;
|
||||
}
|
||||
|
||||
QTextStream& operator>>( QTextStream& str, caf::AppEnumInterface& value );
|
||||
QTextStream& operator<<( QTextStream& str, const caf::AppEnumInterface& value );
|
||||
|
||||
//==================================================================================================
|
||||
/// QTextStream Stream operator overloading for std::vector of things.
|
||||
/// Makes automated IO of PdmField< std::vector< Whatever > possible as long as
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
#include <QThread>
|
||||
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
|
||||
namespace caf
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user