From f236e4d7401d55d18707ac3374f913ada41e5b7b Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Thu, 9 Apr 2015 16:02:21 +0200 Subject: added serialization support for attributes descriptors. --- src/plugins/xml/XmlOutput.cpp | 45 +++++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 10 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/xml/XmlOutput.cpp b/src/plugins/xml/XmlOutput.cpp index 8c45a52..cdca730 100644 --- a/src/plugins/xml/XmlOutput.cpp +++ b/src/plugins/xml/XmlOutput.cpp @@ -51,7 +51,8 @@ struct TransformParams { }; /* - * These are method declarations to allow for cross-references of methods. + * These are forward method declarations to allow for cross-references of + * methods. */ /* @@ -69,6 +70,18 @@ static Rooted transformOntology(Handle parent, static std::string getTypeRef(Handle referencing, Handle referenced); +static Rooted transformStructTypeEntry(Handle parent, + const std::string &tagName, + Handle t, + Handle a, + TransformParams &P); + +static Rooted transformStructType(Handle parent, + const std::string &structTagName, + const std::string &fieldTagName, + Handle t, + TransformParams &P); + static Rooted transformTypesystem(Handle parent, Handle t, TransformParams &P); @@ -301,7 +314,12 @@ static void transformDescriptor(Handle elem, Handle syntax, { // add name. addNameAttribute(d, elem->getAttributes()); - // TODO: transform the attributes descriptor. + // transform the attributes descriptor. + Rooted attributes = transformStructType( + elem, "attributes", "attribute", d->getAttributesDescriptor(), P); + // remove the parent entry if it is there. + attributes->getAttributes().erase("parent"); + elem->addChild(attributes); // transform the syntactic sugar description. { Rooted open = @@ -434,12 +452,13 @@ std::string getTypeRef(Handle referencing, Handle referenced) } Rooted transformStructTypeEntry(Handle parent, + const std::string &tagName, Handle t, Handle a, TransformParams &P) { // create an xml element for the attribute. - Rooted attribute{new Element(P.mgr, parent, "field")}; + Rooted attribute{new Element(P.mgr, parent, tagName)}; addNameAttribute(a, attribute->getAttributes()); // add the type reference { @@ -451,22 +470,27 @@ Rooted transformStructTypeEntry(Handle parent, attribute->getAttributes().emplace("default", toString(a->getDefaultValue(), P)); } - // set the optional flag. - attribute->getAttributes().emplace("optional", - getStringForBool(a->isOptional())); return attribute; } Rooted transformStructType(Handle parent, + const std::string &structTagName, + const std::string &fieldTagName, Handle t, TransformParams &P) { // create an xml element for the struct type itself. - Rooted structType{new Element(P.mgr, parent, "struct")}; + Rooted structType{new Element(P.mgr, parent, structTagName)}; addNameAttribute(t, structType->getAttributes()); + // transformt the parent reference. + if (t->getParentStructure() != nullptr) { + std::string typeRef = + getTypeRef(t->getTypesystem(), t->getParentStructure()); + structType->getAttributes().emplace("parent", typeRef); + } // transform all attributes. - for (auto &a : t->getAttributes()) { + for (auto &a : t->getOwnAttributes()) { Rooted attribute = - transformStructTypeEntry(structType, t, a, P); + transformStructTypeEntry(structType, fieldTagName, t, a, P); structType->addChild(attribute); } return structType; @@ -504,7 +528,8 @@ Rooted transformTypesystem(Handle parent, for (auto tp : t->getTypes()) { Rooted type; if (tp->isa(&RttiTypes::StructType)) { - type = transformStructType(typesystem, tp.cast(), P); + type = transformStructType(typesystem, "struct", "field", + tp.cast(), P); } else { P.logger.warning(std::string("Type ") + tp->getName() + " can not be serialized, because it is neither a " -- cgit v1.2.3