![]() |
The MDL I/O Library
Cornell University Program of Computer Graphics |
![]() |
||||
The I/O LibraryWe have written a C++ library for reading and writing mdl files. The definitive documentation is the comments inmdl.H ,
but this page should serve as a general introduction
to how the library should be used.
The principal objects in the library are
Reading Mdl FilesHere is the essence of the interface tomdlInput :
class mdlInput { public: mdlInput(FILE *inputFile); ~mdlInput(); mdlKey BeginChunk(); void EndChunk(); long ReadInt(); float ReadFloat(); char *ReadString(); int ReadInts(long *dest, int n); int ReadFloats(float *dest, int n); int NumRemain(); };
The constructor takes a file pointer
that has been opened for reading with
Recall that mdl files contain ints, floats, and strings
arranged into nested chunks.
Each chunk has a keyword telling what type of chunk it is
and a sequence of data items,
each of which can be an int, a float, a string, or a chunk.
To read a chunk, you first open it by calling
The functions called
The functions called
The Type Checking in MdlWith every chunk definition comes a specification of the sequence of item types allowed that kind of chunk. Type checking is a way for the I/O code to enforce compilance with this specification, so that the program that reads a data item and the program that wrote it will always agree about what type it is. It also enforces correspondence between the types in a text file and the types that are read from it.
Many optional arguments to the contructors of
mdlInput(FILE *, int checkTypes = TRUE, const mdlChunkSpecList *specs = NULL); mdlOutput(FILE *, int binary = FALSE, int typeCheck = TRUE, mdlByteOrder = mdlSame, mdlChunkSpecList *specs = NULL);
Type checking is turned on by default in both mdlInput and mdlOutput,
so you don't have to do anything
to have your types checked for standard chunks.
If you use non-standard chunks,
the library will warn you that it does not have
a type specification and will not perform type checking on those chunks.
If you want type checking turned off for some reason
(for instance, if you want to read old files
that don't comply with the new standard type specifications),
you can pass
In order to get the benefits of type checking for non-standard chunk types,
you have to provide your own type strings.
You do this by creating a mdlChunkSpecList
and passing it to the constructor of
Type strings use exactly the same format as the type specifications of the syntax description, but the repeating part is separated from the fixed part by a comma, and there are no spaces or parentheses or asterisks. For example:
| ||||||
|