#4683 clang-format on all files in ApplicationCode

This commit is contained in:
Magne Sjaastad
2019-09-06 10:40:57 +02:00
parent 3a317504bb
commit fe9e567825
2092 changed files with 117952 additions and 111846 deletions

View File

@@ -1,37 +1,32 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2017 Statoil ASA
//
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RicfCommandObject.h"
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
RicfCommandObject::RicfCommandObject(): RicfObjectCapability(this, false)
RicfCommandObject::RicfCommandObject()
: RicfObjectCapability( this, false )
{
}
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
RicfCommandObject::~RicfCommandObject()
{
}
RicfCommandObject::~RicfCommandObject() {}

View File

@@ -1,38 +1,38 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2017 Statoil ASA
//
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cafPdmObject.h"
#include "RicfObjectCapability.h"
#include "RicfFieldCapability.h"
#include "RicfCommandResponse.h"
#include "RicfFieldCapability.h"
#include "RicfObjectCapability.h"
#include "cafPdmObject.h"
#define RICF_InitField(field, keyword, default, uiName, iconResourceName, toolTip, whatsThis) \
CAF_PDM_InitField(field, keyword, default, uiName, iconResourceName, toolTip, whatsThis); \
AddRicfCapabilityToField(field)
#define RICF_InitField( field, keyword, default, uiName, iconResourceName, toolTip, whatsThis ) \
CAF_PDM_InitField( field, keyword, default, uiName, iconResourceName, toolTip, whatsThis ); \
AddRicfCapabilityToField( field )
#define RICF_InitFieldNoDefault(field, keyword, uiName, iconResourceName, toolTip, whatsThis) \
CAF_PDM_InitFieldNoDefault(field, keyword, uiName, iconResourceName, toolTip, whatsThis); \
AddRicfCapabilityToField(field)
#define RICF_InitFieldNoDefault( field, keyword, uiName, iconResourceName, toolTip, whatsThis ) \
CAF_PDM_InitFieldNoDefault( field, keyword, uiName, iconResourceName, toolTip, whatsThis ); \
AddRicfCapabilityToField( field )
//==================================================================================================
//
//
//
//
//==================================================================================================
class RicfCommandObject : public caf::PdmObject, public RicfObjectCapability
@@ -43,5 +43,3 @@ public:
virtual RicfCommandResponse execute() = 0;
};

View File

@@ -17,15 +17,13 @@
/////////////////////////////////////////////////////////////////////////////////
#include "RicfCommandResponse.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicfCommandResponse::RicfCommandResponse(Status status, const QString& message)
: m_status(COMMAND_OK)
RicfCommandResponse::RicfCommandResponse( Status status, const QString& message )
: m_status( COMMAND_OK )
{
updateStatus(status, message);
updateStatus( status, message );
}
//--------------------------------------------------------------------------------------------------
@@ -41,7 +39,7 @@ RicfCommandResponse::Status RicfCommandResponse::status() const
//--------------------------------------------------------------------------------------------------
QString RicfCommandResponse::message() const
{
return m_messages.join("\n");
return m_messages.join( "\n" );
}
//--------------------------------------------------------------------------------------------------
@@ -55,7 +53,7 @@ caf::PdmObject* RicfCommandResponse::result() const
//--------------------------------------------------------------------------------------------------
/// Takes ownership of the result object
//--------------------------------------------------------------------------------------------------
void RicfCommandResponse::setResult(caf::PdmObject* result)
void RicfCommandResponse::setResult( caf::PdmObject* result )
{
m_result = result;
}
@@ -63,25 +61,24 @@ void RicfCommandResponse::setResult(caf::PdmObject* result)
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicfCommandResponse::updateStatus(Status status, const QString& message)
void RicfCommandResponse::updateStatus( Status status, const QString& message )
{
m_status = std::max(m_status, status);
if (!message.isEmpty())
m_messages.push_back(QString("%1:%2").arg(statusLabel(status)).arg(message));
m_status = std::max( m_status, status );
if ( !message.isEmpty() ) m_messages.push_back( QString( "%1:%2" ).arg( statusLabel( status ) ).arg( message ) );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RicfCommandResponse::statusLabel(Status status)
QString RicfCommandResponse::statusLabel( Status status )
{
switch (status)
switch ( status )
{
case COMMAND_WARNING:
return "WARNING";
case COMMAND_ERROR:
return "ERROR";
default:
return "";
case COMMAND_WARNING:
return "WARNING";
case COMMAND_ERROR:
return "ERROR";
default:
return "";
}
}

View File

@@ -40,20 +40,21 @@ public:
COMMAND_WARNING,
COMMAND_ERROR
};
public:
RicfCommandResponse(Status status = COMMAND_OK, const QString& message="");
Status status() const;
QString message() const;
caf::PdmObject* result() const;
void setResult(caf::PdmObject* result);
void updateStatus(Status status, const QString& message);
RicfCommandResponse( Status status = COMMAND_OK, const QString& message = "" );
Status status() const;
QString message() const;
caf::PdmObject* result() const;
void setResult( caf::PdmObject* result );
void updateStatus( Status status, const QString& message );
private:
static QString statusLabel(Status status);
static QString statusLabel( Status status );
private:
Status m_status;
QStringList m_messages;
caf::PdmPointer<caf::PdmObject> m_result;
Status m_status;
QStringList m_messages;
caf::PdmPointer<caf::PdmObject> m_result;
};

View File

