codespawn 0.3.3

C++ and Rust code generator. Supports XML and JSON for API definitions.
Documentation
<!-- 
     Sample API v0.1.5 that generates code with all supported features.
-->
<?xml version="1.0" encoding="utf-8" ?>

<!-- <config />: Include an optional config file with type and name redefinitions.
                 You can include as many configs as you want.
     
     * Required attributes: 
        - file - Path to config file.
     * Optional attributes: none
     * Valid children: none
-->
<!-- Include config file for Rust -->
<config name="examples/config.xml" />

<!-- <var />: Generate a single variable. If nested by <func> tags, the variable
            becomes the function's input parameter. 
            
    * Required attributes:
        - type  - Type of the variable. Tag will be ignored in generated code if
                  'type' is overriden to "" in language config (see ellipsis example).
        - name  - Variable name. Requried for standalone variables, optional for function parameters.
    * Optional attributes:
        - value     - Initialization value for the variable or a default value for function parameter.
        - qualifier - Variable's qualifier (extern, static, etc.)
    * Valid children:
        - <fptr />  - If <var /> is a function parameter, it can nest a <fptr /> which will
                      then be interpreted as the actual parameter. In this case, <var /> requires
                      no atributes.
-->
<!-- variable: extern void* void_ptr;  -->
<var type="void*" name="void_ptr" qualifier="extern" />

<!-- variable: int some_number = 1;  -->
<var type="int" name="some_number" value="1" />

<!-- ignored variable - no type specified -->
<var name="ignored_var" />

<!-- <enum></enum>: Generate an enumerator. 

    * Required attributes:
      - name - Enum name.
    * Optional attributes:
      - attribute - Adds an attribute/decorator to the enum. Ignored by C++.
    * Valid children:
      - <attribute /> - Adds an attribute/decorator to the enum. Use it if you want to
                        define multiple attributes.
      - <var /> - Enumerator field. All fields except 'name' are optional.
                  If 'type' is specified, it will be ignored by C++ and interpreted
                  by Rust as a typecast.
-->
<!-- enum: (attribute and var types will be used only by Rust)
    enum GenericEnum {
        EnumVal1,
        EnumVal2,
        Count = 2,
    };
-->
<enum name="GenericEnum">
    <attribute name="C-ABI" />
    <attribute name="DERIVE-DBG" />
    <var name="EnumVal1" type="int" />
    <var name="EnumVal2" type="int" />
    <var name="Count" value="2" type="int" />
</enum>

<!-- <bitflags></bitflags>: Generate a bitflag enumerator. This is a type
     native to Rust language, when C++ is generated, it will create a standard enum.     

    * Required attributes:
      - name - Bitflags name.
      - type - Underlying data type.
    * Optional attributes:
      - attribute - Adds an attribute/decorator to bitflags.
    * Valid children:
      - <attribute /> - Adds an attribute/decorator to bitflags. Use it if you want to
                        define multiple attributes.
      - <var /> - Bitflag numerator field. All fields except 'name' and 'value' are optional.
                  If 'type' is specified, it will be ignored by C++ and interpreted
                  by Rust as a typecast.
-->
<!-- bitflags: 
//generated C++ code
    enum SampleBitflags {
        Field1 = 1,
        Field2 = 2,
    };

//generated Rust code
bitflags! {
    #[repr(C)]
    #[derive(Debug)]
    flags SampleBitflags: c_int {
        const FIELD1 = 1 as c_int,
        const FIELD2 = 2 as c_int,
    }
}
-->
<bitflags name="SampleBitflags" type="int">
    <attribute name="C-ABI" />
    <attribute name="DERIVE-DBG" />
    <var name="Field1" type="int" value="1" />
    <var name="Field2" type="int" value="2" />
</bitflags>

<!-- alternative bitflags example -->

<bitflags name="AltBitflags" type="int" attribute="C-ABI">
    <var name="C_Field1" type="int" value="1" />
</bitflags>

<!-- <func></func>: Generate a function.

    * Required attributes:
      - type - Function's return type.
      - name - Name of the function.
    * Optional attributes:
      - qualifier - Function's qualifier (extern, static, etc.).
    * Valid children:
      - <var />  - Function patameter. Name is optional in this case. Function will take no
                   parameters if no <var />'s are defined.
      - <fptr /> - Function parameter expressed as a function pointer.
-->
<!-- function: int get_ascii(char& letter, bool (*callback)(int code)); -->
<func type="int" name="get_ascii"> 
    <var type="char&amp;" name="letter" />
    <fptr type="bool" name="callback">
        <var type="int" name="code" />
    </fptr>
</func>

<!-- function: int get_ascii_alt(char& letter, bool (*callback)(int code)); -->
<!-- Alternative way of defining a <fptr /> as a function parameter -->
<func type="int" name="get_ascii_alt"> 
    <var type="char&amp;" name="letter" />
    <var>
        <fptr type="bool" name="callback">
            <var type="int" name="code" />
        </fptr>
    </var>
</func>

<!-- function: static void process_func(); -->
<func type="void" name="process_func" qualifier="static" />

<!-- function: void func_ellipsis(const char* str, ...); -->
<func type="void" name="func_ellipsis">
    <var type="const char*" name="str" />
    <var type="..." />
    <var name="ignored_var" /> <!-- no type specified - variable will be ignored -->
</func>

<!-- <fptr></fptr>: Generate a function pointer.

    * Required attributes:
      - type - Function pointer's return type.
      - name - Name of the function pointer.
    * Optional attributes:
      - qualifier - Function pointer's qualifier (extern, static, etc.).
    * Valid children:
      - <var />  - Function patameter. Name is optional in this case. Fptr will take no
                   parameters if no <var />'s are defined.
      - <fptr /> - Function parameter expressed as a function pointer.
-->

<!-- function pointer: int (*func_ptr)(); -->
<fptr type="int" name="func_ptr" />

<!-- function pointer: void (*f_ptr)(const int* fmt, void (*fptr_arg)(char&)); -->
<fptr type="void" name="f_ptr">
    <var type="const int*" name="fmt" />
    <fptr type="void" name="fptr_arg">
        <var type="char&amp;" />
    </fptr>
</fptr>

<!-- <struct></struct>: Generate a structure.

    * Required attributes:
        name - Struct name.
    * Optional attributes: 
        attribute - Adds an attribute/decorator to the struct. Ignored by C++.
    * Valid children:
        - <attribute /> (see enum for description)
        - <var />
        - <func />
        - <fptr />
        - <enum />
        - <struct />
-->
<!-- Generate a structure with nested elements -->
<struct name="GenericStruct">
    <attribute name="C-ABI" />
    <attribute name="DERIVE-DBG" />
    <var type="int" name="x" />
    <var type="int" name="y" />
    <var type="int" name="opt_var" qualifier="OPTION" />
    <func type="int" name="return_int">
        <var type="float" name="arg" />
        <fptr type="float" name="opt_func" qualifier="OPTION_FPTR" />
    </func>
    <fptr type="void" name="internal_ptr">
        <var type="const char*" name="arg" />
    </fptr>
    <fptr type="void" name="opt_fptr" qualifier="OPTION_FPTR">
        <var type="const char*" name="arg" />
    </fptr>
    <struct name="SubStruct" attribute="C-ABI">
        <enum name="SubEnum" attribute="DERIVE-DBG">
            <var name="SubElement1" />
            <var name="SubElement2" />
        </enum>
        <func qualifier="static" type="char" name="do_magic" >
            <var type="int" name="magic_number" value="42" />
        </func>
    </struct>
</struct>

<!-- unsupported items will be ignored -->
<some_item name="unsupported" type="whatever" />