mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-10 07:26:03 -06:00
#1665 Add support for reading enums and lists as parameters in batch command file
This commit is contained in:
parent
3bbc1c9885
commit
df1eb2a962
@ -21,6 +21,8 @@
|
|||||||
#include "RicfFieldHandle.h"
|
#include "RicfFieldHandle.h"
|
||||||
#include "RicfMessages.h"
|
#include "RicfMessages.h"
|
||||||
|
|
||||||
|
#include "cafAppEnum.h"
|
||||||
|
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
@ -63,6 +65,102 @@ struct RicfFieldWriter<QString>
|
|||||||
static void writeFieldData(const QString & fieldValue, QTextStream& outputStream);
|
static void writeFieldData(const QString & fieldValue, QTextStream& outputStream);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
struct RicfFieldReader< caf::AppEnum<T> >
|
||||||
|
{
|
||||||
|
static void readFieldData(caf::AppEnum<T>& fieldValue, QTextStream& inputStream, RicfMessages* errorMessageContainer)
|
||||||
|
{
|
||||||
|
errorMessageContainer->skipWhiteSpaceWithLineNumberCount(inputStream);
|
||||||
|
QString accumulatedFieldValue;
|
||||||
|
QChar nextChar;
|
||||||
|
QChar currentChar;
|
||||||
|
while (!inputStream.atEnd())
|
||||||
|
{
|
||||||
|
nextChar = errorMessageContainer->peekNextChar(inputStream);
|
||||||
|
if (nextChar.isLetterOrNumber() || nextChar == QChar('_'))
|
||||||
|
{
|
||||||
|
currentChar = errorMessageContainer->readCharWithLineNumberCount(inputStream);
|
||||||
|
accumulatedFieldValue += currentChar;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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 + "\"");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
struct RicfFieldWriter< caf::AppEnum<T> >
|
||||||
|
{
|
||||||
|
static void writeFieldData(const caf::AppEnum<T>& fieldValue, QTextStream& outputStream)
|
||||||
|
{
|
||||||
|
outputStream << fieldValue;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
struct RicfFieldReader< std::vector<T> >
|
||||||
|
{
|
||||||
|
static void readFieldData(std::vector<T>& fieldValue, QTextStream& inputStream, RicfMessages* errorMessageContainer)
|
||||||
|
{
|
||||||
|
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(']'))
|
||||||
|
{
|
||||||
|
nextChar = errorMessageContainer->readCharWithLineNumberCount(inputStream);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (nextChar == QChar(','))
|
||||||
|
{
|
||||||
|
nextChar = errorMessageContainer->readCharWithLineNumberCount(inputStream);
|
||||||
|
errorMessageContainer->skipWhiteSpaceWithLineNumberCount(inputStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
typename T value;
|
||||||
|
RicfFieldReader<typename T>::readFieldData(value, inputStream, errorMessageContainer);
|
||||||
|
fieldValue.push_back(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
errorMessageContainer->addError("Array argument is missing start '['. "
|
||||||
|
+ errorMessageContainer->currentArgument + "\" argument of the command: \""
|
||||||
|
+ errorMessageContainer->currentCommand + "\"" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
struct RicfFieldWriter< std::vector<T> >
|
||||||
|
{
|
||||||
|
static void writeFieldData(const std::vector<T>& fieldValue, QTextStream& outputStream)
|
||||||
|
{
|
||||||
|
outputStream << "[";
|
||||||
|
for (size_t i = 0; i < fieldValue.size(); ++i)
|
||||||
|
{
|
||||||
|
RicfFieldWriter<typename T>::writeFieldData(fieldValue[i], outputStream);
|
||||||
|
if (i < fieldValue.size() - 1)
|
||||||
|
{
|
||||||
|
outputStream << ", ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
outputStream << "]";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//==================================================================================================
|
//==================================================================================================
|
||||||
|
Loading…
Reference in New Issue
Block a user