From 07f5bd313bd08aa8c0193c832b9219f72f2704f7 Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Thu, 9 Apr 2015 16:48:40 +0200 Subject: added support for typesystem constants in serialization. --- src/plugins/xml/XmlOutput.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/plugins/xml') diff --git a/src/plugins/xml/XmlOutput.cpp b/src/plugins/xml/XmlOutput.cpp index e67ec19..80b3af5 100644 --- a/src/plugins/xml/XmlOutput.cpp +++ b/src/plugins/xml/XmlOutput.cpp @@ -514,6 +514,23 @@ static Rooted transformEnumType(Handle parent, return enumType; } +static Rooted transformConstant(Handle parent, + Handle t, + Handle c, TransformParams &P) +{ + // create an xml element for the constant. + Rooted constant{new Element(P.mgr, parent, "constant")}; + addNameAttribute(c, constant->getAttributes()); + // add the type reference + { + std::string typeRef = getTypeRef(t, c->getType()); + constant->getAttributes().emplace("type", typeRef); + } + // add the value + constant->getAttributes().emplace("value", toString(c->getValue(), P)); + return constant; +} + Rooted transformTypesystem(Handle parent, Handle t, TransformParams &P) { @@ -560,6 +577,11 @@ Rooted transformTypesystem(Handle parent, typesystem->addChild(type); } } + // transform all constants. + for (auto c : t->getConstants()) { + Rooted constant = transformConstant(typesystem, t, c, P); + typesystem->addChild(constant); + } // return the transformed Ontology. return typesystem; } -- cgit v1.2.3