Skip to content
dale-wilson edited this page Dec 8, 2014 · 2 revisions

Generating C++ classes from XML templates using fast_type_gen.

The fast_type_gen tool is located under the $MFAST_BUILD_DIR/bin directory. It takes a list of FAST XML files and generates C++ files for each of them.

##Command line Examples

The command line:

$MFAST_BUILD_DIR/bin/fast_type_gen test1.xml

will generate three files using the base name from the template file. Thus the above command will generate test1.h, test1.inl, and test1.cpp.

The C++ namespace used in the generated C++ classes will also be the base filename of the xml template.

If more than one template file is included on the fast_type_gen command line, for example:

$MFAST_BUILD_DIR/bin/fast_type_gen test1.xml test2.xml

then three separate files will be generated for each template file.

##Dependencies due to static templateRef elements.

If your input XML specification files have dependencies among them, all input files must be generated at once. An input FAST specification file A is only dependent on another file B if and only if B contains a static templateRef where the name of templateRef is only defined in A.

For example if input2.xml contains a static templateRef that refers to a template defined in input1.xml then both files must appear on the same fast_type_gen command line like this:

$MFAST_BUILD_DIR/bin/fast_type_gen input1.xml input2.xml

The files may appear in either order on the command line, but you cannot parse them separately like this:

$MFAST_BUILD_DIR/bin/fast_type_gen input1.xml
$MFAST_BUILD_DIR/bin/fast_type_gen input2.xml

In addition, fast_type_gen cannot handle circular dependency between its input files.

Other command line options

The fast_type_gen program does not accept any command line options other than the names of the template files. Thus there is no way to adjust the generated output other than by changing the names of the template files, or modifying the generated code after fast_type_gen runs.

##Use of FAST template identifiers. To encode/decode FAST messages correctly, each FAST template must have a unique template identifier. The specification does not define how to map template names to template identifiers. In our implementation, we choose to use the number specified by the id attribute in the template definition, as the template identifier for encoder/decoder purposes. Furthermore, even though FAST specification does not have any restriction on what the id attributes for fields can be, fast_type_gen can generate valid C++ code only when the value for id attributes are unsigned 32 bits integers.

##Limitations of fast_type_gen

There are some limitations in the current implementation fast_type_gen. It is not robust enough to report syntactic or semantic errors from its input files. It's possible that the code generation process can succeed and yet the generated code won't compile or even executed correctly if errors exist in its input files. For example, if the names of templates or fields are not valid C++ identifiers, the generated code would not compile.

This is an issue to be addressed in the future release of this product.