diff options
author | Benjamin Paassen <bpaassen@techfak.uni-bielefeld.de> | 2015-04-09 16:48:40 +0200 |
---|---|---|
committer | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2016-04-25 22:19:35 +0200 |
commit | 07f5bd313bd08aa8c0193c832b9219f72f2704f7 (patch) | |
tree | 6c28f685d29a98186062466667f15ea3955c6f37 | |
parent | b6aefe3e510766001415cf711fbf21ae465e4657 (diff) |
added support for typesystem constants in serialization.
-rw-r--r-- | src/plugins/xml/XmlOutput.cpp | 22 | ||||
-rw-r--r-- | testdata/integration/ontology_serialization/typesystem.in.osml | 6 | ||||
-rw-r--r-- | testdata/integration/ontology_serialization/typesystem.out.osxml | 8 |
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, + "bla" +]"/> </typesystem> <test:a type="0">[ "i"= 4, |