mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#10713 Add flag used to detect if resolveReferences is called from initAfterRead
This commit is contained in:
@@ -15,6 +15,8 @@ PdmObjectHandle::PdmObjectHandle()
|
||||
{
|
||||
m_parentField = nullptr;
|
||||
m_isDeletable = false;
|
||||
|
||||
m_isInsideInitAfterRead = false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -159,6 +159,11 @@ private:
|
||||
std::set<PdmObjectHandle**> m_pointersReferencingMe;
|
||||
|
||||
bool m_isDeletable;
|
||||
|
||||
// m_isInsideInitAfterRead is used to detect if resolveReferencesRecursively() is called from initAfterRead()
|
||||
// Use friend class to avoid public noise
|
||||
friend class PdmXmlObjectHandle;
|
||||
bool m_isInsideInitAfterRead;
|
||||
};
|
||||
} // namespace caf
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include "cafPdmFieldHandle.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QXmlStreamReader>
|
||||
#include <QXmlStreamWriter>
|
||||
|
||||
@@ -341,6 +342,9 @@ void PdmXmlObjectHandle::initAfterReadRecursively( PdmObjectHandle* object )
|
||||
{
|
||||
if ( object == nullptr ) return;
|
||||
|
||||
// Set flag to be able to detect if resolveReferencesRecursively() is called from initAfterRead()
|
||||
object->m_isInsideInitAfterRead = true;
|
||||
|
||||
std::vector<PdmFieldHandle*> fields = object->fields();
|
||||
|
||||
std::vector<PdmObjectHandle*> children;
|
||||
@@ -365,6 +369,16 @@ void PdmXmlObjectHandle::initAfterReadRecursively( PdmObjectHandle* object )
|
||||
{
|
||||
xmlObject->initAfterRead();
|
||||
}
|
||||
|
||||
object->m_isInsideInitAfterRead = false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmXmlObjectHandle::initAfterReadRecursively()
|
||||
{
|
||||
initAfterReadRecursively( this->m_owner );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -375,6 +389,34 @@ void PdmXmlObjectHandle::resolveReferencesRecursively( PdmObjectHandle*
|
||||
{
|
||||
if ( object == nullptr ) return;
|
||||
|
||||
assert( !object->m_isInsideInitAfterRead );
|
||||
if ( object->m_isInsideInitAfterRead )
|
||||
{
|
||||
// In release, the assert above is not triggered, but the resolving might still fail.
|
||||
// In RelWithDebInfo, the following message will be available from the debug output window
|
||||
|
||||
QString text =
|
||||
"Calling resolveReferencesRecursively() from initAfterRead() is not supported, "
|
||||
"as the object model might not be complete. If the object model is incomplete, the resolving might "
|
||||
"fail and assign a null pointer to the pointer field.";
|
||||
|
||||
qDebug() << text;
|
||||
|
||||
std::vector<PdmFieldHandle*> fields = object->fields();
|
||||
if ( !fields.empty() )
|
||||
{
|
||||
text = " Field keywords: ";
|
||||
|
||||
for ( auto f : fields )
|
||||
{
|
||||
text += f->keyword() + ", ";
|
||||
}
|
||||
}
|
||||
qDebug() << text;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<PdmFieldHandle*> fields = object->fields();
|
||||
|
||||
std::vector<PdmObjectHandle*> children;
|
||||
@@ -455,6 +497,14 @@ void PdmXmlObjectHandle::setupBeforeSaveRecursively( PdmObjectHandle* object )
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmXmlObjectHandle::setupBeforeSaveRecursively()
|
||||
{
|
||||
setupBeforeSaveRecursively( this->m_owner );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Implementation of xmlCapability() defined in cafPdmObjectHandle.h
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -51,8 +51,8 @@ public:
|
||||
/// Check if a string is a valid Xml element name
|
||||
static bool isValidXmlElementName( const QString& name );
|
||||
|
||||
void initAfterReadRecursively() { initAfterReadRecursively( this->m_owner ); };
|
||||
void setupBeforeSaveRecursively() { setupBeforeSaveRecursively( this->m_owner ); };
|
||||
void initAfterReadRecursively();
|
||||
void setupBeforeSaveRecursively();
|
||||
|
||||
// Never call resolveReferencesRecursively() from initAfterRead(), as the document is not fully imported and the
|
||||
// resolving might fail. The object needs to be fully inserted into the document before resolving references.
|
||||
|
||||
Reference in New Issue
Block a user