From 54e6141217fc5c90c3869ed410f190d298e5c7f4 Mon Sep 17 00:00:00 2001 From: synesthesiam Date: Wed, 25 Oct 2017 16:45:38 -0400 Subject: [PATCH] Allow MDM structs to explicity specify their type ids Added an ID attribute to the Struct tag in the MDM XML. If this attribute is specified, the struct will be assigned that integer id (as opposed to it being based on the XML ordering of the Struct tags). Structs that do not have explicit ID attributes are assigned ids starting from one past the maximum explicit ID, or zero if none are given. This produces the original id assignment behavior if no explicit Struct ID attributes exist (the first struct has id 1, the second 2, etc.). If any struct has ID="N" (where N is the maximum value in the MDM), then all structs without an ID will start at N+1, increasing with their order in the XML. --- src/avtas/lmcp/lmcpgen/MDM.DTD | 1 + src/avtas/lmcp/lmcpgen/MDMReader.java | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/avtas/lmcp/lmcpgen/MDM.DTD b/src/avtas/lmcp/lmcpgen/MDM.DTD index e04b40e..1594c04 100644 --- a/src/avtas/lmcp/lmcpgen/MDM.DTD +++ b/src/avtas/lmcp/lmcpgen/MDM.DTD @@ -43,6 +43,7 @@ Extends CDATA '' Name CDATA #REQUIRED Series CDATA '' + ID CDATA '' > diff --git a/src/avtas/lmcp/lmcpgen/MDMReader.java b/src/avtas/lmcp/lmcpgen/MDMReader.java index cf7ba82..ae2f725 100644 --- a/src/avtas/lmcp/lmcpgen/MDMReader.java +++ b/src/avtas/lmcp/lmcpgen/MDMReader.java @@ -106,9 +106,21 @@ public static MDMInfo getFromXML(Node node) throws Exception { } info.structs = fillStructs(XMLUtil.getList(node, "StructList", "Struct"), info); + + // Determine start ID by looking for the maximum specified ID (0 by default) + for (int i = 0; i < info.structs.length; i++) { + startId = Math.max(startId, info.structs[i].id + 1); + } + + // Assign IDs for structs that do not yet have one + int idOffset = 0; for (int i = 0; i < info.structs.length; i++) { - info.structs[i].id = startId + i; + if (info.structs[i].id < 1) { + info.structs[i].id = startId + idOffset; + idOffset++; + } } + info.enums = fillEnums(XMLUtil.getList(node, "EnumList", "Enum"), info); return info; @@ -152,6 +164,12 @@ public static StructInfo[] fillStructs(Node[] list, MDMInfo mdm) throws Exceptio struct.comment = getComment(list[i]).replaceAll("[\n\r\f]+", ""); } + // Optional explicit ID + String idStr = XMLUtil.getAttribute(list[i], "ID", ""); + if (!idStr.isEmpty()) { + struct.id = Integer.parseInt(idStr); + } + Node[] fieldNodes; fieldNodes = XMLUtil.getChildren(list[i], "Field");