Skip to content

Commit

Permalink
Merge pull request #11 from synesthesiam/develop
Browse files Browse the repository at this point in the history
Allow MDM structs to explicity specify their type ids
  • Loading branch information
derekkingston committed Oct 27, 2017
2 parents b703c7a + 54e6141 commit 5660dfa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/avtas/lmcp/lmcpgen/MDM.DTD
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
Extends CDATA ''
Name CDATA #REQUIRED
Series CDATA ''
ID CDATA ''
>

<!--- Enumeration definition -->
Expand Down
20 changes: 19 additions & 1 deletion src/avtas/lmcp/lmcpgen/MDMReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,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;
Expand Down Expand Up @@ -154,6 +166,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");
Expand Down

0 comments on commit 5660dfa

Please sign in to comment.