This section of the archives stores flipcode's complete Developer Toolbox collection,
featuring a variety of mini-articles and source code contributions from our readers.

Simple X File Wrapper For Loading Data
Submitted by

This is my first post to COTD, in fact its my first post to Flipcode ever.
Ok, I recently wrote a small proof of concept application and in doing so I
needed to load models from Microsofts X flies. After working with the API
directly for about a day I found it very redundant and not easy to manage so I
went about creating a wrapper to make my life and everyone elses a bit easier.
Im not going to explain how X Files are structured here, just briefly how to
use my wrapper.
This implementation only deals with loading data from a preexisting .x files and
does not address saving data.
The XFile object makes dealing with X files similar to using a stacks and lists.
Data objects are pushed and popped and siblings of the current element are then
iterated in order via next. X files do not allow reverse iteration so once a
push, pop, or next action is executed there is no going back. Initially, the
XFiles current data object is invalid (similar to an iterator pointing to end()
). To iterate through root frames use the NextRoot function, after the first
call the XFile is set to the first root data object. The push operations leave
the current data object invalid ( again similar to an iterator pointing to end()
). In order to access these child data objects the NextSibling function must be
called, after a call to push, NextSibling moves to the first child data object.
All other operations are performed on the current data object ( if valid ).

Below are some simple functions that iterate an X file using the XFile wrapper
object.

In order to compile the XFile object you will need to replace the two macros
D3DEX and PEASSERT as I dont provide the implementations.
Also, the CD3DInterfacePtr will need to be replaced with some other auto COM
pointer, the ATL COM pointer should work fine.