@@ -1,17 +1,17 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2017 Statoil ASA
//
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
@@ -24,35 +24,38 @@
#include <QColor>
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
void RicfFieldReader<QString>::readFieldData(QString& fieldValue, QTextStream& inputStream, RicfMessages* errorMessageContainer, bool stringsAreQuoted)
void RicfFieldReader<QString>::readFieldData( QString& fieldValue,
QTextStream& inputStream,
RicfMessages* errorMessageContainer,
bool stringsAreQuoted )
{
fieldValue = "";
errorMessageContainer->skipWhiteSpaceWithLineNumberCount(inputStream);
errorMessageContainer->skipWhiteSpaceWithLineNumberCount( inputStream );
QString accumulatedFieldValue;
QChar currentChar;
bool validStringStart = !stringsAreQuoted;
bool validStringEnd = !stringsAreQuoted;
if (stringsAreQuoted)
bool validStringStart = !stringsAreQuoted;
bool validStringEnd = !stringsAreQuoted;
if ( stringsAreQuoted )
{
currentChar = errorMessageContainer->readCharWithLineNumberCount(inputStream);
if (currentChar == QChar('"'))
currentChar = errorMessageContainer->readCharWithLineNumberCount( inputStream );
if ( currentChar == QChar( '"' ) )
{
validStringStart = true;
}
}
if (validStringStart)
if ( validStringStart )
{
while ( !inputStream.atEnd() )
{
currentChar = errorMessageContainer->readCharWithLineNumberCount(inputStream);
if ( currentChar != QChar('\\') )
currentChar = errorMessageContainer->readCharWithLineNumberCount( inputStream );
if ( currentChar != QChar( '\\' ) )
{
if ( currentChar == QChar('"') ) // End Quote
if ( currentChar == QChar( '"' ) ) // End Quote
{
// Reached end of string
validStringEnd = true;
@@ -65,27 +68,28 @@ void RicfFieldReader<QString>::readFieldData(QString& fieldValue, QTextStream& i
}
else
{
currentChar = errorMessageContainer->readCharWithLineNumberCount(inputStream);
currentChar = errorMessageContainer->readCharWithLineNumberCount( inputStream );
accumulatedFieldValue += currentChar;
}
}
}
if (!validStringStart)
if ( !validStringStart )
{
// Unexpected start of string, Missing '"'
// Error message
errorMessageContainer->addError("String argument does not seem to be quoted. Missing the start '\"' in the \""
+ errorMessageContainer->currentArgument + "\" argument of the command: \""
+ errorMessageContainer->currentCommand + "\"" );
errorMessageContainer->addError(
"String argument does not seem to be quoted. Missing the start '\"' in the \"" +
errorMessageContainer->currentArgument + "\" argument of the command: \"" +
errorMessageContainer->currentCommand + "\"" );
// Could interpret as unquoted text
}
else if (!validStringEnd)
else if ( !validStringEnd )
{
// Unexpected end of string, Missing '"'
// Error message
errorMessageContainer->addError("String argument does not seem to be quoted. Missing the end '\"' in the \"" +
errorMessageContainer->currentArgument + "\" argument of the command: \"" +
errorMessageContainer->currentCommand + "\"");
errorMessageContainer->addError( "String argument does not seem to be quoted. Missing the end '\"' in the \"" +
errorMessageContainer->currentArgument + "\" argument of the command: \"" +
errorMessageContainer->currentCommand + "\"" );
// Could interpret as unquoted text
}
@@ -93,14 +97,14 @@ void RicfFieldReader<QString>::readFieldData(QString& fieldValue, QTextStream& i
}
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
void RicfFieldWriter<QString>::writeFieldData(const QString& fieldValue, QTextStream& outputStream, bool quoteStrings)
void RicfFieldWriter<QString>::writeFieldData( const QString& fieldValue, QTextStream& outputStream, bool quoteStrings )
{
outputStream << "\"";
for ( int i = 0; i < fieldValue.size(); ++i )
{
if ( fieldValue[i] == QChar('"') || fieldValue[i] == QChar('\\') )
if ( fieldValue[i] == QChar( '"' ) || fieldValue[i] == QChar( '\\' ) )
{
outputStream << "\\";
}
@@ -110,20 +114,23 @@ void RicfFieldWriter<QString>::writeFieldData(const QString& fieldValue, QTextSt
}
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
void RicfFieldReader<bool>::readFieldData(bool& fieldValue, QTextStream& inputStream, RicfMessages* errorMessageContainer, bool stringsAreQuoted)
void RicfFieldReader<bool>::readFieldData( bool& fieldValue,
QTextStream& inputStream,
RicfMessages* errorMessageContainer,
bool stringsAreQuoted )
{
errorMessageContainer->skipWhiteSpaceWithLineNumberCount(inputStream);
errorMessageContainer->skipWhiteSpaceWithLineNumberCount( inputStream );
QString accumulatedFieldValue;
QChar nextChar;
QChar currentChar;
while (!inputStream.atEnd())
QChar nextChar;
QChar currentChar;
while ( !inputStream.atEnd() )
{
nextChar = errorMessageContainer->peekNextChar(inputStream);
if (nextChar.isLetter())
nextChar = errorMessageContainer->peekNextChar( inputStream );
if ( nextChar.isLetter() )
{
currentChar = errorMessageContainer->readCharWithLineNumberCount(inputStream);
currentChar = errorMessageContainer->readCharWithLineNumberCount( inputStream );
accumulatedFieldValue += currentChar;
}
else
@@ -132,48 +139,54 @@ void RicfFieldReader<bool>::readFieldData(bool& fieldValue, QTextStream& inputSt
}
}
// Accept TRUE or False in any case combination.
bool evaluatesToTrue = QString::compare(accumulatedFieldValue, QString("true"), Qt::CaseInsensitive) == 0;
bool evaluatesToFalse = QString::compare(accumulatedFieldValue, QString("false"), Qt::CaseInsensitive) == 0;
if (evaluatesToTrue == evaluatesToFalse)
bool evaluatesToTrue = QString::compare( accumulatedFieldValue, QString( "true" ), Qt::CaseInsensitive ) == 0;
bool evaluatesToFalse = QString::compare( accumulatedFieldValue, QString( "false" ), Qt::CaseInsensitive ) == 0;
if ( evaluatesToTrue == evaluatesToFalse )
{
QString formatString("Boolean argument \"%1\" for the command \"%2\" does not evaluate to either true or false");
QString errorMessage = formatString.arg(errorMessageContainer->currentArgument).arg(errorMessageContainer->currentCommand);
errorMessageContainer->addError(errorMessage);
QString formatString(
"Boolean argument \"%1\" for the command \"%2\" does not evaluate to either true or false" );
QString errorMessage = formatString.arg( errorMessageContainer->currentArgument )
.arg( errorMessageContainer->currentCommand );
errorMessageContainer->addError( errorMessage );
}
fieldValue = evaluatesToTrue;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicfFieldWriter<bool>::writeFieldData(const bool& fieldValue, QTextStream& outputStream, bool quoteStrings)
void RicfFieldWriter<bool>::writeFieldData( const bool& fieldValue, QTextStream& outputStream, bool quoteStrings )
{
// Lower-case true/false is used in the documentation.
outputStream << (fieldValue ? "true" : "false");
outputStream << ( fieldValue ? "true" : "false" );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicfFieldReader<cvf::Color3f>::readFieldData(cvf::Color3f& fieldValue, QTextStream& inputStream, RicfMessages* errorMessageContainer, bool stringsAreQuoted)
void RicfFieldReader<cvf::Color3f>::readFieldData( cvf::Color3f& fieldValue,
QTextStream& inputStream,
RicfMessages* errorMessageContainer,
bool stringsAreQuoted )
{
QString fieldStringValue;
RicfFieldReader<QString>::readFieldData(fieldStringValue, inputStream, errorMessageContainer, stringsAreQuoted);
RicfFieldReader<QString>::readFieldData( fieldStringValue, inputStream, errorMessageContainer, stringsAreQuoted );
QColor qColor(fieldStringValue);
if (qColor.isValid())
QColor qColor( fieldStringValue );
if ( qColor.isValid() )
{
fieldValue = RiaColorTools::fromQColorTo3f(qColor);
fieldValue = RiaColorTools::fromQColorTo3f( qColor );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicfFieldWriter<cvf::Color3f>::writeFieldData(const cvf::Color3f& fieldValue, QTextStream& outputStream, bool quoteStrings)
void RicfFieldWriter<cvf::Color3f>::writeFieldData( const cvf::Color3f& fieldValue,
QTextStream& outputStream,
bool quoteStrings )
{
QColor qColor = RiaColorTools::toQColor(fieldValue);
QColor qColor = RiaColorTools::toQColor( fieldValue );
QString fieldStringValue = qColor.name();
RicfFieldWriter<QString>::writeFieldData(fieldStringValue, outputStream, quoteStrings);
RicfFieldWriter<QString>::writeFieldData( fieldStringValue, outputStream, quoteStrings );
}

View File

@@ -1,17 +1,17 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2017 Statoil ASA
//
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
@@ -25,23 +25,25 @@
#include "cvfColor3.h"
#include <QTextStream>
#include <QString>
#include <QTextStream>
template <typename DataType>
struct RicfFieldReader
{
static void readFieldData(DataType & fieldValue, QTextStream& inputStream, RicfMessages* errorMessageContainer, bool stringsAreQuoted = true)
static void readFieldData( DataType& fieldValue,
QTextStream& inputStream,
RicfMessages* errorMessageContainer,
bool stringsAreQuoted = true )
{
inputStream >> fieldValue;
if (inputStream.status() == QTextStream::ReadCorruptData)
if ( inputStream.status() == QTextStream::ReadCorruptData )
{
errorMessageContainer->addError("Argument value is unreadable in the argument: \""
+ errorMessageContainer->currentArgument + "\" in the command: \""
+ errorMessageContainer->currentCommand + "\"" );
errorMessageContainer->addError( "Argument value is unreadable in the argument: \"" +
errorMessageContainer->currentArgument + "\" in the command: \"" +
errorMessageContainer->currentCommand + "\"" );
inputStream.setStatus( QTextStream::Ok);
inputStream.setStatus( QTextStream::Ok );
}
}
};
@@ -49,63 +51,75 @@ struct RicfFieldReader
template <typename DataType>
struct RicfFieldWriter
{
static void writeFieldData(const DataType & fieldValue, QTextStream& outputStream, bool quoteStrings = true)
static void writeFieldData( const DataType& fieldValue, QTextStream& outputStream, bool quoteStrings = true )
{
outputStream << fieldValue;
outputStream << fieldValue;
}
};
template <>
struct RicfFieldReader<QString>
{
static void readFieldData(QString & fieldValue, QTextStream& inputStream, RicfMessages* errorMessageContainer, bool stringsAreQuoted = true);
static void readFieldData( QString& fieldValue,
QTextStream& inputStream,
RicfMessages* errorMessageContainer,
bool stringsAreQuoted = true );
};
template <>
struct RicfFieldWriter<QString>
{
static void writeFieldData(const QString & fieldValue, QTextStream& outputStream, bool quoteStrings = true);
static void writeFieldData( const QString& fieldValue, QTextStream& outputStream, bool quoteStrings = true );
};
template <>
struct RicfFieldReader<bool>
{
static void readFieldData(bool& fieldValue, QTextStream& inputStream, RicfMessages* errorMessageContainer, bool stringsAreQuoted = true);
static void readFieldData( bool& fieldValue,
QTextStream& inputStream,
RicfMessages* errorMessageContainer,
bool stringsAreQuoted = true );
};
template <>
struct RicfFieldWriter<bool>
{
static void writeFieldData(const bool& fieldValue, QTextStream& outputStream, bool quoteStrings = true);
static void writeFieldData( const bool& fieldValue, QTextStream& outputStream, bool quoteStrings = true );
};
template<>
template <>
struct RicfFieldReader<cvf::Color3f>
{
static void readFieldData(cvf::Color3f& fieldValue, QTextStream& inputStream, RicfMessages* errorMessageContainer, bool stringsAreQuoted = true);
static void readFieldData( cvf::Color3f& fieldValue,
QTextStream& inputStream,
RicfMessages* errorMessageContainer,
bool stringsAreQuoted = true );
};
template<>
template <>
struct RicfFieldWriter<cvf::Color3f>
{
static void writeFieldData(const cvf::Color3f& fieldValue, QTextStream& outputStream, bool quoteStrings = true);
static void writeFieldData( const cvf::Color3f& fieldValue, QTextStream& outputStream, bool quoteStrings = true );
};
template <typename T>
struct RicfFieldReader< caf::AppEnum<T> >
struct RicfFieldReader<caf::AppEnum<T>>
{
static void readFieldData(caf::AppEnum<T>& fieldValue, QTextStream& inputStream, RicfMessages* errorMessageContainer, bool stringsAreQuoted = true)
static void readFieldData( caf::AppEnum<T>& fieldValue,
QTextStream& inputStream,
RicfMessages* errorMessageContainer,
bool stringsAreQuoted = true )
{
errorMessageContainer->skipWhiteSpaceWithLineNumberCount(inputStream);
errorMessageContainer->skipWhiteSpaceWithLineNumberCount( inputStream );
QString accumulatedFieldValue;
QChar nextChar;
QChar currentChar;
while (!inputStream.atEnd())
QChar nextChar;
QChar currentChar;
while ( !inputStream.atEnd() )
{
nextChar = errorMessageContainer->peekNextChar(inputStream);
if (nextChar.isLetterOrNumber() || nextChar == QChar('_'))
nextChar = errorMessageContainer->peekNextChar( inputStream );
if ( nextChar.isLetterOrNumber() || nextChar == QChar( '_' ) )
{
currentChar = errorMessageContainer->readCharWithLineNumberCount(inputStream);
currentChar = errorMessageContainer->readCharWithLineNumberCount( inputStream );
accumulatedFieldValue += currentChar;
}
else
@@ -113,72 +127,77 @@ struct RicfFieldReader< caf::AppEnum<T> >
break;
}
}
if (!fieldValue.setFromText(accumulatedFieldValue))
if ( !fieldValue.setFromText( accumulatedFieldValue ) )
{
// Unexpected enum value
// Error message
errorMessageContainer->addError("Argument must be valid enum value. "
+ errorMessageContainer->currentArgument + "\" argument of the command: \""
+ errorMessageContainer->currentCommand + "\"");
errorMessageContainer->addError( "Argument must be valid enum value. " +
errorMessageContainer->currentArgument + "\" argument of the command: \"" +
errorMessageContainer->currentCommand + "\"" );
}
}
};
template <typename T>
struct RicfFieldWriter< caf::AppEnum<T> >
struct RicfFieldWriter<caf::AppEnum<T>>
{
static void writeFieldData(const caf::AppEnum<T>& fieldValue, QTextStream& outputStream, bool quoteStrings = true)
static void writeFieldData( const caf::AppEnum<T>& fieldValue, QTextStream& outputStream, bool quoteStrings = true )
{
outputStream << fieldValue;
}
};
template <typename T>
struct RicfFieldReader< std::vector<T> >
struct RicfFieldReader<std::vector<T>>
{
static void readFieldData(std::vector<T>& fieldValue, QTextStream& inputStream, RicfMessages* errorMessageContainer, bool stringsAreQuoted = true)
static void readFieldData( std::vector<T>& fieldValue,
QTextStream& inputStream,
RicfMessages* errorMessageContainer,
bool stringsAreQuoted = true )
{
errorMessageContainer->skipWhiteSpaceWithLineNumberCount(inputStream);
QChar chr = errorMessageContainer->readCharWithLineNumberCount(inputStream);
if (chr == QChar('[')) {
while (!inputStream.atEnd())
errorMessageContainer->skipWhiteSpaceWithLineNumberCount( inputStream );
QChar chr = errorMessageContainer->readCharWithLineNumberCount( inputStream );
if ( chr == QChar( '[' ) )
{
while ( !inputStream.atEnd() )
{
errorMessageContainer->skipWhiteSpaceWithLineNumberCount(inputStream);
QChar nextChar = errorMessageContainer->peekNextChar(inputStream);
if (nextChar == QChar(']'))
errorMessageContainer->skipWhiteSpaceWithLineNumberCount( inputStream );
QChar nextChar = errorMessageContainer->peekNextChar( inputStream );
if ( nextChar == QChar( ']' ) )
{
nextChar = errorMessageContainer->readCharWithLineNumberCount(inputStream);
nextChar = errorMessageContainer->readCharWithLineNumberCount( inputStream );
break;
}
else if (nextChar == QChar(','))
else if ( nextChar == QChar( ',' ) )
{
nextChar = errorMessageContainer->readCharWithLineNumberCount(inputStream);
errorMessageContainer->skipWhiteSpaceWithLineNumberCount(inputStream);
nextChar = errorMessageContainer->readCharWithLineNumberCount( inputStream );
errorMessageContainer->skipWhiteSpaceWithLineNumberCount( inputStream );
}
T value;
RicfFieldReader<T>::readFieldData(value, inputStream, errorMessageContainer, true);
fieldValue.push_back(value);
RicfFieldReader<T>::readFieldData( value, inputStream, errorMessageContainer, true );
fieldValue.push_back( value );
}
}
else {
errorMessageContainer->addError("Array argument is missing start '['. "
+ errorMessageContainer->currentArgument + "\" argument of the command: \""
+ errorMessageContainer->currentCommand + "\"" );
else
{
errorMessageContainer->addError( "Array argument is missing start '['. " +
errorMessageContainer->currentArgument + "\" argument of the command: \"" +
errorMessageContainer->currentCommand + "\"" );
}
}
};
template <typename T>
struct RicfFieldWriter< std::vector<T> >
struct RicfFieldWriter<std::vector<T>>
{
static void writeFieldData(const std::vector<T>& fieldValue, QTextStream& outputStream, bool quoteStrings = true)
static void writeFieldData( const std::vector<T>& fieldValue, QTextStream& outputStream, bool quoteStrings = true )
{
outputStream << "[";
for (size_t i = 0; i < fieldValue.size(); ++i)
for ( size_t i = 0; i < fieldValue.size(); ++i )
{
RicfFieldWriter<T>::writeFieldData(fieldValue[i], outputStream);
if (i < fieldValue.size() - 1)
RicfFieldWriter<T>::writeFieldData( fieldValue[i], outputStream );
if ( i < fieldValue.size() - 1 )
{
outputStream << ", ";
}
@@ -187,49 +206,54 @@ struct RicfFieldWriter< std::vector<T> >
}
};
//==================================================================================================
//
//
//
//
//==================================================================================================
template < typename FieldType>
template <typename FieldType>
class RicfFieldCapability : public RicfFieldHandle
{
public:
RicfFieldCapability(FieldType* field, bool giveOwnership) : RicfFieldHandle(field, giveOwnership) { m_field = field; }
RicfFieldCapability( FieldType* field, bool giveOwnership )
: RicfFieldHandle( field, giveOwnership )
{
m_field = field;
}
// Xml Serializing
public:
void readFieldData (QTextStream& inputStream, caf::PdmObjectFactory* objectFactory, RicfMessages* errorMessageContainer, bool stringsAreQuoted = true) override
void readFieldData( QTextStream& inputStream,
caf::PdmObjectFactory* objectFactory,
RicfMessages* errorMessageContainer,
bool stringsAreQuoted = true ) override
{
typename FieldType::FieldDataType value;
RicfFieldReader<typename FieldType::FieldDataType>::readFieldData(value, inputStream, errorMessageContainer, stringsAreQuoted);
RicfFieldReader<typename FieldType::FieldDataType>::readFieldData( value,
inputStream,
errorMessageContainer,
stringsAreQuoted );
if (this->isIOWriteable())
if ( this->isIOWriteable() )
{
m_field->setValue(value);
m_field->setValue( value );
}
}
void writeFieldData(QTextStream& outputStream, bool quoteStrings = true) const override
void writeFieldData( QTextStream& outputStream, bool quoteStrings = true ) const override
{
RicfFieldWriter<typename FieldType::FieldDataType>::writeFieldData(m_field->value(), outputStream, quoteStrings);
RicfFieldWriter<typename FieldType::FieldDataType>::writeFieldData( m_field->value(), outputStream, quoteStrings );
}
private:
FieldType* m_field;
};
template<typename FieldType>
void AddRicfCapabilityToField(FieldType* field)
template <typename FieldType>
void AddRicfCapabilityToField( FieldType* field )
{
if(field->template capability< RicfFieldCapability<FieldType> >() == nullptr)
if ( field->template capability<RicfFieldCapability<FieldType>>() == nullptr )
{
new RicfFieldCapability<FieldType>(field, true);
new RicfFieldCapability<FieldType>( field, true );
}
}

View File

@@ -1,17 +1,17 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2017 Statoil ASA
//
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
@@ -19,22 +19,17 @@
#include "RicfFieldHandle.h"
#include "cafPdmFieldHandle.h"
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
RicfFieldHandle::RicfFieldHandle(caf::PdmFieldHandle* owner, bool giveOwnership)
RicfFieldHandle::RicfFieldHandle( caf::PdmFieldHandle* owner, bool giveOwnership )
{
m_IOWriteable = true;
m_owner = owner;
owner->addCapability(this, giveOwnership);
m_owner = owner;
owner->addCapability( this, giveOwnership );
}
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
RicfFieldHandle::~RicfFieldHandle()
{
}
RicfFieldHandle::~RicfFieldHandle() {}

View File

@@ -1,17 +1,17 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2017 Statoil ASA
//
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
@@ -25,7 +25,7 @@ namespace caf
{
class PdmObjectFactory;
class PdmFieldHandle;
}
} // namespace caf
class RicfMessages;
@@ -33,36 +33,32 @@ class QTextStream;
//==================================================================================================
//
//
//
//
//==================================================================================================
class RicfFieldHandle : public caf::PdmFieldCapability
{
public:
RicfFieldHandle(caf::PdmFieldHandle* owner, bool giveOwnership);
RicfFieldHandle( caf::PdmFieldHandle* owner, bool giveOwnership );
~RicfFieldHandle() override;
bool isIOWriteable() const
{
return m_IOWriteable;
}
void setIOWriteable(bool writeable)
void setIOWriteable( bool writeable )
{
m_IOWriteable = writeable;
}
virtual void readFieldData (QTextStream& inputStream,
caf::PdmObjectFactory* objectFactory,
RicfMessages* errorMessageContainer,
bool stringsAreQuoted = true) = 0;
virtual void writeFieldData(QTextStream& outputStream, bool quoteStrings = true) const = 0;
virtual void readFieldData( QTextStream& inputStream,
caf::PdmObjectFactory* objectFactory,
RicfMessages* errorMessageContainer,
bool stringsAreQuoted = true ) = 0;
virtual void writeFieldData( QTextStream& outputStream, bool quoteStrings = true ) const = 0;
private:
caf::PdmFieldHandle* m_owner;
bool m_IOWriteable;
};

View File

@@ -1,65 +1,65 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2017 Statoil ASA
//
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RicfMessages.h"
#include <QTextStream>
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
void RicfMessages::addWarning(const QString& message)
void RicfMessages::addWarning( const QString& message )
{
m_messages.push_back(std::make_pair(MESSAGE_WARNING, "Line " + QString::number(m_currentLineNumber) +": " + message));
m_messages.push_back(
std::make_pair( MESSAGE_WARNING, "Line " + QString::number( m_currentLineNumber ) + ": " + message ) );
}
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
void RicfMessages::addError(const QString& message)
void RicfMessages::addError( const QString& message )
{
m_messages.push_back(std::make_pair(MESSAGE_ERROR, "Line " + QString::number(m_currentLineNumber) +": " + message));
m_messages.push_back(
std::make_pair( MESSAGE_ERROR, "Line " + QString::number( m_currentLineNumber ) + ": " + message ) );
}
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
void RicfMessages::skipWhiteSpaceWithLineNumberCount(QTextStream& inputStream)
void RicfMessages::skipWhiteSpaceWithLineNumberCount( QTextStream& inputStream )
{
while ( !inputStream.atEnd() )
{
QChar ch = readCharWithLineNumberCount(inputStream);
QChar ch = readCharWithLineNumberCount( inputStream );
if ( !ch.isSpace() )
{
inputStream.seek(inputStream.pos()-1);
inputStream.seek( inputStream.pos() - 1 );
break;
}
}
}
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
QChar RicfMessages::readCharWithLineNumberCount(QTextStream& inputStream)
QChar RicfMessages::readCharWithLineNumberCount( QTextStream& inputStream )
{
QChar ch;
inputStream >> ch;
if ( ch == QChar('\n') )
if ( ch == QChar( '\n' ) )
{
m_currentLineNumber++;
}
@@ -67,23 +67,23 @@ QChar RicfMessages::readCharWithLineNumberCount(QTextStream& inputStream)
}
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
QChar RicfMessages::peekNextChar(QTextStream& inputStream)
QChar RicfMessages::peekNextChar( QTextStream& inputStream )
{
QChar ch;
if (!inputStream.atEnd())
if ( !inputStream.atEnd() )
{
inputStream >> ch;
inputStream.seek(inputStream.pos() - 1);
inputStream.seek( inputStream.pos() - 1 );
}
return ch;
}
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
void RicfMessages::skipLineWithLineNumberCount(QTextStream& inputStream)
void RicfMessages::skipLineWithLineNumberCount( QTextStream& inputStream )
{
inputStream.readLine();
m_currentLineNumber++;

View File

@@ -1,31 +1,34 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2017 Statoil ASA
//
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include <vector>
#include <QString>
#include <vector>
class QTextStream;
class RicfMessages
{
public:
RicfMessages() : m_currentLineNumber(1) {}
RicfMessages()
: m_currentLineNumber( 1 )
{
}
enum MessageType
{
@@ -33,21 +36,19 @@ public:
MESSAGE_ERROR
};
void addWarning(const QString& message);
void addError(const QString& message);
void addWarning( const QString& message );
void addError( const QString& message );
void skipWhiteSpaceWithLineNumberCount(QTextStream& inputStream);
void skipLineWithLineNumberCount(QTextStream& inputStream);
QChar readCharWithLineNumberCount(QTextStream& inputStream);
QChar peekNextChar(QTextStream& inputStream);
void skipWhiteSpaceWithLineNumberCount( QTextStream& inputStream );
void skipLineWithLineNumberCount( QTextStream& inputStream );
QString currentCommand;
QString currentArgument;
std::vector<std::pair<MessageType, QString> > m_messages;
QChar readCharWithLineNumberCount( QTextStream& inputStream );
QChar peekNextChar( QTextStream& inputStream );
QString currentCommand;
QString currentArgument;
std::vector<std::pair<MessageType, QString>> m_messages;
private:
int m_currentLineNumber;
};

View File

@@ -1,72 +1,67 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2017 Statoil ASA
//
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RicfObjectCapability.h"
#include "cafPdmObjectHandle.h"
#include <QTextStream>
#include "RicfFieldHandle.h"
#include "cafPdmXmlFieldHandle.h"
#include "RicfMessages.h"
#include "cafPdmObjectHandle.h"
#include "cafPdmXmlFieldHandle.h"
#include <QTextStream>
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
RicfObjectCapability::RicfObjectCapability(caf::PdmObjectHandle* owner, bool giveOwnership)
RicfObjectCapability::RicfObjectCapability( caf::PdmObjectHandle* owner, bool giveOwnership )
{
m_owner = owner;
m_owner->addCapability(this, giveOwnership);
m_owner->addCapability( this, giveOwnership );
}
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
RicfObjectCapability::~RicfObjectCapability()
{
}
RicfObjectCapability::~RicfObjectCapability() {}
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
void RicfObjectCapability::readFields(QTextStream& inputStream,
caf::PdmObjectFactory* objectFactory,
RicfMessages* errorMessageContainer)
void RicfObjectCapability::readFields( QTextStream& inputStream,
caf::PdmObjectFactory* objectFactory,
RicfMessages* errorMessageContainer )
{
std::set<QString> readFields;
bool isLastArgumentRead = false;
bool isLastArgumentRead = false;
while ( !inputStream.atEnd() && !isLastArgumentRead )
{
// Read field keyword
bool fieldDataFound = false;
bool isEndOfArgumentFound = false;
bool fieldDataFound = false;
bool isEndOfArgumentFound = false;
QString keyword;
{
errorMessageContainer->skipWhiteSpaceWithLineNumberCount(inputStream);
errorMessageContainer->skipWhiteSpaceWithLineNumberCount( inputStream );
{
QChar currentChar;
while (!inputStream.atEnd())
while ( !inputStream.atEnd() )
{
currentChar = errorMessageContainer->readCharWithLineNumberCount(inputStream);
currentChar = errorMessageContainer->readCharWithLineNumberCount( inputStream );
if (currentChar == QChar('=') || currentChar == QChar(')') || currentChar == QChar(',') || currentChar.isSpace())
if ( currentChar == QChar( '=' ) || currentChar == QChar( ')' ) || currentChar == QChar( ',' ) ||
currentChar.isSpace() )
{
break;
}
@@ -74,105 +69,115 @@ void RicfObjectCapability::readFields(QTextStream& inputStream,
{
keyword += currentChar;
}
}
if (currentChar.isSpace())
if ( currentChar.isSpace() )
{
errorMessageContainer->skipWhiteSpaceWithLineNumberCount(inputStream);
currentChar = errorMessageContainer->readCharWithLineNumberCount(inputStream);
errorMessageContainer->skipWhiteSpaceWithLineNumberCount( inputStream );
currentChar = errorMessageContainer->readCharWithLineNumberCount( inputStream );
}
if (currentChar == QChar('='))
if ( currentChar == QChar( '=' ) )
{
fieldDataFound = true;
}
else if (currentChar == QChar(')'))
else if ( currentChar == QChar( ')' ) )
{
if (!keyword.isNull())
if ( !keyword.isNull() )
{
errorMessageContainer->addError(QString("Can't find the '=' after the argument named '%1' in the command '%2'").arg(keyword).arg(errorMessageContainer->currentCommand));
errorMessageContainer->addError(
QString( "Can't find the '=' after the argument named '%1' in the command '%2'" )
.arg( keyword )
.arg( errorMessageContainer->currentCommand ) );
}
isLastArgumentRead = true;
}
else if (currentChar == QChar(','))
else if ( currentChar == QChar( ',' ) )
{
errorMessageContainer->addError(QString("Can't find the '=' after the argument named '%1' in the command '%2'").arg(keyword).arg(errorMessageContainer->currentCommand));
errorMessageContainer->addError(
QString( "Can't find the '=' after the argument named '%1' in the command '%2'" )
.arg( keyword )
.arg( errorMessageContainer->currentCommand ) );
isEndOfArgumentFound = true;
}
else
{
errorMessageContainer->addError(QString("Can't find the '=' after the argument named '%1' in the command '%2'").arg(keyword).arg(errorMessageContainer->currentCommand));
errorMessageContainer->addError(
QString( "Can't find the '=' after the argument named '%1' in the command '%2'" )
.arg( keyword )
.arg( errorMessageContainer->currentCommand ) );
}
}
if ( readFields.count(keyword) )
if ( readFields.count( keyword ) )
{
// Warning message: Referenced the same argument several times
errorMessageContainer->addWarning("The argument: \"" + keyword + "\" is referenced several times in the command: \"" + errorMessageContainer->currentCommand + "\"" );
errorMessageContainer->addWarning( "The argument: \"" + keyword +
"\" is referenced several times in the command: \"" +
errorMessageContainer->currentCommand + "\"" );
}
}
if (fieldDataFound)
if ( fieldDataFound )
{
// Make field read its data
caf::PdmFieldHandle* fieldHandle = m_owner->findField(keyword);
caf::PdmFieldHandle* fieldHandle = m_owner->findField( keyword );
if ( fieldHandle && fieldHandle->xmlCapability() && fieldHandle->capability<RicfFieldHandle>() )
{
caf::PdmXmlFieldHandle* xmlFieldHandle = fieldHandle->xmlCapability();
RicfFieldHandle* rcfField = fieldHandle->capability<RicfFieldHandle>();
RicfFieldHandle* rcfField = fieldHandle->capability<RicfFieldHandle>();
if ( xmlFieldHandle->isIOReadable() )
{
errorMessageContainer->currentArgument = keyword;
rcfField->readFieldData(inputStream, objectFactory, errorMessageContainer);
rcfField->readFieldData( inputStream, objectFactory, errorMessageContainer );
errorMessageContainer->currentArgument = keyword;
}
}
else
{
// Error message: Unknown argument name
errorMessageContainer->addWarning("The argument: \"" + keyword + "\" does not exist in the command: \"" + errorMessageContainer->currentCommand + "\"");
errorMessageContainer->addWarning( "The argument: \"" + keyword + "\" does not exist in the command: \"" +
errorMessageContainer->currentCommand + "\"" );
}
}
// Skip to end of argument ',' or end of call ')'
if (!(isLastArgumentRead || isEndOfArgumentFound) )
// Skip to end of argument ',' or end of call ')'
if ( !( isLastArgumentRead || isEndOfArgumentFound ) )
{
QChar currentChar;
bool isOutsideQuotes = true;
bool isOutsideQuotes = true;
while ( !inputStream.atEnd() )
{
currentChar = errorMessageContainer->readCharWithLineNumberCount(inputStream);
currentChar = errorMessageContainer->readCharWithLineNumberCount( inputStream );
if ( isOutsideQuotes )
{
if ( currentChar == QChar(',') )
if ( currentChar == QChar( ',' ) )
{
break;
}
if ( currentChar == QChar(')') )
if ( currentChar == QChar( ')' ) )
{
isLastArgumentRead = true;
break;
}
if ( currentChar == QChar('\"') )
if ( currentChar == QChar( '\"' ) )
{
isOutsideQuotes = false;
}
}
else
{
if ( currentChar == QChar('\"') )
if ( currentChar == QChar( '\"' ) )
{
isOutsideQuotes = true;
}
if ( currentChar == QChar('\\') )
if ( currentChar == QChar( '\\' ) )
{
currentChar = errorMessageContainer->readCharWithLineNumberCount(inputStream);
currentChar = errorMessageContainer->readCharWithLineNumberCount( inputStream );
}
}
}
@@ -181,21 +186,21 @@ void RicfObjectCapability::readFields(QTextStream& inputStream,
}
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
void RicfObjectCapability::writeFields(QTextStream& outputStream) const
void RicfObjectCapability::writeFields( QTextStream& outputStream ) const
{
std::vector<caf::PdmFieldHandle*> fields;
m_owner->fields(fields);
m_owner->fields( fields );
int writtenFieldCount = 0;
for ( size_t it = 0; it < fields.size(); ++it )
{
const caf::PdmXmlFieldHandle* xmlField = fields[it]->xmlCapability();
const RicfFieldHandle* rcfField = fields[it]->capability<RicfFieldHandle>();
const RicfFieldHandle* rcfField = fields[it]->capability<RicfFieldHandle>();
if ( rcfField && xmlField && xmlField->isIOWritable() )
{
QString keyword = xmlField->fieldHandle()->keyword();
CAF_ASSERT(caf::PdmXmlObjectHandle::isValidXmlElementName(keyword));
CAF_ASSERT( caf::PdmXmlObjectHandle::isValidXmlElementName( keyword ) );
if ( writtenFieldCount >= 1 )
{
@@ -203,8 +208,8 @@ void RicfObjectCapability::writeFields(QTextStream& outputStream) const
}
outputStream << keyword << " = ";
rcfField->writeFieldData(outputStream);
rcfField->writeFieldData( outputStream );
writtenFieldCount++;
}
}

View File

@@ -1,17 +1,17 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2017 Statoil ASA
//
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
@@ -23,29 +23,26 @@ namespace caf
{
class PdmObjectHandle;
class PdmObjectFactory;
}
} // namespace caf
class QTextStream;
class RicfMessages;
//==================================================================================================
//
//
//
//
//==================================================================================================
class RicfObjectCapability : public caf::PdmObjectCapability
{
public:
RicfObjectCapability(caf::PdmObjectHandle* owner, bool giveOwnership);
RicfObjectCapability( caf::PdmObjectHandle* owner, bool giveOwnership );
~RicfObjectCapability() override;
void readFields(QTextStream& inputStream, caf::PdmObjectFactory* objectFactory, RicfMessages* errorMessageContainer);
void writeFields(QTextStream& outputStream) const;
void readFields( QTextStream& inputStream, caf::PdmObjectFactory* objectFactory, RicfMessages* errorMessageContainer );
void writeFields( QTextStream& outputStream ) const;
private:
caf::PdmObjectHandle* m_owner;
};

View File

@@ -1,17 +1,17 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2017 Statoil ASA
//
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
@@ -19,117 +19,117 @@
#include "RifcCommandFileReader.h"
#include "RicfCommandObject.h"
#include "RicfObjectCapability.h"
#include "RicfMessages.h"
#include "RicfObjectCapability.h"
#include "cafPdmObjectFactory.h"
#include <QTextStream>
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
std::vector<RicfCommandObject*> RicfCommandFileReader::readCommands(QTextStream& inputStream,
caf::PdmObjectFactory* objectFactory,
RicfMessages* errorMessageContainer)
std::vector<RicfCommandObject*> RicfCommandFileReader::readCommands( QTextStream& inputStream,
caf::PdmObjectFactory* objectFactory,
RicfMessages* errorMessageContainer )
{
std::vector<RicfCommandObject*> readCommands;
while ( !inputStream.atEnd() )
{
errorMessageContainer->skipWhiteSpaceWithLineNumberCount(inputStream);
errorMessageContainer->skipWhiteSpaceWithLineNumberCount( inputStream );
// Read command name
QString commandName;
{
errorMessageContainer->skipWhiteSpaceWithLineNumberCount(inputStream);
errorMessageContainer->skipWhiteSpaceWithLineNumberCount( inputStream );
while ( !inputStream.atEnd() )
{
QChar currentChar = errorMessageContainer->readCharWithLineNumberCount(inputStream);
QChar currentChar = errorMessageContainer->readCharWithLineNumberCount( inputStream );
if (currentChar == QChar('#'))
if ( currentChar == QChar( '#' ) )
{
errorMessageContainer->skipLineWithLineNumberCount(inputStream);
errorMessageContainer->skipWhiteSpaceWithLineNumberCount(inputStream);
errorMessageContainer->skipLineWithLineNumberCount( inputStream );
errorMessageContainer->skipWhiteSpaceWithLineNumberCount( inputStream );
currentChar = QChar();
}
else if ( currentChar.isSpace() )
{
errorMessageContainer->skipWhiteSpaceWithLineNumberCount(inputStream);
QChar isBracket('a');
isBracket = errorMessageContainer->readCharWithLineNumberCount(inputStream);
if ( isBracket != QChar('(') )
errorMessageContainer->skipWhiteSpaceWithLineNumberCount( inputStream );
QChar isBracket( 'a' );
isBracket = errorMessageContainer->readCharWithLineNumberCount( inputStream );
if ( isBracket != QChar( '(' ) )
{
// Error, could not find start bracket for command
errorMessageContainer->addError("Could not find start bracket for command " + commandName);
errorMessageContainer->addError( "Could not find start bracket for command " + commandName );
return readCommands;
}
break;
}
else if ( currentChar == QChar('(') )
else if ( currentChar == QChar( '(' ) )
{
break;
}
if (!currentChar.isNull())
if ( !currentChar.isNull() )
{
commandName += currentChar;
}
}
}
if (commandName.isEmpty() && inputStream.atEnd())
if ( commandName.isEmpty() && inputStream.atEnd() )
{
// Read past the last command
break;
}
CAF_ASSERT(objectFactory);
caf::PdmObjectHandle* obj = objectFactory->create(commandName);
RicfCommandObject* cObj = dynamic_cast<RicfCommandObject*>(obj);
CAF_ASSERT( objectFactory );
caf::PdmObjectHandle* obj = objectFactory->create( commandName );
RicfCommandObject* cObj = dynamic_cast<RicfCommandObject*>( obj );
if ( cObj == nullptr )
{
errorMessageContainer->addError("The command: \"" + commandName + "\" does not exist.");
errorMessageContainer->addError( "The command: \"" + commandName + "\" does not exist." );
// Error: Unknown command
// Skip to end of command
QChar currentChar;
bool isOutsideQuotes = true;
bool isOutsideQuotes = true;
while ( !inputStream.atEnd() )
{
currentChar = errorMessageContainer->readCharWithLineNumberCount(inputStream);
currentChar = errorMessageContainer->readCharWithLineNumberCount( inputStream );
if ( isOutsideQuotes )
{
if ( currentChar == QChar(')') )
if ( currentChar == QChar( ')' ) )
{
break;
}
if ( currentChar == QChar('\"') )
if ( currentChar == QChar( '\"' ) )
{
isOutsideQuotes = false;
}
}
else
{
if ( currentChar == QChar('\"') )
if ( currentChar == QChar( '\"' ) )
{
isOutsideQuotes = true;
}
if ( currentChar == QChar('\\') )
if ( currentChar == QChar( '\\' ) )
{
currentChar = errorMessageContainer->readCharWithLineNumberCount(inputStream);
currentChar = errorMessageContainer->readCharWithLineNumberCount( inputStream );
}
}
}
}
else
{
readCommands.push_back(cObj);
auto rcfCap = cObj->capability<RicfObjectCapability>();
readCommands.push_back( cObj );
auto rcfCap = cObj->capability<RicfObjectCapability>();
errorMessageContainer->currentCommand = commandName;
rcfCap->readFields(inputStream, objectFactory, errorMessageContainer);
rcfCap->readFields( inputStream, objectFactory, errorMessageContainer );
errorMessageContainer->currentCommand = "";
}
}
@@ -138,19 +138,20 @@ std::vector<RicfCommandObject*> RicfCommandFileReader::readCommands(QTextStream&
}
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
void RicfCommandFileReader::writeCommands(QTextStream& outputStream, const std::vector<RicfCommandObject*>& commandsToWrite)
void RicfCommandFileReader::writeCommands( QTextStream& outputStream,
const std::vector<RicfCommandObject*>& commandsToWrite )
{
for (const auto& cmdObj : commandsToWrite)
for ( const auto& cmdObj : commandsToWrite )
{
auto rcfCap = cmdObj->capability<RicfObjectCapability>();
if (!rcfCap) continue;
if ( !rcfCap ) continue;
outputStream << cmdObj->classKeyword();
outputStream << "(";
rcfCap->writeFields(outputStream);
rcfCap->writeFields( outputStream );
outputStream << ")";
}

View File

@@ -1,17 +1,17 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2017 Statoil ASA
//
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
@@ -25,23 +25,22 @@ class QTextStream;
namespace caf
{
class PdmObjectFactory;
class PdmObjectFactory;
}
class RicfMessages;
//==================================================================================================
//
//
//
//
//==================================================================================================
class RicfCommandFileReader
{
public:
static std::vector<RicfCommandObject*> readCommands(QTextStream& inputStream,
caf::PdmObjectFactory* objectFactory,
RicfMessages* errorMessageContainer);
static std::vector<RicfCommandObject*> readCommands( QTextStream& inputStream,
caf::PdmObjectFactory* objectFactory,
RicfMessages* errorMessageContainer );
static void writeCommands(QTextStream& outputStream,
const std::vector<RicfCommandObject*>& commandsToWrite);
static void writeCommands( QTextStream& outputStream, const std::vector<RicfCommandObject*>& commandsToWrite );
};