summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/plugins/xml/XmlOutput.cpp19
-rw-r--r--testdata/integration/ontology_serialization/typesystem.in.osml8
-rw-r--r--testdata/integration/ontology_serialization/typesystem.out.osxml14
3 files changed, 37 insertions, 4 deletions
diff --git a/src/plugins/xml/XmlOutput.cpp b/src/plugins/xml/XmlOutput.cpp
index 734c3a5..e67ec19 100644
--- a/src/plugins/xml/XmlOutput.cpp
+++ b/src/plugins/xml/XmlOutput.cpp
@@ -497,6 +497,23 @@ Rooted<Element> transformStructType(Handle<Element> parent,
}
return structType;
}
+
+static Rooted<Element> transformEnumType(Handle<Element> parent,
+ Handle<EnumType> e, TransformParams &P)
+{
+ // create an xml element for the enum type itself.
+ Rooted<Element> enumType{new Element(P.mgr, parent, "enum")};
+ addNameAttribute(e, enumType->getAttributes());
+ // add all entries.
+ for (std::string &name : e->names()) {
+ Rooted<Element> enumEntry{new Element(P.mgr, enumType, "entry")};
+ enumType->addChild(enumEntry);
+ Rooted<Text> enumName{new Text(P.mgr, enumEntry, name)};
+ enumEntry->addChild(enumName);
+ }
+ return enumType;
+}
+
Rooted<Element> transformTypesystem(Handle<Element> parent,
Handle<Typesystem> t, TransformParams &P)
{
@@ -532,6 +549,8 @@ Rooted<Element> transformTypesystem(Handle<Element> parent,
if (tp->isa(&RttiTypes::StructType)) {
type = transformStructType(typesystem, "struct", "field",
tp.cast<StructType>(), P);
+ } else if (tp->isa(&RttiTypes::EnumType)) {
+ type = transformEnumType(typesystem, tp.cast<EnumType>(), P);
} else {
P.logger.warning(std::string("Type ") + tp->getName() +
" can not be serialized, because it is neither a "
diff --git a/testdata/integration/ontology_serialization/typesystem.in.osml b/testdata/integration/ontology_serialization/typesystem.in.osml
index ec61dd3..3adbe2e 100644
--- a/testdata/integration/ontology_serialization/typesystem.in.osml
+++ b/testdata/integration/ontology_serialization/typesystem.in.osml
@@ -3,8 +3,14 @@
\struct#myStruct
\field#i[type=int,default=1]
\field#s[type=string,default=""]
+ \enum#myEnum
+ \entry STRICT
+ \entry FUZZY
+ \entry PROBABILISTIC
\ontology#test
\struct#a[root=true]
+ \attributes
+ \attribute#type[type=myEnum]
\primitive[type=myStruct]
-\a [4,"bla"]
+\a[type=STRICT] [4,"bla"]
diff --git a/testdata/integration/ontology_serialization/typesystem.out.osxml b/testdata/integration/ontology_serialization/typesystem.out.osxml
index a8c02ae..e3652e3 100644
--- a/testdata/integration/ontology_serialization/typesystem.out.osxml
+++ b/testdata/integration/ontology_serialization/typesystem.out.osxml
@@ -3,6 +3,9 @@
<ontology name="test">
<struct cardinality="{*}" name="a" root="true" transparent="false">
<syntax/>
+ <attributes>
+ <attribute name="type" type="bla.myEnum"/>
+ </attributes>
<primitive optional="false" subtree="false" type="bla.myStruct">
<syntax/>
</primitive>
@@ -10,11 +13,16 @@
</ontology>
<typesystem name="bla">
<struct name="myStruct">
- <field default="1" name="i" optional="true" type="int"/>
- <field default="" name="s" optional="true" type="string"/>
+ <field default="1" name="i" type="int"/>
+ <field default="" name="s" type="string"/>
</struct>
+ <enum name="myEnum">
+ <entry>FUZZY</entry>
+ <entry>PROBABILISTIC</entry>
+ <entry>STRICT</entry>
+ </enum>
</typesystem>
- <test:a>[
+ <test:a type="0">[
&quot;i&quot;= 4,
&quot;s&quot;= &quot;bla&quot;
]</test:a>