2015-07-29 07:19:43 -05:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "cafPdmObjectCapability.h"
|
|
|
|
|
|
|
|
#include <QString>
|
|
|
|
|
2019-10-09 02:21:28 -05:00
|
|
|
#include <list>
|
2018-12-04 07:10:18 -06:00
|
|
|
#include <vector>
|
|
|
|
|
2015-07-29 07:19:43 -05:00
|
|
|
class QXmlStreamReader;
|
|
|
|
class QXmlStreamWriter;
|
|
|
|
|
|
|
|
|
|
|
|
namespace caf
|
|
|
|
{
|
|
|
|
|
|
|
|
class PdmXmlFieldHandle;
|
|
|
|
class PdmObjectHandle;
|
|
|
|
class PdmObjectFactory;
|
|
|
|
class PdmReferenceHelper;
|
2018-12-04 07:10:18 -06:00
|
|
|
class PdmFieldHandle;
|
2015-07-29 07:19:43 -05:00
|
|
|
|
|
|
|
|
|
|
|
//==================================================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//==================================================================================================
|
|
|
|
class PdmXmlObjectHandle : public PdmObjectCapability
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
PdmXmlObjectHandle(PdmObjectHandle* owner, bool giveOwnership);
|
2018-10-18 09:35:51 -05:00
|
|
|
~PdmXmlObjectHandle() override { }
|
2015-07-29 07:19:43 -05:00
|
|
|
|
|
|
|
/// The classKeyword method is overridden in subclasses by the CAF_PDM_XML_HEADER_INIT macro
|
2016-12-09 14:04:16 -06:00
|
|
|
virtual QString classKeyword() const = 0;
|
2020-02-21 04:01:08 -06:00
|
|
|
virtual bool matchesClassKeyword(const QString& classKeyword) const = 0;
|
2015-07-29 07:19:43 -05:00
|
|
|
|
|
|
|
/// Convenience methods to serialize/de-serialize this particular object (with children)
|
|
|
|
void readObjectFromXmlString(const QString& xmlString, PdmObjectFactory* objectFactory);
|
2016-12-09 14:04:16 -06:00
|
|
|
QString writeObjectToXmlString() const;
|
2019-11-14 13:48:11 -06:00
|
|
|
static PdmObjectHandle* readUnknownObjectFromXmlString(const QString& xmlString, PdmObjectFactory* objectFactory, bool isCopyOperation);
|
2015-10-23 02:00:17 -05:00
|
|
|
PdmObjectHandle* copyByXmlSerialization(PdmObjectFactory* objectFactory);
|
2018-10-23 09:32:40 -05:00
|
|
|
PdmObjectHandle* copyAndCastByXmlSerialization(const QString& destinationClassKeyword,
|
|
|
|
const QString& sourceClassKeyword,
|
|
|
|
PdmObjectFactory* objectFactory);
|
2015-07-29 07:19:43 -05:00
|
|
|
|
|
|
|
// Main XML serialization methods that is used internally by the document serialization system
|
|
|
|
// Not supposed to be used directly.
|
2019-11-14 13:48:11 -06:00
|
|
|
void readFields(QXmlStreamReader& inputStream, PdmObjectFactory* objectFactory, bool isCopyOperation);
|
2016-12-09 14:04:16 -06:00
|
|
|
void writeFields(QXmlStreamWriter& outputStream) const;
|
2015-07-29 07:19:43 -05:00
|
|
|
|
|
|
|
/// Check if a string is a valid Xml element name
|
|
|
|
static bool isValidXmlElementName(const QString& name);
|
|
|
|
|
2015-08-27 04:43:27 -05:00
|
|
|
void initAfterReadRecursively() { initAfterReadRecursively(this->m_owner); };
|
|
|
|
void setupBeforeSaveRecursively() { setupBeforeSaveRecursively(this->m_owner); };
|
2018-12-04 07:10:18 -06:00
|
|
|
|
|
|
|
void resolveReferencesRecursively(std::vector<PdmFieldHandle*>* fieldWithFailingResolve = nullptr);
|
2020-02-18 01:11:22 -06:00
|
|
|
bool inheritsClassWithKeyword(const QString& testClassKeyword) const;
|
|
|
|
|
|
|
|
const std::list<QString>& classInheritanceStack() const;
|
2015-07-29 07:19:43 -05:00
|
|
|
protected: // Virtual
|
|
|
|
/// Method gets called from PdmDocument after all objects are read.
|
|
|
|
/// Re-implement to set up internal pointers etc. in your data structure
|
|
|
|
virtual void initAfterRead() {};
|
|
|
|
/// Method gets called from PdmDocument before saving document.
|
|
|
|
/// Re-implement to make sure your fields have correct data before saving
|
|
|
|
virtual void setupBeforeSave() {};
|
|
|
|
|
|
|
|
/// This method is intended to be used in macros to make compile time errors
|
|
|
|
// if user uses them on wrong type of objects
|
|
|
|
bool isInheritedFromPdmXmlSerializable() { return true; }
|
|
|
|
|
2019-10-09 02:21:28 -05:00
|
|
|
void registerClassKeyword(const QString& registerKeyword);
|
|
|
|
|
2015-08-27 04:43:27 -05:00
|
|
|
private:
|
|
|
|
void initAfterReadRecursively(PdmObjectHandle* object);
|
|
|
|
void setupBeforeSaveRecursively(PdmObjectHandle * object);
|
2018-12-04 07:10:18 -06:00
|
|
|
void resolveReferencesRecursively(PdmObjectHandle* object, std::vector<PdmFieldHandle*>* fieldWithFailingResolve);
|
2015-08-27 04:43:27 -05:00
|
|
|
|
2015-07-29 07:19:43 -05:00
|
|
|
private:
|
|
|
|
friend class PdmObjectHandle ; // Only temporary for void PdmObject::addFieldNoDefault( ) accessing findField
|
|
|
|
|
2019-10-09 02:26:30 -05:00
|
|
|
std::list<QString> m_classInheritanceStack;
|
2019-10-09 02:21:28 -05:00
|
|
|
PdmObjectHandle* m_owner;
|
2015-07-29 07:19:43 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
PdmXmlObjectHandle* xmlObj(PdmObjectHandle* obj);
|
|
|
|
|
|
|
|
} // End of namespace caf
|
|
|
|
|
|
|
|
#include "cafPdmXmlFieldHandle.h"
|