Implementing agnostic version of ParameterGrp for reading XML, replacing XMLReader from src/Base/reader.cpp with new class DocumentReader
This commit is contained in:
@@ -30,6 +30,7 @@
|
||||
|
||||
#include "Property.h"
|
||||
#include "PropertyContainer.h"
|
||||
#include <Base/DocumentReader.h>
|
||||
|
||||
|
||||
FC_LOG_LEVEL_INIT("App",true,true)
|
||||
@@ -402,6 +403,103 @@ void PropertyContainer::Restore(Base::XMLReader &reader)
|
||||
reader.readEndElement("Properties");
|
||||
}
|
||||
|
||||
void PropertyContainer::Restore(Base::DocumentReader &reader)
|
||||
{
|
||||
//TODO NOW
|
||||
Base::Console().Error("PropertyContainer::Restore: DocumentReader\n");
|
||||
reader.clearPartialRestoreProperty();
|
||||
/*
|
||||
reader.clearPartialRestoreProperty();
|
||||
reader.readElement("Properties");
|
||||
int Cnt = reader.getAttributeAsInteger("Count");
|
||||
|
||||
int transientCount = 0;
|
||||
if(reader.hasAttribute("TransientCount"))
|
||||
transientCount = reader.getAttributeAsUnsigned("TransientCount");
|
||||
|
||||
for (int i=0;i<transientCount; ++i) {
|
||||
reader.readElement("_Property");
|
||||
Property* prop = getPropertyByName(reader.getAttribute("name"));
|
||||
if(prop)
|
||||
FC_TRACE("restore transient '" << prop->getName() << "'");
|
||||
if(prop && reader.hasAttribute("status"))
|
||||
prop->setStatusValue(reader.getAttributeAsUnsigned("status"));
|
||||
}
|
||||
|
||||
for (int i=0 ;i<Cnt ;i++) {
|
||||
reader.readElement("Property");
|
||||
std::string PropName = reader.getAttribute("name");
|
||||
std::string TypeName = reader.getAttribute("type");
|
||||
// NOTE: We must also check the type of the current property because a
|
||||
// subclass of PropertyContainer might change the type of a property but
|
||||
// not its name. In this case we would force to read-in a wrong property
|
||||
// type and the behaviour would be undefined.
|
||||
try {
|
||||
auto prop = getPropertyByName(PropName.c_str());
|
||||
if(!prop || prop->getContainer() != this)
|
||||
prop = dynamicProps.restore(*this,PropName.c_str(),TypeName.c_str(),reader);
|
||||
|
||||
decltype(Property::StatusBits) status;
|
||||
if(reader.hasAttribute("status")) {
|
||||
status = decltype(status)(reader.getAttributeAsUnsigned("status"));
|
||||
if(prop)
|
||||
prop->setStatusValue(status.to_ulong());
|
||||
}
|
||||
// name and type match
|
||||
if (prop && strcmp(prop->getTypeId().getName(), TypeName.c_str()) == 0) {
|
||||
if (!prop->testStatus(Property::Transient)
|
||||
&& !status.test(Property::Transient)
|
||||
&& !status.test(Property::PropTransient)
|
||||
&& !prop->testStatus(Property::PropTransient))
|
||||
{
|
||||
FC_TRACE("restore property '" << prop->getName() << "'");
|
||||
prop->Restore(reader);
|
||||
}else
|
||||
FC_TRACE("skip transient '" << prop->getName() << "'");
|
||||
}
|
||||
// name matches but not the type
|
||||
else if (prop) {
|
||||
handleChangedPropertyType(reader, TypeName.c_str(), prop);
|
||||
}
|
||||
// name doesn't match, the sub-class then has to know
|
||||
// if the property has been renamed or removed
|
||||
else {
|
||||
handleChangedPropertyName(reader, TypeName.c_str(), PropName.c_str());
|
||||
}
|
||||
|
||||
if (reader.testStatus(Base::XMLReader::ReaderStatus::PartialRestoreInProperty)) {
|
||||
Base::Console().Error("Property %s of type %s was subject to a partial restore.\n",PropName.c_str(),TypeName.c_str());
|
||||
reader.clearPartialRestoreProperty();
|
||||
}
|
||||
}
|
||||
catch (const Base::XMLParseException&) {
|
||||
throw; // re-throw
|
||||
}
|
||||
catch (const Base::RestoreError &) {
|
||||
reader.setPartialRestore(true);
|
||||
reader.clearPartialRestoreProperty();
|
||||
Base::Console().Error("Property %s of type %s was subject to a partial restore.\n",PropName.c_str(),TypeName.c_str());
|
||||
}
|
||||
catch (const Base::Exception &e) {
|
||||
Base::Console().Error("%s\n", e.what());
|
||||
}
|
||||
catch (const std::exception &e) {
|
||||
Base::Console().Error("%s\n", e.what());
|
||||
}
|
||||
catch (const char* e) {
|
||||
Base::Console().Error("%s\n", e);
|
||||
}
|
||||
#ifndef FC_DEBUG
|
||||
catch (...) {
|
||||
Base::Console().Error("PropertyContainer::Restore: Unknown C++ exception thrown\n");
|
||||
}
|
||||
#endif
|
||||
reader.readEndElement("Property");
|
||||
}
|
||||
reader.readEndElement("Properties");
|
||||
*/
|
||||
}
|
||||
|
||||
void PropertyContainer::onPropertyStatusChanged(const Property &prop, unsigned long oldStatus)
|
||||
{
|
||||
(void)prop;
|
||||
|
||||
Reference in New Issue
Block a user