mirror of
https://github.com/OPM/ResInsight.git
synced 2025-01-26 16:26:48 -06:00
#5749 Python : Add support for std::vector as return value of a function
This commit is contained in:
parent
ead29ef70f
commit
bc56c807c1
@ -146,7 +146,7 @@ public:
|
||||
"Enter some small number here",
|
||||
"This is a place you can enter a small integer value if you want" );
|
||||
|
||||
CAF_PDM_InitField( &m_textField, "TextField", QString( "ÆØÅ Test text end" ), "TextField", "", "Tooltip", "WhatsThis" );
|
||||
CAF_PDM_InitField( &m_textField, "TextField", QString( "<EFBFBD><EFBFBD><EFBFBD> Test text end" ), "TextField", "", "Tooltip", "WhatsThis" );
|
||||
CAF_PDM_InitFieldNoDefault( &m_simpleObjPtrField, "SimpleObjPtrField", "SimpleObjPtrField", "", "Tooltip", "WhatsThis" );
|
||||
CAF_PDM_InitFieldNoDefault( &m_simpleObjPtrField2, "SimpleObjPtrField2", "SimpleObjPtrField2", "", "Tooltip", "WhatsThis" );
|
||||
m_simpleObjPtrField2 = new SimpleObj;
|
||||
@ -191,6 +191,7 @@ public:
|
||||
"Script comment test" );
|
||||
|
||||
CAF_PDM_InitScriptableFieldWithIONoDefault( &m_texts, "Texts", "Some words", "", "", "" );
|
||||
CAF_PDM_InitScriptableFieldWithIONoDefault( &m_numbers, "Numbers", "Some words", "", "", "" );
|
||||
CAF_PDM_InitFieldNoDefault( &m_testEnumField, "TestEnumValue", "An Enum", "", "", "" );
|
||||
CAF_PDM_InitFieldNoDefault( &m_simpleObjectsField,
|
||||
"SimpleObjects",
|
||||
@ -202,7 +203,9 @@ public:
|
||||
|
||||
~InheritedDemoObj() { m_simpleObjectsField.deleteAllChildObjects(); }
|
||||
|
||||
caf::PdmField<std::vector<QString>> m_texts;
|
||||
caf::PdmField<std::vector<QString>> m_texts;
|
||||
caf::PdmField<std::vector<double>> m_numbers;
|
||||
|
||||
caf::PdmField<caf::AppEnum<TestEnumType>> m_testEnumField;
|
||||
caf::PdmChildArrayField<SimpleObj*> m_simpleObjectsField;
|
||||
};
|
||||
@ -248,4 +251,19 @@ TEST( PdmScriptingTest, BasicUse )
|
||||
|
||||
std::unique_ptr<caf::PdmCodeGenerator> generator( caf::PdmCodeGeneratorFactory::instance()->create( fileExt ) );
|
||||
auto generatedText = generator->generate( caf::PdmDefaultObjectFactory::instance() );
|
||||
|
||||
auto string = generatedText.toStdString();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST( PdmScriptingTest, CheckIsVector )
|
||||
{
|
||||
InheritedDemoObj obj;
|
||||
|
||||
auto isVector = obj.m_numbers.xmlCapability()->isVectorField();
|
||||
EXPECT_TRUE( isVector );
|
||||
|
||||
// auto xmlCap = obj.xmlCapability();
|
||||
// auto string = xmlCap->writeObjectToXmlString();
|
||||
}
|
||||
|
@ -133,6 +133,28 @@ private:
|
||||
FieldType* m_field;
|
||||
};
|
||||
|
||||
template < typename DataType>
|
||||
class PdmFieldXmlCap< PdmField<std::vector<DataType>> > : public PdmXmlFieldHandle
|
||||
{
|
||||
typedef PdmField<std::vector<DataType>> FieldType;
|
||||
public:
|
||||
PdmFieldXmlCap(FieldType* field, bool giveOwnership) : PdmXmlFieldHandle(field, giveOwnership)
|
||||
{
|
||||
m_field = field;
|
||||
|
||||
m_dataTypeName = QString("%1").arg(typeid(DataType).name());
|
||||
}
|
||||
|
||||
// Xml Serializing
|
||||
public:
|
||||
void readFieldData(QXmlStreamReader& xmlStream, PdmObjectFactory* objectFactory) override;
|
||||
void writeFieldData(QXmlStreamWriter& xmlStream) const override;
|
||||
bool resolveReferences() override;
|
||||
bool isVectorField() const;
|
||||
private:
|
||||
FieldType* m_field;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -449,4 +449,52 @@ bool caf::PdmFieldXmlCap< caf::PdmChildArrayField<DataType*> >::isVectorField()
|
||||
return true;
|
||||
}
|
||||
|
||||
//==================================================================================================
|
||||
/// XML Implementation for PdmFieldXmlCap<std::vector<DataType>> methods
|
||||
///
|
||||
//==================================================================================================
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename DataType>
|
||||
bool caf::PdmFieldXmlCap<caf::PdmField<std::vector<DataType>>>::isVectorField() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template<typename DataType >
|
||||
void caf::PdmFieldXmlCap<caf::PdmField<std::vector<DataType>>>::readFieldData(QXmlStreamReader& xmlStream,
|
||||
PdmObjectFactory* objectFactory)
|
||||
{
|
||||
this->assertValid();
|
||||
typename FieldType::FieldDataType value;
|
||||
PdmFieldReader<typename FieldType::FieldDataType>::readFieldData(value, xmlStream, objectFactory);
|
||||
m_field->setValue(value);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template<typename DataType >
|
||||
void caf::PdmFieldXmlCap<caf::PdmField<std::vector<DataType>>>::writeFieldData(QXmlStreamWriter& xmlStream) const
|
||||
{
|
||||
this->assertValid();
|
||||
PdmFieldWriter<typename FieldType::FieldDataType>::writeFieldData(m_field->value(), xmlStream);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename DataType>
|
||||
bool caf::PdmFieldXmlCap<caf::PdmField<std::vector<DataType>>>::resolveReferences()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
} // End namespace caf
|
||||
|
Loading…
Reference in New Issue
Block a user