enmlFile /Utilities

ENML is an human readable parsing language which is very similar to INI files. It separates its values into global entity scopes called enml-entities.

ENML objects are very useful for saving specific game data, such as high scores, user data, preferences, and more. It was designed to be very easy and fast to write and to read, by humans or non-humans.

As it may work directly with strings, the programmer may implement his own cryptography algorithm to protect data.

The syntax:

[sample.enml]

// my first entity
theWall
{
    // each attribute's value ends with a ';' character.
    artist = Pink Floyd;
    // use '\;' to write ';' characters into the attribute
    formation = David Gilmour\; Nick Mason\; Roger Waters\; Bob Klose;
    year = 1979;
}

// my second entity
myCar
{
    name = Beetle;
    year = 1978; cc = 1500;
    Manufacturer = Volkswagen;

    // it also supports multi-line values:
    sucessorList = 
        Volkswagen Golf
        Volkswagen Jetta (Sedan)
        Volkswagen New Beetle
        Volkswagen Gol (in Brazil); // don't forget to finish with ';'
}

numbers
{
    pi = 3.1415;
    posX = 1.5;
    myInteger = 13;
}

Loading an ENML file and retrieving data:

const string str = GetStringFromFile(GetResourceDirectory() + "sample.enml");

enmlFile f;
f.parseString(str);
string name = f.get("myCar", "name");
string artist = f.get("theWall", "artist");

double myPi;
f.getDouble("numbers", "pi", myPi);

float posX;
f.getFloat("numbers", "posX", posX);

uint myInteger;
f.getUInt("numbers", "myInteger", myInteger);

Writing an ENML file:

enmlFile f;

enmlEntity entity;
entity.add("class", "rogue");
entity.add("level", "85");
entity.add("name", "Nathan");
f.addEntity("partyMember0", entity);

entity.clear();
entity.add("class", "paladin");
entity.add("level", "71");
entity.add("name", "John");
f.addEntity("partyMember1", entity);

string str = f.generateString();
SaveStringToFile(GetExternalStorageDirectory() + "myFile.txt", str);

The example above will output:

[myFile.txt]

partyMember0
{
    class = rogue;
    level = 85;
    name = Nathan;
}

partyMember1
{
    class = paladin;
    level = 71;
    name = John;
}

Heads up!

Things it cannot do:

  • Can't have trees (entities inside another entity). All entities MUST be global.
  • Values that start with \n return character.
  • Receive attributes with empty values

Remarks:

  • In the files, use '\\' and '\;' to input '\' and ';' characters as value
  • Use '//' for comments. It won't work inside value definitions.