IFF Format Library

IFF Format Library provides header structures and utility functions for reading and writing data files in the Interchange Files.
Download

IFF Format Library Ranking & Summary

Advertisement

  • Rating:
  • License:
  • MIT/X Consortium Lic...
  • Price:
  • FREE
  • Publisher Name:
  • Mike Sharov
  • Publisher web site:

IFF Format Library Tags


IFF Format Library Description

IFF Format Library provides header structures and utility functions for reading and writing data files in the Interchange Files. IFF Format Library provides header structures and utility functions for reading and writing data files in the Interchange Files.The Interchange File Format is a simple structured binary file format consisting of sized and typed chunks of data, selectively readable without having to know the format of each chunk.This functionality is similar to what XML provides for text documents, and the IFF format can indeed be viewed as a sort of a binary XML. IFF's extensibility is an excellent way of not breaking old applications when the file format changes, making it an excellent choice for your next application's data files.The IFF is also the simplest and the smallest such data format, ensuring that your files consist of real data rather than overhead and that your code spends more time on real work than on parsing the data file. This library defines the IFF header structures and provides simple algorithms for directly writing many of your objects as chunks and containers.Installation:This library can be downloaded from SourceForge, as can its sole prerequisite: libiff - The library source package.uSTL - An STL implementation, required.First, unpack and install uSTL, as described in its documentation. Unpack libiff and run ./configure; make install, which will install the library to /usr/local/lib and headers to /usr/local/include. ./configure --help lists available configuration options, in the usual autoconf fashion. The one thing to be aware of is that by default the library will not be completely conforming to EA85 specification. Why that is so, and why you should take the default options anyway, is discussed in detail in the next section. If you really want to use the original EA85 format, you can to pass --with-bigendian --with-2grain to configure. Usage:If you are using C++, chances are you already have an object-oriented design of some kind. You have a collection of objects, related to each other in some way, and you want to write them all to a file in some way. It is, of course, possible to just write them all to the file, one after the other, but that approach makes things difficult if you ever decide to change the structure of those objects, write more or fewer of them, or explain to other people how to read your format. Hence, it is desirable to create some kind of structure in the file, to be able to determine where each objects begins and ends, and what kind of object is where. When using an IFF format, you'll make simple objects into chunks, and objects containing other objects into FORMs, LISTs, or CATs.The first task is to make each of your objects readable and writable through uSTL streams. To do that you'll need to define three methods, read, write, and stream_size, and create flow operator overrides with a STD_STREAMABLE macro. Here is a typical example: #include < iff.h > // iff header includes ustl.h, but doesn't use the namespace.using namespace ustl; // it is recommended to leave iff:: namespace on./// Stores player's vital statistics.class CPlayerStats {public: void read (istream& is); void write (ostream& os) const; size_t stream_size (void) const;private: uint16_t m_HP; uint16_t m_MaxHP; uint16_t m_Mana; uint16_t m_MaxMana;};// Since the object is simple, and contains no other objects,// we'll make it a simple chunk.enum { // Define a chunk format for writing this object. fmt_PlayerStats = IFF_FMT('S','T','A','T')}; // In a hex editor you'll see STAT at the beginning of the object // making it easy to find when you want to hack something in it./// Reads the object from stream p isvoid CPlayerStats::read (istream& is){ is >> m_HP >> m_MaxHP >> m_Mana >> m_MaxMana;}/// Writes the object to stream p os.void CPlayerStats::write (ostream& os) const{ os


IFF Format Library Related Software