Giter Site home page Giter Site logo

kastork / disenumerations Goto Github PK

View Code? Open in Web Editor NEW

This project forked from open-dis/dis-enumerations

0.0 1.0 0.0 10.36 MB

Some code that can generate enumeration/constants to ease the human reading of code. Currently uses out of date XML that should be fixed.

License: BSD 2-Clause "Simplified" License

Makefile 0.01% XSLT 2.43% C# 10.52% C++ 23.29% Java 11.97% TSQL 51.78%

disenumerations's Introduction

DIS Enumeration

This is older, essentially obsolete software, but the the product generated is still somewhat useful.

What happened was SISO did an initial description of DIS entities in siso-std-10.xml, which contains names and descriptions to accompany arbitrary numbers. The problem is that the format of the code here should be rewritten to match the new XML format used by SISO. But, in the end, it's kind of useful as is.

This is what tXML looked like for PDU types, for example:

 <enum length="8" id="2" cname="pduheader.pdutype" name="PDU Type" source="3.2">
    <enumrow id="0" description="Other"/>
    <enumrow id="1" description="Entity State"/>
    <enumrow id="2" description="Fire"/>
    <enumrow id="3" description="Detonation"/>
    <enumrow id="4" description="Collision"/>
    <enumrow id="5" description="Service Request"/>

That shows some English, "Entity State," associated with the number 1, meaning that all entity state PDUs should have an ID number of 1. It's the number that's actually included in the packet transmitted over the network or DIS code.

We want language constants that let us use english-like, but also code-friendly variable names that help us read code. This, for example, is not very readable:


if(aPdu.type == 1)
{
   doSomething();
}

What does 1 mean? The following is easier to read:

if(aPdu.type == PduType.ENTITY_STATE.value)
{
  doSomething();
}

It's easier to understand the purpose of the code in the second quotation.

An example Java enumeration file used for enumerataion values

public enum PduType 
{

    OTHER(0, "Other"),
    ENTITY_STATE(1, "Entity State"),
    FIRE(2, "Fire"),
    DETONATION(3, "Detonation"),
    COLLISION(4, "Collision"),
    SERVICE_REQUEST(5, "Service Request"),
    RESUPPLY_OFFER(6, "Resupply Offer"),
...  
    /** The enumerated value */
    public final int value;

    /** Text/english description of the enumerated value */
    public final String description;

And so on. In this case the XML includes the text "Entity State", including the space. That's translated into a Java-friendly variable name, entirely capitalized, with no spaces in the ENTITY_STATE name. Other examples of the text from the XML can include commas and such. The generating code translates it into language-firendly text. The constant name used, such as "ENTITY_STATE", is somewhat arbitrary.

Again, the XML format from SISO has changed some since this code has been written, so the code needs to be modified a bit.

Also, I've added a non-generated PduTypeDIS7 file manually, rather than generating it. DIS7 has some slightly different names for some PDUs, kind of, since the PDU names aren't exactly official. There's no XML to generated it, but it's still useful to have the PDU types enumeration for DIS7. So I just wrote a manual DIS7 class for that.

Also, there are some generated enumerations for C# and c++. Pretty primitive, though.

DMcG

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.