summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/plugins/xml/XmlOutput.cpp22
-rw-r--r--testdata/integration/ontology_serialization/typesystem.in.osml6
-rw-r--r--testdata/integration/ontology_serialization/typesystem.out.osxml8
3 files changed, 33 insertions, 3 deletions
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<Element> transformEnumType(Handle<Element> parent,
return enumType;
}
+static Rooted<Element> transformConstant(Handle<Element> parent,
+ Handle<Typesystem> t,
+ Handle<Constant> c, TransformParams &P)
+{
+ // create an xml element for the constant.
+ Rooted<Element> 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<Element> transformTypesystem(Handle<Element> parent,
Handle<Typesystem> t, TransformParams &P)
{
@@ -560,6 +577,11 @@ Rooted<Element> transformTypesystem(Handle<Element> parent,
typesystem->addChild(type);
}
}
+ // transform all constants.
+ for (auto c : t->getConstants()) {
+ Rooted<Element> constant = transformConstant(typesystem, t, c, P);
+ typesystem->addChild(constant);
+ }
// return the transformed Ontology.
return typesystem;
}
diff --git a/testdata/integration/ontology_serialization/typesystem.in.osml b/testdata/integration/ontology_serialization/typesystem.in.osml
index 3adbe2e..1f0ccd5 100644
--- a/testdata/integration/ontology_serialization/typesystem.in.osml
+++ b/testdata/integration/ontology_serialization/typesystem.in.osml
@@ -1,8 +1,10 @@
\document
\typesystem#bla
- \struct#myStruct
+ \struct#myParentStruct
\field#i[type=int,default=1]
+ \struct#myStruct[parent=myParentStruct]
\field#s[type=string,default=""]
+ \constant#C[type=myStruct, value=[4,"bla"]]
\enum#myEnum
\entry STRICT
\entry FUZZY
@@ -13,4 +15,4 @@
\attribute#type[type=myEnum]
\primitive[type=myStruct]
-\a[type=STRICT] [4,"bla"]
+\a[type=STRICT] C
diff --git a/testdata/integration/ontology_serialization/typesystem.out.osxml b/testdata/integration/ontology_serialization/typesystem.out.osxml
index e3652e3..a822191 100644
--- a/testdata/integration/ontology_serialization/typesystem.out.osxml
+++ b/testdata/integration/ontology_serialization/typesystem.out.osxml
@@ -12,8 +12,10 @@
</struct>
</ontology>
<typesystem name="bla">
- <struct name="myStruct">
+ <struct name="myParentStruct">
<field default="1" name="i" type="int"/>
+ </struct>
+ <struct name="myStruct" parent="myParentStruct">
<field default="" name="s" type="string"/>
</struct>
<enum name="myEnum">
@@ -21,6 +23,10 @@
<entry>PROBABILISTIC</entry>
<entry>STRICT</entry>
</enum>
+ <constant name="C" type="myStruct" value="[
+ 4,
+ &quot;bla&quot;
+]"/>
</typesystem>
<test:a type="0">[
&quot;i&quot;= 4,